withdraw.js 3.9 KB

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