From a14852bb2bd99e39d4634e90b4b114778046c116 Mon Sep 17 00:00:00 2001 From: pyt <626651354@qq.com> Date: 星期四, 16 一月 2025 18:48:08 +0800 Subject: [PATCH] fix --- pages/home/home.js | 425 ++++++++++++++++++++++++++++------------------------ 1 files changed, 231 insertions(+), 194 deletions(-) diff --git a/pages/home/home.js b/pages/home/home.js index ed1db91..b9e8f9d 100644 --- a/pages/home/home.js +++ b/pages/home/home.js @@ -76,8 +76,8 @@ isDj: 1, tip: '0元', changePeople: "选乘车人", - changeModel:'线上计费', - payModel:'线上计费', + changeModel: '线上计费', + payModel: '线上计费', yyTime: '现在', btnDisabled: false, //呼叫车按钮, multiArray: [ @@ -171,44 +171,44 @@ sameUserInfoObj: {}, //小件物流个人信息 // 协议痰喘显示隐藏 agreementShow: wx.getStorageSync('token') ? false : !wx.getStorageSync('isAgreement') && true, - showModel:false, + showModel: false, }, //选择计费方式 - changeModel(){ + changeModel() { this.setData({ - showModel:true + showModel: true }) }, //关闭弹窗 - onClose(){ + onClose() { this.setData({ - showModel:false + showModel: false }) }, //切换计费方式 - changeTab1(){ + changeTab1() { this.setData({ - changeModel:'线上计费' + changeModel: '线上计费' }) }, - //切换计费方式 - changeTab2(){ + //切换计费方式 + changeTab2() { console.log(2222222222); this.setData({ - changeModel:'打表计费' + changeModel: '打表计费' }) }, - changePayModel(){ + changePayModel() { this.setData({ - payModel:this.data.changeModel, - showModel:false, + payModel: this.data.changeModel, + showModel: false, }) }, @@ -452,8 +452,8 @@ // type: 'bd09ll', success: function (res) { that.setData({ - latitude: this.transformFromGCJToBaidu(res.latitude,res.longitude).latitude, - longitude: this.transformFromGCJToBaidu(res.latitude,res.longitude).longitude, + latitude: this.transformFromGCJToBaidu(res.latitude, res.longitude).latitude, + longitude: this.transformFromGCJToBaidu(res.latitude, res.longitude).longitude, }) that.getLocal(res.latitude, res.longitude) that.getCarNum(res.latitude, res.longitude, that.data.busId) @@ -462,15 +462,18 @@ } }, - transformFromGCJToBaidu(latitude, longitude) { + transformFromGCJToBaidu(latitude, longitude) { var pi = 3.14159265358979324 * 3000.0 / 180.0; - + var z = Math.sqrt(longitude * longitude + latitude * latitude) + 0.00002 * Math.sin(latitude * pi); var theta = Math.atan2(latitude, longitude) + 0.000003 * Math.cos(longitude * pi); var a_latitude = (z * Math.sin(theta) + 0.006); var a_longitude = (z * Math.cos(theta) + 0.0065); - - return { latitude: a_latitude, longitude: a_longitude }; + + return { + latitude: a_latitude, + longitude: a_longitude + }; }, //queryLogisticsNumber 获取首页小件物流订单数量 async queryLogisticsNumber() { @@ -787,9 +790,8 @@ let mapCtx = wx.createMapContext('map4select'); mapCtx.moveToLocation({ success: (res) => { - console.log('adsadsad',res); - this.getLocal(wx.getStorageSync('userLocation').split(",")[1], wx.getStorageSync('userLocation').split(",")[0]) - // this.getLocal(wx.getStorageSync('latitude'), wx.getStorageSync('longitude')) + console.log('adsadsad', res); + this.getLocal(wx.getStorageSync('latitude'), wx.getStorageSync('longitude')) this.setData({ newCityName: "", @@ -975,7 +977,8 @@ endLon: '', }) // this.getLocal(wx.getStorageSync('latitude'), wx.getStorageSync('longitude')) - this.getLocal(wx.getStorageSync('userLocation').split(",")[1], wx.getStorageSync('userLocation').split(",")[0]) + // this.getLocal(wx.getStorageSync('userLocation').split(",")[1], wx.getStorageSync('userLocation').split(",")[0]) + this.getLocal(wx.getStorageSync('latitude'), wx.getStorageSync('longitude')) }, // 获取隐私协议和用户协议 getAgreement() { @@ -1087,7 +1090,7 @@ }) bmap.regeocoding({ - coordtype:'bd09ll', + coordtype: 'bd09ll', success: (res) => { // that.setData({ // cityName:res[0].regeocodeData.addressComponent.city, @@ -1162,7 +1165,7 @@ }) bmap.regeocoding({ - coordtype:'bd09ll', + coordtype: 'bd09ll', success: (res) => { that.setData({ cityName: res.originalData.result.addressComponent.city, @@ -1219,7 +1222,7 @@ }) bmap.regeocoding({ - coordtype:'bd09ll', + coordtype: 'bd09ll', success: (res) => { that.setData({ cityName: res.originalData.result.addressComponent.city, @@ -1258,38 +1261,54 @@ var bmap = new BaiduMap.BMapWX({ ak: 'fi3HGJjW153NCNsaTb9FekxeX1Lj3auo' // 必填,您的key }) - - bmap.regeocoding({ - coordtype:'bd09ll', - success: (res) => { - console.log('---------------------------------------------', res); + wx.getLocation({ + success: res => { that.setData({ - cityName: res.originalData.result.addressComponent.city, - latitude: res.originalData.result.location.lat, - longitude: res.originalData.result.location.lng, - adcode: res.originalData.result.addressComponent.adcode, - cityNameStart: res.originalData.result.formatted_address, - district: res.originalData.result.addressComponent.district, - province: res.originalData.result.addressComponent.province, - formatted_address: res.originalData.result.formatted_address + latitude: res.latitude, + longitude: res.longitude }) - wx.setStorageSync('latitude', res.originalData.result.location.lat) - wx.setStorageSync('longitude', res.originalData.result.location.lng) - wx.setStorageSync('adcode', res.originalData.result.addressComponent.adcode) - wx.setStorageSync('cityName', res.originalData.result.addressComponent.city) - wx.setStorageSync('cityNameStart', res.originalData.result.formatted_address) - wx.setStorageSync('district', res.originalData.result.addressComponent.district) - wx.setStorageSync('province', res.originalData.result.addressComponent.province) - wx.setStorageSync('formatted_address', res.originalData.result.formatted_address) - that.queryBusiness(res.originalData.result.addressComponent.city, res.originalData.result.addressComponent.district, res.originalData.result.addressComponent.province) - that.getCarNum(res.originalData.result.location.lat, res.originalData.result.location.lng, that.data.busId) - that.openCity(res.originalData.result.addressComponent.adcode) - that.getadver2(wx.getStorageSync('adcode') || res.originalData.result.addressComponent.adcode) - }, - fail(err) { - console.log(err) + wx.setStorageSync('latitude', res.latitude) + wx.setStorageSync('longitude', res.longitude) + wx.request({ + url: `https://api.map.baidu.com/geoconv/v2/?coords=${res.longitude},${res.latitude}&model=1&ak=3mHKIXMArjgIkgADzOlTYp4XssNSNkwr`, + success: function (res) { + bmap.regeocoding({ + coordtype: 'bd09ll', + location: res.data.result[0].y + ',' + res.data.result[0].x, + success: function (res) { + that.setData({ + cityName: res.originalData.result.addressComponent.city, + // latitude: res.originalData.result.location.lat, + // longitude: res.originalData.result.location.lng, + adcode: res.originalData.result.addressComponent.adcode, + cityNameStart: res.originalData.result.formatted_address, + district: res.originalData.result.addressComponent.district, + province: res.originalData.result.addressComponent.province, + formatted_address: res.originalData.result.formatted_address + }) + + wx.setStorageSync('adcode', res.originalData.result.addressComponent.adcode) + wx.setStorageSync('cityName', res.originalData.result.addressComponent.city) + wx.setStorageSync('cityNameStart', res.originalData.result.formatted_address) + wx.setStorageSync('district', res.originalData.result.addressComponent.district) + wx.setStorageSync('province', res.originalData.result.addressComponent.province) + wx.setStorageSync('formatted_address', res.originalData.result.formatted_address) + that.queryBusiness(res.originalData.result.addressComponent.city, res.originalData.result.addressComponent.district, res.originalData.result.addressComponent.province) + that.getCarNum(res.originalData.result.location.lat, res.originalData.result.location.lng, that.data.busId) + that.openCity(res.originalData.result.addressComponent.adcode) + that.getadver2(wx.getStorageSync('adcode') || res.originalData.result.addressComponent.adcode) + }, + fail: function (res) { + that.setData({ + cityNameStart: "正在定位中" + }) + }, + }) + } + }) } }) + } }, }) @@ -1382,7 +1401,7 @@ btnDisabled: true }) var DATE = unit.formatTimeUser(new Date()); - + if (this.data.checkDown == 2) { if (this.data.yyTime == "现在") { this.setData({ @@ -1430,8 +1449,8 @@ if (!this.data.changePeople) this.data.changePeople = '选乘车人' let btnCarData = { endAddress: this.data.endAddress || '', - endLat: this.data.nextLatitude || '', - endLon: this.data.nextLongitude || '', + endLat: JSON.parse(JSON.stringify(this.data.nextLatitude || '')), + endLon: JSON.parse(JSON.stringify(this.data.nextLongitude || '')), orderSource: 3, orderType: this.data.isDj, passengers: this.data.changePeople, @@ -1439,109 +1458,119 @@ placementLat: this.data.latitude, placementLon: this.data.longitude, startAddress: this.data.changeStartName || this.data.cityNameStart, - startLat: startLat, - startLon: startLon, - areaCode:wx.getStorageSync('adcode'), + startLat: JSON.parse(JSON.stringify(startLat)), + startLon: JSON.parse(JSON.stringify(startLon)), + areaCode: wx.getStorageSync('adcode'), substitute: this.data.substitute, //代下单 tipMoney: +this.data.tip.substr(0, this.data.tip.length - 1), travelTime: this.data.date, - payManner:this.data.payModel=='线上计费'?1:2 + payManner: this.data.modeSelectId == 2 ? 3 : this.data.payModel == '线上计费' ? 1 : 2 } - console.log('wdawdad',btnCarData); - if (Object.keys(btnCarData).length == 17) { - btnCarData.oldPeople = Number(!mode) - if (Number(!mode)) { - btnCarData.endAddress = '' - btnCarData.endLat = '' - btnCarData.endLon = '' - this.setData({ - endAddress: '', - nextLatitude: '', - nextLongitude: '', - }) - } - - - unit.post(app.globalData.Url + '/api/taxi/taxiOrder', - btnCarData, - ) - .then((res) => { - if (res.data.code == 200) { - wx.setStorageSync('orderID', res.data.data.id) - wx.navigateTo({ - url: '../../pages/waiting/waiting?startAddress=' + - (this.data.changeStartName || this.data.cityNameStart) + '&startLat=' + - startLat + '&startLon=' + - startLon + '&endAddress=' + - this.data.endAddress + '&endLat=' + - this.data.nextLatitude + '&endLon=' + - this.data.nextLongitude + '&time=' + - this.data.date + '&orderType=' + 2 + "&onekey=" + - index - - }) + wx.request({ + url: `https://api.map.baidu.com/geoconv/v2/?coords=${btnCarData.startLon},${btnCarData.startLat};${btnCarData.endLon},${btnCarData.endLat}&model=1&ak=3mHKIXMArjgIkgADzOlTYp4XssNSNkwr`, + success: (res) => { + btnCarData.startLon = res.data.result[0].x + btnCarData.startLat = res.data.result[0].y + btnCarData.endLon = res.data.result[1].x + btnCarData.endLat = res.data.result[1].y + if (Object.keys(btnCarData).length == 17) { + btnCarData.oldPeople = Number(!mode) + if (Number(!mode)) { + btnCarData.endAddress = '' + btnCarData.endLat = '' + btnCarData.endLon = '' this.setData({ - btnDisabled: false, - startChangeCar: true, //没有选择之前底部样式 - endChangeCar: false, //选择起始点以后底部样式 - nextCityName: "您要去哪儿", - yyTime: "现在", - tip: "0元", - markers: "", - points: "", - polyline: [], - showLocationIcon: true, - changephone: "", - changePeople: "更换乘车人", - startLon: "", - startLat: "", - nextBoolean: false, - endAddress: '', - endLat: '', - endLon: '', - + nextLatitude: '', + nextLongitude: '', }) - } else if (res.data.code == 600 || res.data.code == 700) { - // 清空本地token - wx.navigateTo({ - url: '/pages/index/index', - }) - setTimeout(() => { - this.setData({ - btnDisabled: false - }) - }) - } else if (res.data.code == 500) { - if (res.data.msg == '有未完成的订单') { - this.getNowOrder() - } else { - app.showToastSuccess(res.data.msg, null, 'none', 1500) - } - - setTimeout(() => { - this.setData({ - btnDisabled: false - }) - }, 2000) - } else { - setTimeout(() => { - this.setData({ - btnDisabled: false - }) - }, 2000) - app.showToastSuccess(res.data.msg, null, 'none', 1500) } - }) - } else { - setTimeout(() => { - this.setData({ - btnDisabled: false - }) - }, 2000) - app.showToastSuccess('参数错误', null, 'none', 1500) - } + + + unit.post(app.globalData.Url + '/api/taxi/taxiOrder', + btnCarData, + ) + .then((res) => { + if (res.data.code == 200) { + wx.setStorageSync('orderID', res.data.data.id) + wx.navigateTo({ + url: '../../pages/waiting/waiting?startAddress=' + + (this.data.changeStartName || this.data.cityNameStart) + '&startLat=' + + startLat + '&startLon=' + + startLon + '&endAddress=' + + this.data.endAddress + '&endLat=' + + this.data.nextLatitude + '&endLon=' + + this.data.nextLongitude + '&time=' + + this.data.date + '&orderType=' + 2 + "&onekey=" + + index + + }) + this.setData({ + btnDisabled: false, + startChangeCar: true, //没有选择之前底部样式 + endChangeCar: false, //选择起始点以后底部样式 + nextCityName: "您要去哪儿", + yyTime: "现在", + tip: "0元", + markers: "", + points: "", + polyline: [], + showLocationIcon: true, + changephone: "", + changePeople: "更换乘车人", + startLon: "", + startLat: "", + nextBoolean: false, + + endAddress: '', + endLat: '', + endLon: '', + + }) + } else if (res.data.code == 600 || res.data.code == 700) { + // 清空本地token + wx.navigateTo({ + url: '/pages/index/index', + }) + setTimeout(() => { + this.setData({ + btnDisabled: false + }) + }) + } else if (res.data.code == 500) { + if (res.data.msg == '有未完成的订单') { + this.getNowOrder() + } else { + app.showToastSuccess(res.data.msg, null, 'none', 1500) + } + + setTimeout(() => { + this.setData({ + btnDisabled: false + }) + }, 2000) + } else { + setTimeout(() => { + this.setData({ + btnDisabled: false + }) + }, 2000) + app.showToastSuccess(res.data.msg, null, 'none', 1500) + } + }) + } else { + setTimeout(() => { + this.setData({ + btnDisabled: false + }) + }, 2000) + app.showToastSuccess('参数错误', null, 'none', 1500) + } + }, + }) + console.log('wdawdad', btnCarData); + }, //下单按钮 btnCar(e) { @@ -1821,17 +1850,23 @@ }, //获取附近空闲司机 getCarNum(lat, lon, type) { - unit.post(app.globalData.Url + '/base/driver/queryIdleDriver', { - lat: lat, - lon: lon, - type: type - }) - .then((res) => { - console.log(res) - this.setData({ - carNum: res.data.data.number - }) - }) + wx.request({ + url: `https://api.map.baidu.com/geoconv/v2/?coords=${lon},${lat}&model=1&ak=3mHKIXMArjgIkgADzOlTYp4XssNSNkwr`, + success: function (res) { + console.log('shuju', res); + unit.post(app.globalData.Url + '/base/driver/queryIdleDriver', { + lat: res.data.result[0].y, + lon: res.data.result[0].x, + type: type + }) + .then((res) => { + this.setData({ + carNum: res.data.data.number + }) + }) + }, + }) + }, //选择车的类型 /base/openCity/queryBusiness queryBusiness(city, district, province) { @@ -1960,33 +1995,35 @@ ak: 'fi3HGJjW153NCNsaTb9FekxeX1Lj3auo' // 必填,您的key }) let that = this; - bmap.regeocoding({ - coordtype:'bd09ll', - location: latitude + ',' + longitude, + wx.request({ + url: `https://api.map.baidu.com/geoconv/v2/?coords=${longitude},${latitude}&model=1&ak=3mHKIXMArjgIkgADzOlTYp4XssNSNkwr`, success: function (res) { - console.log('454545d4454545451', res) - //这里的res参数里有具体的城市数据 - var name = res.originalData.result.addressComponent - that.setData({ - changeStartName: '', - startLat: '', - startLon: '', - cityNameStart: res.originalData.result.formatted_address, - adcode: res.originalData.result.addressComponent.adcode, - latitude: res.originalData.result.location.lat, - longitude: res.originalData.result.location.lng + bmap.regeocoding({ + coordtype: 'bd09ll', + location: res.data.result[0].y + ',' + res.data.result[0].x, + success: function (res) { + //这里的res参数里有具体的城市数据 + var name = res.originalData.result.addressComponent + that.setData({ + changeStartName: '', + startLat: '', + startLon: '', + cityNameStart: res.originalData.result.formatted_address, + adcode: res.originalData.result.addressComponent.adcode, + latitude, + longitude + }) + that.queryBusiness(name.city, name.district, name.province) + that.openCity(res.originalData.result.addressComponent.adcode) + }, + fail: function (res) { + that.setData({ + cityNameStart: "正在定位中" + }) + }, }) - that.queryBusiness(name.city, name.district, name.province) - that.openCity(res.originalData.result.addressComponent.adcode) - }, - fail: function (res) { - console.log('////////////',res); - that.setData({ - cityNameStart: "正在定位中" - }) - }, - complete: function (res) {} - }); + } + }) }, //选择要去的位置跳转 @@ -2020,7 +2057,7 @@ let startLat = that.data.startLat || that.data.latitude let startLon = that.data.startLon || that.data.longitude - + // unit.get('https://apis.map.qq.com/ws/direction/v1/driving/?from=' + // startLat + ',' + // startLon + '&to=' + that.data.nextLatitude + ',' + @@ -2066,10 +2103,10 @@ var coors = res.data.result.routes[0].steps var polyline = []; coors.forEach(function (step) { - polyline.push({ - latitude: step.end_location.lat, - longitude: step.end_location.lng - }); + polyline.push({ + latitude: step.end_location.lat, + longitude: step.end_location.lng + }); }); that.setData({ polyline: [{ -- Gitblit v1.7.1