scan_result.js 11 KB

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