| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- var _request = require('../../../../utils/request.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- price: '',
- page: 1,
- per_page: 10,
- cashList: [],
- cashList_more: true,
- cashList_change: false,
- cashTotal: 0,
- confirmedTransferIds: {}
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.getCashTotal()
- this.getCashList()
- },
- onShow () {
- },
- 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()
- }
- },
- 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 url = 'v1/user/takecash/flow'
- var params = {
- page: that.data.page,
- per_page: that.data.per_page
- }
- var success = function (res) {
- 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 (confirmedTransferIds[item.id]) {
- item.can_confirm_transfer = false
- }
- })
- var result = 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
- 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'
- })
- }
- })
|