12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316 |
- //index.js
- //获取应用实例
- let app = getApp();
- let wechat = require("../../utils/wechat");
- let amap = require("../../utils/amap");
- let Util = require("../../utils/util");
- let log = require('../../utils/log.js');
- let wxpro = require('../../utils/wx-promise-pro.js');
- let mapregionchange_makertap = false;
- wxpro.promisifyAll()
- // wxpro.promisify(wx.getSystemInfo)().then(console.log)
- for (var variable in wx) {
- if (wx.hasOwnProperty(variable)) {
- wx.pro[variable] = wxpro.promisify(wx[variable])
- }
- }
- Page({
- data: {
- scanFlag:false,
- markers: [],
- latitude: 39.9088120620532,
- longitude: 116.39747668717192,
- user_lat: 39.9088120620532,
- user_lon: 116.39747668717192,
- textData: null,
- city: null,
- markerId: null,
- keywords: "搜索充电桩",
- userInfo: {},
- isLogin: false,
- myChargeStationsIds: '',
- distanceinfo: [
- // {
- // value: 1000,
- // text: '1km'
- // }, {
- // value: 2000,
- // text: '2km'
- // }, {
- // value: 5000,
- // text: '5km'
- // },
- {
- value: 10000,
- text: '10km'
- },
- // {
- // value: 20000,
- // text: '20km'
- // },
- {
- value: 50000,
- text: '50km'
- }, {
- value: 100000,
- text: '100km'
- }],
- distanceinfoindex: 0,
- polygon: [{
- points: [{
- latitude: 31,
- longitude: 131
- }, {
- latitude: 31,
- longitude: 131.1
- }, {
- latitude: 31.1,
- longitude: 131.1
- }, , {
- latitude: 31.1,
- longitude: 131
- }]
-
- }],
- showModal: false,
- notice: null,
- carParkingRate: false,
- showPrivacy:false
- },
- howtouse(){
- wx.navigateTo({
- url:'/pages/howtouse/howtouse'
- });
- },
- wxScan(q) {
- //console.log(decodeURIComponent(e.q));
- let charePileId = decodeURIComponent(q).replace("https://cdgl.pjnes.com/", "");
- log.info('[首页]', '[微信扫一扫]', { 'q': q });
- if(!charePileId){
- charePileId = "0"
- }
- if (charePileId) {
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- if (isLogin && userInfo.flag) {
- return;
- }
- if (!isLogin) {
- log.info('[首页]', '[未登陆跳转登录界面]');
- let url = `/pages/login/phone_login/phone_login`;
- wx.navigateTo({
- url
- });
- return;
- } else {
- log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
- data: {
- userId: userInfo.userId
- },
- method: 'POST',
- success(res) {
- let {
- data
- } = res;
- log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
- if (data && data.code == 200) {
- log.info('[首页]', '[有未完成订单跳充电界面]');
- //onShow会跳转
- } else {
- //console.log('无订单');
- log.info('[首页]', '[用户无未完成订单]');
- log.info('[首页]', '[获取微信扫一扫充电桩]', '[请求]', charePileId);
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
- // data: charePileId,
- data:{
- chargPileId:charePileId,
- userId: userInfo.userId
- },
- method: 'POST',
- success(res) {
- //console.log(res.data);
- log.info('[首页]', '[获取微信扫一扫充电桩]', '[响应]', res.data);
- if (!res.data || res.data.code == 500) {
- //没有该充电桩信息
- wx.showModal({
- showCancel: false,
- content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
- confirmColor:'#00AADD',
- });
- } else {
- res.data = res.data.result
- //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
- if (!res.data.chargstatus || res.data.chargstatus == 0 || res.data.chargstatus == 1 || res.data.chargstatus == 4 || res.data.chargstatus == 5 || res.data.chargstatus == 6 || res.data.chargstatus == 9) {
- //充电桩故障
- wx.showModal({
- showCancel: false,
- content: '终端故障,维修中',
- confirmColor:'#00AADD',
- });
- } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
- wx.showModal({
- showCancel: false,
- content: '正在充电中',
- confirmColor:'#00AADD',
- });
- } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
- wx.setStorage({
- key: "scan_chargpile",
- data: res.data
- });
- log.info('[首页]', '[微信扫一扫充电桩空闲跳转去充电界面]');
- let url = `/pages/scan_result/scan_result`;
- wx.navigateTo({
- url
- });
- }
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- }
- }
- },
- resetchargStations(data){
- let that = this
- // 刷新 stationTag)
-
- for(let i=0;i<data.length;i++){
- let seeInfoChargPile = data[i];
- that.resetStationTag(seeInfoChargPile);
- let resultTable = seeInfoChargPile.resultList
- that.resetResultList(resultTable);
- that.resetResultData(resultTable,seeInfoChargPile)
-
- }
- },
- resetResultData(resultList,data){
- if(!resultList){
- return;
- }
- for(let i=0;i<resultList.length;i++){
- if(resultList[i].currentTime){
- data.chargprice = resultList[i].elecPrice
- data.serviceprice = resultList[i].servicePrice
- }
- }
- },
- resetStationTag(seeInfoChargPile){
- let that = this
- if(!seeInfoChargPile){
- return;
- }
- if(!seeInfoChargPile?.stationTag){
- return;
- }
- seeInfoChargPile.stationTagList = seeInfoChargPile.stationTag.split("|");
- },
- resetResultList(resultList){
- let that = this
- if(!resultList){
- return;
- }
- resultList.forEach(item=>{
- item["sumPrice"] = that.resetResultListSumPrice(item);
- if(!item.elecPrice && item.elecPrice!=0){
- item["elecPrice"] = '暂无费用'
- }
- if(!item.servicePrice && item.servicePrice!=0){
- item["servicePrice"] = '暂无费用'
- }
- })
- },
- resetResultListSumPrice(item){
-
- if(!item.elecPrice && item.elecPrice!=0){
- return '暂无费用'
- }
- if(!item.servicePrice && item.servicePrice!=0){
- return '暂无费用'
- }
- return parseFloat((item.elecPrice + item.servicePrice).toFixed(6))
- },
- onLoad(e) {
- // 隐私开始
- wx.getPrivacySetting({
- success: res => {
- console.log(res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
- if (res.needAuthorization) {
- // 需要弹出隐私协议
- this.setData({
- showPrivacy: true
- })
- } else {
- // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
- // wx.getUserProfile()
- // wx.chooseMedia()
- // wx.getClipboardData()
- // wx.startRecord()
- }
- },
- fail: () => {},
- complete: () => {}
- })
-
- // 隐私结束
- this.data.scanFlag = false;
- wx.hideLoading();
- if (e.q) {
- //console.log(decodeURIComponent(e.q));
- //let charePileId = decodeURIComponent(e.q).replace("https://cdgl.pjnes.com/", "");
- //console.log(charePileId);
- //if (charePileId){
- //}
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- // userInfo.flag=true;
- this.setData({
- userInfo,
- isLogin
- });
- this.click_scan_control(e.q,false);
- // this.wxScan(e.q);
- }
- log.info('[首页]', '[加载完成]');
- amap.getRegeo(function () {
- var fail = function (obj) {
- wx.showModal({
- title: '请求失败',
- content: obj.errMsg,
- confirmColor:'#00AADD',
- });
- }
- })
- .then(d => {
- //console.log(d);
- let {
- latitude,
- longitude,
- latitude: user_lat,
- longitude: user_lon
- } = d[0];
- //console.log(d[0].regeocodeData.addressComponent);
- var {
- city
- } = d[0].regeocodeData.addressComponent;
- if (d[0].regeocodeData.addressComponent.city.length == 0) {
- var {
- province: city
- } = d[0].regeocodeData.addressComponent;
- }
- let that = this;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- // userInfo.flag=true;
- this.setData({
- city,
- latitude,
- longitude,
- user_lat,
- user_lon,
- userInfo,
- isLogin
- });
- //开始请求充电站信息
- var chargStationType;
- if (!userInfo.flag) {
- //用户是普通用户
- chargStationType = '2';
- }
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
- data: {
- lon: longitude,
- lat: latitude,
- distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
- chargStationType
- },
- method: 'POST',
- success(res) {
- //userInfo.flag = true;
- that.resetchargStations(res.data)
- if (isLogin && userInfo.flag) {
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/userChargStations',
- data: {
- userId: userInfo.userId,
- lat: latitude,
- lon: longitude
- },
- method: 'POST',
- success(res1) {
- var myChargeStationsIds = '';
- res1.data.forEach((item, index) => {
- myChargeStationsIds += item.id + ",";
- });
- //console.log(myChargeStationsIds);
- let {
- data
- } = res;
- let markers = [];
- data.forEach((item, index) => {
- //item.callout = {
- // content: item.name, //文本 String 1.2.0
- // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
- // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
- // };
- var iconPath = "/images/marker.png";
- if (myChargeStationsIds.indexOf(item.id + ',') != -1) {
- iconPath = "/images/marker1.png";
- }
- if (item.breaknum && item.breaknum != 0) {
- iconPath = "/images/marker_b.png";
- }
- /**
- * 运营状态 初始,待运营,运营中,暂停营业,关闭,未运营
- * */
- //private Long operationState;
- var marker = {
- name: item.chargStationName,
- address: item.address,
- width: "46rpx",
- height: "67rpx",
- chargfeatures: item.chargfeatures ,
- iconPath: iconPath,
- id: item.id,
- callout: {},
- latitude: item.lat,
- longitude: item.lon,
- //distance: item.distance / 1000,
- distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
- chargPileNum: item.fastCharg + item.slowCharg,
- fastCharg: item.fastCharg,
- slowCharg: item.slowCharg,
- freenum: item.freenum,
- fastfreenum: item.fastfreenum,
- slowfreenum: item.slowfreenum,
- breaknum: item.breaknum,
- /** 电费 */
- chargprice: item.chargprice,
- /** 服务费 */
- serviceprice: item.serviceprice,
- /** 停车费 */
- stopprice: item.stopprice,
- operationState: item.operationState,
- chargStationId: item.id,
- stationTag: item.stationTag,
- stationTagList: item.stationTagList,
- offlineServicecall: item.offlineServicecall,
- };
- markers[index] = marker;
- });
- that.setData({
- markers,
- myChargeStationsIds
- });
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- } else {
- let {
- data
- } = res;
- let markers = [];
- if(data){
- data.forEach((item, index) => {
- //item.callout = {
- // content: item.name, //文本 String 1.2.0
- // display: 'BYCLICK', //'BYCLICK': 点击显示; 'ALWAYS': 常显 String 1.2.0
- // textAlign: 'center' //文本对齐方式。有效值: left, right, center String 1.6.0
- // };
- var iconPath = "/images/marker.png";
- //撤销普通用户显示异常站
- //if (item.breaknum && item.breaknum != 0) {
- // iconPath = "/images/marker_b.png";
- //}
- //撤销结束
- var marker = {
- name: item.chargStationName,
- address: item.address,
- width: "46rpx",
- height: "67rpx",
- chargfeatures: item.chargfeatures ,
- iconPath: iconPath,
- id: item.id,
- callout: {},
- latitude: item.lat,
- longitude: item.lon,
- //distance: item.distance / 1000,
- distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
- chargPileNum: item.fastCharg + item.slowCharg,
- fastCharg: item.fastCharg,
- slowCharg: item.slowCharg,
- freenum: item.freenum,
- fastfreenum: item.fastfreenum,
- slowfreenum: item.slowfreenum,
- breaknum: item.breaknum,
- /** 电费 */
- chargprice: item.chargprice,
- /** 服务费 */
- serviceprice: item.serviceprice,
- /** 停车费 */
- stopprice: item.stopprice,
- operationState: item.operationState,
- sharpChargPrice : item.sharpChargPrice,
- sharpServicePrice : item.sharpServicePrice,
- peakChargPrice : item.peakChargPrice,
- peakServicePrice : item.peakServicePrice,
- flatChargPrice : item.flatChargPrice,
- flatServicePrice : item.flatServicePrice,
- valleyChargPrice : item.valleyChargPrice,
- valleyServicePrice : item.valleyServicePrice,
- resultList: item.resultList,
- chargStationId: item.id,
- stationTag: item.stationTag,
- stationTagList: item.stationTagList,
- offlineServicecall: item.offlineServicecall,
- };
- markers[index] = marker;
- });
- }
- that.setData({
- markers
- });
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- })
- .catch(e => {
- console.log(e);
- });
- let that = this;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- //console.log(userInfo);
- if (isLogin) {
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/lastNotice',
- data: { loginName: userInfo.loginName },
- method: 'POST',
- success(res) {
- //console.log(res);
- //res.data = { noticeTitle: '派捷充电例行维护通知', noticeContent:'nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好nihao你好'};
- if (res.data) {
- that.setData({
- showModal: true,
- notice: res.data
- });
- } else {
- that.setData({
- showModal: false,
- notice: null
- });
- }
- },
- fail(e) {
- //console.log(e);
- that.setData({
- showModal: false,
- notice: null
- });
- getApp().showNetworkError();
- }
- });
- }
- },
- //跳转个人中心
- bindUserAvatarUrl() {
- let url = `/pages/ucenter/index/index`;
- wx.navigateTo({
- url
- });
- },
- //搜索
- bindInput() {
- var {
- user_lat: latitude,
- user_lon: longitude,
- city
- } = this.data;
- //console.log(this.data.city);
- let url = `/pages/inputtip/inputtip?city=${city}&lonlat=${longitude},${latitude}`;
- wx.navigateTo({
- url
- });
- },
- //单击地图mark
- makertap(e) {
- mapregionchange_makertap = true;
- //console.log(e);
- let {
- markerId
- } = e.detail;
- // console.log({
- // e
- // });
- let {
- markers
- } = this.data;
- //撤销普通用户显示异常站
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let showBadMark = false;
- if (isLogin && userInfo.flag) {
- showBadMark = true;
- }
- //撤销结束
- markers.forEach((item, index) => {
- item.iconPath = "/images/marker.png";
- if (this.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
- item.iconPath = "/images/marker1.png";
- }
- //撤销普通用户显示异常站
- if (showBadMark) {
- //撤销结束
- if (item.breaknum && item.breaknum != 0) {
- item.iconPath = "/images/marker_b.png";
- }
- //撤销普通用户显示异常站
- }
- //撤销结束
- if (item.id == markerId) {
- item.iconPath = "/images/marker_checked.png";
- this.showMarkerInfo(item);
- }
- });
- this.setData({
- markers,
- markerId
- });
- },
- //将mark呈现在地图中心点,并弹出详细信息框
- showMarkerInfo(data) {
- let that = this
- let {
- latitude,
- longitude
- } = data;
- this.setData({
- textData: data,
- latitude: latitude,
- longitude: longitude
- })
- console.info(data)
- // 查询是否需要显示
- that.execParking(that,data.id)
- },
- execParking(that,stationId){
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/carParkingRate?stationId=' + stationId,
- // data: {
- // loginName: userInfo.loginName
- // },
- method: 'POST',
- success: function (res) {
- // 是否减免停车费
- // carParkingRate: false,
- // parkTime: 0,
- console.info(res)
- let reduceTime = res.data?.reduceTime;
- if(!reduceTime){
- that.setData({
- carParkingRate:false
- })
- return;
- }
- that.setData({
- carParkingRate:true
- })
- try{
- that.setData({
- parkTime: parseFloat((reduceTime/ 3600).toFixed(2))
- })
- }catch(e){
- that.setData({
- carParkingRate:false
- })
- }
- },
- fail(e) {
- console.log("用户数据同步失败");
- log.info('[扫码]', '[同步用户数据]', '[fail]', e);
- }
- });
- },
- //改变选中mark的颜色
- changeMarkerColor(markerId) {
- let {
- markers
- } = this.data;
- //撤销普通用户显示异常站
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let showBadMark = false;
- if (isLogin && userInfo.flag) {
- showBadMark = true;
- }
- //撤销结束
- markers.forEach((item, index) => {
- item.iconPath = "/images/marker.png";
- if (this.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
- item.iconPath = "/images/marker1.png";
- }
- //撤销普通用户显示异常站
- if (showBadMark) {
- //撤销结束
- if (item.breaknum && item.breaknum != 0) {
- item.iconPath = "/images/marker_b.png";
- }
- //撤销普通用户显示异常站
- }
- //撤销结束
- if (item.id == markerId) {
- item.iconPath = "/images/marker_checked.png";
- }
- })
- this.setData({
- markers,
- markerId
- });
- },
- seeInfo(e){
- console.log("11111");
- // 起点
- let {
- user_lat: latitude,
- user_lon: longitude,
- markers,
- markerId,
- city,
- textData
- } = this.data;
- let {
- name,
- address,
- chargprice,
- serviceprice,
- } = textData;
- console.log("222222");
- console.log(markers);
- if (!markers.length) return;
- console.log("3333333");
- // 终点
- markers.forEach((item, index) => {
- if (markerId && markerId == item.id) {
- let {
- name: latitude2,
- longitude: longitude2
- } = item;
- wx.setStorage({
- key: "index_seeInfo_chargpile",
- data: item
- });
- let url = `/pages/charginfo/charginfo?name=${name}&address=${address}&chargprice=${chargprice}&serviceprice=${serviceprice}&chargid=${markerId}`;
- //console.log(url);
- wx.navigateTo({
- url
- });
- }
- });
- },
- //导航
- getRoute(e) {
- //console.log(e);
- // 起点
- let {
- user_lat: latitude,
- user_lon: longitude,
- markers,
- markerId,
- city,
- textData
- } = this.data;
- let {
- name,
- address
- } = textData;
- if (!markers.length) return;
- // 终点
- markers.forEach((item, index) => {
- if (markerId && markerId == item.id) {
- let {
- latitude: latitude2,
- longitude: longitude2
- } = item;
- let url = `/pages/routes/routes?longitude=${longitude}&latitude=${latitude}&longitude2=${longitude2}&latitude2=${latitude2}&city=${city}&name=${name}&desc=${address}`;
- //console.log(url);
- wx.navigateTo({
- url
- });
- }
- });
- return;
- },
- //回到当前位置
- click_location_control(e) {
- //console.log("回到用户当前定位点");
- // let {
- // controlId
- // } = e;
- let mpCtx = wx.createMapContext("map");
- mpCtx.moveToLocation();
- },
- //打开扫一扫
- click_scan_control_outer(){
- this.click_scan_control("",true)
- },
- click_scan_control(scanResult,inner) {
- if(this.data.scanFlag){
- return;
- }
- this.data.scanFlag = true;
- wx.showLoading({
- title: '努力加载中...',
- })
-
- console.log("打开扫一扫");
- log.info('[首页]', '[打开扫一扫]');
- let that = this;
- if (!this.data.isLogin) {
- log.info('[首页]', '[未登陆跳转登录界面]');
- let url = `/pages/login/phone_login/phone_login`;
- that.data.scanFlag = false;
- wx.hideLoading();
- wx.navigateTo({
- url
- });
- return;
- } else {
- if(!this.phoneCheck()){
- return;
- }
- log.info('[首页]', '[获取用户是否有未支付订单]', '[请求]', { userId: this.data.userInfo.userId });
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
- data: {
- userId: this.data.userInfo.userId
- },
- method: 'POST',
- success(res) {
- let {
- data
- } = res;
- let {
- result: order
- } = data;
- log.info('[首页]', '[获取用户是否有未支付订单]', '[响应]', data);
- if (data && order && data.code == 200) {
- that.data.scanFlag = false;
- wx.hideLoading();
- log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
- wx.showModal({
- showCancel: false,
- content: '你有未支付的订单,请先支付',
- confirmColor:'#00AADD',
- success: function (res) {
- //console.log(res);
- if (!res.cancel) {
- //点击确定
- let url = `/pages/order/order?orderid=${order.orderid}&userId=${order.userId}&chargPileId=${order.chargPileId}`;
- wx.navigateTo({
- url
- });
- }
- }
- });
- //console.log(that.data.result);
- } else {
- //console.log('无订单');
- log.info('[首页]', '[用户无未支付订单]');
- //console.log("打开扫一扫");
-
- if(inner){
- wx.pro.scanCode().then(d=>{
- that.afterScanCode(d,that,inner)
- }).catch(e=>{
- that.data.scanFlag = false;
- wx.hideLoading();
- });
- }else{
- that.afterScanCode(scanResult,that,inner)
- }
- }
- },
- fail(e) {
- that.data.scanFlag = false;
- wx.hideLoading();
- getApp().showNetworkError();
- }
- });
- }
-
- },
- afterScanCode(d,that,inner){
- let scanResult = ""
- if(inner){
- //console.log("完成扫一扫");
- //console.log(d);
- //兼容标准格式hlht://202001022222220101.330414214二维码
- scanResult = d.result;
- if((!scanResult) || scanResult == ""){
- scanResult="*"
- }
- }else{
- scanResult = decodeURIComponent(d)
- //console.log(charePileId);
- log.info('[首页]', '[微信扫一扫]', { 'd': d });
- if(!scanResult){
- scanResult = "0"
- }
- }
- // 是否电池包
- let batteryFlag = false;
- if (scanResult.startsWith("tkd")){
- scanResult = scanResult.substring(3);
- batteryFlag = true
- }
- if (scanResult.startsWith("hlht://") || scanResult.startsWith("HLHT://")){
- scanResult = scanResult.substring(7, scanResult.indexOf("."));
- }
- scanResult = scanResult.replace("https://cdgl.pjnes.com/", "");
- scanResult = scanResult.replace("https://cdglyy.pjnes.com/", "");
- console.log('扫描到的内容: [' + scanResult + '] , 是否内部按钮:' + inner)
- log.info('[首页]', '[用户完成扫一扫]', scanResult);
- log.info('[首页]', '[获取扫一扫充电桩]', '[请求]', scanResult);
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/' + (batteryFlag? 'chargBattery' : 'chargPile'),
- // data: scanResult,
- data: {
- chargPileId:scanResult,
- userId: that.data.userInfo.userId
- },
- method: 'POST',
- success(res) {
- console.log( res.data);
- log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
- if (!res.data || res.data.code == 500) {
- that.data.scanFlag = false;
- wx.hideLoading();
- //没有该充电桩信息
- wx.showModal({
- showCancel: false,
- content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号',
- confirmColor:'#00AADD',
- });
- } else {
- res.data = res.data.result
- // 拨乱反正, 将电池包的逻辑强行合并
- if(batteryFlag){
- // 0空闲
- let status = res.data.parkStatus
- if(status == 1){
- wx.showModal({
- showCancel: false,
- content: '当前停靠点占用',
- confirmColor:'#00AADD',
- });
- }else if(status == 0){
- wx.hideLoading();
- that.data.scanFlag = false;
- // 判断电池包
- if(res?.data?.chargPileList?.length==0 || !res?.data?.chargPileList){
- wx.showModal({
- showCancel: false,
- content: '暂无可用电池包',
- confirmColor:'#00AADD',
- });
- return;
- }
- wx.setStorage({
- key: "elpackage",
- data: res.data
- });
- let url = `/pages/scan_result/elpackage`;
- wx.navigateTo({
- url
- });
- }else{
- wx.showModal({
- showCancel: false,
- content: '未知错误,电池包返回状态码异常:' + res.data.parkStatus,
- confirmColor:'#00AADD',
- });
- }
- that.data.scanFlag = false;
- wx.hideLoading();
- return;
- }
-
- //SZP
- // park_status
- //充电状态0:离线、1:故障、2:空闲中、3:充电中、4:欠压故障、5:过压故障、6:过电流故障、8:预约、9:在线升级、10:操作中、11:已插枪等
- if (!res.data.chargstatus || res.data.chargstatus == 0 || res.data.chargstatus == 1 || res.data.chargstatus == 4 || res.data.chargstatus == 5 || res.data.chargstatus == 6 || res.data.chargstatus == 9) {
- //充电桩故障
- wx.showModal({
- showCancel: false,
- content: '终端故障,维修中',
- confirmColor:'#00AADD',
- });
- } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
- wx.showModal({
- showCancel: false,
- content: '正在充电中',
- confirmColor:'#00AADD',
- });
- } else if (res.data.chargstatus == 2 || res.data.chargstatus == 11) {
- wx.setStorage({
- key: "scan_chargpile",
- data: res.data
- });
- log.info('[首页]', '[扫一扫充电桩空闲跳转去充电界面]');
- let url = `/pages/scan_result/scan_result`;
- that.data.scanFlag = false;
- wx.hideLoading();
- wx.navigateTo({
- url
- });
- }
- that.data.scanFlag = false;
- wx.hideLoading();
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- },
- //地图位移
- mapchange(e) {
- if (e.type == 'end') {
- if (!mapregionchange_makertap) {
- //console.log("移动地图");
- let that = this;
- let wMap = wx.createMapContext('map');
- wMap.getCenterLocation({
- type: 'gcj02',
- success: function (res) {
- let {
- latitude,
- longitude
- } = res;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- var chargStationType;
- if (!userInfo.flag) {
- //用户是普通用户
- chargStationType = '2';
- }
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargStations',
- data: {
- lon: longitude,
- lat: latitude,
- distance: that.data.distanceinfo[that.data.distanceinfoindex].value,
- chargStationType
- },
- method: 'POST',
- success(res) {
- that.resetchargStations(res.data)
- let {
- data
- } = res;
- let markers = [];
- var flag = false;
- if(data){
- data.forEach((item, index) => {
- var iconPath;
- if (that.data.markerId && that.data.markerId == item.id) {
- iconPath = "/images/marker_checked.png";
- flag = true;
- } else {
- iconPath = "/images/marker.png";
- if (that.data.myChargeStationsIds.indexOf(item.id + ',') != -1) {
- iconPath = "/images/marker1.png";
- }
- //撤销普通用户显示异常站
- if (isLogin && userInfo.flag) {
- //撤销结束
- if (item.breaknum && item.breaknum != 0) {
- iconPath = "/images/marker_b.png";
- }
- //撤销普通用户显示异常站
- }
- //撤销结束
- }
- //console.log(Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon));
- var marker = {
- name: item.chargStationName,
- address: item.address,
- width: "46rpx",
- height: "67rpx",
- chargfeatures: item.chargfeatures ,
- iconPath: iconPath,
- id: item.id,
- callout: {},
- latitude: item.lat,
- longitude: item.lon,
- //distance: item.distance / 1000,
- distance: Util.distance(that.data.user_lat, that.data.user_lon, item.lat, item.lon),
- chargPileNum: item.fastCharg + item.slowCharg,
- fastCharg: item.fastCharg,
- slowCharg: item.slowCharg,
- freenum: item.freenum,
- fastfreenum: item.fastfreenum,
- slowfreenum: item.slowfreenum,
- breaknum: item.breaknum,
- /** 电费 */
- chargprice: item.chargprice,
- /** 服务费 */
- serviceprice: item.serviceprice,
- /** 停车费 */
- stopprice: item.stopprice,
-
- operationState: item.operationState,
- sharpChargPrice : item.sharpChargPrice,
- sharpServicePrice : item.sharpServicePrice,
- peakChargPrice : item.peakChargPrice,
- peakServicePrice : item.peakServicePrice,
- flatChargPrice : item.flatChargPrice,
- flatServicePrice : item.flatServicePrice,
- valleyChargPrice : item.valleyChargPrice,
- valleyServicePrice : item.valleyServicePrice,
- resultList: item.resultList,
- chargStationId: item.id,
- stationTag: item.stationTag,
- stationTagList: item.stationTagList,
- offlineServicecall: item.offlineServicecall,
-
- };
- markers[index] = marker;
- });
- }
- if (!flag) {
- that.setData({
- textData: null,
- markerId: null,
- });
- }
- that.setData({
- markers: markers
- });
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- }
- });
- } else {
- //点击marker的情况下
- //console.log("点击marker");
- mapregionchange_makertap = false;
- }
- }
- },
- phoneCheck(){
- if (this.data.userInfo.bindingPhone==0) {
- wx.hideLoading();
- wx.showModal({
- title: '提示',
- content: '当前账户未绑定手机号,请您进行手机号绑定操作',
- showCancel:false,
- confirmText: '去绑定',
- confirmColor:'#00AADD',
- success: function (res1) {
- let url = `/pages/bindPhone/bindPhone`;
- wx.navigateTo({
- url
- });
- }
- })
- return false;
- }else{
- return true;
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- this.data.scanFlag = false;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- // 页面显示
- if (userInfo && isLogin) {
- //console.log(userInfo);
- //userInfo.flag = true;
- this.setData({
- userInfo: userInfo,
- isLogin: isLogin
- });
- if ((!userInfo.userId && userInfo.userId != 0)){
- log.info('[首页]', '[已登陆未有用户ID跳转登录界面]');
- let url = `/pages/login/phone_login/phone_login`;
- wx.navigateTo({
- url
- });
- return;
- }
- // 查询订单
- log.info('[首页]', '[获取用户是否有未完成订单]', '[请求]', { userId: userInfo.userId });
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
- data: {
- userId: userInfo.userId
- },
- method: 'POST',
- success(res) {
- let {
- data
- } = res;
- log.info('[首页]', '[获取用户是否有未完成订单]', '[响应]', data);
- if (data && data.code == 200) {
- log.info('[首页]', '[有未完成订单跳充电界面]');
- //获取用户正在充电的订单,并跳转到该页面
- let url = `/pages/charging/charging?orderid=${data.result.orderid}&userId=${userInfo.userId}&chargPileId=${data.result.chargPileId}`;
- //let url = `/pages/charging/charging?userId=${userInfo.userId}`;
- wx.navigateTo({
- url
- });
- } else {
- //console.log(res);
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- // 查询呼叫电车
- console.log("查询呼叫电车")
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/ivCarRequirement' +
- '?userId='+userInfo.userId,
- data: {
- },
- method: 'POST',
- success(res) {
- console.log(res?.data?.result?.requirementStep)
- // 0-7 进等待 8进终端详情
- if(res?.data?.result?.requirementStep>=0 && res?.data?.result?.requirementStep<=7){
- // 等待
- let url = `/pages/batteryPack/batteryPackWait`;
- wx.reLaunch({
- url
- });
- }else if(res?.data?.result?.requirementStep==8){
- // 8进终端详情
- let url = `/pages/batteryPack/batteryPackWait`;
- wx.reLaunch({
- url
- });
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- } else {
- //未登录信息
- this.setData({
- userInfo: {}
- });
- }
- },
- bindDistanceinfoChange: function (e) {
- let distance = this.data.distanceinfo[e.detail.value].value;
- this.setData({
- distanceinfoindex: e.detail.value
- });
- },
- Sure: function () {
- this.setData({
- showModal: false
- });
- },
- handleAgreePrivacyAuthorization() {
- console.info('3333333333333');
- this.setData({
- showPrivacy: false
- })
- // 用户同意隐私协议事件回调
- // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
- // wx.getUserProfile()
- // wx.chooseMedia()
- // wx.getClipboardData()
- // wx.startRecord()
- },
- handleOpenPrivacyContract() {
- // 打开隐私协议页面
- wx.openPrivacyContract({
- success: () => {}, // 打开成功
- fail: () => {}, // 打开失败
- complete: () => {}
- })
- }
- })
|