outmoney.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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. confirmColor:'#00AADD',
  80. });
  81. return;
  82. }
  83. log.info('[提现]', '[用户触发提现流程]');
  84. wx.showLoading({
  85. title: '提现中...',
  86. mask: true
  87. });
  88. let that = this;
  89. log.info('[提现]', '[用户触发提现流程]', '[wx.login请求]');
  90. wx.login({
  91. success(res) {
  92. console.log(res);
  93. log.info('[提现]', '[用户触发提现流程]', '[wx.login响应]', res);
  94. if (res.code) {
  95. // 发起网络请求
  96. log.info('[提现]', '[服务端提现]', '[请求]', {
  97. //outTradeNo: new Date().getTime(), //订单号
  98. //totalFee: that.data.chargemoney_select, //钱
  99. totalFee: that.data.outMoney,
  100. userId: that.data.userInfo.userId,
  101. loginName: that.data.userInfo.loginName,
  102. remark: that.data.remarkArray[that.data.remarkArrayIndex].text,
  103. code: res.code
  104. });
  105. wx.request({
  106. url: getApp().globalData.postHeadAgreement +'/restapi/wechatpay/dopayTransfers',
  107. data: {
  108. //outTradeNo: new Date().getTime(), //订单号
  109. //totalFee: that.data.chargemoney_select, //钱
  110. totalFee: that.data.outMoney,
  111. userId: that.data.userInfo.userId,
  112. loginName: that.data.userInfo.loginName,
  113. remark: that.data.remarkArray[that.data.remarkArrayIndex].text,
  114. code: res.code
  115. },
  116. header: {
  117. 'content-type': 'application/x-www-form-urlencoded;charset=utf-8',
  118. },
  119. method: 'POST',
  120. success(res1) {
  121. wx.hideLoading();
  122. let {
  123. data
  124. } = res1;
  125. log.info('[提现]', '[服务端提现]', '[响应]', data);
  126. if (data && data.code == 200) {
  127. wx.navigateBack();
  128. wx.showModal({
  129. showCancel: false,
  130. content: '提现成功',
  131. confirmColor:'#00AADD',
  132. });
  133. log.info('[提现]', '[服务端提现]', '[提现成功]', data);
  134. } else {
  135. wx.showModal({
  136. showCancel: false,
  137. content: data.msg,
  138. confirmColor:'#00AADD',
  139. });
  140. log.info('[提现]', '[服务端提现]', '[提现失败data null||data.code<>200]', data);
  141. }
  142. }
  143. });
  144. } else {
  145. wx.hideLoading();
  146. console.log('登录失败!' + res.errMsg);
  147. log.info('[提现]', '[用户触发提现流程]', '[wx.login响应失败code null]', res);
  148. }
  149. }
  150. })
  151. },
  152. bindRemarkChange: function (e) {
  153. //console.log(e.detail.value);
  154. //let remarkValue = this.data.remarkArray[e.detail.value].value;
  155. this.setData({
  156. remarkArrayIndex: e.detail.value
  157. });
  158. if (this.data.userInfo.repaidbalance && this.data.outMoney && this.data.outMoney >= 0.3 && this.data.outMoney <= this.data.userInfo.repaidbalance) {
  159. this.setData({
  160. checkPass: true
  161. });
  162. }else{
  163. this.setData({
  164. checkPass: false
  165. });
  166. }
  167. },
  168. /**
  169. * 生命周期函数--监听页面加载
  170. */
  171. onLoad: function(options) {
  172. },
  173. /**
  174. * 生命周期函数--监听页面初次渲染完成
  175. */
  176. onReady: function() {
  177. },
  178. /**
  179. * 生命周期函数--监听页面显示
  180. */
  181. onShow: function() {
  182. log.info('[提现]', '[加载完成]');
  183. let userInfo = wx.getStorageSync('userInfo');
  184. let isLogin = wx.getStorageSync('isLogin');
  185. let that = this;
  186. log.info('[提现]', '[同步用户数据]', '[请求]', {
  187. loginName: userInfo.loginName
  188. });
  189. wx.request({
  190. url: getApp().globalData.postHeadAgreement +'/restapi/wechat/syncUser',
  191. data: {
  192. loginName: userInfo.loginName
  193. },
  194. method: 'POST',
  195. success: function(res) {
  196. let {
  197. data
  198. } = res;
  199. log.info('[提现]', '[同步用户数据]', '[响应]', data);
  200. if (data.code && data.code != 200) {
  201. wx.removeStorageSync('userInfo');
  202. wx.removeStorageSync('isLogin');
  203. let url = '/pages/login/phone_login/phone_login';
  204. wx.redirectTo({
  205. url,
  206. });
  207. log.info('[提现]', '[同步用户数据]', '[失败data null||data.code<>200跳转登陆界面]', data);
  208. } else {
  209. that.setData({
  210. userInfo: data,
  211. isLogin: true
  212. });
  213. wx.setStorageSync('userInfo', data);
  214. wx.setStorageSync('isLogin', true);
  215. log.info('[提现]', '[同步用户数据]', '[成功]', data);
  216. log.info('[提现]', '[获取用户是否有未完成订单]', '[请求]', {
  217. userId: userInfo.userId
  218. });
  219. wx.request({
  220. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatchargstatus',
  221. data: {
  222. userId: userInfo.userId
  223. },
  224. method: 'POST',
  225. success(res) {
  226. let {
  227. data
  228. } = res;
  229. log.info('[提现]', '[获取用户是否有未完成订单]', '[响应]', data);
  230. if (data && data.code == 200) {
  231. //有正在充电的订单
  232. that.setData({
  233. msg: '暂时无法退款,请先完成订单!'
  234. });
  235. log.info('[提现]', '[获取用户是否有未完成订单]', '[用户有未完成订单无法体现]', data);
  236. } else {
  237. console.log(res);
  238. log.info('[提现]', '[获取用户是否有未完成订单]', '[用户没有未完成订单]', data);
  239. }
  240. }
  241. });
  242. log.info('[提现]', '[获取用户是否有未支付订单]', '[请求]', {
  243. userId: that.data.userInfo.userId
  244. });
  245. wx.request({
  246. url: getApp().globalData.postHeadAgreement + '/restapi/pileLog/wechatsettlement',
  247. data: {
  248. userId: that.data.userInfo.userId
  249. },
  250. method: 'POST',
  251. success(res) {
  252. let {
  253. data
  254. } = res;
  255. log.info('[提现]', '[获取用户是否有未支付订单]', '[响应]', data);
  256. let {
  257. result: order
  258. } = data;
  259. if (data && order && data.code == 200) {
  260. //有未支付的订单
  261. that.setData({
  262. msg: '暂时无法退款,请先完成订单!'
  263. });
  264. log.info('[提现]', '[获取用户是否有未支付订单]','[用户有未支付订单无法提现]');
  265. } else {
  266. console.log(res);
  267. log.info('[提现]', '[获取用户是否有未支付订单]', '[用户没有未支付订单]');
  268. }
  269. }
  270. });
  271. }
  272. },
  273. fail(e) {
  274. console.log("用户数据同步失败");
  275. log.info('[提现]', '[同步用户数据]', '[fail]', e);
  276. }
  277. });
  278. },
  279. /**
  280. * 生命周期函数--监听页面隐藏
  281. */
  282. onHide: function() {
  283. },
  284. /**
  285. * 生命周期函数--监听页面卸载
  286. */
  287. onUnload: function() {
  288. },
  289. /**
  290. * 页面相关事件处理函数--监听用户下拉动作
  291. */
  292. onPullDownRefresh: function() {
  293. },
  294. /**
  295. * 页面上拉触底事件的处理函数
  296. */
  297. onReachBottom: function() {
  298. },
  299. /**
  300. * 用户点击右上角分享
  301. */
  302. onShareAppMessage: function() {
  303. }
  304. })