cash.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. var _request = require('../../../../utils/request.js')
  2. var util = require('../../../../utils/util.js')
  3. var MAX_MERCHANT_TRANSFER_CASH = 20000
  4. var TAKE_CASH_SUBSCRIBE_TEMPLATE_ID = "pmQeRrQUpBvt2jgDF4XwSEfDd7n2Gnyk8k_au1G6wP8"
  5. Page({
  6. data: {
  7. page: 1,
  8. per_page: 20,
  9. list: [],
  10. more: true,
  11. balance: 0,
  12. confirmDialog:false,
  13. min_cash:0,
  14. max_cahs:0,
  15. fee:0,
  16. withdraw_num:0,
  17. view_withdraw:0,
  18. view_fee:0
  19. },
  20. onLoad: function (options) {
  21. this.getBalanceInfo()
  22. this.getBalanceList()
  23. // this.getCashTotal()
  24. },
  25. onShow () {
  26. },
  27. onReachBottom: function () {
  28. if (this.data.more) {
  29. var page = this.data.page + 1
  30. this.setData({
  31. page: page
  32. })
  33. this.getBalanceList()
  34. }
  35. },
  36. getBalanceInfo () {
  37. var that = this
  38. var url = 'v1/user/cash/balance/info'
  39. var params = {
  40. }
  41. var success = function (res) {
  42. var result = res.data.available
  43. that.setData({
  44. balance: result,
  45. cashTotal: res.data
  46. })
  47. that.getWithDrawlimit()
  48. }
  49. _request.$get(url, params, success)
  50. },
  51. getBalanceList () {
  52. var that = this
  53. var url = 'v1/user/cash/balances'
  54. var params = {
  55. page: this.data.page,
  56. per_page: this.data.per_page
  57. }
  58. var success = function (res) {
  59. var result = that.data.list.concat(res.data.balance_list || [])
  60. that.setData({
  61. list: result
  62. })
  63. var listMore = res.data.balance_count > that.data.list.length
  64. that.setData({
  65. more: listMore
  66. })
  67. }
  68. _request.$get(url, params, success)
  69. },
  70. getDetail (val) {
  71. var id = val.currentTarget.dataset.val
  72. wx.navigateTo({
  73. url: '/packageUser/pages/user/cashDetail/cashDetail?id=' + id
  74. })
  75. },
  76. onShareAppMessage: function (val) {
  77. return _request.share({
  78. sc: 'xcx_user_radish'
  79. })
  80. },
  81. getCashTotal () {
  82. var that = this
  83. var url = 'v1/user/cash/balance/info'
  84. var params = {
  85. }
  86. var success = function (res) {
  87. console.log('res.data',res.data)
  88. that.setData({
  89. cashTotal: res.data
  90. })
  91. }
  92. _request.$get(url, params, success)
  93. },
  94. getWithDrawlimit () {
  95. var that = this
  96. var url = 'v1/user/takecash/limit'
  97. var params = {}
  98. var success = function (res) {
  99. var maxCash = Math.min(res.data.max_limit_cash || MAX_MERCHANT_TRANSFER_CASH, MAX_MERCHANT_TRANSFER_CASH)
  100. var withdrawnum = that.data.balance > maxCash ? maxCash : that.data.balance;
  101. that.setData({
  102. min_cash: res.data.min_limit_cash,
  103. max_cash: maxCash,
  104. fee:res.data.fee_bl ? res.data.fee_bl : 0,
  105. withdraw_num: withdrawnum,
  106. view_withdraw:parseFloat(withdrawnum/100).toFixed(2),
  107. view_fee:parseFloat(withdrawnum * (res.data.fee_bl?res.data.fee_bl/100:0)/100).toFixed(2)
  108. })
  109. }
  110. _request.$get(url, params, success)
  111. },
  112. goWithdrawClick () {
  113. wx.navigateTo({
  114. url: '/packageUser/pages/user/withdraw/withdraw'
  115. })
  116. },
  117. getBankInfoAndTip(){
  118. var that = this
  119. that.requestTakeCashSubscribe(function () {
  120. that.showWithdrawConfirm()
  121. })
  122. },
  123. showWithdrawConfirm () {
  124. var that = this
  125. // var url = 'v1/user/get_bank_info'
  126. // var params = {
  127. // }
  128. // var success = function (res) {
  129. // that.setData({
  130. // has_bank:res.data.has_bank
  131. // })
  132. // if(that.data.has_bank){
  133. that.data.confirmDialog = !that.data.confirmDialog
  134. if (that.data.withdraw_num > that.data.min_cash) {
  135. that.setData({
  136. confirmDialog: that.data.confirmDialog
  137. })
  138. } else {
  139. wx.showToast({
  140. title: '单次提现金额范围,大于'+parseFloat(that.data.min_cash/100).toFixed(2) +'元 单次最高'+parseFloat(that.data.max_cash/100).toFixed(2) +'元',
  141. icon: 'none',
  142. duration: 2000
  143. })
  144. }
  145. // }
  146. // _request.$get(url, params, success)
  147. },
  148. confrimClick () {
  149. var that = this
  150. console.log('that.data.has_bank',that.data.has_bank)
  151. // if (that.data.has_bank) {
  152. that.withdrawClick()
  153. // } else {
  154. // that.setData({
  155. // confirmDialog: false,
  156. // identityDialog: true
  157. // })
  158. // }
  159. },
  160. requestTakeCashSubscribe (done) {
  161. if (!wx.requestSubscribeMessage) {
  162. done && done()
  163. return
  164. }
  165. wx.requestSubscribeMessage({
  166. tmplIds: [TAKE_CASH_SUBSCRIBE_TEMPLATE_ID],
  167. success: function (res) {
  168. console.log("take cash subscribe message", res)
  169. },
  170. fail: function (res) {
  171. console.log("take cash subscribe message fail", res)
  172. },
  173. complete: function () {
  174. done && done()
  175. }
  176. })
  177. },
  178. closedDialog () {
  179. var that = this
  180. that.setData({
  181. confirmDialog: false
  182. })
  183. },
  184. withdrawClick () {
  185. var that = this
  186. var url = 'v1/user/takecash'
  187. var params = {
  188. amount: that.data.withdraw_num
  189. }
  190. var success = function (res) {
  191. if (res.data) {
  192. that.setData({
  193. confirmDialog: false
  194. })
  195. // that.data.lockWithdraw = false
  196. wx.showToast({
  197. title: '提现成功~',
  198. icon: 'none',
  199. duration: 2000
  200. })
  201. that.getBalanceInfo()
  202. that.getBalanceList()
  203. that.getCashTotal()
  204. that.getWithDrawlimit()
  205. wx.navigateTo({
  206. url: '/packageUser/pages/user/withdraw/withdraw'
  207. })
  208. }
  209. }
  210. _request.$post(url, params, success)
  211. },
  212. })