import * as API from '@/apis/buytickets.js' export default { data() { return { noback:true, id: '', num: 0, pic: '', list: [], selectList: [], subForm: { pageIndex: 1, pageSize: 20, totalPage: 1 } } }, methods: { gotoHome(){ uni.switchTab({ url: '/pages/index/index' }); }, submit() { var obj = this.carhelp.get("form"); obj.oplist = [] for (var i in this.list) { if (this.list[i].ck) { obj.oplist.push(this.list[i]); } } this.carhelp.set("form", obj); uni.navigateTo({ url: '/pages/buytickets/selectSite?id=' + this.id }) }, ckBtn(item) { item.ck = !item.ck; if (item.ck) { var bl=true for (var i = 0; i < this.selectList.length; i++) { if (this.selectList[i].upStationId != item.upStationId) { bl=false; } break; } if(!bl){ item.ck = !item.ck; this.$refs.common.alert("所选乘客上车站点不一致,请重新选择。"); return; } this.num++; this.selectList.push(item); } else { this.num--; for (var i = 0; i < this.selectList.length; i++) { if (this.selectList[i].id == item.id) { this.selectList.splice(i, 1); } } } console.log(this.selectList) }, getPassengerInfo() { var thisform = { id: this.id, openId: this.carhelp.getOpenId() } this.$refs.common.showLoading() API.getPassengerInfo(thisform).then((response) => { if (!response.result) { this.$refs.common.goError(response.message) return } this.passengerInfo = response.data var obj = this.carhelp.get("form"); if(!obj){ obj={} } obj.list = this.passengerInfo.list; obj.name= 'buytickets'; obj.id= this.id; this.carhelp.set("form", obj); if (response.data.supply) { //this.$refs.common.goError(response.message) this.$refs.common.setFnc(()=>{ uni.switchTab({ url: '/pages/news/index' }); },()=>{ if (!response.data.id) { uni.redirectTo({ url: '/pages/buytickets/index?id=' + this.id+'&back=true' }) } else { this.getShiftInfo() } }) this.$refs.common.confirm('存在需要补票的订单,是否前去查看?') return; } if (!response.data.id) { uni.redirectTo({ url: '/pages/buytickets/index?id=' + this.id+'&back=true' }) } else { this.upBusNoTicketList(); } }).catch(error => { if (error) { this.$refs.common.goError(error) return } //this.$refs.common.showLoading(false,error) }) }, upBusNoTicketList() { this.$refs.common.showLoading(); this.subForm.id = this.id; var obj = this.carhelp.get("form") this.list = []; API.upBusNoTicketList(this.subForm).then((res) => { var list = res.data.data; if(!list.length){ this.$refs.common.alert2("无照片,请上车刷脸或联系司机"); return; } for (var i in list) { list[i].show = true; list[i].ck = false; for (var j in obj.list) { if (obj.list[j].id == list[i].id) { list[i].show = false; break; } } if (list[i].show) { this.list.push(list[i]); } } this.selectList=[];//清空选中 if (this.list.length != 0) { this.$refs.common.showLoading(false, "刷新成功"); } else { this.$refs.common.showLoading(false); } }).catch(error => { this.$refs.common.showLoading(false, error); }) } }, onLoad(op) { if(op.back){ this.noback=!op.back } this.id = op.id }, onReady() { if (!this.id) { this.$refs.common.goError() } var obj = this.carhelp.get("form") if (obj && obj.name == 'buytickets' && obj.id == this.id) { //不创建新订单 } else { this.carhelp.set("form", { name: 'buytickets', id: this.id, oplist: [], //当前添加的2人 list: [] // 一共添加的人 }); } if (false&&!this.carhelp.getPersonInfo()) { this.$refs.common.setFnc(this.confirmBtn) this.$refs.common.alert2('您还不是东胜掌上通勤用户,注册后再购买车票。', '前往注册', '尚未注册') } else { } this.getPassengerInfo() } }