// 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 () {
|
|
}
|
})
|