outmoney.js 9.3 KB

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