var _request = require('../../../../utils/request.js') var util = require('../../../../utils/util.js') var MAX_MERCHANT_TRANSFER_CASH = 20000 var TAKE_CASH_SUBSCRIBE_TEMPLATE_ID = "pmQeRrQUpBvt2jgDF4XwSEfDd7n2Gnyk8k_au1G6wP8" var PENDING_VIRTUAL_RECHARGE_ORDER_KEY = 'pendingVirtualRechargeOrderId' Page({ data: { page: 1, per_page: 20, list: [], more: true, balance: 0, confirmDialog:false, min_cash:0, max_cahs:0, fee:0, withdraw_num:0, view_withdraw:0, view_fee:0, syncingPendingRecharge:false }, onLoad: function (options) { this.getBalanceInfo() this.getBalanceList() // this.getCashTotal() }, onShow () { this.syncPendingVirtualRecharge() if (getApp().globalData.rechargeChanged) { getApp().globalData.rechargeChanged = false this.refreshBalancePage() } }, onReachBottom: function () { if (this.data.more) { var page = this.data.page + 1 this.setData({ page: page }) this.getBalanceList() } }, getBalanceInfo () { var that = this var url = 'v1/user/cash/balance/info' var params = { } var success = function (res) { var result = res.data.available that.setData({ balance: result, cashTotal: res.data }) that.getWithDrawlimit() } _request.$get(url, params, success) }, getBalanceList () { var that = this var url = 'v1/user/cash/balances' var params = { page: this.data.page, per_page: this.data.per_page } var success = function (res) { var result = that.data.list.concat(res.data.balance_list || []) that.setData({ list: result }) var listMore = res.data.balance_count > that.data.list.length that.setData({ more: listMore }) } _request.$get(url, params, success) }, refreshBalancePage () { this.setData({ page: 1, list: [], more: true }) this.getBalanceInfo() this.getBalanceList() }, syncPendingVirtualRecharge () { var that = this if (that.data.syncingPendingRecharge) { return } var url = 'v1/virtual_pay/recharge/sync_pending' var success = function (res) { that.setData({ syncingPendingRecharge: false }) if (res.data && res.data.synced_count > 0) { wx.removeStorageSync(PENDING_VIRTUAL_RECHARGE_ORDER_KEY) getApp().globalData.rechargeChanged = false wx.showToast({ title: '充值成功', icon: 'success', duration: 1000 }) that.refreshBalancePage() } } var fail = function () { that.setData({ syncingPendingRecharge: false }) } that.setData({ syncingPendingRecharge: true }) _request.$get(url, {}, success, fail) }, getDetail (val) { var id = val.currentTarget.dataset.val wx.navigateTo({ url: '/packageUser/pages/user/cashDetail/cashDetail?id=' + id }) }, onShareAppMessage: function (val) { return _request.share({ sc: 'xcx_user_radish' }) }, getCashTotal () { var that = this var url = 'v1/user/cash/balance/info' var params = { } var success = function (res) { console.log('res.data',res.data) that.setData({ cashTotal: res.data }) } _request.$get(url, params, success) }, getWithDrawlimit () { var that = this var url = 'v1/user/takecash/limit' var params = {} var success = function (res) { var maxCash = Math.min(res.data.max_limit_cash || MAX_MERCHANT_TRANSFER_CASH, MAX_MERCHANT_TRANSFER_CASH) var withdrawnum = that.data.balance > maxCash ? maxCash : that.data.balance; that.setData({ min_cash: res.data.min_limit_cash, max_cash: maxCash, fee:res.data.fee_bl ? res.data.fee_bl : 0, withdraw_num: withdrawnum, view_withdraw:parseFloat(withdrawnum/100).toFixed(2), view_fee:parseFloat(withdrawnum * (res.data.fee_bl?res.data.fee_bl/100:0)/100).toFixed(2) }) } _request.$get(url, params, success) }, goWithdrawClick () { wx.navigateTo({ url: '/packageUser/pages/user/withdraw/withdraw' }) }, getBankInfoAndTip(){ var that = this that.requestTakeCashSubscribe(function () { that.showWithdrawConfirm() }) }, showWithdrawConfirm () { var that = this // var url = 'v1/user/get_bank_info' // var params = { // } // var success = function (res) { // that.setData({ // has_bank:res.data.has_bank // }) // if(that.data.has_bank){ that.data.confirmDialog = !that.data.confirmDialog if (that.data.withdraw_num > that.data.min_cash) { that.setData({ confirmDialog: that.data.confirmDialog }) } else { wx.showToast({ title: '单次提现金额范围,大于'+parseFloat(that.data.min_cash/100).toFixed(2) +'元 单次最高'+parseFloat(that.data.max_cash/100).toFixed(2) +'元', icon: 'none', duration: 2000 }) } // } // _request.$get(url, params, success) }, confrimClick () { var that = this console.log('that.data.has_bank',that.data.has_bank) // if (that.data.has_bank) { that.withdrawClick() // } else { // that.setData({ // confirmDialog: false, // identityDialog: true // }) // } }, requestTakeCashSubscribe (done) { if (!wx.requestSubscribeMessage) { done && done() return } wx.requestSubscribeMessage({ tmplIds: [TAKE_CASH_SUBSCRIBE_TEMPLATE_ID], success: function (res) { console.log("take cash subscribe message", res) }, fail: function (res) { console.log("take cash subscribe message fail", res) }, complete: function () { done && done() } }) }, closedDialog () { var that = this that.setData({ confirmDialog: false }) }, withdrawClick () { var that = this var url = 'v1/user/takecash' var params = { amount: that.data.withdraw_num } var success = function (res) { if (res.data) { that.setData({ confirmDialog: false }) // that.data.lockWithdraw = false wx.showToast({ title: '提现成功~', icon: 'none', duration: 2000 }) getApp().globalData.withdrawChanged = true that.refreshBalancePage() that.getCashTotal() wx.navigateTo({ url: '/packageUser/pages/user/withdraw/withdraw' }) } } _request.$post(url, params, success) }, })