withdraw.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.getCashTotal()
  27. this.getCashList()
  28. },
  29. onShow () {
  30. },
  31. onPullDownRefresh: function () {
  32. this.setData({
  33. page: 1,
  34. cashList_more: true,
  35. cashList_change: true
  36. })
  37. this.getCashList()
  38. wx.stopPullDownRefresh()
  39. },
  40. onReachBottom: function () {
  41. if (this.data.cashList_more) {
  42. var page = this.data.page + 1
  43. this.setData({
  44. page: page
  45. })
  46. this.getCashList()
  47. }
  48. },
  49. getCashTotal () {
  50. var that = this
  51. var url = 'v1/user/cash/balance/info'
  52. var params = {
  53. }
  54. var success = function (res) {
  55. that.setData({
  56. cashTotal: res.data
  57. })
  58. }
  59. _request.$get(url, params, success)
  60. },
  61. getCashList () {
  62. console.log(this.data.page)
  63. var that = this
  64. var url = 'v1/user/takecash/flow'
  65. var params = {
  66. page: that.data.page,
  67. per_page: that.data.per_page
  68. }
  69. var success = function (res) {
  70. if (that.data.cashList_change) {
  71. that.setData({
  72. cashList: [],
  73. cashList_change: false
  74. })
  75. }
  76. var confirmedTransferIds = that.data.confirmedTransferIds || {}
  77. var list = res.data.list || []
  78. list.forEach(function (item) {
  79. if (item.state_cn === 'WAIT_USER_CONFIRM') {
  80. item.state_cn = formatWithdrawStateText(item.state_cn)
  81. } else if (item.transfer_state === 'WAIT_USER_CONFIRM') {
  82. item.state_cn = formatWithdrawStateText(item.transfer_state)
  83. }
  84. if (confirmedTransferIds[item.id]) {
  85. item.can_confirm_transfer = false
  86. }
  87. })
  88. var result = that.data.cashList.concat(list)
  89. var listMore = res.data.list_count > result.length
  90. that.setData({
  91. cashList: result,
  92. cashList_more: listMore
  93. })
  94. }
  95. _request.$get(url, params, success)
  96. },
  97. confirmMerchantTransfer (e) {
  98. var that = this
  99. var index = e.currentTarget.dataset.index
  100. var item = that.data.cashList[index] || {}
  101. if (item.confirming_transfer) {
  102. return
  103. }
  104. if (!item.can_confirm_transfer || !item.package_info) {
  105. wx.showToast({
  106. title: '当前提现无需确认收款',
  107. icon: 'none',
  108. duration: 2000
  109. })
  110. return
  111. }
  112. if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
  113. wx.showToast({
  114. title: '当前微信版本不支持确认收款,请升级微信',
  115. icon: 'none',
  116. duration: 2000
  117. })
  118. return
  119. }
  120. var cashList = that.data.cashList
  121. cashList[index].can_confirm_transfer = false
  122. cashList[index].confirming_transfer = true
  123. that.setData({
  124. cashList: cashList
  125. })
  126. wx.requestMerchantTransfer({
  127. mchId: String(item.mch_id || ''),
  128. appId: String(item.app_id || ''),
  129. package: item.package_info,
  130. success: function () {
  131. wx.showToast({
  132. title: '确认收款已提交',
  133. icon: 'none',
  134. duration: 2000
  135. })
  136. var confirmedTransferIds = that.data.confirmedTransferIds || {}
  137. confirmedTransferIds[item.id] = true
  138. that.setData({
  139. page: 1,
  140. cashList_more: true,
  141. cashList_change: true,
  142. confirmedTransferIds: confirmedTransferIds
  143. })
  144. that.getCashList()
  145. },
  146. fail: function (res) {
  147. var cashList = that.data.cashList
  148. if (cashList[index]) {
  149. cashList[index].can_confirm_transfer = true
  150. cashList[index].confirming_transfer = false
  151. that.setData({
  152. cashList: cashList
  153. })
  154. }
  155. wx.showToast({
  156. title: (res && res.errMsg) ? res.errMsg : '确认收款失败',
  157. icon: 'none',
  158. duration: 3000
  159. })
  160. }
  161. })
  162. },
  163. onShareAppMessage: function (val) {
  164. return _request.share({
  165. sc: 'xcx_user_withdraw'
  166. })
  167. }
  168. })