| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- var _request = require('../../../../utils/request.js')
- var util = require('../../../../utils/util.js')
- var MAX_MERCHANT_TRANSFER_CASH = 20000
- 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,
- submittingTakeCash:false,
- transferConfirmDialog:false,
- pendingTakeCash:null,
- transferConfirming:false,
- transferCanceling: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.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
- // })
- // }
- },
- closedDialog () {
- var that = this
- that.setData({
- confirmDialog: false
- })
- },
- withdrawClick () {
- var that = this
- if (that.data.submittingTakeCash) {
- return
- }
- var url = 'v1/user/takecash'
- var params = {
- amount: that.data.withdraw_num
- }
- that.setData({
- submittingTakeCash: true
- })
- var success = function (res) {
- that.setData({
- submittingTakeCash: false
- })
- if (res.data) {
- that.setData({
- confirmDialog: false
- })
- if (res.data.can_confirm_transfer && res.data.package_info) {
- that.showTakeCashTransferConfirm(res.data)
- } else {
- that.finishTakeCashTransfer('提现成功~')
- }
- }
- }
- var fail = function () {
- that.setData({
- submittingTakeCash: false
- })
- }
- _request.$post(url, params, success, fail)
- },
- showTakeCashTransferConfirm (order) {
- this.setData({
- pendingTakeCash: order,
- transferConfirmDialog: true,
- transferConfirming: false,
- transferCanceling: false
- })
- },
- confirmTakeCashTransfer () {
- var that = this
- var order = that.data.pendingTakeCash || {}
- if (that.data.transferConfirming) {
- return
- }
- if (!order.package_info) {
- wx.showToast({
- title: '提现确认信息缺失,请稍后重试',
- icon: 'none',
- duration: 2000
- })
- return
- }
- if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
- wx.showToast({
- title: '当前微信版本不支持确认收款,请升级微信',
- icon: 'none',
- duration: 2000
- })
- return
- }
- that.setData({
- transferConfirming: true
- })
- wx.requestMerchantTransfer({
- mchId: String(order.mch_id || ''),
- appId: String(order.app_id || ''),
- package: order.package_info,
- success: function () {
- that.setData({
- transferConfirmDialog: false,
- pendingTakeCash: null,
- transferConfirming: false
- })
- that.finishTakeCashTransfer('确认收款已提交')
- },
- fail: function (res) {
- that.setData({
- transferConfirming: false
- })
- var errMsg = (res && res.errMsg) ? res.errMsg : ''
- wx.showToast({
- title: errMsg.indexOf('cancel') >= 0 ? '用户取消确认,可继续确认或取消提现' : '确认收款失败,请稍后重试',
- icon: 'none',
- duration: 3000
- })
- }
- })
- },
- cancelTakeCashTransfer () {
- var that = this
- var order = that.data.pendingTakeCash || {}
- if (that.data.transferCanceling) {
- return
- }
- if (!order.order_id && !order.id) {
- that.setData({
- transferConfirmDialog: false,
- pendingTakeCash: null
- })
- return
- }
- that.setData({
- transferCanceling: true
- })
- var params = {
- order_id: order.order_id || '',
- id: order.id || ''
- }
- var success = function () {
- that.setData({
- transferConfirmDialog: false,
- pendingTakeCash: null,
- transferCanceling: false
- })
- wx.showToast({
- title: '已取消提现',
- icon: 'none',
- duration: 2000
- })
- getApp().globalData.withdrawChanged = true
- that.refreshBalancePage()
- that.getCashTotal()
- }
- var fail = function () {
- that.setData({
- transferCanceling: false
- })
- }
- _request.$post('v1/user/takecash/cancel', params, success, fail)
- },
- finishTakeCashTransfer (title) {
- wx.showToast({
- title: title || '提现成功~',
- icon: 'none',
- duration: 2000
- })
- getApp().globalData.withdrawChanged = true
- this.refreshBalancePage()
- this.getCashTotal()
- wx.navigateTo({
- url: '/packageUser/pages/user/withdraw/withdraw'
- })
- },
- })
|