纸通宝SAAS仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

127 lines
4.1 KiB

// pages/process/payment/index.js
import Dialog from '../../../components/dialog/dialog'
import { getPeymentList, paymentOrder } from "../../../api/saas"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const math = require('../../../utils/math') //导入模块
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
safeBottom: app.globalData.safeBottom,
form: {
status: 4,
pageNum: 1,
pageSize: 100
},
amount: 0,
orderList: null,
params: {
settleType: '1',
ids: [],
payRemark: ''
},
requesting: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.mobile){
this.data.form.mobile = options.mobile
wx.showLoading({ title: '正在获取', mask: true })
getPeymentList(this.data.form).then(result => {
wx.hideLoading()
this.amountList(result.data.records)
}).catch(err => {
wx.hideLoading()
this.setData({ safeBottom: app.globalData.safeBottom })
util.showToast(err)
})
} else if(options.channel){
let channel = this.getOpenerEventChannel()
let that = this
channel.on('onParam', function (data) {
that.amountList([data])
})
}
},
amountList: function(orderList){
var amount = 0
this.data.params.ids = []
if (orderList && orderList.length) {
for (let index = 0; index < orderList.length; index++) {
const element = orderList[index]
amount = math.plus(amount, element.settlePrice)
this.data.params.ids.push(element.id)
if(index == 0 && Number(element.settleType) == 2 && !util.isEmpty(element.bankCardNo)){
this.data.params.settleType = '2'
this.data.params.bankCardNo = element.bankCardNo
}
}
this.setData({ safeBottom: app.globalData.safeBottom, orderList, amount, params: this.data.params })
} else {
this.setData({ safeBottom: app.globalData.safeBottom })
}
},
onTypeChange: function({detail}){
this.setData({ ['params.settleType']: detail })
},
onTypeClick(e) {
if(Number(e.currentTarget.dataset.name == 2) && util.isEmpty(this.data.params.bankCardNo)){
util.showToast('暂无客户银行卡信息,无法进行银行卡转账')
return
}
this.setData({ ['params.settleType']: e.currentTarget.dataset.name })
},
onChange: function(e){
console.log(e.detail)
var item = this.data.orderList[e.currentTarget.dataset.index]
item.checked = !e.detail
var amount = 0
this.data.params.ids = []
for (let index = 0; index < this.data.orderList.length; index++) {
if(!this.data.orderList[index].checked){
amount = math.plus(amount, this.data.orderList[index].settlePrice)
this.data.params.ids.push(this.data.orderList[index].id)
}
}
this.setData({ ['orderList[' + e.currentTarget.dataset.index + '].checked']: !e.detail, amount })
},
lookItem: function(e){
var item = this.data.orderList[e.currentTarget.dataset.index]
// wx.navigateTo({ url: `/pages/process/order-info/index?id=${item.id}` })
},
bindInput: function (e) {
this.data.params[e.target.id] = e.detail.value
},
paymentOrder: function(){
if(this.data.requesting){
return
}
if(this.data.params.ids.length <= 0){
util.showToast('请选择要付款的订单')
return
}
Dialog.confirm({ title: '温馨提示', message: '确定要付款吗?' }).then(() => {
wx.showLoading({ title: '正在获取', mask: true })
this.data.requesting = true
this.data.params.settleType = Number(this.data.params.settleType)
paymentOrder(this.data.params).then(result => {
wx.hideLoading()
util.showBackToast('订单已经付款')
const channel = this.getOpenerEventChannel()
channel.emit('onOrderChange', { what: 12, desc: 'PaymentOrder' })
event.emit('OrderMessage', { what: 12, desc: 'PaymentOrder' })
}).catch(err => {
wx.hideLoading()
this.data.requesting = false
util.showToast(err)
})
}).catch(err => {
})
}
})