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.
274 lines
8.7 KiB
274 lines
8.7 KiB
// pages/order/create/index.js
|
|
const request = require('../../../utils/request'); //导入模块
|
|
const util = require('../../../utils/util');
|
|
const event = require('../../../utils/event.js')
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
form: {
|
|
centerId: null,
|
|
latitude: 0,
|
|
longitude: 0,
|
|
provinceId: '',
|
|
cityId: '',
|
|
regionId: '',
|
|
districtId: '',
|
|
fullAddress: '',
|
|
poiName: '',
|
|
streetNumber: '',
|
|
appointDate: '',
|
|
appointTimePeriodStr: '',
|
|
appointTimePeriod: '',
|
|
remark: '',
|
|
orderPapers: [],
|
|
vehicleTypeDemand: -1,
|
|
settlementType: 0,
|
|
weightType: -1,
|
|
shippingType: -1,
|
|
maxVehicleType: -1,
|
|
estimatePrice: 0,
|
|
estimateWeight: 0,
|
|
transportDistance: '', // 提货距离
|
|
loadDistance: '' // 运输距离
|
|
},
|
|
orderPapers: [{ cateId: '', cateName: '', guidePrice: 0, price: 0, weight: 0, paperState: '', paperStateStr: '' }],
|
|
cateList: [],
|
|
cateStatusList: [
|
|
{ value: '1', text: '散纸' },
|
|
{ value: '2', text: '已装袋' },
|
|
{ value: '3', text: '已压包' }
|
|
],
|
|
keyboard: false,
|
|
picking: false,
|
|
requesting: false
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
// /scrapStatusList/v150废品状态列表
|
|
request.get('/recycle-service/scrapStatusList/v150').then(result => {
|
|
//成功回调
|
|
var statusList = []
|
|
result.data.forEach((item) => {
|
|
statusList.push({ text: item.name, value: item.id })
|
|
})
|
|
this.setData({ cateStatusList: statusList })
|
|
})
|
|
// /paperCategoryList 获取纸品列表
|
|
request.get('/recycle-service/paperCategoryList').then(result => {
|
|
//成功回调
|
|
result.data.forEach((item) => {
|
|
this.data.cateList.push({ text: item.name, value: item.id, price: item.guidePrice })
|
|
})
|
|
this.setData({ cateList: this.data.cateList })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
})
|
|
|
|
this.pickerView = this.pickerView || this.selectComponent('#picker-view')
|
|
this.checkView = this.checkView || this.selectComponent('#check-view')
|
|
this.timeView = this.timeView || this.selectComponent('#picker-time')
|
|
},
|
|
onReady: function(){
|
|
wx.getLocation({
|
|
type: 'wgs84',
|
|
success(res) {
|
|
const latitude = res.latitude
|
|
const longitude = res.longitude
|
|
util.showToast(res.latitude + ',' + res.longitude)
|
|
}
|
|
})
|
|
},
|
|
getDateString: function (addDayCount) {
|
|
const day = new Date()
|
|
day.setDate(dd.getDate() + addDayCount) // 获取AddDayCount天后的日期
|
|
const y = dd.getFullYear()
|
|
const m =
|
|
dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
|
|
const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
|
|
return y + '-' + m + '-' + d
|
|
},
|
|
showPaperPicker: function (e) {
|
|
var index = e.currentTarget.dataset.index
|
|
var item = this.data.orderPapers[index]
|
|
this.pickerView.showPicker(this.data.cateList, item.cateId, index)
|
|
this.setData({ picking: true })
|
|
},
|
|
showStatusPicker: function (e) {
|
|
var index = e.currentTarget.dataset.index
|
|
var item = this.data.orderPapers[index]
|
|
this.setData({ picking: true })
|
|
this.checkView.showPicker(this.data.cateStatusList, item.paperState, index)
|
|
},
|
|
onStatusChange: function (e) {
|
|
this.setData({ picking: false })
|
|
if(!e.detail){
|
|
return
|
|
}
|
|
var index = e.detail.type
|
|
var paperState = ''
|
|
var paperStateStr = ''
|
|
var list = e.detail.value.sort((a, b) => parseInt(a.value) - parseInt(b.value))
|
|
list.forEach(item => {
|
|
paperState += item.value + ','
|
|
paperStateStr += item.text + ';'
|
|
})
|
|
this.setData({
|
|
['orderPapers[' + index + '].paperState']: paperState.substr(0, paperState.length - 1),
|
|
['orderPapers[' + index + '].paperStateStr']: paperStateStr.substr(0, paperStateStr.length - 1)
|
|
})
|
|
},
|
|
onPaperChange: function (e) {
|
|
this.setData({ picking: false })
|
|
if(!e.detail){
|
|
return
|
|
}
|
|
for (var i = 0; i < this.data.orderPapers.length; i++) {
|
|
if (Number(this.data.orderPapers[i].cateId) == Number(e.detail.value)) {
|
|
util.showToast('纸品已经存在,请不要重复添加')
|
|
return
|
|
}
|
|
}
|
|
var index = e.detail.type
|
|
this.setData({
|
|
['orderPapers[' + index + '].cateId']: e.detail.value,
|
|
['orderPapers[' + index + '].cateName']: e.detail.text
|
|
})
|
|
},
|
|
bindPrice: function (e) {
|
|
var index = e.currentTarget.dataset.index
|
|
this.setData({
|
|
['orderPapers[' + index + '].price']: e.detail.value
|
|
})
|
|
},
|
|
bindWeight: function (e) {
|
|
var index = e.currentTarget.dataset.index
|
|
var value = float.checkWeight(e.detail.value);
|
|
this.setData({
|
|
['orderPapers[' + index + '].weight']: Number(value)
|
|
})
|
|
},
|
|
addCate: function (e) {
|
|
this.data.orderPapers.push({ cateId: '', cateName: '', guidePrice: 0, price: 0, weight: 0, paperState: '', paperStateStr: '' })
|
|
this.setData({ orderPapers: this.data.orderPapers })
|
|
},
|
|
deleteCate: function (e) {
|
|
this.data.orderPapers.splice(e.currentTarget.dataset.index, 1)
|
|
this.setData({ orderPapers: this.data.orderPapers })
|
|
this.sumAmount(e)
|
|
},
|
|
sumAmount: function (e) {
|
|
var index = e.currentTarget.dataset.index
|
|
var item = this.data.orderPapers[index]
|
|
if (Number(item.weight) > 0 && Number(item.price) > 0) {
|
|
this.checkOrderPaper()
|
|
}
|
|
},
|
|
checkOrderPaper: function () {
|
|
var estimatePrice = 0
|
|
var estimateWeight = 0
|
|
for (let i = 0; i < this.data.orderPapers.length; i++) {
|
|
this.data.orderPapers[i].guidePrice = parseInt(Number(this.data.orderPapers[i].price) * 100)
|
|
estimatePrice += parseFloat(this.data.orderPapers[i].weight) * parseFloat(Number(this.data.orderPapers[i].price) * 100)
|
|
estimateWeight += Number(this.data.orderPapers[i].weight)
|
|
}
|
|
this.setData({
|
|
['form.estimatePrice']: estimatePrice,
|
|
['form.estimateWeight']: estimateWeight
|
|
})
|
|
},
|
|
chooseLocation: function () {
|
|
wx.chooseLocation({
|
|
success: (res) => {
|
|
this.setData({
|
|
['form.latitude']: res.latitude,
|
|
['form.longitude']: res.longitude,
|
|
['form.fullAddress']: res.address,
|
|
['form.poiName']: res.name
|
|
});
|
|
}
|
|
})
|
|
},
|
|
showDatePicker: function (e) {
|
|
this.timeView.showPicker()
|
|
this.setData({ picking: true })
|
|
},
|
|
bindKeyboard: function(e){
|
|
this.setData({ keyboard: e.detail.height > 0 })
|
|
},
|
|
onDateChange: function (e) {
|
|
this.setData({ picking: false })
|
|
if(!e.detail){
|
|
return
|
|
}
|
|
this.setData({
|
|
['form.appointDate']: e.detail[0].text,
|
|
['form.appointTimePeriod']: parseInt(e.detail[1].value),
|
|
['form.appointTimePeriodStr']: e.detail[1].text,
|
|
})
|
|
},
|
|
bindForm: function (e) {
|
|
var form_data = 'form.' + e.target.id
|
|
this.setData({
|
|
[form_data]: e.detail.value
|
|
})
|
|
},
|
|
submitForm: function (e) {
|
|
for (let i = 0; i < this.data.orderPapers.length; i++) {
|
|
if (util.isEmpty(this.data.orderPapers[i].cateId)) {
|
|
util.showToast('请选择第' + (i + 1) + '项废纸品类')
|
|
return
|
|
}
|
|
if (util.isEmpty(this.data.orderPapers[i].paperState)) {
|
|
util.showToast('请选择第' + (i + 1) + '项纸品状态')
|
|
return
|
|
}
|
|
if (parseFloat(this.data.orderPapers[i].price) <= 0) {
|
|
util.showToast('请输入第' + (i + 1) + '项预估价格,价格必须为正数')
|
|
return
|
|
}
|
|
if (parseFloat(this.data.orderPapers[i].weight) <= 0) {
|
|
util.showToast('请输入第' + (i + 1) + '项预估重量,重量必须为正数')
|
|
return
|
|
}
|
|
}
|
|
if (util.isEmpty(this.data.form.appointDate)) {
|
|
util.showToast('请选择收货日期')
|
|
return
|
|
}
|
|
this.checkOrderPaper()
|
|
this.data.form.orderPapers = this.data.orderPapers
|
|
this.setData({ requesting: true })
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
request.post('/warehouse/h5/customerOrders', this.data.form).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
event.emit('EventMessage', { what: 2, desc: 'OrderCreate' })
|
|
wx.showModal({
|
|
title: '温馨提示',
|
|
content: '订单提交已经成功,可以查看下单详情',
|
|
showCancel: false,
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
wx.redirectTo({ url: '/pages/order/order-info/index?orderId=' + result.response.id })
|
|
}
|
|
}
|
|
})
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
this.setData({ requesting: false })
|
|
})
|
|
}
|
|
|
|
})
|