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.
311 lines
10 KiB
311 lines
10 KiB
// pages/order/create/index.js
|
|
import { getVehicleList, getFactoryPriceDetail, getRelation, postRelation, getProxyOrderInfo, createProxyOrder } from "../../api/ztb"
|
|
const util = require('../../../utils/util')
|
|
const math = require('../../../utils/math')
|
|
const event = require('../../../utils/event.js')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
safeBottom: app.globalData.safeBottom,
|
|
form: {
|
|
paperCategoryId: '',
|
|
unitPrice: ''
|
|
},
|
|
timeList: [],
|
|
cateName: '',
|
|
factoryDetail: null,
|
|
vehicleList: [{}],
|
|
plateList: [],
|
|
vateList: [],
|
|
cateList: [],
|
|
plateNumber: '',
|
|
plateString: '',
|
|
vindex: -1,
|
|
picking: false,
|
|
requesting: false
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
if(options.activityId){
|
|
this.data.form.activityId = options.activityId
|
|
}
|
|
if(options.id){
|
|
this.data.form.paperCategoryId = options.categoryId
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
getVehicleList().then(result => {
|
|
this.data.plateList = result.data.records
|
|
if(this.data.plateList.length <= 7){
|
|
this.setData({ vateList: this.data.plateList })
|
|
} else {
|
|
this.data.vateList = this.data.plateList.slice(0, 7)
|
|
this.data.vateList.push({plateNumber: '查看更多', fold: 1})
|
|
this.setData({ vateList: this.data.vateList })
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
})
|
|
getFactoryPriceDetail(options.id).then(result => {
|
|
//成功回调
|
|
this.data.cateList = []
|
|
if(result.data.paperCategoryList && result.data.paperCategoryList.length){
|
|
for (let index = 0; index < result.data.paperCategoryList.length; index++) {
|
|
const element = result.data.paperCategoryList[index]
|
|
if(element.categoryId == options.categoryId){
|
|
if(options.unitPrice){
|
|
this.data.form.unitPrice = Number(options.unitPrice)
|
|
} else {
|
|
this.data.form.unitPrice = element.unitPrice
|
|
}
|
|
this.data.cateName = element.categoryName
|
|
}
|
|
if(!util.isEmpty(element.unitPrice)){
|
|
var unitPrice = math.times(element.unitPrice, 1000)
|
|
this.data.cateList.push({value: element.categoryId, text: element.categoryName + '(预估单价:' + unitPrice + '元/吨)'})
|
|
}
|
|
}
|
|
}
|
|
this.data.form.customerName = app.globalData.userInfo.realName
|
|
this.setData({
|
|
factoryDetail: result.data,
|
|
cateName: this.data.cateName,
|
|
form: this.data.form,
|
|
safeBottom: app.globalData.safeBottom
|
|
})
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
this.setData({ safeBottom: app.globalData.safeBottom })
|
|
util.showToast(err)
|
|
})
|
|
} else if(options.orderId){
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
getProxyOrderInfo(options.orderId).then(result => {
|
|
//成功回调
|
|
this.setData({
|
|
form: result.data,
|
|
cateName: result.data.paperCategory,
|
|
safeBottom: app.globalData.safeBottom,
|
|
['form.totalEstimatedWeight']: math.divide(result.data.estimatedWeight, 1000)
|
|
})
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
getRelation().then(result => {
|
|
if(util.isEmpty(result.data) || util.isEmpty(result.data.bizUserId)){
|
|
this.showDialog()
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
})
|
|
var day = new Date()
|
|
for (let i = 0; i < 7; i++) {
|
|
day.setDate(day.getDate() + (i > 1 ? 1 : i))
|
|
this.data.timeList.push({ value: (i + 1), text: util.formatDate(day, 'Y-M-D') })
|
|
}
|
|
},
|
|
showDialog: function(){
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
var that = this
|
|
this.wuxDialog.prompt({
|
|
resetOnClose: false,
|
|
maskClosable: false,
|
|
title: '邀请码',
|
|
content: '联系相关业务人员获取邀请码',
|
|
placeholder: '填写业务人员邀请码(必填)',
|
|
maxlength: 6,
|
|
onConfirm(e, response) {
|
|
if(util.isEmpty(response)){
|
|
util.showToast('请输入邀请码')
|
|
that.showDialog()
|
|
return
|
|
}
|
|
that.bindRelation(response)
|
|
},
|
|
onCancel(){
|
|
wx.navigateBack({ delta: 1 })
|
|
}
|
|
})
|
|
},
|
|
bindRelation: function(code){
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
postRelation(code).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
this.showDialog()
|
|
})
|
|
},
|
|
bindInput: function (event) {
|
|
var form_data = 'form.' + event.target.id
|
|
this.setData({ [form_data]: event.detail.value })
|
|
},
|
|
showKeyboard: function(e){
|
|
var item = this.data.vehicleList[e.currentTarget.dataset.index]
|
|
this.keyboard = this.keyboard || this.selectComponent('#wux-keyboard')
|
|
this.setData({ picking: true })
|
|
this.keyboard.show(item.plateNumber, e.currentTarget.dataset.index)
|
|
},
|
|
onPlatenumber: function({detail}){
|
|
if(detail && detail.plateNumber){
|
|
this.setData({ ['vehicleList[' + detail.type + '].plateNumber']: detail.plateNumber, picking: false })
|
|
} else {
|
|
this.setData({ picking: false })
|
|
}
|
|
},
|
|
addCate: function (e) {
|
|
if(this.data.vehicleList.length >= 5){
|
|
util.showToast('一次预约不能超过5辆车')
|
|
return
|
|
}
|
|
this.data.vehicleList.push({ plateNumber: '', driverName: '', driverPhone: '', packageNum: '' })
|
|
this.setData({ vehicleList: this.data.vehicleList })
|
|
},
|
|
deleteCate: function (e) {
|
|
this.data.vehicleList.splice(e.currentTarget.dataset.index, 1)
|
|
this.setData({ vehicleList: this.data.vehicleList })
|
|
},
|
|
bindList: function(event){
|
|
this.setData({ ['vehicleList[' + event.currentTarget.dataset.index + '].' + event.target.id]: event.detail.value })
|
|
},
|
|
showPicker: function (e) {
|
|
if(!util.isEmpty(this.data.form.activityId) && e.currentTarget.id == 'cateName'){
|
|
return
|
|
}
|
|
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
|
|
if(e.currentTarget.id == 'deliveryTime'){
|
|
this.pickerView.showPicker(this.data.timeList, null, 1)
|
|
} else if(e.currentTarget.id == 'cateName'){
|
|
this.pickerView.showPicker(this.data.cateList, this.data.form.paperCategoryId, 2)
|
|
}
|
|
this.setData({ picking: true })
|
|
},
|
|
onPickerChange: function ({detail}) {
|
|
this.setData({ picking: false })
|
|
if(!detail){
|
|
return
|
|
}
|
|
if(detail.type == 1){
|
|
this.setData({ ['form.deliveryTime']: detail.text })
|
|
} else if(detail.type == 2){
|
|
for (let index = 0; index < this.data.factoryDetail.paperCategoryList.length; index++) {
|
|
const element = this.data.factoryDetail.paperCategoryList[index]
|
|
if(element.categoryId == detail.value){
|
|
this.data.form.unitPrice = element.unitPrice
|
|
this.data.cateName = element.categoryName
|
|
break
|
|
}
|
|
}
|
|
this.data.form.paperCategoryId = detail.value
|
|
this.setData({ ['form.unitPrice']: this.data.form.unitPrice, cateName: this.data.cateName })
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
if(message.what == 402){
|
|
// this.setData({ pageIndex: 0 })
|
|
this.setData({ ['vehicleList[' + this.data.vindex + '].plateNumber']: message.obj.plateNumber,
|
|
['vehicleList[' + this.data.vindex + '].driverName']: message.obj.driverName,
|
|
['vehicleList[' + this.data.vindex + '].driverPhone']: message.obj.driverPhone })
|
|
}
|
|
},
|
|
tagChange: function(e){
|
|
var item = this.data.vateList[e.target.dataset.index]
|
|
if(item.fold == 1){
|
|
this.data.vateList = this.data.plateList.slice(0, 16)
|
|
// this.data.vateList.push({plateNumber: '收起', fold: 2})
|
|
this.setData({ vateList: this.data.vateList })
|
|
return
|
|
}
|
|
if(item.fold == 2){
|
|
this.data.vateList = this.data.plateList.slice(0, 7)
|
|
this.data.vateList.push({plateNumber: '展开', fold: 1})
|
|
this.setData({ vateList: this.data.vateList })
|
|
return
|
|
}
|
|
for (let index = 0; index < this.data.vehicleList.length; index++) {
|
|
if(this.data.vehicleList[index].plateNumber == item.plateNumber){
|
|
return
|
|
}
|
|
}
|
|
for (let index = 0; index < this.data.vehicleList.length; index++) {
|
|
if(util.isEmpty(this.data.vehicleList[index].plateNumber)){
|
|
this.setData({ ['vehicleList[' + index+ '].plateNumber']: item.plateNumber })
|
|
return
|
|
}
|
|
}
|
|
if(this.data.vehicleList.length >= 5){
|
|
util.showToast('一次预约不能超过5辆车')
|
|
return
|
|
}
|
|
this.data.vehicleList.push({plateNumber: item.plateNumber})
|
|
this.setData({ vehicleList: this.data.vehicleList })
|
|
},
|
|
submitForm: function (e) {
|
|
if (util.isEmpty(this.data.form.totalEstimatedWeight)) {
|
|
util.showToast('请输入预估重量')
|
|
return
|
|
}
|
|
if (Number(this.data.form.totalEstimatedWeight) <= 0) {
|
|
util.showToast('预估重量必须大于0')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.form.deliveryTime)) {
|
|
util.showToast('请选择货到时间')
|
|
return
|
|
}
|
|
var vehicleList = []
|
|
for (let index = 0; index < this.data.vehicleList.length; index++) {
|
|
const element = this.data.vehicleList[index]
|
|
if(!util.isEmpty(element.plateNumber)){
|
|
vehicleList.push(element)
|
|
}
|
|
}
|
|
if (vehicleList.length < 1) {
|
|
util.showToast('请选择或者输入车牌号码')
|
|
return
|
|
}
|
|
var that = this
|
|
wx.requestSubscribeMessage({
|
|
tmplIds: app.agentMsgIds,
|
|
success(res) {
|
|
that.data.form.totalEstimatedWeight = math.times(that.data.form.totalEstimatedWeight, 1000)
|
|
that.data.form.carInfos = vehicleList
|
|
that.setData({ requesting: true })
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
createProxyOrder(that.data.form).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
wx.redirectTo({ url: '/pages/agent/result/index' })
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
that.data.form.totalEstimatedWeight = math.divide(that.data.form.totalEstimatedWeight, 1000)
|
|
that.setData({ requesting: false })
|
|
})
|
|
}
|
|
})
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
|
|
})
|