// 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: { safeBottom: app.globalData.safeBottom, paperList: null, form: null, columns: [] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ wx.showLoading({ title: '正在获取', mask: true }) getPaperList({pageNum: 1, pageSize: 100}).then(result => { this.data.paperList = result.data.records this.data.columns = [] for (let index = 0; index < this.data.paperList.length; index++) { this.data.columns.push(this.data.paperList[index].name) } this.setData({ safeBottom: app.globalData.safeBottom, columns: this.data.columns, paperList: this.data.paperList }) }).catch(err => { this.setData({ safeBottom: app.globalData.safeBottom }) 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) } 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) } } 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 weightNoteList = [] 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) + '项废纸品类结算单价') return } if(!util.isEmpty(this.data.form.scrapPaperReceiptId)){ var cate = this.findCateById(element.productId) console.log(cate) 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 + '元/公斤') return } if(element.lowestUnitPrice && Number(element.settleUnitPrice) < Number(element.lowestUnitPrice)){ util.showToast('第' + (index + 1) + '项废纸品类单价不得低于:' + element.lowestUnitPrice + '元/公斤') return } var item = { productId: element.productId, scrapPaperPurchaseOrderId: element.scrapPaperPurchaseOrderId } item.deductWeight = element.deductWeight item.deductPercent = element.deductPercent item.settleUnitPrice = element.settleUnitPrice weightNoteList.push(item) } repeatSideOrder({scrapPaperReceiptId: this.data.form.scrapPaperReceiptId, productCategorySettleInfoDtoList: weightNoteList }).then(result => { wx.hideLoading() event.emit('OrderMessage', { what: 12, desc: 'repeatSideOrder' }) util.showBackToast('订单审核已通过') }).catch(err => { wx.hideLoading() util.showToast(err) }) } })