123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582 |
- import * as API from '@/apis/route.js'
- import * as API_index from '@/apis/index.js'
- import * as WxJsApi from '@/utils/wxJsApi.js'
-
- import Carmap from '@/components/Carmap.vue'
- export default {
- data() {
- return {
- wxinit:false,
- mapopen:false,
- initBl: false,
- title: '乘车人',
- show: false,
- id: 0, // 使用 marker点击事件 需要填写id
- upid:'',
- downid:'',
- downItem:{},
- //地图居中后的位置
- longitude: 112.276527,
- latitude: 30.306427,
- show1: false,
- show2: false,
- centerBl:false,
- shiftInfo: {
- },
- remindList:[],
- list: [{}, {}],
- carList:[],
- caritem:{
- driverInfo:{}
- },
- caritemBl:false,
- stationList: [],
- routeTimeTableList:[],
- dis:'',
- //个人
- info: {
- obj: null,
- init: true,
- longitude: '',
- latitude: '',
- },
- reverseInit:false,
- myinterval: '',
- routeInfo:{},
- popid:0,
- radiolist: [
- {
- name: '不提醒',
- isRemind: "0",
- },
- {
- name: '提前1站',
- isRemind: "1",
- },
- {
- name: '提前2站',
- isRemind: "2",
- }
- ]
- }
- },
- components: {
- Carmap
- },
- methods: {
- selectBtn(i){
-
- this.popid=i;
-
- this.$forceUpdate()
- },
- makePhoneCall(tel){
- uni.makePhoneCall({
- phoneNumber: tel //仅为示例
- });
- },
- radioChange(e){
- console.log(e)
- },
- vehicleStationDis(){
-
- if(this.stationList[0].id==this.downItem.id&&this.routeTimeTableList&&this.routeTimeTableList.length){
-
-
- var nowDate =new Date();
- var curDay=nowDate.getFullYear()+"-"+(nowDate.getMonth()+1)+"-"+nowDate.getDate();
- var startDate =null;
-
- for(var i in this.routeTimeTableList){
- var obj=this.routeTimeTableList[i]
- var objDate =new Date(curDay+" "+obj.startTime+":00");
-
- if(nowDate.getTime()<objDate.getTime()){
- if(startDate==null){
- startDate=objDate;
- }
- if(objDate<startDate){
- startDate=objDate;
- }
- }
- }
-
- if(startDate==null){
- this.dis="今日发车已经结束,明日发车时间"+this.routeInfo.startTime
- }else{
- console.log(startDate)
- console.log(nowDate)
- var d= parseInt((startDate.getTime()-nowDate.getTime())/1000/60)
- this.dis="等待发车... 大约"+d+"分钟发车"
- }
-
- }else{
- var obj={
- startStationId:this.stationList[0].id,
- currentStationId :this.downItem.id,
- routeId:this.routeInfo.id,
- }
- //this.$refs.common.showLoading();
- API.vehicleStationDis(obj).then((res) => {
- this.dis=res.data;
- //this.$refs.common.showLoading(false);
- }).catch(error => {
- this.$refs.common.showLoading(false,error);
- })
- }
-
- },
- radioGroupChange(){
-
- this.downItem.isRemind=this.popid;
- var item= this.downItem
-
- if(item.isRemind==0){
- if(this.downItem.remindId){
- this.del(item.remindId,item.isRemind!=0)
- }else{
- this.show1 = false
- this.$forceUpdate()
- }
- return
- }
- if(item.remindId){
- this.del(item.remindId,item.isRemind!=0)
- }else{
- this.remindAdd()
- }
-
- },del(id,bl){
- API_index.cancelRemind(id).then((res) => {
- this.downItem.remindId=""
- if(bl){
- this.remindAdd()
- }else{
- this.show1 = false
- this.$forceUpdate()
- this.$refs.common.alert( "设置成功");
- }
- }).catch(error => {
- this.$refs.common.alert( error);
- })
- },
-
- remind(){
- var myBtn = document.getElementById("subscribe-btn").tap();
- myBtn.tap();
- },
- showCar(item){
-
- for(var i in this.carList){
- var car= this.carList[i]
-
- if(car.currentStationStatus=="3"){
- if(car.currentStationId==this.stationList[this.stationList.length-1].id&&car.currentStationId==item.id){
-
- return true;
- }else if(car.currentStationId2==item.id){
-
- return true;
- }
- }else{
- if(car.currentStationId==item.id){
- return true;
- }
- }
-
-
- }
- return false;
- },
- showname(name){
- if(!name){
- return "";
- }
-
- return name.substring(0,1)+'师傅';
- },
- getCar(){
-
- if(this.stationList.length==0){
- return;
- }
- var obj={
- routeId:this.id,
- startStationId:this.stationList[0].id,
- }
-
- API.routeShiftList(obj).then((response) => {
-
- this.carList=response.data;
- this.$refs.amap.ifCenter(this.carList[0]);
-
- if(!this.centerBl&&this.carList.length){
- this.centerBl=this.$refs.amap.setCenter(this.carList[0]);
-
- this.$refs.amap.ifCenter(this.carList[0]);
-
- //this.centerBl=true;
- if(this.centerBl){
- document.getElementById('map-route-main').scrollLeft = 0
- this.$nextTick(function() {
- const query = uni.createSelectorQuery().in(this);
- query.select('.map-route-car').boundingClientRect(data => {
- if(data){
- document.getElementById('map-route-main').scrollLeft = data.left-100;
- }
-
- //this.downBtn()
- }).exec();
- });
- }
- }
-
- //car.currentStationId=this.stationList[this.stationList.length-1].id
- //car.currentStationStatus="1";
-
- // this.carList=[];
- // this.carList.push({
- // currentStationId:"9e5be927-178b-4163-a34b-49bba6460eec",
- // currentStationStatus:"1"
-
- // })
- // this.carList.push({
- // currentStationId:"ff2251e0-26ca-41ad-a4a0-43ece7ab3471",
- // currentStationStatus:"2"
-
- // })
- for(var j in this.stationList){
- var station =this.stationList[j];
- station.currentStationStatus="1";
- }
- console.log("this.stationList")
-
- console.log(this.stationList)
- console.log("this.stationList")
- for(var j in this.stationList){
-
- var station =this.stationList[j];
- // station.currentStationStatus="1";
-
- for(var i in this.carList){
- var car =this.carList[i];
-
-
- if(car.currentStationId==station.id){
- console.log(car.licensePlateNumber+"------"+station.name)
- if(car.currentStationStatus==3){
-
- if(eval(j+"+"+1)!=this.stationList.length){
- console.log(this.stationList[eval(j+"+"+1)].id);
- car.currentStationId2=this.stationList[eval(j+"+"+1)].id
- this.stationList[eval(j+"+"+1)].currentStationStatus="2";
-
- console.log("--------this.carList----A------"+car.licensePlateNumber)
-
-
- }else{
- car.currentStationStatus=1
- this.stationList[j].currentStationStatus="1";
- console.log("--------this.carList----B------"+car.licensePlateNumber)
-
- }
-
-
- }else{
- this.stationList[j].currentStationStatus=car.currentStationStatus;
- console.log("--------this.carList----c------"+car.licensePlateNumber)
-
- }
-
- break;
- }
- }
-
- }
- console.log("--------this.carList----------")
- console.log(this.carList)
- console.log("--------this.carList----------")
-
- this.$refs.amap.setCarList(this.carList);
- this.vehicleStationDis();
- }).catch(error => {
- console.log(error);
- this.$refs.common.showLoading(false,error)
- })
- },
- 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) {
-
- this.$refs.amap.setSite(item);
- this.$refs.amap.setCenter(item);
- this.downid=item.id;
- this.downItem=item;
- this.vehicleStationDis();
- this.$forceUpdate()
- },
- remindAdd(){
- if(this.downItem.id){
-
- var obj={
- startStationId:this.stationList[0].id,
- endStationId:this.stationList[this.stationList.length-1].id,
- remindStationId :this.downItem.id,
- stopInAdvance:this.downItem.isRemind,
- remindType:"1",
- routeId:this.routeInfo.id,
- openId:this.carhelp.getOpenId()
- }
- API_index.saveRemind(obj).then((res) => {
- this.downItem.remindId=res.data.id
- this.$refs.common.alert( "设置成功");
- this.show1 = false
- this.$forceUpdate()
- }).catch(error => {
- this.$refs.common.alert( error);
- })
- }
- },
-
- drawing(point, startend) {
- if (this.$refs.amap) {
- this.$refs.amap.initMap(point, this.stationList,startend);
- }
- },
- carShow2(item){
- console.log(item)
- if(item.type=="car"){
- setTimeout(()=>{
- this.carShow3(item.obj)
- }, 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);
- }
-
- },
- carShow3(item){
-
- var caritem =item;
-
- this.caritem=caritem;
- this.caritemBl=true;
-
- },
- carShow(item){
-
-
- this.$refs.amap.setCenter(item);
-
- },
- reverse(){
- this.centerBl=false;
- this.stationList.reverse();
- this.getCar()
- this.passengerShiftRemindList();
-
- this.$refs.amap.setStartend(this.stationList);
- 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();
- });
-
- },
- setRemind(){
- for(var i in this.stationList){
- var item=this.stationList[i];
- item.isRemind=0;
- item.remindId="";
- for(var j in this.remindList){
- var obj=this.remindList[j];
- if(this.stationList[0].id==obj.startStationId&&obj.remindType==1){
- if(obj.remindStationId==item.id){
- item.remindId=obj.id;
- item.isRemind=obj.stopInAdvance;
- }
- }
- }
-
- }
- this.$forceUpdate()
- },
- passengerShiftRemindList(){
- this.$refs.common.showLoading()
- API.passengerShiftRemindList({
- routeId:this.id,
- openId:this.carhelp.getOpenId(),
- }).then((response) => {
- this.remindList=response.data;
- this.setRemind();
- this.$refs.common.showLoading(false)
- })
- },
- getPassengerInfo() {
-
- this.$refs.common.showLoading()
-
- API.routeDetail(this.id).then((response) => {
-
- var list=response.data.stationInfoList;
- if(this.upid&&list.length){
-
- if(this.upid==list[list.length-1].id){
- list.reverse();
- }
- this.upid="";
- }
- this.stationList=list;
- for(var i in list){
- list[i].isRemind=0;
- if(list[i].id==this.downid){
- this.downItem=list[i];
- }
- }
- this.passengerShiftRemindList();
-
- this.$refs.common.showLoading(false)
-
- var point = [];
- this.routeInfo=response.data.routeInfo;
- this.routeTimeTableList=response.data.routeTimeTableList;
- this.title=this.routeInfo.name;
- if(!response.data.routeInfo.mapPath){
- this.$refs.common.showLoading(false,"路线加载失败!")
- return;
- }
- response.data.routeInfo.mapPath.split("|").forEach((item) => {
- var sz = item.split(",");
-
- point.push({
- longitude: sz[0],
- latitude: sz[1],
- })
- })
- var startend = [{
- longitude: this.stationList[0].longitude,
- latitude: this.stationList[0].latitude,
- name: this.stationList[0].name
- }, {
- longitude: this.stationList[this.stationList.length-1].longitude,
- latitude: this.stationList[this.stationList.length-1].latitude,
- name: this.stationList[this.stationList.length-1].name
- }];
-
- this.drawing(point,startend);
- this.$refs.common.showLoading(false)
-
- //this.getPoint()
-
-
-
- }).catch(error => {
- this.$refs.common.showLoading(false,error)
- })
- },
- mapdown(){
- this.getPoint();
-
- if(this.downid=="null"){
- this.downid="";
- }else{
- this.centerBl=true;
- }
- if(this.downid){
- this.downBtn(this.downItem)
- }
-
- },
- getPoint() {
-
- if (!this.info.init) {
- WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
- // this.$refs.common.showLoading(false)
- this.getLocation()
- });
- }else{
- this.getLocation()
- }
- this.getCar();
- var pages = getCurrentPages();
- var page = (pages[pages.length - 1]).route;
- if (page == "pages/route2/index") {
- setTimeout(this.getPoint, 10000);
- }
- },
- getLocation(){
- WxJsApi.getLocation().then((res) => {
- console.log("----getLocation ok-----")
- 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,true);
-
- }).catch(error => {
- console.log(error)
- })
- }
- },
- onLoad(op) {
- this.upid=op.upid;
- this.id = op.id
- this.downid=op.downid;
- },
- onUnload() {
- if (this.myinterval) {
- clearInterval(this.myinterval)
- }
- },
- onReady() {
- WxJsApi.getWxConfig([ 'getLocation','getSetting']).then(() => {
- // this.$refs.common.showLoading(false)
- this.wxinit=true;
-
-
- });
-
- this.getPassengerInfo()
-
- }
- }
|