withdraw.js 2.9 KB

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