| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- var _request = require('../../../../utils/request.js')
- function formatWithdrawStateText (state) {
- if (state === 'WAIT_USER_CONFIRM') {
- return '待确认,确认后到帐'
- }
- return state || ''
- }
- function uniqueWithdrawList (list) {
- var result = []
- var seen = {}
- ;(list || []).forEach(function (item) {
- var key = item.order_id || item.id
- if (!key) {
- result.push(item)
- return
- }
- if (seen[key]) {
- return
- }
- seen[key] = true
- result.push(item)
- })
- return result
- }
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- price: '',
- page: 1,
- per_page: 10,
- cashList: [],
- cashList_more: true,
- cashList_change: false,
- cashTotal: 0,
- confirmedTransferIds: {}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.refreshCashList()
- },
- onShow () {
- if (getApp().globalData.withdrawChanged) {
- getApp().globalData.withdrawChanged = false
- this.refreshCashList()
- }
- },
- onPullDownRefresh: function () {
- this.setData({
- page: 1,
- cashList_more: true,
- cashList_change: true
- })
- this.getCashList()
- wx.stopPullDownRefresh()
- },
- onReachBottom: function () {
- if (this.data.cashList_more) {
- var page = this.data.page + 1
- this.setData({
- page: page
- })
- this.getCashList()
- }
- },
- refreshCashList () {
- this.setData({
- page: 1,
- cashList: [],
- cashList_more: true,
- cashList_change: false
- })
- this.getCashTotal()
- this.getCashList()
- },
- getCashTotal () {
- var that = this
- var url = 'v1/user/cash/balance/info'
- var params = {
- }
- var success = function (res) {
- that.setData({
- cashTotal: res.data
- })
- }
- _request.$get(url, params, success)
- },
- getCashList () {
- console.log(this.data.page)
- var that = this
- var requestPage = that.data.page
- var url = 'v1/user/takecash/flow'
- var params = {
- page: requestPage,
- per_page: that.data.per_page
- }
- var success = function (res) {
- var shouldReplace = requestPage === 1 || that.data.cashList_change
- if (that.data.cashList_change) {
- that.setData({
- cashList: [],
- cashList_change: false
- })
- }
- var confirmedTransferIds = that.data.confirmedTransferIds || {}
- var list = res.data.list || []
- list.forEach(function (item) {
- if (item.state_cn === 'WAIT_USER_CONFIRM') {
- item.state_cn = formatWithdrawStateText(item.state_cn)
- } else if (item.transfer_state === 'WAIT_USER_CONFIRM') {
- item.state_cn = formatWithdrawStateText(item.transfer_state)
- }
- if (confirmedTransferIds[item.id]) {
- item.can_confirm_transfer = false
- }
- })
- var result = uniqueWithdrawList((shouldReplace ? [] : that.data.cashList).concat(list))
- var listMore = res.data.list_count > result.length
- that.setData({
- cashList: result,
- cashList_more: listMore
- })
- }
- _request.$get(url, params, success)
- },
- confirmMerchantTransfer (e) {
- var that = this
- var index = e.currentTarget.dataset.index
- var item = that.data.cashList[index] || {}
- if (item.confirming_transfer) {
- return
- }
- if (!item.can_confirm_transfer || !item.package_info) {
- wx.showToast({
- title: '当前提现无需确认收款',
- icon: 'none',
- duration: 2000
- })
- return
- }
- if (!wx.canIUse || !wx.canIUse('requestMerchantTransfer')) {
- wx.showToast({
- title: '当前微信版本不支持确认收款,请升级微信',
- icon: 'none',
- duration: 2000
- })
- return
- }
- var cashList = that.data.cashList
- cashList[index].can_confirm_transfer = false
- cashList[index].confirming_transfer = true
- that.setData({
- cashList: cashList
- })
- wx.requestMerchantTransfer({
- mchId: String(item.mch_id || ''),
- appId: String(item.app_id || ''),
- package: item.package_info,
- success: function () {
- wx.showToast({
- title: '确认收款已提交',
- icon: 'none',
- duration: 2000
- })
- var confirmedTransferIds = that.data.confirmedTransferIds || {}
- confirmedTransferIds[item.id] = true
- getApp().globalData.withdrawChanged = true
- that.setData({
- page: 1,
- cashList_more: true,
- cashList_change: true,
- confirmedTransferIds: confirmedTransferIds
- })
- that.getCashList()
- },
- fail: function (res) {
- var cashList = that.data.cashList
- if (cashList[index]) {
- cashList[index].can_confirm_transfer = true
- cashList[index].confirming_transfer = false
- that.setData({
- cashList: cashList
- })
- }
- wx.showToast({
- title: (res && res.errMsg) ? res.errMsg : '确认收款失败',
- icon: 'none',
- duration: 3000
- })
- }
- })
- },
- onShareAppMessage: function (val) {
- return _request.share({
- sc: 'xcx_user_withdraw'
- })
- }
- })
|