withdraw.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. var _request = require('../../../../utils/request.js')
  2. function formatWithdrawStateText (state) {
  3. if (state === 'WAIT_USER_CONFIRM') {
  4. return '待确认,确认后到帐'
  5. }
  6. return state || ''
  7. }
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. price: '',
  14. page: 1,
  15. per_page: 10,
  16. cashList: [],
  17. cashList_more: true,
  18. cashList_change: false,
  19. cashTotal: 0,
  20. confirmedTransferIds: {}
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. this.refreshCashList()
  27. },
  28. onShow () {
  29. if (getApp().globalData.withdrawChanged) {
  30. getApp().globalData.withdrawChanged = false
  31. this.refreshCashList()
  32. }
  33. },
  34. onPullDownRefresh: function () {
  35. this.setData({
  36. page: 1,
  37. cashList_more: true,
  38. cashList_change: true
  39. })
  40. this.getCashList()
  41. wx.stopPullDownRefresh()
  42. },
  43. onReachBottom: function () {
  44. if (this.data.cashList_more) {
  45. var page = this.data.page + 1
  46. this.setData({
  47. page: page
  48. })
  49. this.getCashList()
  50. }
  51. },
  52. refreshCashList () {
  53. this.setData({
  54. page: 1,
  55. cashList: [],
  56. cashList_more: true,
  57. cashList_change: false
  58. })
  59. this.getCashTotal()
  60. this.getCashList()
  61. },
  62. getCashTotal () {
  63. var that = this
  64. var url = 'v1/user/cash/balance/info'
  65. var params = {
  66. }
  67. var success = function (res) {
  68. that.setData({
  69. cashTotal: res.data
  70. })
  71. }
  72. _request.$get(url, params, success)
  73. },
  74. getCashList () {
  75. console.log(this.data.page)
  76. var that = this
  77. var url = 'v1/user/takecash/flow'
  78. var params = {
  79. page: that.data.page,
  80. per_page: that.data.per_page
  81. }
  82. var success = function (res) {
  83. if (that.data.cashList_change) {
  84. that.setData({
  85. cashList: [],
  86. cashList_change: false
  87. })
  88. }
  89. var confirmedTransferIds = that.data.confirmedTransferIds || {}
  90. var list = res.data.list || []
  91. list.forEach(function (item) {
  92. if (item.state_cn === 'WAIT_USER_CONFIRM') {
  93. item.state_cn = formatWithdrawStateText(item.state_cn)
  94. } else if (item.transfer_state === 'WAIT_USER_CONFIRM') {
  95. item.state_cn = formatWithdrawStateText(item.transfer_state)
  96. }
  97. if (confirmedTransferIds[item.id]) {
  98. item.can_confirm_transfer = false
  99. }
  100. })
  101. var result = that.data.cashList.concat(list)
  102. var listMore = res.data.list_count > result.length
  103. that.setData({
  104. cashList: result,
  105. cashList_more: listMore
  106. })
  107. }
  108. _request.$get(url, params, success)
  109. },
  110. confirmMerchantTransfer (e) {
  111. var that = this
  112. var index = e.currentTarget.dataset.index
  113. var item = that.data.cashList[index] || {}
  114. if (item.confirming_transfer) {
  115. return
  116. }
  117. if (!item.can_confirm_transfer || !item.package_info) {
  118. wx.showToast({
  119. title: '当前提现无需确认收款',
  120. icon: 'none',
  121. duration: 2000
  122. })
  123. return
  124. }
  125. if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
  126. wx.showToast({
  127. title: '当前微信版本不支持确认收款,请升级微信',
  128. icon: 'none',
  129. duration: 2000
  130. })
  131. return
  132. }
  133. var cashList = that.data.cashList
  134. cashList[index].can_confirm_transfer = false
  135. cashList[index].confirming_transfer = true
  136. that.setData({
  137. cashList: cashList
  138. })
  139. wx.requestMerchantTransfer({
  140. mchId: String(item.mch_id || ''),
  141. appId: String(item.app_id || ''),
  142. package: item.package_info,
  143. success: function () {
  144. wx.showToast({
  145. title: '确认收款已提交',
  146. icon: 'none',
  147. duration: 2000
  148. })
  149. var confirmedTransferIds = that.data.confirmedTransferIds || {}
  150. confirmedTransferIds[item.id] = true
  151. getApp().globalData.withdrawChanged = true
  152. that.setData({
  153. page: 1,
  154. cashList_more: true,
  155. cashList_change: true,
  156. confirmedTransferIds: confirmedTransferIds
  157. })
  158. that.getCashList()
  159. },
  160. fail: function (res) {
  161. var cashList = that.data.cashList
  162. if (cashList[index]) {
  163. cashList[index].can_confirm_transfer = true
  164. cashList[index].confirming_transfer = false
  165. that.setData({
  166. cashList: cashList
  167. })
  168. }
  169. wx.showToast({
  170. title: (res && res.errMsg) ? res.errMsg : '确认收款失败',
  171. icon: 'none',
  172. duration: 3000
  173. })
  174. }
  175. })
  176. },
  177. onShareAppMessage: function (val) {
  178. return _request.share({
  179. sc: 'xcx_user_withdraw'
  180. })
  181. }
  182. })