// 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: { 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() var amount = 0 this.data.params.ids = [] if (result.data && result.data.records.length) { for (let index = 0; index < result.data.records.length; index++) { amount = math.plus(amount, result.data.records[index].settlePrice) this.data.params.ids.push(result.data.records[index].id) } this.setData({ safeBottom: app.globalData.safeBottom, orderList: result.data.records, amount }) } else { this.setData({ safeBottom: app.globalData.safeBottom }) } }).catch(err => { wx.hideLoading() this.setData({ safeBottom: app.globalData.safeBottom }) util.showToast(err) }) }, lookItem: function(e){ var item = this.data.orderList[e.currentTarget.dataset.index] item.checked = !item.checked 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']: item.checked, amount }) }, 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 paymentOrder(this.data.params).then(result => { wx.hideLoading() util.showBackToast('订单已经付款') event.emit('OrderMessage', { what: 12, desc: 'cancelOrder' }) }).catch(err => { wx.hideLoading() this.data.requesting = false util.showToast(err) }) }).catch(err => { }) } })