import * as WxJsApi from '@/utils/wxJsApi.js' import * as API from '@/apis/index.js' import { getRemind } from '@/utils' export default { data() { return { rbool:false, wxinit:false, index:0, btn:{ color: '#1677FF' }, remindBl:false, remindInfo:null, isLoading:false, getPointBl:false,//是否定位完成 longitude: '', latitude: '', optionsName:'荆州', options1:[ { label: '荆州', value: '荆州', }, { label: '沙市', value: '沙市', }, ], list: [ ], siteList:[ ], radiolist: [ { name: '不提醒', isRemind: "0", }, { name: '提前1站', isRemind: "1", }, { name: '提前2站', isRemind: "2", } ], // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中 value: 'orange', } }, onLoad(){ }, methods: { // 选中某个单选框时,由radio时触发 radioChange(e) { // console.log(e); }, // 选中任一radio时,由radio-group触发 remindHD(){ var item= this.remindInfo if(item.isRemind==0){ if(this.remindInfo.remindId){ this.del(item.remindId,item.isRemind!=0) } return } if(item.remindId){ this.del(item.remindId,item.isRemind!=0) }else{ this.add() } }, del(id,bl){ API.cancelRemind(id).then((res) => { this.remindInfo.remindId="" if(bl){ this.add() }else{ this.$refs.common.alert( "设置成功"); } }).catch(error => { this.$refs.common.alert( error); }) }, add(){ var item= this.remindInfo var obj={ startStationId:item.startStationId, remindStationId :item.ticketDownStationId, stopInAdvance:item.isRemind, remindType:"2", vehicleShiftId:item.vehicleShiftId, openId:this.carhelp.getOpenId() } API.saveRemind(obj).then((res) => { item.remindId=res.data.id this.$refs.common.alert( "设置成功"); }).catch(error => { this.$refs.common.alert( error); }) }, radioGroupChange(item) { this.remindHD(); }, getRemindInfo(){ API.queryRemind(this.carhelp.getOpenId()).then((res) => { if(res.data.length){ this.remindInfo=res.data[0] var obj=this.remindInfo if(obj.remindId){ this.rbool=true; obj.isRemind=obj.stopInAdvance; }else{ obj.isRemind="0"; } } }).catch(error => { this.$refs.common.alert( error); }) }, getBtn(){ }, getNewNum(){ var pages = getCurrentPages(); var page = (pages[pages.length - 1]).route; if(page=="pages/index/index"|| page=="pages/my/index"|| page=="pages/news/index"){ setTimeout(this.getNewNum,10000) }else{ setTimeout(this.getNewNum,1000) return; } var data={ openId:this.carhelp.getOpenId() }; if(!this.carhelp.getOpenId()){ return } API.passengerMessageNoReadNum(data).then((res) => { var num=res.data.num; if(num){ uni.setTabBarBadge({ index: 2, text: num+'' }) }else{ uni.removeTabBarBadge({ index:2 }) } }).catch(error => { }) } , getBanner() { API.getBannerInfo("1").then((res) => { this.list=res.data; for(var i in this.list){ var obj=this.list[i] obj.url=obj.linkUrl obj.image=obj.picUrl obj.title=obj.name } this.carhelp.set("bannerList",this.list); }).catch(error => { this.$refs.common.alert( error); }) }, bindPickerChange: function(e) { // console.log('picker发送选择改变,携带值为', e.target.value) this.index = e.target.value }, gotoQuery(){ uni.navigateTo({ url:'/pages/query/index?back=true' }) }, gotoLine(item,downid){ uni.navigateTo({ url:'/pages/route/index?id='+item.routeId+"&upid="+item.startStationId+"&downid="+downid }) }, getPoint() { this.$refs.common.alert("正在获取定位信息,为您查找附近的站点..."); WxJsApi.getLocation().then((res) => { var latitude = parseFloat(res.latitude); var longitude = parseFloat(res.longitude); this.latitude = latitude; this.longitude = longitude; //this.$refs.common.alert("定位中...",); this.passengerNearbyStation() this.getPointBl=true this.$refs.common.showLoading(false); }).catch(error => { this.$refs.common.alert( error); }) }, passengerNearbyStation(){ if(process.car.SIMPLE_RUN){ this.latitude = '30.306452'; this.longitude = '112.27642'; } var form={ longitude:this.longitude, latitude:this.latitude, pageIndex:1, pageSize:5 } this.$refs.common.showLoading(); API.passengerNearbyStation(form).then((res) => { this.siteList=res.data; this.isLoading=true; //this.$refs.common.showLoading(fa); if(this.siteList.length){ this.$refs.common.alert( "已为您查询出附近的站点"); }else{ this.$refs.common.alert( "查询成功,附近暂无站点信息!"); } }).catch(error => { this.$refs.common.alert( error); }) }, getScan(){ this.$refs.common.showLoading() WxJsApi.scanQRCode(0,this.$refs.common).then(function(url){ console.log(url) window.location.href=url; }).catch(error => { this.$refs.common.showLoading(false,error) }); }, clickSwiper(index){ var url=this.list[index].url; if(url){ if(url.indexOf("http")==0){ window.location.href=url; }else if(url.indexOf("/pages/")==0){ uni.navigateTo({ url:this.list[index].url }) } } }, closeDropdown() { this.$refs.uDropdown.close(); } },onReady(){ WxJsApi.getWxConfig(['scanQRCode','getLocation','addEventListener']).then(()=>{ this.wxinit=true; var _this=this; }) //WxJsApi.requestSubscribeMessage(['Ilxy2TX264A3RHqRyDZqL_xUDxi9OuBNeJoDOBfMRHg']) var list=this.carhelp.get("bannerList"); if(list){ this.list=list; } //this.remindHD() this.getPoint(); this.getBanner(); this.getNewNum(); this.getRemindInfo(); this.getBtn(); //清空缓存 this.carhelp.set("form",{}); },onShow(){ this.getPoint(); this.getRemindInfo(); }, }