// pages/process/payment/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { getPeymentList, paymentOrder, getFactoryOrderInfo } from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const math = require('../../../utils/math') //导入模块 const app = getApp() Scene({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight, safeBottom: app.globalData.safeBottom, form: { status: 4, pageNum: 1, pageSize: 100 }, amount: 0, orderList: null, orderStatus: null, params: { settleType: '1', ids: [], payRemark: '' }, requesting: false, popup: false, show: false, detail: null }, /** * 生命周期函数--监听页面加载 */ 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({ height: app.globalData.fragmentHeight, 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.data.orderStatus = orderList[0].status this.setData({ height: app.globalData.fragmentHeight, safeBottom: app.globalData.safeBottom, orderList, amount, params: this.data.params, orderStatus: this.data.orderStatus }) } else { this.setData({ height: app.globalData.fragmentHeight, 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){ 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.showLoading({ title: '正在获取', mask: true }) getFactoryOrderInfo(item.id).then(result => { this.setData({ popup: true, detail: result.data }) wx.hideLoading() }).catch(err => { wx.hideLoading() util.showToast(err) }) }, bindInput: function (e) { this.data.params[e.target.id] = e.detail.value }, agentPayment: function(settleType){ if(Number(settleType) != 1 && Number(settleType) != 2){ settleType = 3 } wx.showLoading({ title: '正在处理', mask: true }) this.data.requesting = true this.data.params.settleType = settleType paymentOrder(this.data.params).then(result => { wx.hideLoading() if(!util.isEmpty(result.message)){ util.showBackToast(result.message) } else { 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 console.log(err) if(err.indexOf('用户未实名') >= 0){ Dialog.confirm({ title: '温馨提示', message: '您还没有实名认证,无法使用千鸟代付,现在去实名认证?' }).then(() => { wx.navigateTo({ url: '/pages/setting/authory/index' }) }).catch(err => { }) } else if(err.indexOf('客户未注册') >= 0){ Dialog.confirm({ title: '温馨提示', message: '该客户注册成为纸通宝用户,才可以使用千鸟代付,现在去注册?' }).then(() => { var cid = this.data.orderList[0].factoryCustomerId wx.navigateTo({ url: '/pages/client/registe/index?id=' + cid }) }).catch(err => { }) } else if(err.indexOf('没有开通代付') >= 0){ Dialog.confirm({ title: '温馨提示', message: '您还没有开通千鸟代付,现在去了解并开通?' }).then(() => { wx.navigateTo({ url: '/pages/htmls/auths/index' }) }).catch(err => { }) } else { util.showToast(err) } }) }, paymentOrder: function(){ if(this.data.requesting){ return } if(this.data.params.ids.length <= 0){ util.showToast('请选择要付款的订单') return } Dialog.confirm({ title: '温馨提示', message: '订单已经付款,在此进行确认?' }).then(() => { this.agentPayment(this.data.params.settleType) }).catch(err => { }) }, onPopupClose: function(){ this.setData({ popup: false, show: false}) }, viewImage: function (e) { var imgList = [] if(e.currentTarget.dataset.type == 0){ for (let index = 0; index < this.data.detail.totalWeighingPicture.length; index++) { imgList.push(this.data.detail.totalWeighingPicture[index].url) } } else { for (let index = 0; index < this.data.detail.emptyWeighingPicture.length; index++) { imgList.push(this.data.detail.emptyWeighingPicture[index].url) } } wx.previewImage({ urls: imgList, current: e.currentTarget.dataset.url }) } })