recharge.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. const app = getApp()
  2. var api = require('../../utils/request');
  3. var util = require('../../utils/util');
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. loading: false,
  10. bank: {
  11. money: 0,
  12. due_money: 0,
  13. lack_money: 0,
  14. income_monney: 0,
  15. shop_money: 0,
  16. orderParams: {}, // 支付参数
  17. chickPayBtn: false, //点击了支付按钮(订单信息交由古德云组件)
  18. chickOnPay: false, // 用户是否已经点击了「支付」并成功跳转到 古德云收银台 小程序
  19. },
  20. },
  21. /**
  22. * 生命周期函数--监听页面显示
  23. */
  24. onShow: function () {
  25. this.getBank();
  26. },
  27. /**
  28. * 读取我的账单
  29. */
  30. getBank: function () {
  31. let that = this;
  32. app.api().Get("api/v3/fastshop/bank/index", function (result) {
  33. if (result.code == 200) {
  34. that.setData({ bank: result.data });
  35. }
  36. })
  37. },
  38. /**
  39. * 申请提现
  40. */
  41. onSubmit: function (e) {
  42. let that = this;
  43. var data = e.detail.value;
  44. var isPost = false;
  45. //安全密码
  46. if (util.isNull(data.safepassword)) {
  47. wx.showModal({
  48. content: '安全密码必须填写', showCancel: false
  49. })
  50. } else{
  51. if (util.isNull(data.money)) {
  52. wx.showModal({
  53. content: '转入金额必须填写', showCancel: false
  54. })
  55. } else {
  56. if (!(/^\d+$/.test(data.money))) {
  57. wx.showModal({
  58. content: '转入金额只能输入整数', showCancel: false
  59. })
  60. } else {
  61. if (data < 100) {
  62. wx.showModal({
  63. content: '最小转入金额100元', showCancel: false
  64. })
  65. }else{
  66. isPost = true;
  67. }
  68. }
  69. }
  70. }
  71. //提交数据
  72. if (isPost == true) {
  73. wx.showLoading({
  74. title: '提交申请中',
  75. mask: true
  76. })
  77. var parms = {
  78. money: data.money,
  79. safepassword: data.safepassword,
  80. }
  81. app.api().Post('api/v3/fastshop/bank/recharge', parms, function (rel) {
  82. if (rel.code == 200){
  83. if (rel.data.type == 1) {
  84. that.setData({
  85. chickPayBtn: true,
  86. orderParams: rel.data.order
  87. })
  88. } else {
  89. app.doWechatPay(rel.data.order, function (res) {
  90. wx.navigateBack({
  91. delta: 1
  92. })
  93. }, function (res) {
  94. wx.showModal({
  95. content: '充值失败',
  96. showCancel: false
  97. })
  98. })
  99. }
  100. }
  101. })
  102. }
  103. },
  104. /**
  105. * 支付成功的事件处理函数
  106. * res.detail 为 payjs 小程序返回的订单信息
  107. * 可通过 res.detail.payjsOrderId 拿到 payjs 订单号
  108. * 可通过 res.detail.responseData 拿到详细支付信息
  109. */
  110. goodPaySuccess: function (res) {
  111. if (res.detail.return_code = "SUCCESS") {
  112. wx.navigateBack({
  113. delta: 1
  114. })
  115. }
  116. },
  117. /**
  118. * 支付失败的事件处理函数
  119. * res.detail.error 为 true 代表传入小组件的参数存在问题
  120. * res.detail.navigateSuccess 代表了是否成功跳转到 PAYJS 小程序
  121. * res.detail.event 可能存有失败的原因
  122. * 如果下单成功但是用户取消支付则 res.detail.event.return_code == FAIL
  123. */
  124. goodPayFail: function (res) {
  125. this.setData({
  126. chickPayBtn: false,
  127. })
  128. },
  129. /**
  130. * 支付完毕的事件处理函数
  131. * 无论支付成功或失败均会执行
  132. */
  133. goodPayComplete: function () {
  134. this.setData({
  135. chickPayBtn: false,
  136. })
  137. },
  138. /**
  139. * 组件内部数据被修改时的事件
  140. * 当用户跳转到 云收银台 小程序并等待返回的过程中 chickOnPay 值为 true
  141. */
  142. goodPayChange(res) {
  143. if (res.detail.chickOnPay) {
  144. this.setData({
  145. chickOnPay: res.detail.chickOnPay
  146. })
  147. }
  148. }
  149. })