123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934 |
- //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 mapregionchange_makertap = false;
- 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
- },
- wxScan(q) {
- //console.log(decodeURIComponent(e.q));
- let charePileId = decodeURIComponent(q).replace("https://cdgl.pjnes.com/", "");
- //console.log(charePileId);
- 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 :'无效的终端编号'
- });
- } 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: '终端故障,维修中'
- });
- } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
- wx.showModal({
- showCancel: false,
- content: '正在充电中'
- });
- } 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();
- }
- });
- }
- }
- },
- onLoad(e) {
- this.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){
- //}
- this.wxScan(e.q);
- }
- log.info('[首页]', '[加载完成]');
- amap.getRegeo(function () {
- var fail = function (obj) {
- wx.showModal({
- title: '请求失败',
- content: obj.errMsg,
- });
- }
- })
- .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;
- 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) {
- //console.log(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",
- 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
- };
- 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",
- 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
- };
- 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 {
- latitude,
- longitude
- } = data;
- this.setData({
- textData: data,
- latitude: latitude,
- longitude: longitude
- })
- },
- //改变选中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(e);
- // 起点
- let {
- user_lat: latitude,
- user_lon: longitude,
- markers,
- markerId,
- city,
- textData
- } = this.data;
- let {
- name,
- address,
- chargprice,
- serviceprice,
- } = textData;
- if (!markers.length) return;
- // 终点
- markers.forEach((item, index) => {
- if (markerId && markerId == item.id) {
- let {
- name: latitude2,
- longitude: longitude2
- } = 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
- });
- }
- });
- },
- //回到当前位置
- click_location_control(e) {
- //console.log("回到用户当前定位点");
- // let {
- // controlId
- // } = e;
- let mpCtx = wx.createMapContext("map");
- mpCtx.moveToLocation();
- },
- //打开扫一扫
- click_scan_control(e) {
- if(this.scanFlag){
- return;
- }
- this.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.scanFlag = false;
- wx.hideLoading();
- wx.navigateTo({
- url
- });
- return;
- } else {
- 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.scanFlag = false;
- wx.hideLoading();
- log.info('[首页]', '[用户有未支付订单跳转订单支付界面]');
- wx.showModal({
- showCancel: false,
- content: '你有未支付的订单,请先支付',
- 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("打开扫一扫");
- wx.scanCode({
- success: function (d) {
- //console.log("完成扫一扫");
- //console.log(d);
- //兼容标准格式hlht://202001022222220101.330414214二维码
- let scanResult = d.result;
- if((!scanResult) || scanResult == ""){
- scanResult="*"
- }
- console.log(scanResult);
- if (scanResult.startsWith("hlht://") || scanResult.startsWith("HLHT://")){
- scanResult = scanResult.substring(7, scanResult.indexOf("."));
- }
- console.log(scanResult);
- log.info('[首页]', '[用户完成扫一扫]', scanResult);
- log.info('[首页]', '[获取扫一扫充电桩]', '[请求]', scanResult);
- wx.request({
- url: getApp().globalData.postHeadAgreement + '/restapi/wechat/chargPile',
- // data: scanResult,
- data: {
- chargPileId:scanResult,
- userId: that.data.userInfo.userId
- },
- method: 'POST',
- success(res) {
- console.log(scanResult);
- log.info('[首页]', '[获取扫一扫充电桩]', '[响应]', res.data);
- if (!res.data || res.data.code == 500) {
- that.scanFlag = false;
- wx.hideLoading();
- //没有该充电桩信息
- wx.showModal({
- showCancel: false,
- content: res && res.data && res.data.msg ? res.data.msg :'无效的终端编号'
- });
- } 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: '终端故障,维修中'
- });
- } else if (res.data.chargstatus == 3 || res.data.chargstatus == 8 || res.data.chargstatus == 10) {
- wx.showModal({
- showCancel: false,
- content: '正在充电中'
- });
- } 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.scanFlag = false;
- wx.hideLoading();
- wx.navigateTo({
- url
- });
- }
- that.scanFlag = false;
- wx.hideLoading();
- }
- },
- fail(e) {
- getApp().showNetworkError();
- }
- });
- },
- fail(e){
- that.scanFlag = false;
- wx.hideLoading();
- }
- });
- }
- },
- fail(e) {
- that.scanFlag = false;
- wx.hideLoading();
- 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) {
- 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",
- 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
- };
- 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;
- }
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- 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();
- }
- });
- } 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
- });
- }
-
- })
|