cash.js 4.8 KB

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