// pages/process/order-check/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { pricingOrder, getFactoryOrderInfo} from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { form: { orderPapers: [{ productId: '', productName: '', unitPrice: ''}], appointDate: null } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if(options.id){ wx.showLoading({ title: '正在获取', mask: true }) getFactoryOrderInfo(options.id).then(result => { wx.hideLoading() this.setData({ form: result.data, admin: app.userInfo.type && app.userInfo.type.indexOf('ADMIN') >= 0 }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } }, bindInput: function (e) { this.data.form.orderPapers[e.currentTarget.dataset.index].unitPrice = e.detail.value }, cancelOrder: 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) }) }) }, fileChange: function({detail}){ console.log(detail) }, submitForm: function(){ if(util.isEmpty(this.data.form.factoryCustomerName)){ util.showToast('请选择客户') return } if(util.isEmpty(this.data.form.plateNumber)){ util.showToast('请输入车牌号码') return } if(util.isEmpty(this.data.form.driverName)){ util.showToast('请选择司机') return } for (let index = 0; index < this.data.form.orderPapers.length; index++) { const element = this.data.form.orderPapers[index] if(util.isEmpty(element.productId)){ util.showToast('请选择第' + (index + 1) + '项废纸品类') return } if(!util.isEmpty(this.data.form.id)){ var cate = this.findCateById(element.productId) if(cate){ element.highestUnitPrice = cate.highestUnitPrice element.lowestUnitPrice = cate.lowestUnitPrice } } if(element.highestUnitPrice && Number(element.unitPrice) > Number(element.highestUnitPrice)){ util.showToast('第' + (index + 1) + '项废纸品类单价过高,价格范围:' + element.lowestUnitPrice + '元/公斤-'+ element.highestUnitPrice + '元/公斤') return } if(element.lowestUnitPrice && Number(element.unitPrice) < Number(element.lowestUnitPrice)){ util.showToast('第' + (index + 1) + '项废纸品类单价过低,价格范围:' + element.lowestUnitPrice + '元/公斤-'+ element.highestUnitPrice + '元/公斤') return } } wx.showLoading({ title: '处理中', mask: true }) pricingOrder(this.data.form).then(result => { wx.hideLoading() util.showBackToast('定价成功') event.emit('OrderMessage', { what: 12, desc: 'pricingOrder' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } })