// pages/process/order-check/index.js import Scene from '../../index/scene' import Dialog from '../../../components/dialog/dialog' import { pricingOrder, getFactoryOrderInfo, getPaperList} from "../../../api/saas" const event = require('../../../utils/event') const util = require('../../../utils/util') const app = getApp() Scene({ /** * 页面的初始数据 */ data: { safeBottom: app.globalData.safeBottom, paperList: null, form: { orderPapers: [{ productId: '', productName: '', unitPrice: ''}], appointDate: null }, columns: [], visible: false, cateIndex: -1, nowItem: null, column1: [], column4: [ { values: [], className: 'column1' }, { values: ['8:00~10:00', '10:00~12:00', '12:00~14:00', '14:00~16:00', '16:00~18:00', '18:00~20:00'], className: 'column2' } ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { wx.showLoading({ title: '正在获取', mask: true }) var day = new Date() for (let i = 0; i < 3; i++) { day.setDate(day.getDate() + (i > 1 ? 1 : i)) this.data.column4[0].values.push(util.formatDate(day, 'Y-M-D')) } getPaperList({pageNum: 1, pageSize: 100}).then(result => { this.data.paperList = result.data.records this.data.column1 = [] for (let index = 0; index < this.data.paperList.length; index++) { this.data.column1.push(this.data.paperList[index].name) } this.setData({ safeBottom: app.globalData.safeBottom }) if(!options.id){ wx.hideLoading() } }).catch(err => { this.setData({ safeBottom: app.globalData.safeBottom }) util.showToast(err) if(!options.id){ wx.hideLoading() } }) if(options.id){ getFactoryOrderInfo(options.id).then(result => { wx.hideLoading() this.setData({ form: result.data }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } }, chooseCustomer: function (e) { var that = this var events = {} events.onCallback = function(data){ if (data.what == 130) { that.data.form.factoryCustomerId = data.detail.id that.setData({ ['form.factoryCustomerName']: data.detail.name }) } } wx.navigateTo({url: `/pages/home/customer-list/index?type=1`, events}) }, chooseEmploy: function (e) { var that = this var events = {} events.onCallback = function(data){ if (data.what == 121 && e.currentTarget.id == 'driverName') { that.data.form.driverId = data.detail.id that.setData({ ['form.driverName']: data.detail.enterpriseMemberName }) } else if (data.what == 121 && e.currentTarget.id == 'operatorName') { that.data.form.operatorId = data.detail.id that.setData({ ['form.operatorName']: data.detail.enterpriseMemberName }) } } wx.navigateTo({url: `/pages/home/employee/index?type=1`, events}) }, showPlate: function (e) { this.keyboard = this.keyboard || this.selectComponent('#wux-keyboard') this.keyboard.show(this.data.form.plateNumber, 0) }, onPlatenumber: function({detail}){ if(detail && detail.plateNumber){ this.setData({ ['form.plateNumber']: detail.plateNumber }) } }, showCategory: function(e){ if(e.currentTarget.dataset.index >= 0){ this.data.cateIndex = e.currentTarget.dataset.index this.setData({ visible: true, columns: this.data.column1 }) } else { this.data.cateIndex = -1 this.setData({ visible: true, columns: this.data.column4 }) } }, onConfirm: function({detail}){ if(Array.isArray(detail.index)){ this.setData({ visible: false, ['form.appointDate']: (detail.value[0] + ' ' + detail.value[1]) }) } else { var nowItem = this.data.paperList[detail.index] for (var i = 0; i < this.data.form.orderPapers.length; i++) { if (this.data.form.orderPapers[i].productId == nowItem.id){ this.setData({ visible: false }) util.showToast('纸品已经存在,请不要重复添加') return } } var product = {productId: nowItem.id, productName: detail.value, unitPrice: nowItem.defaultUnitPrice} product.highestUnitPrice = nowItem.highestUnitPrice product.lowestUnitPrice = nowItem.lowestUnitPrice this.setData({ visible: false, ['form.orderPapers[' + this.data.cateIndex + ']']: product }) } }, onHide: function(){ this.setData({ visible: false }) }, bindInput: function (e) { this.data.form.orderPapers[e.currentTarget.dataset.index].unitPrice = e.detail.value }, onChange: function(e) { this.data.form.inspectionRemark = e.detail }, addCate: function(e){ this.data.form.orderPapers.push({ productId: '', productName: '', unitPrice: ''}) this.setData({ ['form.orderPapers']: this.data.form.orderPapers }) }, deleteCate: function(e){ this.data.form.orderPapers.splice(e.currentTarget.dataset.index, 1) this.setData({ ['form.orderPapers']: this.data.form.orderPapers }) }, 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 }, 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) }) }) }, 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) }) } })