纸通宝SAAS仓库
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.
 

299 lines
11 KiB

import Scene from '../../index/scene'
import { getVehicleList, getFactoryPriceDetail, getRelation, postRelation, getProxyOrderInfo, createProxyOrder } from "../../../api/ztb"
const util = require('../../../utils/util')
const math = require('../../../utils/math')
const app = getApp()
Scene({
/**
* 页面的初始数据
*/
data: {
height: app.globalData.fragmentHeight,
safeBottom: app.globalData.safeBottom,
keyboardHeight: 0,
form: {
paperCategoryId: '',
unitPrice: ''
},
timeList: [],
cateName: '',
factoryDetail: null,
vehicleList: [{}],
plateList: [],
vateList: [],
cateList: [],
plateNumber: '',
plateString: '',
vindex: -1,
requesting: false,
columns: [],
toolbar: '',
toolId: '',
visible: false,
show: false,
code: ''
},
onLoad: function (options) {
if(options.activityId){
this.data.form.activityId = options.activityId
}
this.data.windowWidth = wx.getSystemInfoSync().windowWidth
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, height: app.globalData.fragmentHeight - app.globalData.safeBottom - 120 })
} else {
this.data.vateList = this.data.plateList.slice(0, 7)
this.data.vateList.push({plateNumber: '查看更多', fold: 1})
this.setData({ vateList: this.data.vateList, height: app.globalData.fragmentHeight - app.globalData.safeBottom - 120})
}
}).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 {
if(element.publicSubsidies && Number(element.publicSubsidies) > 0){
this.data.form.publicSubsidies = element.publicSubsidies
this.data.form.unitPrice = math.plus(element.unitPrice, element.publicSubsidies)
} else {
this.data.form.unitPrice = element.unitPrice
}
}
this.data.cateName = element.categoryName
}
if(!util.isEmpty(element.unitPrice)){
var unitPrice = math.times(element.unitPrice, 1000)
if(element.publicSubsidies && Number(element.publicSubsidies) > 0){
unitPrice = math.times(math.plus(element.unitPrice, element.publicSubsidies), 1000)
}
this.data.cateList.push(element.categoryName + '(预估单价:' + unitPrice + '元/吨)')
}
}
}
this.data.form.customerName = app.userInfo.realName
this.setData({ factoryDetail: result.data, cateName: this.data.cateName, form: this.data.form, safeBottom: app.globalData.safeBottom })
}).catch(err => {
this.setData({ safeBottom: app.globalData.safeBottom })
util.showToast(err)
})
getRelation().then(result => {
if(util.isEmpty(result.data) || util.isEmpty(result.data.bizUserId)){
this.dialog = this.dialog || this.selectComponent('#van-dialog')
this.dialog.stopLoading()
this.setData({ show: true })
}
wx.hideLoading()
}).catch(err => {
wx.hideLoading()
})
} 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)
})
}
var day = new Date()
for (let i = 0; i < 7; i++) {
day.setDate(day.getDate() + (i > 1 ? 1 : i))
this.data.timeList.push(util.formatDate(day, 'Y-M-D'))
}
},
onInput: function(e){
if(!util.isEmpty(e.currentTarget.id)){
var form_data = 'form.' + e.currentTarget.id
this.setData({ [form_data]: e.detail })
}
},
bindInput: function (e) {
if(!util.isEmpty(e.currentTarget.id)){
var form_data = 'form.' + e.currentTarget.id
if(e.currentTarget.id == 'remark'){
this.setData({ [form_data]: e.detail })
} else {
this.setData({ [form_data]: e.detail.value })
}
} else {
this.data.code = e.detail.value
}
},
showKeyboard: function(e){
var item = this.data.vehicleList[e.currentTarget.dataset.index]
this.keyboard = this.keyboard || this.selectComponent('#wux-keyboard')
this.keyboard.show(item.plateNumber, e.currentTarget.dataset.index)
},
onPlatenumber: function({detail}){
if(detail && detail.plateNumber){
this.setData({ ['vehicleList[' + detail.type + '].plateNumber']: detail.plateNumber })
}
},
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.data.toolId = e.currentTarget.id
if(e.currentTarget.id == 'deliveryTime'){
this.setData({ visible: true, columns: this.data.timeList, toolbar: '选择到货时间' })
} else if(e.currentTarget.id == 'cateName'){
this.setData({ visible: true, columns: this.data.cateList, toolbar: '选择纸品' })
}
},
onHide: function(){
this.setData({ visible: false })
},
onConfirm: function ({detail}) {
if(this.data.toolId == 'deliveryTime'){
this.setData({ ['form.deliveryTime']: detail.value, visible: false })
} else if(this.data.toolId == 'cateName'){
const element = this.data.factoryDetail.paperCategoryList[detail.index]
if(element.publicSubsidies && Number(element.publicSubsidies) > 0){
this.data.form.publicSubsidies = element.publicSubsidies
this.data.form.unitPrice = math.plus(element.unitPrice, element.publicSubsidies)
} else {
this.data.form.unitPrice = element.unitPrice
this.data.form.publicSubsidies = 0
}
this.data.cateName = element.categoryName
this.data.form.paperCategoryId = element.categoryId
this.setData({ ['form.unitPrice']: this.data.form.unitPrice, ['form.publicSubsidies']: this.data.form.publicSubsidies,
cateName: this.data.cateName, visible: false })
}
},
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(!app.userInfo.isAuth) {
// Dialog.alert({ title: '温馨提示', message: '您暂未实名认证,请实名认证后提交订单。' }).then(() => {
// wx.navigateTo({ url: '/pages/setting/authory/index' })
// })
// return
// }
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
}
this.data.form.carInfos = vehicleList
var that = this
wx.requestSubscribeMessage({
tmplIds: app.tmplIds,
complete(res) {
that.submitOrder()
}
})
},
submitOrder: function(){
if(this.data.requesting){
return
}
this.data.form.totalEstimatedWeight = math.times(this.data.form.totalEstimatedWeight, 1000)
this.setData({ requesting: true })
wx.showLoading({ title: '处理中', mask: true })
createProxyOrder(this.data.form).then(result => {
wx.hideLoading()
wx.redirectTo({ url: '/pages/agent/result/index' })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
this.data.form.totalEstimatedWeight = math.divide(this.data.form.totalEstimatedWeight, 1000)
this.setData({ requesting: false })
})
},
onCodeing: function(){
if(util.isEmpty(this.data.code)){
util.showToast('请输入邀请码')
this.dialog = this.dialog || this.selectComponent('#van-dialog')
this.dialog.stopLoading()
return
}
// this.setData({ requesting: true })
wx.showLoading({ title: '处理中', mask: true })
postRelation(this.data.code).then(result => {
wx.hideLoading()
this.setData({ show: false, requesting: false })
}).catch(err => {
wx.hideLoading()
util.showToast(err)
this.dialog = this.dialog || this.selectComponent('#van-dialog')
this.dialog.stopLoading()
})
}
})