define([
'text!./index.html',
'css!./index.css'
], function (template) {
// import { orderExport, orderTemp, orderDeliveryAll, orderDelivery, getSender } from '@/api/kefu'
return {
template,
name: "delivery",
props: {
isShow: {
type: Boolean,
default: false
},
orderId: {
type:[ String, Number],
default: ''
}
},
watch: {
'formValidate.shipStatus': {
handler(nVal, oVal) {
if (nVal == 2 && !this.formValidate.sendName) {
getSender().then(res => {
this.formValidate.sendName = res.data.to_name
this.formValidate.sendPhone = res.data.to_tel
this.formValidate.sendAddress = res.data.to_add
})
}
this.$refs['formValidate'].resetFields()
},
deep: true
},
'formValidate.gender': {
handler(nVal, oVal) {
this.$refs['formValidate'].resetFields()
},
deep: true
}
},
data() {
return {
shipType: [
{
key: 1,
title: '手动填写'
},
{
key: 2,
title: '电子面单打印'
},
],
radioList: [
{
key: 1,
title: '发货'
},
{
key: 2,
title: '送货'
},
{
key: 3,
title: '虚拟'
}
],
ruleInline: {
logisticsCode: [
{ required: true, message: '请选择快递公司', trigger: 'change' }
],
number: [
{ required: true, message: '请填写快递单号', trigger: 'change' }
],
sendName: [
{ required: true, message: '请填写寄件人姓名', trigger: 'change' }
],
sendPhone: [
{ required: true, message: '请填写寄件人手机', trigger: 'change' },
{ pattern: /^1[3456789]\d{9}$/, message: "手机号码格式不正确", trigger: "blur" }
],
sendAddress: [
{ required: true, message: '请填写寄件人地址', trigger: 'change' }
],
msg: [
{ required: true, message: '请填写备注信息', trigger: 'change' }
],
},
formValidate: {
gender: 1,
shipStatus: 1,
logisticsCode: '', // 快递公司编号
logisticsName: '', // 快递公司名称
number: '', // 快递单号
electronic: '', //电子面单
sendName: '', //寄件人姓名
sendPhone: '', // 寄件人电话
sendAddress: '', //寄件人地址
postPeople: '', // 配送员
msg: '' // 备注
},
logisticsList: [],
orderTempList: [],
deliveryList: []
}
},
mounted() {
this.getOrderExport()
this.getDelivery()
},
methods: {
// 获取配送人
getDelivery() {
orderDeliveryAll().then(res => {
this.deliveryList = res.data
})
},
//查看大图
inited(viewer) {
this.$viewer = viewer
},
//物流公司
getOrderExport() {
orderExport().then(res => {
this.logisticsList = res.data
})
},
handleSubmit(name) {
if (this.formValidate.gender == 1) {
this.$refs[name].validate((valid) => {
let paramsData = {}
paramsData.type = this.formValidate.gender
paramsData.express_record_type = parseFloat(this.formValidate.shipStatus)
paramsData.delivery_name = this.formValidate.logisticsName
paramsData.delivery_code = this.formValidate.logisticsCode
if (valid) {
// 手动
if (this.formValidate.gender == 1 && this.formValidate.shipStatus == 1) {
paramsData.delivery_id = this.formValidate.number
}
// 电子
if (this.formValidate.gender == 1 && this.formValidate.shipStatus == 2) {
paramsData.to_name = this.formValidate.sendName
paramsData.to_tel = this.formValidate.sendPhone
paramsData.to_addr = this.formValidate.sendAddress
paramsData.express_temp_id = this.formValidate.electronic
}
orderDelivery(this.orderId, paramsData).then(res => {
this.$Message.success(res.msg)
this.$emit('ok')
}).catch(error => {
this.$Message.error(error.msg)
})
} else {
}
})
}
if (this.formValidate.gender == 2) {
let people = {}
this.deliveryList.forEach((el, index) => {
if (el.id == this.formValidate.postPeople) {
people = el
}
})
orderDelivery(this.orderId, {
type: this.formValidate.gender,
sh_delivery_name: people.wx_name,
sh_delivery_id: people.phone,
sh_delivery_uid: people.id
}).then(res => {
this.$Message.success(res.msg)
this.$emit('ok')
}).catch(error => {
this.$Message.error(error.msg)
})
}
if (this.formValidate.gender == 3) {
orderDelivery(this.orderId, {
type: this.formValidate.gender,
remark: this.formValidate.msg
}).then(res => {
this.$Message.success(res.msg)
this.$emit('ok')
}).catch(error => {
this.$Message.error(error.msg)
})
}
},
close() {
this.$emit('close')
},
// 物流选中
bindChange(val) {
this.formValidate.logisticsName = val.label
if (this.formValidate.shipStatus == 2) {
orderTemp({
com: val.value
}).then(res => {
this.orderTempList = res.data.data
})
}
},
lookImg() {
if (this.formValidate.electronic) {
this.orderTempList.forEach((el, index) => {
if (el.temp_id == this.formValidate.electronic) {
this.$viewer.view(index)
}
})
} else {
this.$Message.error('请选择电子面单')
}
}
}
}
});