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