董国庆
2026-07-14 11fa99f45663fc39cda7918aa97e134c8e337de7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
// pages/advoad-city-search/advoad-message/advoad-message.js
const app = getApp()
var WxParse  = require("../../../utils/wxParse/wxParse")
const GdMap = require('../../../utils/amap-wx')
 
const {
  queryLocation,
  queryOrderMoney,
  orderCrossCity,
  queryBalance,
  queryByType,
  isElectronicLedger,
  areaMonitoringexport
} = require('../../../utils/ajax')
const ADVOAD_START_LOCATION_STORAGE_KEY = 'advoadStartSelectedLocation'
const ADVOAD_END_LOCATION_STORAGE_KEY = 'advoadEndSelectedLocation'
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    couponId:'',//优惠券id
    radio:[
      {name:"不包车",check:true,id:1},
      {name:'包车',check:false,id:2}
    ],
    maskList : [
      {name:"大件行李",id:1,checked:false},
      {name:"携带宠物",id:2,checked:false},
      {name:"孕妇老人",id:3,checked:false},
      {name:"携童上车",id:4,checked:false}
    ],//备注信息
    self:{},//司机信息
    peopleNum:"请选择出行人数",
    peopleNumBallen:false,
    people7:false,
    people5:false,
    zwNum:"请选择座位",
    startLocation:"请选择上车点",
    endLocation:"请选择下车点",
    startInfo :{
 
    },//起点信息
    endInfo : {
 
    },//终点信息
    aboutMoney : '0.00',//初始预估金额
    radioVlaue:1,//包车 不包车
    peopleId:"",//人数参数
    canOrder:true,//禁止下单
    wxParse:false,//乘车须知
    isAllIn:false,//是否包车 显示选择座位
    canChooseSeat:true,//是否展示选座
    peopleArr:0,
    lineDestinationId:'',
    skipStartLocationCacheSync:false
  },
  getAvailablePeopleCount(data = this.data){
    const self = data.self || {}
    const numberText = String(self.number || '')
    const [usedSeatText, totalSeatText] = numberText.split('/')
    const usedSeat = Number(usedSeatText || 0)
    const totalSeat = Number(totalSeatText || 0)
    const availableSeat = totalSeat - usedSeat
    return availableSeat > 0 ? availableSeat : 0
  },
  getEffectivePeopleId(data = this.data){
    if(Number(data.radioVlaue) == 2){
      return this.getAvailablePeopleCount(data)
    }
    return data.peopleId
  },
  isSeatSelectionRequired(data = this.data){
    return data.radioVlaue != 2 && data.canChooseSeat
  },
  getStoredRouteLocation(where){
    const storageKey = where == 'startLocation'
      ? ADVOAD_START_LOCATION_STORAGE_KEY
      : ADVOAD_END_LOCATION_STORAGE_KEY
    return wx.getStorageSync(storageKey)
  },
  getCurrentLocationDetail(){
    return new Promise(async (resolve) => {
      try{
        const locationRes = await new Promise((locationResolve, locationReject) => {
          wx.getLocation({
            type: 'gcj02',
            success: locationResolve,
            fail: locationReject
          })
        })
        const latitude = locationRes.latitude
        const longitude = locationRes.longitude
        const myAmapFun = new GdMap.AMapWX({
          key: 'cea7923a93987b959ab1d2f8ab44d497'
        })
        const regeoRes = await new Promise((regeoResolve, regeoReject) => {
          myAmapFun.getRegeo({
            location: `${longitude},${latitude}`,
            success: regeoResolve,
            fail: regeoReject
          })
        })
        const item = regeoRes && regeoRes[0]
        const regeocodeData = item && item.regeocodeData
        const addressComponent = (regeocodeData && regeocodeData.addressComponent) || {}
        const pois = (regeocodeData && regeocodeData.pois) || []
        const landmarkName = (item && item.name) || (pois[0] && pois[0].name) || '当前位置'
        const formattedAddress = (regeocodeData && regeocodeData.formatted_address) || landmarkName
        const adcode = addressComponent.adcode || wx.getStorageSync('adcode') || ''
        const userLocation = `${longitude},${latitude}`
        wx.setStorageSync('latitude', latitude)
        wx.setStorageSync('longitude', longitude)
        wx.setStorageSync('adcode', adcode)
        wx.setStorageSync('formatted_address', formattedAddress)
        wx.setStorageSync('userLocation', userLocation)
        resolve({
          latitude,
          longitude,
          adcode,
          landmarkName,
          formattedAddress,
          location: userLocation
        })
      }catch(error){
        resolve(null)
      }
    })
  },
  async tryAutoFillCurrentStartLocation(){
    const self = this.data.self || {}
    if(!self.abovadStartId){
      return
    }
    if(
      this.data.startLocation != '请选择上车点' &&
      Object.keys(this.data.startInfo || {}).length !== 0
    ){
      return
    }
    const currentLocation = await this.getCurrentLocationDetail()
    if(!currentLocation || !currentLocation.adcode){
      return
    }
    try{
      const res = await areaMonitoringexport(
        currentLocation.adcode,
        currentLocation.location,
        self.abovadStartId
      )
      const data = res.data || {}
      if(data.code == 200 && data.data == 1){
        this.setData({
          startLocation: currentLocation.formattedAddress || currentLocation.landmarkName || '当前位置',
          startInfo: {
            startLat: currentLocation.latitude,
            startLon: currentLocation.longitude
          }
        },()=>{
          this.queryOrderMoney()
        })
      }
    }catch(error){
    }
  },
  syncStoredRouteLocation(options = {}){
    const {
      syncStart = true,
      syncEnd = true
    } = options
    let self = this.data.self || {}
    if(Object.keys(self).length === 0){
      return
    }
    let updates = {}
    let startLocationCache = this.getStoredRouteLocation('startLocation')
    let endLocationCache = this.getStoredRouteLocation('endLocation')
    if(
      syncStart &&
      startLocationCache &&
      String(startLocationCache.siteId) == String(self.abovadStartId) &&
      startLocationCache.locationName &&
      startLocationCache.locationInfo
    ){
      updates.startLocation = startLocationCache.locationName
      updates.startInfo = startLocationCache.locationInfo
    }
    if(
      syncEnd &&
      endLocationCache &&
      String(endLocationCache.siteId) == String(self.abovadEndId) &&
      endLocationCache.locationName &&
      endLocationCache.locationInfo
    ){
      updates.endLocation = endLocationCache.locationName
      updates.endInfo = endLocationCache.locationInfo
      updates.lineDestinationId = endLocationCache.lineDestinationId || ''
    }
    if(Object.keys(updates).length > 0){
      this.setData(updates,()=>{
        this.queryOrderMoney()
      })
    }
  },
  closePop(){
    this.setData({
      showWxParse:false
    })
  },
  //切换是否包车?
  checkedTap(e){
     let radioVlaue = e.detail.value
     if(radioVlaue == 2){
        this.setData({
          isAllIn:true,
          zwNum:this.data.canChooseSeat ? "请选择座位" : "",
        })
     }else{
        this.setData({
          isAllIn:false,
          zwNum:this.data.canChooseSeat ? "请选择座位" : ""
        })
     }
     this.setData({
      radioVlaue
     },()=>{
      this.queryOrderMoney()
     })
  },
  //选择乘客人数
  handelClickPeopleNum(e){
    let self  = this.data.self
    let canPeople = Number(self.number.split('/')[1])-Number(self.number.split('/')[0])
    let peopleAjaxInfo = {
      canPeople,
      id:self.lineShiftDriverId,
    }
    this.setData({
      peopleNumBallen:true,
      peopleAjaxInfo:JSON.stringify(peopleAjaxInfo),
    })
  },
  //确认人数事件
  onParentEvent(e){
    console.log(e)
    let peopleNum = e.detail.peopeltext
    let peopleId = e.detail.peopleId
    this.setData({
      peopleNum:peopleId+'人',
      peopleId,
      zwNum:this.data.canChooseSeat ? '请选择座位' : '',
    },()=>{
      this.queryOrderMoney()
    })
  },
  //选择座位
  zwNum(){
    let self  = this.data.self
    let data = this.data
    if(Number(data.radioVlaue) != 2 && data.peopleNum=='请选择出行人数'){
     app.showToastSuccess('请先选择出行人数',null,'none',1500)
     return false
    }
    let canPeople = self.number.split('/')[1]
    canPeople < 6 
    ? (
      this.setData({
      people5:true,
      peopleArr:this.data.peopleArr+1,
      peopleAjax:JSON.stringify({
        id:self.lineShiftDriverId,
        peopleNum:data.peopleId,
        people5:this.data.peopleArr,
        tip:this.data.tip5,
        zwNum:this.data.zwNum
      }),
    })
    )
    :
    (
      this.setData({
      people7:true,
      peopleAjax:JSON.stringify({
        id:self.lineShiftDriverId,
        peopleNum:data.peopleId,
        people5:this.data.peopleArr,
        tip:this.data.tip7,
        zwNum:this.data.zwNum
      }),
    })
    )
  },
  //选择5人作为
  onParentEvent5(e){
    console.log(e)
    let  self = e.detail
    this.setData({
      zwNum:self.ids,
      tip5:self.tip
    },()=>{
      this.queryOrderMoney()
    })
  },
  onParentEvent7(e){
    console.log(e)
    let  self = e.detail
    this.setData({
      zwNum:self.ids,
      tip7:self.tip
    },()=>{
      this.queryOrderMoney()
    })
  },
  //备注信息
  getMask(e){
    let self  = e.currentTarget.dataset.name
    this.setData({
      maskList : this.data.maskList.map( x=> {
        if(x.id == self.id){
          x.checked=!x.checked
        }
        return x
      })
    })
  },
  //显示乘车须知
  showWxParse(){
   
    this.initPares()
  },
  async initPares(){
    let type = {
      type : 11
    }
    let res = await queryByType(type)
    res.data.code == 200 
    ?(
      this.setData({
        showWxParse:true
      }),
      //弹窗富文本
      WxParse.wxParse('rule','html', res.data.data.content, this)
    ):
    app.showToastSuccess(res.data.data.msg,null,'none',1500)
  },
  //下单功能
  iCanSeeYou(){
    this.setData({
      showWxParse:false
    })
    this.orderCrossCityAjax()
  },
  async orderCrossCityAjax (){
    let dataSelf = this.data.self
    let data = this.data
    let peopleId = this.getEffectivePeopleId(data)
    console.log('数据',this.data);
    let userLocation = wx.getStorageSync('userLocation')
    let needChooseSeat = this.isSeatSelectionRequired(data)
    let zwNumLength = needChooseSeat && data.zwNum ? data.zwNum.split(',').length : 0
    let mask = '' 
      data.maskList.map( x =>{
        if(x.checked){
          console.log(x.name)
          mask+=','+x.name
        } 
      })
      console.log(peopleId,zwNumLength)
      if(needChooseSeat && (peopleId!==zwNumLength)){
        app.showToastSuccess('请正确选择座位',null,'none',1500)
        return false
      }
    let seatNumber = needChooseSeat && data.zwNum != '请选择座位' ? data.zwNum : ''
    let dataInfo = {
      carId : dataSelf.carId,//车辆id
      distance :data.distance ,//行驶里程数
      driverId :dataSelf.driverId,//司机ID
      endAddress : data.endLocation,//终点详细位置
      endLat  : data.endInfo.startLat,//终点未读
      endLon :  data.endInfo.startLon,//终点经度
      lineId  : dataSelf.lineSelf.id||dataSelf.lineId,//线路ID
      lineShiftDriverId  : dataSelf.lineShiftDriverId,//排班ID
      lineDestinationId : data.lineDestinationId || '',
      orderSource  : 3,
      peopleNumber  : peopleId,//出行人数
      placementAddress : wx.getStorageSync('formatted_address'),//下单详细位置
      placementLat  : userLocation.split(',')[1],//下单经纬
      placementLon   : userLocation.split(',')[0],
      remark:mask.substr(1),//备注
      seatNumber :seatNumber,//座位编号
      serverCarModelId  : dataSelf.serverCarModelId,//服务车型ID
      startAddress  : data.startLocation,//起点
      startLat  : data.startInfo.startLat,//
      startLon :data.startInfo.startLon,
      totalSeat  : dataSelf.number.split('/')[1],
      travelMode : data.radioVlaue,//出行方式
      // travelTime  : dataSelf.isTodayData +' '+dataSelf.startTime
      travelTime: dataSelf.isTodayData + " " + dataSelf.startTime.split("-")[0]
    }
   try{
    let res = await orderCrossCity(dataInfo)
    console.log(res)
    res.data.code == 200 ?(
      this.setData({
        showPayVan:true
      })
    ):(app.showToastSuccess(res.data.msg,null,'none',1500) )
    let dataRes = {
      orderId: res.data.data.id,
      orderType  :3,
      couponId:this.data.couponId,
    }
    let payInfo = {
      orderType:3,
      couponId:this.data.couponId,
      orderId:res.data.data.id
    }
    let  people = ''
    let peopleNum = ''
    if( data.radioVlaue == 2){
      people ='包车',
      peopleNum =  Number(dataSelf.number.split('/')[1])-Number(dataSelf.number.split('/')[0])
    }
    let viewInfo = {
      startLocation: data.startLocation,
      endLocation:data.endLocation,
      driveInfo:dataSelf.name + '-' +dataSelf.carLicensePlate,
      zwNum: people || seatNumber,
      zwPeople : peopleNum||peopleId,
      orderId: res.data.data.id,
      orderType:3,
      couponId:this.data.couponId,
      endLocationInfo :  data.startInfo.startLon+','+data.startInfo.startLat,
      time:dataSelf.isTodayData +' '+dataSelf.startTime
    }
    if(res.data.code == 200){
        wx.setStorageSync('carId', this.data.self.carId)
      wx.redirectTo({
        url: `/pages/advoad-city-search/advoad-message/electronic-wait-pay/electronic-wait-pay?paypaydata=${JSON.stringify(viewInfo)}&paymoney=${this.data.aboutMoney}`,
      })
      // this.setData({
      //   payPayData:data,
      //   palPay:true,
      //   payMoney:this.data.aboutMoney,
      //   payInfo
      // })
    }else{
    }
   }catch(err){
    console.log(err)
   }
  },
  //选择起始点电子围栏
  startLocationClick(){
    let {
      abovadEndId,
      abovadStartId,
      abvoadStartLocation
    } = this.data.self
    wx.navigateTo({
      url: `./electronic-fence/electronic-fence?where=startLocation&abovadStartId=${abovadStartId}&abvoadStartLocation=${abvoadStartLocation}`,
    })
  },
  //选择终点电子围栏
  endLocationClick(){
    let {
      abovadEndId,
      abovadStartId,
      abvoadEndLocation
    } = this.data.self
    wx.navigateTo({
      url: `./electronic-fence/electronic-fence?where=endLocation&abovadStartId=${abovadStartId}&abovadEndId=${abovadEndId}&abvoadEndLocation=${abvoadEndLocation}`,
    })
  },
  //获取预估金额
 async queryOrderMoney(){
    let data = this.data
    let peopleId = this.getEffectivePeopleId(data)
    let totalSeat = data.self.number.split('/')[1]
    let needChooseSeat = this.isSeatSelectionRequired(data)
    let seatReady = !needChooseSeat || data.zwNum !== '请选择座位'
    let seatNumber = needChooseSeat ? data.zwNum : ''
    if(seatReady&&data.startLocation!=='请选择上车点'&&
    data.endLocation!=='请选择下车点'&&
    Object.keys(data.startInfo).length!==0&&
    Object.keys(data.endInfo).length!==0&&
    peopleId!==''&&
    data.radioVlaue!==''&&
    (!needChooseSeat || data.zwNum!=='')
    ){
      this.setData({
        canOrder:false
      })
      let endLonLat =data.endInfo.startLon+','+data.endInfo.startLat
      let startLonLat =data.startInfo.startLon+','+data.startInfo.startLat
      let res = await queryOrderMoney(
        endLonLat ,
        startLonLat ,
        data.self.lineSelf.id||data.self.lineId ,
        peopleId ,
        seatNumber ,
        data.self.serverCarModelId ,
        totalSeat ,
        data.radioVlaue ,
        data.lineDestinationId || ''
      )
      res.data.code == 200
      ?
      this.setData({
        distance:res.data.data.distance,
        aboutMoney:res.data.data.price.toFixed(2)
      })
      : 
      app.showToastSuccess(res.data.data.msg,null,'none',1500)
    }else{
      this.setData({
        canOrder:true
      })
    }
  },
       
 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.removeStorageSync('driverPay')
    wx.removeStorageSync('driverPayId')
    wx.removeStorageSync('driverOrderId')
     console.log(options)
     let pages = getCurrentPages();
     console.log(pages)
     if(options){
       let  self = JSON.parse(options.self)
       console.log(self)
       this.setData({
         self,
         canChooseSeat:self.chooseSeat !== false,
         zwNum:self.chooseSeat === false ? '' : this.data.zwNum,
         skipStartLocationCacheSync:true
       },()=>{
         this.tryAutoFillCurrentStartLocation()
       })
     }
  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
       console.log(this.data.startInfo,this.data.endInfo)
       this.syncStoredRouteLocation({
        syncStart: !this.data.skipStartLocationCacheSync
       })
       wx.removeStorageSync(ADVOAD_END_LOCATION_STORAGE_KEY)
       if(this.data.skipStartLocationCacheSync){
        this.setData({
          skipStartLocationCacheSync:false
        })
       }
 
  },
 
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
 
  },
 
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
 
  },
 
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
 
  },
 
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
 
  },
 
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
 
  }
})