// pages/process/order-check/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { poundSideOrder, getSideOrderInfo} 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, form: null, param: { scrapPaperReceiptId: null, offsiteGrossWeight: null, offsiteTareWeight: null, } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ this.data.id = options.id this.fetchOrderInfo() } }, fetchOrderInfo: function(){ wx.showLoading({ title: '正在获取', mask: true }) getSideOrderInfo({id: this.data.id}).then(result => { wx.hideLoading() this.data.param.offsiteGrossWeight = result.data.offsiteGrossWeight this.data.param.offsiteTareWeight = result.data.offsiteTareWeight this.setData({ form: result.data, admin: app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0 }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, onProductChange: function({detail}){ this.data.form.productCategoryInfos[detail.index] = detail.item var netWeight = 0 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.netWeight) && Number(element.netWeight) > 0){ netWeight = math.plus(netWeight, element.netWeight) } if(!util.isEmpty(element.estimatedAmount) && Number(element.estimatedAmount) > 0){ estimatedAmount = math.plus(estimatedAmount, element.estimatedAmount) } } this.setData({ ['form.netWeight']: netWeight, ['form.estimatedAmount']: estimatedAmount.toFixed(2) }) }, bindInput: function (e) { this.data.param[e.currentTarget.id] = e.detail.value }, cancelForm: function(e){ Dialog.confirm({ title: '温馨提示', message: '确定取消该订单?' }).then(() => { wx.showLoading({ title: '处理中', mask: true }) cancelOrder(this.data.form.id).then(result => { wx.hideLoading() util.showBackToast('订单已经删除') event.emit('OrderMessage', { what: 12, desc: 'cancelOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }) }, eidtForm: function(){ wx.redirectTo({url: `/pages/process/outside-add/index?id=${this.data.id}` }) }, saveForm: function(){ var weightNoteList = [] for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) { const element = this.data.form.productCategoryInfos[index] var item = {grossWeight: element.grossWeight, tareWeight: element.tareWeight,weightNoteImage: element.weightNoteImage } item.scrapPaperPurchaseOrderId = element.scrapPaperPurchaseOrderId weightNoteList.push(item) } this.data.param.weightNoteList = weightNoteList wx.showLoading({ title: '处理中', mask: true }) poundSideOrder(this.data.param).then(result => { wx.hideLoading() util.showBackToast('保存成功') event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, submitForm: function(){ if(util.isEmpty(this.data.param.offsiteGrossWeight)){ util.showToast('请输入厂外毛重') return } if(util.isEmpty(this.data.param.offsiteTareWeight)){ util.showToast('请输入厂外皮重') return } var weightNoteList = [] for (let index = 0; index < this.data.form.productCategoryInfos.length; index++) { const element = this.data.form.productCategoryInfos[index] if(util.isEmpty(element.grossWeight)){ util.showToast('请输入第' + (index + 1) + '项废纸品类毛重') return } if(util.isEmpty(element.weightNoteImage)){ util.showToast('请上传第' + (index + 1) + '项废纸品类过磅凭证') return } if(element.weightNoteImage.length < 3){ util.showToast('每个品类过磅凭证图片必须3张以上') return } var item = {grossWeight: element.grossWeight, tareWeight: element.tareWeight,weightNoteImage: element.weightNoteImage } item.scrapPaperPurchaseOrderId = element.scrapPaperPurchaseOrderId weightNoteList.push(item) } this.data.param.scrapPaperReceiptId = this.data.form.scrapPaperReceiptId this.data.param.weightNoteList = weightNoteList wx.showLoading({ title: '处理中', mask: true }) poundSideOrder(this.data.param).then(result => { wx.hideLoading() util.showBackToast('提交成功') event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) }, repeatForm: function(){ wx.redirectTo({url: `/pages/process/outside-check/index?id=${this.data.id}` }) }, priceForm: function(){ }, checkForm: function(){ } })