import * as WxJsApi from '@/utils/wxJsApi.js' import * as API from '@/apis/buytickets.js' import Carmap from '@/components/Carmap.vue' export default { data() { return { caritemBl:false, show1: false, show2: false, buy:"", look:false, initBl: false, title: '乘车人', show: false, id: 0, // 使用 marker点击事件 需要填写id k:0, //地图居中后的位置 longitude: 112.276527, latitude: 30.306427, upid:'', shiftInfo: { }, mapopen:false, list: [{}, {}], //车的位置 car: { obj: null, longitude: '', latitude: '', }, stationList: [], //个人 info: { obj: null, init: false, longitude: '', latitude: '', }, showInfo:{ driver:{} }, myinterval: '', downId: '', downName: '', passengerInfo:{ totalAmount:0, id:'', list:[] } } }, components: { Carmap }, methods: { makePhoneCall(tel){ uni.makePhoneCall({ phoneNumber: tel //仅为示例 }); }, mapopenBtn(){ this.mapopen=!this.mapopen; if(this.mapopen){ this.$refs.amap.setMyStyle("width: 100%; height: 340px;") }else{ this.$refs.amap.setMyStyle("width: 100%; height: 140px;") } }, downBtn(item) { if (!this.look&&item.id==this.car.currentStationId&&this.upid!=item.id) { this.downId = item.id this.downName = item.stationName this.$refs.amap.setDown(item); } if (!this.look&&item.status != 0) { this.downId = item.id this.downName = item.stationName this.$refs.amap.setDown(item); } this.$refs.amap.setCenter(item); }, selectSiteBtn(){ var obj=this.carhelp.get("form"); var upid=''; upid=obj.oplist[0].upStationId; var downid=this.downId; this.$refs.common.showLoading(); var thisform={ ticketUpStationId:upid, ticketDownStationId:downid , ticketDownStationName:this.downName, price1:0, price2:0 } thisform.ticketType=1; API.ticketAmount(thisform).then((response) => { thisform.price1=response.data.price thisform.ticketType=2; API.ticketAmount(thisform).then((response2) => { thisform.price2=response2.data.price obj.ticket=thisform; if(obj.op){ obj.op.ticketDownStationId=this.downId; obj.op.ticketDownStationName=this.downName; } this.carhelp.set("form",obj); //uni.navigateBack() uni.redirectTo({ url: '/pages/buytickets/site?id='+this.id }) }) }).catch(error => { this.$refs.common.showLoading(false, error); }) }, drawing(point, startend) { if(this.$refs.amap){ this.$refs.amap.initMap(point, this.stationList, startend); } }, getShiftInfoResponse(response, response2) { this.$refs.common.showLoading(); var res = response.data this.title = res.routeName; this.shiftInfo = res; this.car.latitude = res.latitude; this.car.longitude = res.longitude; var point = []; res.mapPath.split("|").forEach((item) => { var sz = item.split(","); point.push({ longitude: sz[0], latitude: sz[1], }) if (!process.car.SIMPLE_RUN) { this.longitude = sz[0] this.latitude = sz[1] } }) var obj = this.carhelp.get("form") obj.getShiftInfo = response; obj.getVehicleStationInfo = response2; var list = obj.getVehicleStationInfo.data; for (var i in list) { list[i].status = 0; } this.stationList = list obj = this.carhelp.set("form", obj) var sz1 = response.data.startStationCoordinate.split("|") var sz2 = response.data.endStationCoordinate.split("|") var startend = [{ longitude: sz1[0], latitude: sz1[1], name: response.data.startStation }, { longitude: sz2[0], latitude: sz2[1], name: response.data.endStation }]; this.drawing(point, startend); //this.$refs.common.showLoading(false); this.getPoint() }, showname(name){ if(!name){ return ""; } return name.substring(0,1)+'师傅'; }, carShow(){ this.caritemBl=true; }, getShiftInfo() { this.$refs.common.showLoading(); var obj = this.carhelp.get("form") if (false&&obj.getShiftInfo && obj.getVehicleStationInfo) { this.stationList = obj.getVehicleStationInfo.data this.getShiftInfoResponse(obj.getShiftInfo, obj.getVehicleStationInfo); return; } API.getShiftInfo(this.id).then((response) => { if (!response.result) { this.$refs.common.goError(response.message) return } this.showInfo={ driver:response.data.driver, licensePlateNumber:response.data.licensePlateNumber } API.getVehicleStationInfo(this.id).then((response2) => { this.getShiftInfoResponse(response, response2); }) }).catch(error => { this.$refs.common.showLoading(false, error); }) }, carShow2(item){ console.log(item) if(item.type=="car"){ setTimeout(()=>{ this.carShow() }, 100); } if(item.type=="point"){ setTimeout(()=>{ this.downBtn(item.obj) document.getElementById('map-route-main').scrollLeft = 0 this.$nextTick(function() { const query = uni.createSelectorQuery().in(this); query.select('.map-down').boundingClientRect(data => { if(data){ document.getElementById('map-route-main').scrollLeft = data.left-100; } this.$refs.common.showLoading(false); //this.downBtn() }).exec(); }); }, 100); } }, getPoint() { if (!this.initBl) { this.$refs.common.showLoading(); } //this.k=0 API.getVehicleInfo(this.id).then((response) => { this.car = response.data; //this.car.currentStationId=this.stationList[this.k].id //this.car.currentStationStatus="2" //this.car.currentStationId=this.stationList[2].id //this.car.currentStationStatus="2"; this.$refs.amap.setCar(this.car); var bl = false; var bl2 = false; for (var i in this.stationList) { var stat = this.stationList[i]; stat.status = 0 if (bl2) { stat.status = 2; } if (bl) { stat.status = 1; bl = false; bl2 = true; } if (stat.id == this.car.currentStationId) { if(this.car.currentStationStatus=="3"){ if(eval(i+"+"+1)!=this.stationList.length){ this.car.currentStationId2=this.stationList[eval(i+"+"+1)].id; } } bl = true; if(i==this.stationList.length-1){ stat.status = 1; } if(this.buy){ this.downBtn(stat) } } } if (!this.initBl) { this.initBl = true this.$nextTick(function() { const query = uni.createSelectorQuery().in(this); query.select('#map-now').boundingClientRect(data => { if(data){ document.getElementById('map-route-main').scrollLeft = data.left-100; } this.$refs.common.showLoading(false); }).exec(); }); }else{ this.$refs.common.showLoading(false); } }).catch(error => { this.$refs.common.showLoading(false, error); }) WxJsApi.getLocation().then((res) => { var latitude = parseFloat(res.latitude); var longitude = parseFloat(res.longitude); if (!this.info.init) { this.latitude = latitude; this.longitude = longitude; } this.info.init = true this.info.latitude = latitude; this.info.longitude = longitude; this.$refs.amap.setPerson(this.info); }).catch(error => { }) var pages = getCurrentPages(); var page = (pages[pages.length - 1]).route; if(page=="pages/buytickets/selectSite"){ setTimeout(this.getPoint, 10000); } }, }, onLoad(op) { if(op.select){ this.look=false; }else{ this.look=true;// 只读界面 } this.id = op.id var obj=this.carhelp.get("form"); if(obj.oplist&&obj.oplist.length){ this.upid=obj.oplist[0].upStationId; } }, onUnload() { if (this.myinterval) { clearInterval(this.myinterval) } },onShow(){ console.log("onShowonShowonShowonShow") this.$nextTick(function() { try{ const query = uni.createSelectorQuery().in(this); query.select('#map-now').boundingClientRect(data => { if(data){ document.getElementById('map-route-main').scrollLeft = data.left-100; } this.$refs.common.showLoading(false); }).exec(); }catch(err){ console.log("err") } }); }, onReady() { this.$refs.common.showLoading() WxJsApi.getWxConfig(['getLocation']).then(()=>{ this.$refs.common.showLoading(false) }); var obj = this.carhelp.get("form"); this.buy=obj.buy; this.getShiftInfo() var pages = getCurrentPages(); var page = (pages[pages.length - 1]).route; } }