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

132 lines
5.4 KiB

// pages/process/order-check/index.js
import Scene from '../../index/scene'
import Dialog from '../../../components/dialog/dialog'
import { repeatSideOrder, getPaperList, getSideOrderInfo} 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,
paperList: [],
form: null,
intoview: ''
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if(options.id){
var height = app.globalData.fragmentHeight - app.globalData.safeBottom - 120
wx.showLoading({ title: '正在获取', mask: true })
getPaperList({pageNum: 1, pageSize: 100}).then(result => {
this.setData({ safeBottom: app.globalData.safeBottom, paperList: result.data.records, height })
}).catch(err => {
this.setData({ safeBottom: app.globalData.safeBottom, height })
util.showToast(err)
})
getSideOrderInfo({ id: options.id }).then(result => {
result.data.settleTotalAmount = 0
for (let index = 0; index < result.data.productCategoryInfos.length; index++) {
const element = result.data.productCategoryInfos[index]
element.settlePrice = math.times(element.settleWeight, element.settleUnitPrice)
result.data.settleTotalAmount = math.plus(result.data.settleTotalAmount, element.settlePrice)
}
if(app.userInfo.factory.settlePriceType == 2){
result.data.settleTotalAmount = Math.floor(result.data.settleTotalAmount)
} else if(app.userInfo.factory.settlePriceType == 3){
result.data.settleTotalAmount = math.round(result.data.settleTotalAmount, 0)
}
this.setData({ form: result.data })
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
},
onProductChange: function({detail}){
this.data.form.productCategoryInfos[detail.index] = detail.item
var estimatedAmount = 0
for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) {
const element = this.data.form.productCategoryInfos[index]
if(!util.isEmpty(element.settlePrice) && Number(element.settlePrice) > 0){
estimatedAmount = math.plus(estimatedAmount, element.settlePrice)
}
}
if(app.userInfo.factory.settlePriceType == 2){
estimatedAmount = Math.floor(estimatedAmount)
} else if(app.userInfo.factory.settlePriceType == 3){
estimatedAmount = math.round(estimatedAmount, 0)
}
this.setData({ ['form.settleTotalAmount']: estimatedAmount.toFixed(2) })
},
checkForm: function(){
if(this.data.form.onsideGrossWeight) {
this.checkOrder()
} else {
var message = '此订单没有厂内毛重数据,按照正常流程请刷卡过磅,获取厂内毛重数据,如果已经无法获取,请仔细查验品类和相关数据,确定没有问题后,进行审核。'
Dialog.confirm({ title: '温馨提示', message, confirmButtonText: '确定审核' }).then(() => {
this.checkOrder()
})
}
},
findCateById: function(productId){
for (let index = 0; index < this.data.paperList.length; index++) {
const element = this.data.paperList[index]
if(element.id == productId){
return element
}
}
return null
},
checkOrder: function(){
var productCategorySettleInfoDtoList = []
for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) {
const element = this.data.form.productCategoryInfos[index]
if(util.isEmpty(element.settleUnitPrice) || Number(element.settleUnitPrice) <= 0){
util.showToast('请输入第' + (index + 1) + '项收货品类结算单价')
this.setData({ intoview: 'item' + index })
return
}
if(!util.isEmpty(this.data.form.scrapPaperReceiptId)){
var cate = this.findCateById(element.productId)
if(cate){
element.highestUnitPrice = cate.highestUnitPrice
element.lowestUnitPrice = cate.lowestUnitPrice
}
}
if(element.highestUnitPrice && Number(element.settleUnitPrice) > Number(element.highestUnitPrice)){
util.showToast('第' + (index + 1) + '项收货品类单价不得高于:' + element.highestUnitPrice + '元/公斤')
this.setData({ intoview: 'item' + index })
return
}
var item = { productId: element.productId, scrapPaperPurchaseOrderId: element.scrapPaperPurchaseOrderId }
item.deductWeight = element.deductWeight
item.deductPercent = element.deductPercent
item.settleUnitPrice = element.settleUnitPrice
productCategorySettleInfoDtoList.push(item)
}
var that = this
wx.requestSubscribeMessage({
tmplIds: ['DJaSy0a5TNp9v_ICQ0ZY5-hkZ91dEXZuKq_hQVBTnOA', '4IWtlcg1HhLN7AFepB3VeZF-4D0b9gbjwWBruKMhAJM'],
complete(res) {
wx.showLoading({ title: '处理中', mask: true })
repeatSideOrder({scrapPaperReceiptId: that.data.form.scrapPaperReceiptId, productCategorySettleInfoDtoList }).then(result => {
wx.hideLoading()
event.emit('OrderMessage', { what: 12, desc: 'repeatSideOrder' })
util.showBackToast('订单审核已通过')
}).catch(err => {
wx.hideLoading()
util.showToast(err)
})
}
})
}
})