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.
222 lines
7.9 KiB
222 lines
7.9 KiB
// pages/process/order-check/index.js
|
|
import Scene from '../../index/scene'
|
|
import Dialog from '../../../components/dialog/dialog'
|
|
import { createSideOrder, getSideOrderInfo, editSideOrder, getPaperList, cancelOrder} from "../../../api/saas"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
paperList: null,
|
|
form: {
|
|
productCategoryInfos: [{ productId: '', productCategoryName: '', unitPrice: ''}],
|
|
predictDeliveryToFactoryTime: null
|
|
},
|
|
columns: [],
|
|
visible: false,
|
|
visible2: false,
|
|
cateIndex: -1,
|
|
nowItem: null,
|
|
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
|
|
if(!options.id){
|
|
wx.hideLoading()
|
|
}
|
|
}).catch(err => {
|
|
util.showToast(err)
|
|
if(!options.id){
|
|
wx.hideLoading()
|
|
}
|
|
})
|
|
if(options.id){
|
|
getSideOrderInfo({id: 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.enterpriseMemberId
|
|
that.setData({ ['form.driverName']: data.detail.enterpriseMemberName })
|
|
} else if (data.what == 121 && e.currentTarget.id == 'operatorName') {
|
|
that.data.form.operatorId = data.detail.enterpriseMemberId
|
|
that.setData({ ['form.operatorName']: data.detail.enterpriseMemberName })
|
|
}
|
|
}
|
|
wx.navigateTo({url: `/pages/home/employee/index?type=1`, events})
|
|
},
|
|
showPlate: function (e) {
|
|
var that = this
|
|
var events = {}
|
|
events.onCallback = function(data){
|
|
that.data.form.driverId = data.detail.driverId
|
|
that.setData({ ['form.plateNumber']: data.detail.plateNumber, ['form.driverName']: data.detail.driverName })
|
|
}
|
|
wx.navigateTo({url: `/pages/setting/vehicle-list/index?type=1`, events})
|
|
},
|
|
showCategory: function(e){
|
|
if(e.currentTarget.dataset.index >= 0){
|
|
this.setData({ visible2: true, paperList: this.data.paperList, cateIndex: e.currentTarget.dataset.index })
|
|
} else {
|
|
this.setData({ visible: true, columns: this.data.column4, cateIndex: -1 })
|
|
}
|
|
},
|
|
onConfirm: function({detail}){
|
|
this.setData({ visible: false, ['form.predictDeliveryToFactoryTime']: (detail.value[0] + ' ' + detail.value[1]) })
|
|
},
|
|
onCateConfirm: function(e){
|
|
this.data.cIndex = e.currentTarget.dataset.index
|
|
var nowItem = this.data.paperList[this.data.cIndex]
|
|
for (var index = 0; index < this.data.form.productCategoryInfos.length; index++) {
|
|
if (this.data.form.productCategoryInfos[index].productId == nowItem.id && this.data.cateIndex != index){
|
|
this.setData({ visible: false })
|
|
util.showToast('纸品已经存在,请不要重复添加')
|
|
return
|
|
}
|
|
}
|
|
var product = {productId: nowItem.id, productCategoryName: nowItem.categoryName, unitPrice: nowItem.defaultUnitPrice}
|
|
product.highestUnitPrice = nowItem.highestUnitPrice
|
|
product.lowestUnitPrice = nowItem.lowestUnitPrice
|
|
this.setData({ visible2: false, ['form.productCategoryInfos[' + this.data.cateIndex + ']']: product })
|
|
},
|
|
onHide: function(){
|
|
this.setData({ visible: false, visible2: false })
|
|
},
|
|
bindInput: function (e) {
|
|
this.data.form.productCategoryInfos[e.currentTarget.dataset.index].unitPrice = e.detail
|
|
},
|
|
onChange: function({detail}) {
|
|
this.data.form.equipmentRemark = detail
|
|
},
|
|
addCate: function(e){
|
|
this.data.form.productCategoryInfos.push({ productId: '', productCategoryName: '', unitPrice: ''})
|
|
this.setData({ ['form.productCategoryInfos']: this.data.form.productCategoryInfos })
|
|
},
|
|
deleteCate: function(e){
|
|
this.data.form.productCategoryInfos.splice(e.currentTarget.dataset.index, 1)
|
|
this.setData({ ['form.productCategoryInfos']: this.data.form.productCategoryInfos })
|
|
},
|
|
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.scrapPaperReceiptId).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.productCategoryInfos.length; index++) {
|
|
const element = this.data.form.productCategoryInfos[index]
|
|
if(util.isEmpty(element.productId)){
|
|
util.showToast('请选择第' + (index + 1) + '项品类')
|
|
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.unitPrice) > Number(element.highestUnitPrice)){
|
|
util.showToast('第' + (index + 1) + '项品类单价不得高于:' + element.highestUnitPrice + '元/公斤')
|
|
return
|
|
}
|
|
if(element.lowestUnitPrice && Number(element.unitPrice) < Number(element.lowestUnitPrice)){
|
|
util.showToast('第' + (index + 1) + '项品类单价不得低于:' + element.lowestUnitPrice + '元/公斤')
|
|
return
|
|
}
|
|
}
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
if(this.data.form.scrapPaperReceiptId){
|
|
editSideOrder(this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
util.showToast('修改订单成功')
|
|
wx.redirectTo({ url: `/pages/process/outside-price/index?id=${this.data.form.scrapPaperReceiptId}` })
|
|
event.emit('OrderMessage', { what: 12, desc: 'createSideOrder' })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
} else {
|
|
createSideOrder(this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
util.showBackToast('创建订单成功')
|
|
event.emit('OrderMessage', { what: 12, desc: 'createSideOrder' })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
|
|
}
|
|
})
|