scan_result.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. // pages/scan_result/scan_result.js
  2. let log = require('../../utils/log.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. chargPile: null,
  9. orderid: null,
  10. userId: null,
  11. repaidbalance: 0
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. let that = this;
  18. wx.getStorage({
  19. key: 'scan_chargpile',
  20. success: function (res) {
  21. //console.log(res);
  22. //console.log(res.data);
  23. var chargPile = res.data;
  24. chargPile.sharpTotalPrice = (chargPile.sharpChargPrice + chargPile.sharpServicePrice).toFixed(4);
  25. chargPile.peakTotalPrice = (chargPile.peakChargPrice + chargPile.peakServicePrice).toFixed(4);
  26. chargPile.flatTotalPrice = (chargPile.flatChargPrice + chargPile.flatServicePrice).toFixed(4);
  27. chargPile.valleyTotalPrice = (chargPile.valleyChargPrice + chargPile.valleyServicePrice).toFixed(4);
  28. chargPile.totalprice = (chargPile.chargprice + chargPile.serviceprice).toFixed(4);
  29. that.setData({
  30. chargPile
  31. });
  32. //console.log(chargPile);
  33. wx.removeStorage({
  34. key: 'scan_chargpile',
  35. success(res) {
  36. console.log(res);
  37. }
  38. });
  39. log.info('[扫码]', '[加载完成]', '[参数]', res.data);
  40. let userInfo = wx.getStorageSync('userInfo');
  41. wx.request({
  42. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/syncUser',
  43. data: {
  44. loginName: userInfo.loginName
  45. },
  46. method: 'POST',
  47. success: function (res) {
  48. let {
  49. data
  50. } = res;
  51. log.info('[扫码]', '[同步用户数据]', '[响应]', data);
  52. console.info('[扫码]', '[同步用户数据]', '[响应]', data);
  53. if (data.code && data.code != 200) {
  54. log.info('[扫码]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  55. } else {
  56. that.setData({
  57. repaidbalance:data.repaidbalance
  58. });
  59. }
  60. },
  61. fail(e) {
  62. console.log("用户数据同步失败");
  63. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  64. }
  65. });
  66. }
  67. });
  68. },
  69. beginCharge(e) {
  70. let userInfo = wx.getStorageSync('userInfo');
  71. let isLogin = wx.getStorageSync('isLogin');
  72. wx.showLoading({
  73. title: '开启充电中...',
  74. mask: true
  75. });
  76. log.info('[扫码]', '[开始充电流程]');
  77. //同步用户数据
  78. let that = this;
  79. log.info('[扫码]', '[同步用户数据]', '[请求]', {
  80. loginName: userInfo.loginName
  81. });
  82. wx.request({
  83. url: getApp().globalData.postHeadAgreement + '/restapi/wechat/syncUser',
  84. data: {
  85. loginName: userInfo.loginName
  86. },
  87. method: 'POST',
  88. success: function (res) {
  89. wx.hideLoading();
  90. let {
  91. data
  92. } = res;
  93. log.info('[扫码]', '[同步用户数据]', '[响应]', data);
  94. console.info('[扫码]', '[同步用户数据]', '[响应]', data);
  95. if (data.code && data.code != 200) {
  96. wx.removeStorageSync('userInfo');
  97. wx.removeStorageSync('isLogin');
  98. let url = '/pages/login/phone_login/phone_login';
  99. wx.redirectTo({
  100. url,
  101. });
  102. log.info('[扫码]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  103. } else {
  104. wx.setStorageSync('userInfo', data);
  105. wx.setStorageSync('isLogin', true);
  106. let repaidbalance = data.repaidbalance;
  107. that.setData({
  108. repaidbalance
  109. });
  110. console.info("sssssss " + data.repaidbalance)
  111. //开始充电
  112. if(data.bindingPhone==0){
  113. wx.showModal({
  114. title: '提示',
  115. content: '您未绑定手机号,请重新登录后自动刷新绑定信息',
  116. confirmText: '去登录',
  117. showCancel:false,
  118. confirmColor:'#00AADD',
  119. success: function (res1) {
  120. if (res1.confirm) {
  121. wx.removeStorageSync('userInfo');
  122. wx.removeStorageSync('isLogin');
  123. let url = '/pages/login/phone_login/phone_login';
  124. wx.redirectTo({
  125. url
  126. })
  127. }
  128. }
  129. });
  130. log.info('[扫码]', '[同步用户数据]', '[未绑定手机号]', data);
  131. }else if (!data.repaidbalance || data.repaidbalance <= 0) {
  132. wx.showModal({
  133. showCancel: false,
  134. content: '余额不足,请充值!',
  135. confirmColor:'#00AADD',
  136. success: function (res) {
  137. if (res.confirm) {
  138. let url = "/pages/chargemoney/chargemoney";
  139. wx.navigateTo({
  140. url
  141. });
  142. }
  143. }
  144. });
  145. log.info('[扫码]', '[同步用户数据]', '[data.repaidbalance null||data.repaidbalance<=0余额不足跳转充值界面]', data);
  146. } else if (data.repaidbalance > 0 && data.repaidbalance <= 15) {
  147. wx.showModal({
  148. title: '余额:' + data.repaidbalance + '元',
  149. showCancel: false,
  150. confirmText: "去充值",
  151. confirmColor:'#00AADD',
  152. content: '余额过低,请尽快充值!',
  153. success: function (res) {
  154. if (res.confirm) {
  155. let url = "/pages/chargemoney/chargemoney";
  156. wx.navigateTo({
  157. url
  158. });
  159. }
  160. }
  161. });
  162. log.info('[扫码]', '[同步用户数据]', '[0<data.repaidbalance<=15余额过低]', data);
  163. // wx.showModal({
  164. // title:'请选择',
  165. // showCancel: true,
  166. // confirmText:"继续充电",
  167. // cancelText:"去充值",
  168. // content: '余额过低,请尽快充值!',
  169. // success: function (res) {
  170. // if (res.confirm) {
  171. // that.beginCharge_satrt();
  172. // } else if (res.cancel) {
  173. // let url = "/pages/chargemoney/chargemoney";
  174. // wx.navigateTo({
  175. // url
  176. // });
  177. // }
  178. // }
  179. // });
  180. } else if (data.repaidbalance > 15) {
  181. log.info('[扫码]', '[同步用户数据]', '[余额充足开始充电]', data);
  182. that.beginCharge_satrt();
  183. }
  184. }
  185. },
  186. fail(e) {
  187. console.log("用户数据同步失败");
  188. log.info('[扫码]', '[同步用户数据]', '[fail]', e);
  189. }
  190. });
  191. },
  192. beginCharge_satrt() {
  193. wx.showLoading({
  194. title: '开启充电中...',
  195. mask: true
  196. });
  197. let that = this;
  198. let terminalNum = this.data.chargPile.chargPileId;
  199. let userInfo = wx.getStorageSync('userInfo');
  200. let isLogin = wx.getStorageSync('isLogin');
  201. console.log(terminalNum);
  202. let userId = userInfo.userId;
  203. let chargstarttime = new Date().getTime();
  204. console.log(chargstarttime);
  205. log.info('[扫码]', '[开始充电]', '[请求]', {
  206. //chargPileId: '201811010000004202',
  207. chargPileId: terminalNum,
  208. userId: userId,
  209. chargstarttime: chargstarttime
  210. });
  211. wx.request({
  212. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/miniprogramadd',
  213. data: {
  214. //chargPileId: '201811010000004202',
  215. chargPileId: terminalNum,
  216. userId: userId,
  217. chargstarttime: chargstarttime
  218. },
  219. method: 'POST',
  220. fail(e) {
  221. wx.hideLoading();
  222. //开启充电失败,提示用户
  223. wx.showModal({
  224. showCancel: false,
  225. content: '开启充电失败',
  226. confirmColor:'#00AADD',
  227. });
  228. log.info('[扫码]', '[开始充电]', '[fail]', e);
  229. },
  230. success(res) {
  231. wx.hideLoading();
  232. let {
  233. data
  234. } = res;
  235. log.info('[扫码]', '[开始充电]', '[响应]', data);
  236. if (data && data.code == 200) {
  237. //if (data && data.code == 200 && data.orderid) {
  238. //开启充电成功,跳转到正在充电界面
  239. let {
  240. orderid
  241. } = data;
  242. log.info('[扫码]', '[开始充电]', '[成功,跳转充电中页面]', data);
  243. //console.log(this.data.city);
  244. let url = `/pages/charging/charging?orderid=${orderid}&userId=${userId}&chargPileId=${terminalNum}`;
  245. wx.redirectTo({
  246. url
  247. });
  248. } else if (data && data.code == 501) {
  249. //开启充电失败,提示用户
  250. wx.showModal({
  251. showCancel: false,
  252. content: '余额不足,请充值!',
  253. confirmColor:'#00AADD',
  254. });
  255. log.info('[扫码]', '[开始充电]', '[失败data.code=501余额不足]', data);
  256. } else if (data && data.code == 502) {
  257. //开启充电失败,提示用户
  258. wx.showModal({
  259. showCancel: false,
  260. content: data.message,
  261. confirmColor:'#00AADD',
  262. });
  263. log.info('[扫码]', '[开始充电]', '[失败data.code=502' + data.message + ']', data);
  264. } else {
  265. //开启充电失败,提示用户
  266. wx.showModal({
  267. showCancel: false,
  268. content: '开启充电失败',
  269. confirmColor:'#00AADD',
  270. });
  271. log.info('[扫码]', '[开始充电]', '[失败]', data);
  272. }
  273. }
  274. });
  275. },
  276. /**
  277. * 生命周期函数--监听页面初次渲染完成
  278. */
  279. onReady: function () {
  280. },
  281. /**
  282. * 生命周期函数--监听页面显示
  283. */
  284. onShow: function () {
  285. },
  286. /**
  287. * 生命周期函数--监听页面隐藏
  288. */
  289. onHide: function () {
  290. },
  291. /**
  292. * 生命周期函数--监听页面卸载
  293. */
  294. onUnload: function () {
  295. },
  296. /**
  297. * 页面相关事件处理函数--监听用户下拉动作
  298. */
  299. onPullDownRefresh: function () {
  300. },
  301. /**
  302. * 页面上拉触底事件的处理函数
  303. */
  304. onReachBottom: function () {
  305. },
  306. /**
  307. * 用户点击右上角分享
  308. */
  309. onShareAppMessage: function () {
  310. }
  311. })