纸通宝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.
 

240 lines
9.0 KiB

// pages/process/payment/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { getPeymentList, paymentOrder, getSideOrderInfo, getCustomerInfo } from "../../../api/saas"
const event = require('../../../utils/event')
const util = require('../../../utils/util')
const math = require('../../../utils/math') //导入模块
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
id: null,
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: []
},
settleType: '1',
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({ height: app.globalData.fragmentHeight, safeBottom: app.globalData.safeBottom })
util.showToast(err)
})
} else if(Number(options.channel) == 1){
let channel = this.getOpenerEventChannel()
let that = this
channel.on('onParam', function (data) {
that.amountList([data])
})
} else if(options.id){
this.data.id = options.id
wx.showLoading({ title: '正在获取', mask: true })
getSideOrderInfo({id: options.id}).then(result => {
this.data.amount = 0
var settleWeight = 0
var productName = ''
for (let index = 0; index < result.data.productCategoryInfos.length; index++) {
const element = result.data.productCategoryInfos[index]
if(util.isEmpty(productName)){
productName = element.productCategoryName
} else {
productName += ',' + element.productCategoryName
}
settleWeight = math.plus(element.settleWeight, settleWeight)
element.settlePrice = math.times(element.settleWeight, element.settleUnitPrice)
this.data.amount = math.plus(this.data.amount, element.settlePrice)
}
result.data.id = result.data.scrapPaperReceiptId
result.data.productName = productName
result.data.settleWeight = settleWeight
result.data.settlePrice = this.data.amount
this.setData({ orderList: [result.data], amount: this.data.amount, orderStatus: result.data.orderStatus })
this.fetchCustomerInfo(result.data)
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
},
fetchCustomerInfo: function(orderInfo){
getCustomerInfo(orderInfo.factoryCustomerId).then(result => {
wx.hideLoading()
this.data.params.bankCardNo = result.data.bankCardNo
this.data.settleType = '' + result.data.defaultPaymentMethod
this.data.params.ids = []
this.data.params.ids.push(orderInfo.scrapPaperReceiptId)
this.setData({ params: this.data.params })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
},
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(!util.isEmpty(element.bankCardNo)){
this.data.params.bankCardNo = element.bankCardNo
}
this.data.settleType = String(element.settleType)
}
this.data.orderStatus = orderList[0].status
this.setData({
height: app.globalData.fragmentHeight,
safeBottom: app.globalData.safeBottom,
orderList,
amount,
params: this.data.params,
settleType: this.data.settleType,
orderStatus: this.data.orderStatus
})
} else {
this.setData({ height: app.globalData.fragmentHeight, safeBottom: app.globalData.safeBottom })
}
},
onTypeChange: function({detail}){
this.setData({ settleType: detail })
},
onTypeClick(e) {
if(Number(e.currentTarget.dataset.name) == 2 && util.isEmpty(this.data.params.bankCardNo)){
util.showToast('暂无客户银行卡信息,无法进行银行卡转账')
return
}
this.setData({ 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]
if(!util.isEmpty(item.scrapPaperReceiptId)){
wx.navigateTo({ url: `/pages/process/outside-info/index?id=${item.scrapPaperReceiptId}` })
} else {
wx.navigateTo({ url: `/pages/process/order-info/index?id=${item.id}` })
}
},
bindInput: function (e) {
var form_data = 'params.' + e.currentTarget.id
this.setData({ [form_data]: e.detail })
},
agentPayment: function(settleType){
wx.showLoading({ title: '正在处理', mask: true })
this.data.requesting = true
this.data.params.settleType = Number(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
if((typeof err == 'object') && err.code == 200101){
Dialog.confirm({ title: '温馨提示', message: '该客户注册成为纸通宝用户,才可以使用千鸟代付,现在去注册?', confirmButtonText: '去注册' }).then(() => {
var cid = this.data.orderList[0].factoryCustomerId
wx.navigateTo({ url: '/pages/home/registe/index?id=' + cid })
}).catch(err => {
})
} else if(err.indexOf('用户未实名') >= 0){
Dialog.confirm({ title: '温馨提示', message: '您还没有实名认证,无法使用千鸟代付,现在去实名认证?', confirmButtonText: '去认证' }).then(() => {
wx.navigateTo({ url: '/pages/setting/authory/index' })
}).catch(err => {
})
} else if(err.indexOf('客户未注册') >= 0){
Dialog.confirm({ title: '温馨提示', message: '该客户注册成为纸通宝用户,才可以使用千鸟代付,现在去注册?', confirmButtonText: '去注册' }).then(() => {
var cid = this.data.orderList[0].factoryCustomerId
wx.navigateTo({ url: '/pages/home/registe/index?id=' + cid })
}).catch(err => {
})
} else if(err.indexOf('没有开通') >= 0){
Dialog.confirm({ title: '温馨提示', message: '您还没有开通千鸟代付,现在去了解并开通?', confirmButtonText: '去开通' }).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(() => {
if(Number(this.data.settleType) == 3) {
var that = this
wx.requestSubscribeMessage({
tmplIds: ['4IWtlcg1HhLN7AFepB3VeZF-4D0b9gbjwWBruKMhAJM', 'DJaSy0a5TNp9v_ICQ0ZY5-hkZ91dEXZuKq_hQVBTnOA'],
complete(res) {
that.agentPayment(that.data.settleType)
}
})
} else {
this.agentPayment(this.data.settleType)
}
}).catch(err => {
})
},
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 })
}
})