outmoney.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // pages/outmoney/outmoney.js
  2. let log = require('../../utils/log.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. outMoney: null,
  9. checkPass: false,
  10. msg:null,
  11. userInfo: {},
  12. isLogin: false,
  13. remarkArray: [{
  14. value: 1,
  15. text:'充电站位置不方便'
  16. },{
  17. value: 2,
  18. text:'电费过高'
  19. },{
  20. value: 3,
  21. text:'服务费过高'
  22. },{
  23. value: 4,
  24. text:'充电慢'
  25. },{
  26. value: 5,
  27. text:'油车或电车占位'
  28. },{
  29. value: 6,
  30. text:'停放环境堪忧'
  31. },{
  32. value: 7,
  33. text:'长时间离线无人维修'
  34. },{
  35. value: 8,
  36. text:'充电桩存在安全隐患'
  37. },{
  38. value: 9,
  39. text:'小程序经常卡顿'
  40. },{
  41. value: 10,
  42. text:'变更住所'
  43. },{
  44. value: 11,
  45. text:'车已售出'
  46. },{
  47. value: 12,
  48. text:'其他'
  49. }],
  50. remarkArrayIndex: null
  51. },
  52. outMoney(e) {
  53. console.log(e);
  54. let outMoney = e.detail.value;
  55. this.setData({
  56. outMoney
  57. });
  58. if (this.data.userInfo.repaidbalance && outMoney && outMoney >= 0.3 && outMoney <= this.data.userInfo.repaidbalance) {
  59. if (this.data.remarkArrayIndex){
  60. this.setData({
  61. checkPass: true
  62. });
  63. }else{
  64. this.setData({
  65. checkPass: false
  66. });
  67. }
  68. } else {
  69. this.setData({
  70. checkPass: false
  71. });
  72. }
  73. },
  74. beginOutMoney(e) {
  75. if (this.data.msg) {
  76. wx.showModal({
  77. showCancel: false,
  78. content: this.data.msg
  79. });
  80. return;
  81. }
  82. log.info('[提现]', '[用户触发提现流程]');
  83. wx.showLoading({
  84. title: '提现中...',
  85. mask: true
  86. });
  87. let that = this;
  88. log.info('[提现]', '[用户触发提现流程]', '[wx.login请求]');
  89. wx.login({
  90. success(res) {
  91. console.log(res);
  92. log.info('[提现]', '[用户触发提现流程]', '[wx.login响应]', res);
  93. if (res.code) {
  94. // 发起网络请求
  95. log.info('[提现]', '[服务端提现]', '[请求]', {
  96. //outTradeNo: new Date().getTime(), //订单号
  97. //totalFee: that.data.chargemoney_select, //钱
  98. totalFee: that.data.outMoney,
  99. userId: that.data.userInfo.userId,
  100. loginName: that.data.userInfo.loginName,
  101. remark: that.data.remarkArray[that.data.remarkArrayIndex].text,
  102. code: res.code
  103. });
  104. wx.request({
  105. url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/dopayTransfers',
  106. data: {
  107. //outTradeNo: new Date().getTime(), //订单号
  108. //totalFee: that.data.chargemoney_select, //钱
  109. totalFee: that.data.outMoney,
  110. userId: that.data.userInfo.userId,
  111. loginName: that.data.userInfo.loginName,
  112. remark: that.data.remarkArray[that.data.remarkArrayIndex].text,
  113. code: res.code
  114. },
  115. header: {
  116. 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
  117. },
  118. method: 'POST',
  119. success(res1) {
  120. wx.hideLoading();
  121. let {
  122. data
  123. } = res1;
  124. log.info('[提现]', '[服务端提现]', '[响应]', data);
  125. if (data && data.code == 200) {
  126. wx.navigateBack();
  127. wx.showModal({
  128. showCancel: false,
  129. content: '提现成功'
  130. });
  131. log.info('[提现]', '[服务端提现]', '[提现成功]', data);
  132. } else {
  133. wx.showModal({
  134. showCancel: false,
  135. content: data.msg
  136. });
  137. log.info('[提现]', '[服务端提现]', '[提现失败data null||data.code<>200]', data);
  138. }
  139. }
  140. });
  141. } else {
  142. wx.hideLoading();
  143. console.log('登录失败!' + res.errMsg);
  144. log.info('[提现]', '[用户触发提现流程]', '[wx.login响应失败code null]', res);
  145. }
  146. }
  147. })
  148. },
  149. bindRemarkChange: function (e) {
  150. //console.log(e.detail.value);
  151. //let remarkValue = this.data.remarkArray[e.detail.value].value;
  152. this.setData({
  153. remarkArrayIndex: e.detail.value
  154. });
  155. if (this.data.userInfo.repaidbalance && this.data.outMoney && this.data.outMoney >= 0.3 && this.data.outMoney <= this.data.userInfo.repaidbalance) {
  156. this.setData({
  157. checkPass: true
  158. });
  159. }else{
  160. this.setData({
  161. checkPass: false
  162. });
  163. }
  164. },
  165. /**
  166. * 生命周期函数--监听页面加载
  167. */
  168. onLoad: function(options) {
  169. },
  170. /**
  171. * 生命周期函数--监听页面初次渲染完成
  172. */
  173. onReady: function() {
  174. },
  175. /**
  176. * 生命周期函数--监听页面显示
  177. */
  178. onShow: function() {
  179. log.info('[提现]', '[加载完成]');
  180. let userInfo = wx.getStorageSync('userInfo');
  181. let isLogin = wx.getStorageSync('isLogin');
  182. let that = this;
  183. log.info('[提现]', '[同步用户数据]', '[请求]', {
  184. loginName: userInfo.loginName
  185. });
  186. wx.request({
  187. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/syncUser',
  188. data: {
  189. loginName: userInfo.loginName
  190. },
  191. method: 'POST',
  192. success: function(res) {
  193. let {
  194. data
  195. } = res;
  196. log.info('[提现]', '[同步用户数据]', '[响应]', data);
  197. if (data.code && data.code != 200) {
  198. wx.removeStorageSync('userInfo');
  199. wx.removeStorageSync('isLogin');
  200. let url = '/pages/login/phone_login/phone_login';
  201. wx.redirectTo({
  202. url,
  203. });
  204. log.info('[提现]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  205. } else {
  206. that.setData({
  207. userInfo: data,
  208. isLogin: true
  209. });
  210. wx.setStorageSync('userInfo', data);
  211. wx.setStorageSync('isLogin', true);
  212. log.info('[提现]', '[同步用户数据]', '[成功]', data);
  213. log.info('[提现]', '[获取用户是否有未完成订单]', '[请求]', {
  214. userId: userInfo.userId
  215. });
  216. wx.request({
  217. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  218. data: {
  219. userId: userInfo.userId
  220. },
  221. method: 'POST',
  222. success(res) {
  223. let {
  224. data
  225. } = res;
  226. log.info('[提现]', '[获取用户是否有未完成订单]', '[响应]', data);
  227. if (data && data.code == 200) {
  228. //有正在充电的订单
  229. that.setData({
  230. msg: '暂时无法退款,请先完成订单!'
  231. });
  232. log.info('[提现]', '[获取用户是否有未完成订单]', '[用户有未完成订单无法体现]', data);
  233. } else {
  234. console.log(res);
  235. log.info('[提现]', '[获取用户是否有未完成订单]', '[用户没有未完成订单]', data);
  236. }
  237. }
  238. });
  239. log.info('[提现]', '[获取用户是否有未支付订单]', '[请求]', {
  240. userId: that.data.userInfo.userId
  241. });
  242. wx.request({
  243. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  244. data: {
  245. userId: that.data.userInfo.userId
  246. },
  247. method: 'POST',
  248. success(res) {
  249. let {
  250. data
  251. } = res;
  252. log.info('[提现]', '[获取用户是否有未支付订单]', '[响应]', data);
  253. let {
  254. result: order
  255. } = data;
  256. if (data && order && data.code == 200) {
  257. //有未支付的订单
  258. that.setData({
  259. msg: '暂时无法退款,请先完成订单!'
  260. });
  261. log.info('[提现]', '[获取用户是否有未支付订单]','[用户有未支付订单无法提现]');
  262. } else {
  263. console.log(res);
  264. log.info('[提现]', '[获取用户是否有未支付订单]', '[用户没有未支付订单]');
  265. }
  266. }
  267. });
  268. }
  269. },
  270. fail(e) {
  271. console.log("用户数据同步失败");
  272. log.info('[提现]', '[同步用户数据]', '[fail]', e);
  273. }
  274. });
  275. },
  276. /**
  277. * 生命周期函数--监听页面隐藏
  278. */
  279. onHide: function() {
  280. },
  281. /**
  282. * 生命周期函数--监听页面卸载
  283. */
  284. onUnload: function() {
  285. },
  286. /**
  287. * 页面相关事件处理函数--监听用户下拉动作
  288. */
  289. onPullDownRefresh: function() {
  290. },
  291. /**
  292. * 页面上拉触底事件的处理函数
  293. */
  294. onReachBottom: function() {
  295. },
  296. /**
  297. * 用户点击右上角分享
  298. */
  299. onShareAppMessage: function() {
  300. }
  301. })