scan_result.js 8.0 KB

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