123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- // pages/scan_result/scan_result.js
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- chargPile: null,
- orderid: null,
- userId: null
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- let that = this;
- wx.getStorage({
- key: 'scan_chargpile',
- success: function (res) {
- //console.log(res);
- //console.log(res.data);
- that.setData({
- chargPile: res.data
- });
- wx.removeStorage({
- key: 'scan_chargpile',
- success(res) {
- console.log(res);
- }
- })
- }
- });
- },
- beginCharge(e) {
- wx.showLoading({
- title: '开启充电中...',
- mask: true
- });
- //同步用户数据
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- let that = this;
- wx.request({
- url: getApp().globalData.postHeadAgreement + '://cdgl.xinyhy.cn/restapi/wechat/syncUser',
- data: {
- loginName: userInfo.loginName
- },
- method: 'POST',
- success: function (res) {
- wx.hideLoading();
- let {
- data
- } = res;
- if (data.code && data.code != 200) {
- wx.removeStorageSync('userInfo');
- wx.removeStorageSync('isLogin');
- let url = '/pages/login/login';
- wx.redirectTo({
- url,
- });
- } else {
- wx.setStorageSync('userInfo', data);
- wx.setStorageSync('isLogin', true);
- //开始充电
- if (!data.repaidbalance||data.repaidbalance<=0){
- wx.showModal({
- showCancel: false,
- content: '余额不足,请充值!',
- success: function (res) {
- if (res.confirm){
- let url = "/pages/chargemoney/chargemoney";
- wx.navigateTo({
- url
- });
- }
- }
- });
-
- } else if (data.repaidbalance > 0 && data.repaidbalance<=10){
- wx.showModal({
- title: '余额:' + data.repaidbalance+'元',
- showCancel: false,
- confirmText: "去充值",
- content: '余额过低,请尽快充值!',
- success: function (res) {
- if (res.confirm) {
- let url = "/pages/chargemoney/chargemoney";
- wx.navigateTo({
- url
- });
- }
- }
- });
- // wx.showModal({
- // title:'请选择',
- // showCancel: true,
- // confirmText:"继续充电",
- // cancelText:"去充值",
- // content: '余额过低,请尽快充值!',
- // success: function (res) {
- // if (res.confirm) {
-
- // that.beginCharge_satrt();
- // } else if (res.cancel) {
- // let url = "/pages/chargemoney/chargemoney";
- // wx.navigateTo({
- // url
- // });
- // }
- // }
- // });
- } else if (data.repaidbalance > 10 ) {
- that.beginCharge_satrt();
- }
- }
- },
- fail(e) {
- console.log("用户数据同步失败");
- }
- });
- },
- beginCharge_satrt(){
- wx.showLoading({
- title: '开启充电中...',
- mask: true
- });
- let that = this;
- let terminalNum = this.data.chargPile.chargPileId;
- let userInfo = wx.getStorageSync('userInfo');
- let isLogin = wx.getStorageSync('isLogin');
- console.log(terminalNum);
- let userId = userInfo.userId;
- let chargstarttime = new Date().getTime();
- console.log(chargstarttime);
- wx.request({
- url: getApp().globalData.postHeadAgreement + '://cdgl.xinyhy.cn/restapi/pileLog/miniprogramadd',
- data: {
- //chargPileId: '201811010000004202',
- chargPileId: terminalNum,
- userId: userId,
- chargstarttime: chargstarttime
- },
- method: 'POST',
- fail() {
- wx.hideLoading();
- //开启充电失败,提示用户
- wx.showModal({
- showCancel: false,
- content: '开启充电失败'
- });
- },
- success(res) {
- wx.hideLoading();
- let {
- data
- } = res;
- if (data && data.code == 200 ) {
- //if (data && data.code == 200 && data.orderid) {
- //开启充电成功,跳转到正在充电界面
- let {
- orderid
- } = data;
- //console.log(this.data.city);
- let url = `/pages/charging/charging?orderid=${orderid}&userId=${userId}&chargPileId=${terminalNum}`;
- wx.redirectTo({
- url
- });
- } else if (data && data.code == 501) {
- //开启充电失败,提示用户
- wx.showModal({
- showCancel: false,
- content: '余额不足,请充值!'
- });
- message
- } else if (data && data.code == 502) {
- //开启充电失败,提示用户
- wx.showModal({
- showCancel: false,
- content: data.message
- });
- }else {
- //开启充电失败,提示用户
- wx.showModal({
- showCancel: false,
- content: '开启充电失败'
- });
- }
- }
- });
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|