|
|
@@ -353,14 +353,6 @@
|
|
|
</div>
|
|
|
|
|
|
<!-- 增值服务 -->
|
|
|
-<!-- 增值服务:-->
|
|
|
-<!-- 包装:isPack-->
|
|
|
-<!-- 保价:guaranteeMoney-->
|
|
|
-<!-- 超长超重:isOverLongWeight-->
|
|
|
-<!-- 签单返还:isReceiptCollect-->
|
|
|
-<!-- 打木架:isWoodenCrate-->
|
|
|
-<!-- 京东 包装 保价 签单反 保价有的话传值 没有的话传 空 签单反 没筛选了-->
|
|
|
-
|
|
|
<div class="form-card full-width">
|
|
|
<div class="card-header with-blue-line">
|
|
|
<div class="blue-line"></div>
|
|
|
@@ -404,15 +396,6 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
-<!-- <div class="service-item">-->
|
|
|
-<!-- <span class="service-label">超长超重</span>-->
|
|
|
-<!-- <el-switch-->
|
|
|
-<!-- v-model="valueServices.overweight"-->
|
|
|
-<!-- size="large"-->
|
|
|
-<!-- active-color="#1890ff"-->
|
|
|
-<!-- />-->
|
|
|
-<!-- </div>-->
|
|
|
-
|
|
|
<div class="service-item" v-if="productType == '1'">
|
|
|
<span class="service-label">签单返还</span>
|
|
|
<div class="sign-return-wrapper">
|
|
|
@@ -444,14 +427,6 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
-<!-- <div class="service-item" v-if="productType == '2'">-->
|
|
|
-<!-- <span class="service-label">打木架</span>-->
|
|
|
-<!-- <el-switch-->
|
|
|
-<!-- v-model="valueServices.woodenFrame"-->
|
|
|
-<!-- size="large"-->
|
|
|
-<!-- active-color="#1890ff"-->
|
|
|
-<!-- />-->
|
|
|
-<!-- </div>-->
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
@@ -467,9 +442,6 @@
|
|
|
<div class="price-notice">
|
|
|
实际费用以快递员核实为准
|
|
|
</div>
|
|
|
-<!-- <el-checkbox v-model="agreed" size="large">-->
|
|
|
-<!-- 我已理解并同意遵守《快件服务协议》-->
|
|
|
-<!-- </el-checkbox>-->
|
|
|
</div>
|
|
|
<el-button
|
|
|
type="primary"
|
|
|
@@ -494,25 +466,21 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref, reactive, computed, onMounted, watch } from 'vue'
|
|
|
+import { ref, reactive, computed, onMounted, watch, getCurrentInstance } from 'vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import RegionCascader from '@/components/RegionCascader.vue'
|
|
|
-// 导入地址簿弹窗组件
|
|
|
import AddressBookDialog from './components/AddressBookDialog.vue'
|
|
|
import PickupTimeCascader from './components/PickupTimeCascader.vue'
|
|
|
|
|
|
-
|
|
|
-// 导入本地 JSON 数据
|
|
|
-import { areaData,getCodesByNames } from '@/utils/area-data.js'
|
|
|
+import { areaData, getCodesByNames } from '@/utils/area-data.js'
|
|
|
import { addBook } from "@/api/logistics/book"
|
|
|
import { addOrder } from "@/api/logistics/order"
|
|
|
|
|
|
-
|
|
|
const { proxy } = getCurrentInstance()
|
|
|
const { jd_logistics_product_code, sf_logistics_product_code } = proxy.useDict("jd_logistics_product_code", "sf_logistics_product_code")
|
|
|
|
|
|
import { useRoute } from 'vue-router';
|
|
|
-import {updateBook,getDefaultAddress,getAddressInfo} from "../../../api/logistics/book.js";
|
|
|
+import { updateBook, getDefaultAddress, getAddressInfo } from "../../../api/logistics/book.js";
|
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
|
@@ -527,8 +495,8 @@ const sender = reactive({
|
|
|
cityName: '',
|
|
|
countyName: '',
|
|
|
detailedAddress: '',
|
|
|
- region: [], // 用于绑定RegionCascader组件
|
|
|
- defaultFlag: '0' //是否默认 0非默认 1默认
|
|
|
+ region: [],
|
|
|
+ defaultFlag: '0'
|
|
|
})
|
|
|
|
|
|
// 收件人信息
|
|
|
@@ -551,11 +519,11 @@ const deliveryMethod = ref('pickup')
|
|
|
const deliveryForm = reactive({
|
|
|
pickupTime: [],
|
|
|
expressType: '',
|
|
|
- pickupStartTime: '', // 新增:上门开始时间
|
|
|
- pickupEndTime: '' // 新增:上门结束时间
|
|
|
+ pickupStartTime: '',
|
|
|
+ pickupEndTime: ''
|
|
|
})
|
|
|
|
|
|
-// 寄件方式验证规则(针对PickupTimeCascader组件)
|
|
|
+// 寄件方式验证规则
|
|
|
const deliveryRules = {
|
|
|
pickupTime: [
|
|
|
{
|
|
|
@@ -564,7 +532,6 @@ const deliveryRules = {
|
|
|
if (!value || value.length === 0) {
|
|
|
callback(new Error('请选择上门时间'))
|
|
|
} else {
|
|
|
- // 验证时间格式是否正确(假设PickupTimeCascader返回数组)
|
|
|
if (Array.isArray(value) && value.length >= 2) {
|
|
|
callback()
|
|
|
} else {
|
|
|
@@ -580,7 +547,6 @@ const deliveryRules = {
|
|
|
]
|
|
|
}
|
|
|
|
|
|
-// 寄件方式表单引用
|
|
|
const deliveryFormRef = ref(null)
|
|
|
|
|
|
// 物品信息
|
|
|
@@ -600,11 +566,9 @@ const valueServices = reactive({
|
|
|
woodenFrame: false
|
|
|
})
|
|
|
|
|
|
-// 保价金额
|
|
|
const insuranceAmount = ref('')
|
|
|
const insuranceAmountError = ref('')
|
|
|
|
|
|
-// 签单返还类型
|
|
|
const signReturnType = ref('')
|
|
|
const signReturnTypeError = ref('')
|
|
|
const signReturnOptions = ref([
|
|
|
@@ -612,10 +576,8 @@ const signReturnOptions = ref([
|
|
|
{ label: '纸质凭证', value: 'paper' }
|
|
|
])
|
|
|
|
|
|
-// 协议同意
|
|
|
const agreed = ref(true)
|
|
|
|
|
|
-// 表单验证规则(已添加长度限制)
|
|
|
const senderRules = {
|
|
|
contactName: [
|
|
|
{ required: true, message: '请输入寄件人姓名', trigger: 'blur' },
|
|
|
@@ -668,11 +630,9 @@ const receiverRules = {
|
|
|
],
|
|
|
detailedAddress: [
|
|
|
{ required: true, message: '请输入详细地址', trigger: 'blur' },
|
|
|
- // { min: 3, max: 100, message: '地址长度在3-100个字符之间', trigger: 'blur' }
|
|
|
]
|
|
|
}
|
|
|
|
|
|
-// 物品信息验证规则(已添加长度限制)
|
|
|
const itemInfoRules = {
|
|
|
type: [
|
|
|
{ required: true, message: '请输入物品类型', trigger: 'blur' },
|
|
|
@@ -684,11 +644,7 @@ const itemInfoRules = {
|
|
|
validator: (rule, value, callback) => {
|
|
|
if (value <= 0) {
|
|
|
callback(new Error('重量必须大于0'))
|
|
|
- }
|
|
|
- // else if (value > 1000) {
|
|
|
- // callback(new Error('重量不能超过1000kg'))
|
|
|
- // }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
callback()
|
|
|
}
|
|
|
},
|
|
|
@@ -701,11 +657,7 @@ const itemInfoRules = {
|
|
|
validator: (rule, value, callback) => {
|
|
|
if (value <= 0) {
|
|
|
callback(new Error('体积必须大于0'))
|
|
|
- }
|
|
|
- // else if (value > 100) {
|
|
|
- // callback(new Error('体积不能超过100m³'))
|
|
|
- // }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
callback()
|
|
|
}
|
|
|
},
|
|
|
@@ -718,11 +670,7 @@ const itemInfoRules = {
|
|
|
validator: (rule, value, callback) => {
|
|
|
if (value <= 0) {
|
|
|
callback(new Error('件数必须大于0'))
|
|
|
- }
|
|
|
- // else if (value > 999) {
|
|
|
- // callback(new Error('件数不能超过999件'))
|
|
|
- // }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
callback()
|
|
|
}
|
|
|
},
|
|
|
@@ -731,39 +679,28 @@ const itemInfoRules = {
|
|
|
]
|
|
|
}
|
|
|
|
|
|
-// 表单引用
|
|
|
const senderForm = ref(null)
|
|
|
const receiverForm = ref(null)
|
|
|
const itemInfoForm = ref(null)
|
|
|
|
|
|
-// 地址簿弹窗相关(迁移到组件)
|
|
|
const addressBookVisible = ref(false)
|
|
|
const addressBookType = ref('sender')
|
|
|
|
|
|
-// 存储原始地址信息(用于判断是否修改)
|
|
|
const senderOriginalAddress = ref(null)
|
|
|
const receiverOriginalAddress = ref(null)
|
|
|
|
|
|
-
|
|
|
-// 监听快递类型变化
|
|
|
watch(() => deliveryForm.expressType, (newVal) => {
|
|
|
- // 快递类型变化时清空可能的错误状态
|
|
|
if (newVal && deliveryFormRef.value) {
|
|
|
- // 清除快递类型的验证错误
|
|
|
deliveryFormRef.value.clearValidate(['expressType'])
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// 监听上门时间变化
|
|
|
watch(() => deliveryForm.pickupTime, (newVal) => {
|
|
|
- // 上门时间变化时清空可能的错误状态
|
|
|
if (newVal && newVal.length > 0 && deliveryFormRef.value) {
|
|
|
- // 清除上门时间的验证错误
|
|
|
deliveryFormRef.value.clearValidate(['pickupTime'])
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// 监听签单返还开关变化
|
|
|
watch(() => valueServices.signReturn, (newVal) => {
|
|
|
if (!newVal) {
|
|
|
signReturnType.value = ''
|
|
|
@@ -771,29 +708,24 @@ watch(() => valueServices.signReturn, (newVal) => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-// 监听保价金额变化
|
|
|
watch(insuranceAmount, () => {
|
|
|
validateInsuranceAmount()
|
|
|
})
|
|
|
|
|
|
-// 监听签单返还类型变化
|
|
|
watch(signReturnType, (newVal) => {
|
|
|
if (newVal) {
|
|
|
signReturnTypeError.value = ''
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-
|
|
|
-// ==================== 新增智能识别相关 ====================
|
|
|
+// ==================== 智能识别 ====================
|
|
|
const senderRecognitionText = ref('')
|
|
|
const receiverRecognitionText = ref('')
|
|
|
const recognitionLoading = ref(false)
|
|
|
|
|
|
-// 处理识别
|
|
|
const handleRecognition = async (type, actionType) => {
|
|
|
let text = ''
|
|
|
if (actionType === 1) {
|
|
|
- // 粘贴并识别:读取剪贴板
|
|
|
try {
|
|
|
const clipboardText = await navigator.clipboard.readText()
|
|
|
if (!clipboardText) {
|
|
|
@@ -812,7 +744,6 @@ const handleRecognition = async (type, actionType) => {
|
|
|
return
|
|
|
}
|
|
|
} else {
|
|
|
- // 直接识别:使用当前文本域内容
|
|
|
text = type === 'sender' ? senderRecognitionText.value : receiverRecognitionText.value
|
|
|
}
|
|
|
|
|
|
@@ -829,18 +760,11 @@ const handleRecognition = async (type, actionType) => {
|
|
|
const result = res.data.result[0]
|
|
|
const target = type === 'sender' ? sender : receiver
|
|
|
|
|
|
- // 清空原有 addressId,视为新地址
|
|
|
target.addressId = ''
|
|
|
-
|
|
|
- // 姓名
|
|
|
target.contactName = result.name || ''
|
|
|
-
|
|
|
- // 电话(取第一个)
|
|
|
if (result.mobile && result.mobile.length > 0) {
|
|
|
target.contactPhone = result.mobile[0]
|
|
|
}
|
|
|
-
|
|
|
- // 省市区
|
|
|
if (result.xzq) {
|
|
|
let province = '', city = '', district = ''
|
|
|
if (result.xzq.fullName) {
|
|
|
@@ -857,11 +781,9 @@ const handleRecognition = async (type, actionType) => {
|
|
|
target.cityName = city
|
|
|
target.countyName = district
|
|
|
|
|
|
- // 获取省市区代码并设置 region(用于 RegionCascader 回显)
|
|
|
const codes = getCodesByNames(province, city, district)
|
|
|
target.region = codes
|
|
|
|
|
|
- // 详细地址
|
|
|
if (result.xzq.subArea) {
|
|
|
target.detailedAddress = result.xzq.subArea
|
|
|
} else if (result.address) {
|
|
|
@@ -871,7 +793,6 @@ const handleRecognition = async (type, actionType) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 清空对应识别文本域(可选)
|
|
|
if (type === 'sender') {
|
|
|
senderRecognitionText.value = ''
|
|
|
} else {
|
|
|
@@ -889,109 +810,69 @@ const handleRecognition = async (type, actionType) => {
|
|
|
recognitionLoading.value = false
|
|
|
}
|
|
|
}
|
|
|
-// ==================== 新增代码结束 ====================
|
|
|
+// ================================================
|
|
|
|
|
|
-// 处理寄件人地区变化
|
|
|
const handleSenderRegionChange = (regionInfo) => {
|
|
|
- console.log('寄件人地区信息:', regionInfo)
|
|
|
- // 同时更新省份、城市、区县名称
|
|
|
sender.provinceName = regionInfo.provinceName || ''
|
|
|
sender.cityName = regionInfo.cityName || ''
|
|
|
sender.countyName = regionInfo.districtName || ''
|
|
|
- sender.region = [regionInfo.provinceCode,regionInfo.cityCode,regionInfo.districtCode]
|
|
|
-
|
|
|
- // 如果是从地址簿选择的地址,修改后清空addressId
|
|
|
+ sender.region = [regionInfo.provinceCode, regionInfo.cityCode, regionInfo.districtCode]
|
|
|
if (sender.addressId) {
|
|
|
sender.addressId = ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 处理收件人地区变化
|
|
|
const handleReceiverRegionChange = (regionInfo) => {
|
|
|
- console.log('收件人地区信息:', regionInfo)
|
|
|
receiver.provinceName = regionInfo.provinceName || ''
|
|
|
receiver.cityName = regionInfo.cityName || ''
|
|
|
receiver.countyName = regionInfo.districtName || ''
|
|
|
- receiver.region = [regionInfo.provinceCode,regionInfo.cityCode,regionInfo.districtCode]
|
|
|
-
|
|
|
- // 如果是从地址簿选择的地址,修改后清空addressId
|
|
|
+ receiver.region = [regionInfo.provinceCode, regionInfo.cityCode, regionInfo.districtCode]
|
|
|
if (receiver.addressId) {
|
|
|
receiver.addressId = ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 处理上门时间变化
|
|
|
const handlePickupTimeChange = (value) => {
|
|
|
- console.log('上门时间选择:', value)
|
|
|
- // 当用户选择上门时间后,清除验证错误
|
|
|
if (value && deliveryFormRef.value) {
|
|
|
deliveryFormRef.value.clearValidate(['pickupTime'])
|
|
|
}
|
|
|
-
|
|
|
- let formattedPickupStartTime = ''
|
|
|
- let formattedPickupEndTime = ''
|
|
|
- if (Array.isArray(deliveryForm.pickupTime) && deliveryForm.pickupTime.length > 0) {
|
|
|
- // 假设PickupTimeCascader返回的数组结构为 [日期, 时间段]
|
|
|
- const timeArr = deliveryForm.pickupTime[1].split('-')
|
|
|
- console.log('deliveryForm.pickupTime===',deliveryForm.pickupTime)
|
|
|
- console.log('timeArr===',timeArr)
|
|
|
- console.log('deliveryForm.pickupTime[0] + timeArr[0]===',deliveryForm.pickupTime[0] + ' ' + timeArr[0])
|
|
|
- formattedPickupStartTime = deliveryForm.pickupTime[0] + ' ' + timeArr[0] + ":00"
|
|
|
- formattedPickupEndTime = deliveryForm.pickupTime[0] + ' ' + timeArr[1] + ":00"
|
|
|
- console.log('formattedPickupStartTime===',formattedPickupStartTime)
|
|
|
- console.log('formattedPickupEndTime===',formattedPickupEndTime)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
+ // 解析逻辑保持不变(仅用于日志)
|
|
|
}
|
|
|
|
|
|
-// 处理寄件人表单变化
|
|
|
const handleSenderChange = () => {
|
|
|
- // 如果是从地址簿选择的地址,修改后清空addressId
|
|
|
if (sender.addressId) {
|
|
|
sender.addressId = ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 处理收件人表单变化
|
|
|
const handleReceiverChange = () => {
|
|
|
- // 如果是从地址簿选择的地址,修改后清空addressId
|
|
|
if (receiver.addressId) {
|
|
|
receiver.addressId = ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 方法:打开地址簿
|
|
|
const openAddressBook = (type) => {
|
|
|
addressBookType.value = type
|
|
|
addressBookVisible.value = true
|
|
|
}
|
|
|
|
|
|
-// 方法:关闭地址簿
|
|
|
const closeAddressBook = () => {
|
|
|
addressBookVisible.value = false
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-// 方法:应用选择的地址(修改:清空验证错误)
|
|
|
const applyAddress = (address) => {
|
|
|
if (address) {
|
|
|
if (addressBookType.value === 'sender') {
|
|
|
sender.addressId = address.addressId || ''
|
|
|
sender.contactName = address.contactName || ''
|
|
|
sender.contactPhone = address.contactPhone || ''
|
|
|
-
|
|
|
sender.provinceName = address.provinceName
|
|
|
sender.cityName = address.cityName
|
|
|
sender.countyName = address.countyName
|
|
|
-
|
|
|
sender.detailedAddress = address.detailedAddress || ''
|
|
|
sender.defaultFlag = address.defaultFlag || '0'
|
|
|
+ sender.region = getCodesByNames(sender.provinceName, sender.cityName, sender.countyName)
|
|
|
|
|
|
- sender.region = getCodesByNames(sender.provinceName,sender.cityName,sender.countyName)
|
|
|
- console.log('region===========', sender.region)
|
|
|
-
|
|
|
- // 保存原始地址信息(用于判断是否修改)
|
|
|
senderOriginalAddress.value = {
|
|
|
contactName: address.contactName || '',
|
|
|
contactPhone: address.contactPhone || '',
|
|
|
@@ -1002,7 +883,6 @@ const applyAddress = (address) => {
|
|
|
defaultFlag: address.defaultFlag || '0'
|
|
|
}
|
|
|
|
|
|
- // 清空寄件人表单的验证错误
|
|
|
if (senderForm.value) {
|
|
|
senderForm.value.clearValidate()
|
|
|
}
|
|
|
@@ -1010,18 +890,13 @@ const applyAddress = (address) => {
|
|
|
receiver.addressId = address.addressId || ''
|
|
|
receiver.contactName = address.contactName || ''
|
|
|
receiver.contactPhone = address.contactPhone || ''
|
|
|
-
|
|
|
receiver.provinceName = address.provinceName
|
|
|
receiver.cityName = address.cityName
|
|
|
receiver.countyName = address.countyName
|
|
|
-
|
|
|
receiver.detailedAddress = address.detailedAddress || ''
|
|
|
receiver.defaultFlag = address.defaultFlag || '0'
|
|
|
+ receiver.region = getCodesByNames(receiver.provinceName, receiver.cityName, receiver.countyName)
|
|
|
|
|
|
- receiver.region = getCodesByNames(receiver.provinceName,receiver.cityName,receiver.countyName)
|
|
|
- console.log('region===========', receiver.region)
|
|
|
-
|
|
|
- // 保存原始地址信息(用于判断是否修改)
|
|
|
receiverOriginalAddress.value = {
|
|
|
contactName: address.contactName || '',
|
|
|
contactPhone: address.contactPhone || '',
|
|
|
@@ -1032,22 +907,16 @@ const applyAddress = (address) => {
|
|
|
defaultFlag: address.defaultFlag || '0'
|
|
|
}
|
|
|
|
|
|
- // 清空收件人表单的验证错误
|
|
|
if (receiverForm.value) {
|
|
|
receiverForm.value.clearValidate()
|
|
|
}
|
|
|
}
|
|
|
- // ElMessage.success('已应用选择的地址')
|
|
|
- } else {
|
|
|
- // ElMessage.warning('请先选择一个地址')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 方法:加入地址簿
|
|
|
const addToAddressBook = async (type) => {
|
|
|
let formRef = null
|
|
|
let formData = null
|
|
|
- let regionInfo = null
|
|
|
|
|
|
if (type === 'sender') {
|
|
|
formRef = senderForm.value
|
|
|
@@ -1071,7 +940,7 @@ const addToAddressBook = async (type) => {
|
|
|
}
|
|
|
|
|
|
const addressData = {
|
|
|
- addressId: formData.addressId || '', // 如果有addressId则传递,为空则新增
|
|
|
+ addressId: formData.addressId || '',
|
|
|
contactName: formData.contactName,
|
|
|
contactPhone: formData.contactPhone,
|
|
|
detailedAddress: formData.detailedAddress,
|
|
|
@@ -1082,11 +951,10 @@ const addToAddressBook = async (type) => {
|
|
|
tag: 'custom',
|
|
|
}
|
|
|
try {
|
|
|
- // 如果是新增,更新addressId
|
|
|
let response = {}
|
|
|
if (formData.addressId) {
|
|
|
response = await updateBook(addressData)
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
response = await addBook(addressData)
|
|
|
}
|
|
|
if (response.code === 200) {
|
|
|
@@ -1100,7 +968,6 @@ const addToAddressBook = async (type) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 方法:处理保价开关变化
|
|
|
const handleInsuranceChange = (value) => {
|
|
|
if (!value) {
|
|
|
insuranceAmount.value = ''
|
|
|
@@ -1108,30 +975,22 @@ const handleInsuranceChange = (value) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 方法:验证保价金额
|
|
|
const validateInsuranceAmount = () => {
|
|
|
if (valueServices.insurance && insuranceAmount.value) {
|
|
|
const amount = parseFloat(insuranceAmount.value)
|
|
|
-
|
|
|
- // 检查是否为数字
|
|
|
if (isNaN(amount) || amount <= 0) {
|
|
|
insuranceAmountError.value = '保价金额必须大于0且为数字'
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
- // 检查是否超过最大值
|
|
|
if (amount > 1000000) {
|
|
|
insuranceAmountError.value = '保价金额不能超过100万'
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
- // 检查小数位数
|
|
|
const decimalPart = insuranceAmount.value.toString().split('.')[1]
|
|
|
if (decimalPart && decimalPart.length > 2) {
|
|
|
insuranceAmountError.value = '保价金额最多保留两位小数'
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
insuranceAmountError.value = ''
|
|
|
return true
|
|
|
} else if (valueServices.insurance && !insuranceAmount.value) {
|
|
|
@@ -1143,7 +1002,6 @@ const validateInsuranceAmount = () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 方法:处理签单返还开关变化
|
|
|
const handleSignReturnChange = (value) => {
|
|
|
if (!value) {
|
|
|
signReturnType.value = ''
|
|
|
@@ -1153,23 +1011,17 @@ const handleSignReturnChange = (value) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 方法:验证表单数据
|
|
|
const validateFormData = () => {
|
|
|
let isValid = true
|
|
|
-
|
|
|
- // 验证保价金额
|
|
|
if (valueServices.insurance) {
|
|
|
if (!validateInsuranceAmount()) {
|
|
|
isValid = false
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- // 验证签单返还类型
|
|
|
if (valueServices.signReturn && !signReturnType.value && productType == '2') {
|
|
|
signReturnTypeError.value = '请选择签单返还凭证类型'
|
|
|
isValid = false
|
|
|
}
|
|
|
-
|
|
|
return isValid
|
|
|
}
|
|
|
|
|
|
@@ -1178,7 +1030,6 @@ function close() {
|
|
|
proxy.$tab.closeOpenPage(obj)
|
|
|
}
|
|
|
|
|
|
-// 方法:提交订单
|
|
|
const isSubmit = ref(false)
|
|
|
const submitOrder = async () => {
|
|
|
if (!agreed.value) {
|
|
|
@@ -1186,7 +1037,6 @@ const submitOrder = async () => {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 验证寄件人表单
|
|
|
let senderValid = false
|
|
|
try {
|
|
|
await senderForm.value.validate()
|
|
|
@@ -1194,13 +1044,11 @@ const submitOrder = async () => {
|
|
|
} catch (error) {
|
|
|
senderValid = false
|
|
|
}
|
|
|
-
|
|
|
if (!senderValid) {
|
|
|
ElMessage.warning('请填写完整的寄件人信息')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 验证收件人表单
|
|
|
let receiverValid = false
|
|
|
try {
|
|
|
await receiverForm.value.validate()
|
|
|
@@ -1208,13 +1056,11 @@ const submitOrder = async () => {
|
|
|
} catch (error) {
|
|
|
receiverValid = false
|
|
|
}
|
|
|
-
|
|
|
if (!receiverValid) {
|
|
|
ElMessage.warning('请填写完整的收件人信息')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 验证寄件方式表单(上门时间和快递类型)
|
|
|
let deliveryValid = false
|
|
|
try {
|
|
|
await deliveryFormRef.value.validate()
|
|
|
@@ -1222,13 +1068,11 @@ const submitOrder = async () => {
|
|
|
} catch (error) {
|
|
|
deliveryValid = false
|
|
|
}
|
|
|
-
|
|
|
if (!deliveryValid) {
|
|
|
ElMessage.warning('请填写完整的寄件方式信息')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 验证物品信息表单
|
|
|
let itemInfoValid = false
|
|
|
try {
|
|
|
await itemInfoForm.value.validate()
|
|
|
@@ -1236,133 +1080,150 @@ const submitOrder = async () => {
|
|
|
} catch (error) {
|
|
|
itemInfoValid = false
|
|
|
}
|
|
|
-
|
|
|
if (!itemInfoValid) {
|
|
|
ElMessage.warning('请填写完整的物品信息')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // 验证其他表单数据(增值服务相关)
|
|
|
if (!validateFormData()) {
|
|
|
return
|
|
|
}
|
|
|
- if(isSubmit.value){
|
|
|
+ if (isSubmit.value) {
|
|
|
return
|
|
|
}
|
|
|
isSubmit.value = true
|
|
|
proxy.$modal.loading("正在创建订单,请稍候...")
|
|
|
+
|
|
|
let formattedPickupStartTime = ''
|
|
|
let formattedPickupEndTime = ''
|
|
|
if (Array.isArray(deliveryForm.pickupTime) && deliveryForm.pickupTime.length > 0) {
|
|
|
- // 假设PickupTimeCascader返回的数组结构为 [日期, 时间段]
|
|
|
- const timeArr = deliveryForm.pickupTime[1].split('-')
|
|
|
- console.log('deliveryForm.pickupTime===',deliveryForm.pickupTime)
|
|
|
- console.log('timeArr===',timeArr)
|
|
|
- console.log('deliveryForm.pickupTime[0] + timeArr[0]===',deliveryForm.pickupTime[0] + ' ' + timeArr[0])
|
|
|
+ const timeArr = deliveryForm.pickupTime[1].split('-')
|
|
|
formattedPickupStartTime = deliveryForm.pickupTime[0] + ' ' + timeArr[0] + ":00"
|
|
|
formattedPickupEndTime = deliveryForm.pickupTime[0] + ' ' + timeArr[1] + ":00"
|
|
|
- console.log('formattedPickupStartTime===',formattedPickupStartTime)
|
|
|
- console.log('formattedPickupEndTime===',formattedPickupEndTime)
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // <!-- 增值服务:-->
|
|
|
- // <!-- 包装:isPack-->
|
|
|
- // <!-- 保价:guaranteeMoney-->
|
|
|
- // <!-- 超长超重:isOverLongWeight-->
|
|
|
- // <!-- 签单返还:isReceiptCollect-->
|
|
|
- // <!-- 打木架:isWoodenCrate-->
|
|
|
- // <!-- 京东 包装 保价 签单反 保价有的话传值 没有的话传 空 签单反 没筛选了-->
|
|
|
- let services = {
|
|
|
- isPack:valueServices.isPack,
|
|
|
- guaranteeMoney:valueServices.insurance ? insuranceAmount.value : null,
|
|
|
- isReceiptCollect: valueServices.signReturn ? signReturnType.value : null
|
|
|
}
|
|
|
|
|
|
- if(productType.value == '1'){ //京东
|
|
|
+ let services = {}
|
|
|
+ if (productType.value == '1') {
|
|
|
services = {
|
|
|
- isPack:valueServices.packaging ? true : null,
|
|
|
- guaranteeMoney:valueServices.insurance ? insuranceAmount.value : null,
|
|
|
+ isPack: valueServices.packaging ? true : null,
|
|
|
+ guaranteeMoney: valueServices.insurance ? insuranceAmount.value : null,
|
|
|
isReceiptCollect: valueServices.signReturn ? true : null
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
services = {
|
|
|
- isPack:valueServices.packaging ? true : null,
|
|
|
- guaranteeMoney:valueServices.insurance ? insuranceAmount.value : null,
|
|
|
- isReceiptCollect: valueServices.signReturn ? true : null
|
|
|
+ isPack: valueServices.packaging ? true : null,
|
|
|
+ guaranteeMoney: valueServices.insurance ? insuranceAmount.value : null,
|
|
|
+ isReceiptCollect: valueServices.signReturn ? signReturnType.value : null
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 构建完整的订单数据
|
|
|
const orderData = {
|
|
|
- orderType: productType.value, //1-非时效件(京东),2-时效件(顺丰)
|
|
|
- senderName:sender.contactName,
|
|
|
- senderPhone:sender.contactPhone,
|
|
|
- senderProvince:sender.provinceName,
|
|
|
- senderCity:sender.cityName,
|
|
|
- senderCounty:sender.countyName,
|
|
|
- senderAddress:sender.detailedAddress,
|
|
|
- receiverName:receiver.contactName,
|
|
|
- receiverPhone:receiver.contactPhone,
|
|
|
- receiverProvince:receiver.provinceName,
|
|
|
- receiverCity:receiver.cityName,
|
|
|
- receiverCounty:receiver.countyName,
|
|
|
- receiverAddress:receiver.detailedAddress,
|
|
|
-
|
|
|
- goodsName:itemInfo.type,
|
|
|
- goodsWeight:itemInfo.weight,
|
|
|
- goodsVolume:itemInfo.volume,
|
|
|
- goodsQty:itemInfo.quantity,
|
|
|
-
|
|
|
- sendStartTime:formattedPickupStartTime,//上门取件时间
|
|
|
- sendEndTime:formattedPickupEndTime,//上门取件时间
|
|
|
-
|
|
|
- productCode: deliveryForm.expressType, //快递类型
|
|
|
+ orderType: productType.value,
|
|
|
+ senderName: sender.contactName,
|
|
|
+ senderPhone: sender.contactPhone,
|
|
|
+ senderProvince: sender.provinceName,
|
|
|
+ senderCity: sender.cityName,
|
|
|
+ senderCounty: sender.countyName,
|
|
|
+ senderAddress: sender.detailedAddress,
|
|
|
+ receiverName: receiver.contactName,
|
|
|
+ receiverPhone: receiver.contactPhone,
|
|
|
+ receiverProvince: receiver.provinceName,
|
|
|
+ receiverCity: receiver.cityName,
|
|
|
+ receiverCounty: receiver.countyName,
|
|
|
+ receiverAddress: receiver.detailedAddress,
|
|
|
+ goodsName: itemInfo.type,
|
|
|
+ goodsWeight: itemInfo.weight,
|
|
|
+ goodsVolume: itemInfo.volume,
|
|
|
+ goodsQty: itemInfo.quantity,
|
|
|
+ sendStartTime: formattedPickupStartTime,
|
|
|
+ sendEndTime: formattedPickupEndTime,
|
|
|
+ productCode: deliveryForm.expressType,
|
|
|
addedService: JSON.stringify(services),
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- console.log('提交订单数据:', orderData)
|
|
|
try {
|
|
|
const response = await addOrder(orderData)
|
|
|
- if(response.code == 200){
|
|
|
- console.log('订单提交成功:', response.data)
|
|
|
+ if (response.code == 200) {
|
|
|
ElMessage.success('订单创建成功!')
|
|
|
close()
|
|
|
} else {
|
|
|
isSubmit.value = false
|
|
|
- // ElMessage.error(response.msg || '订单创建失败!')
|
|
|
}
|
|
|
} catch (error) {
|
|
|
isSubmit.value = false
|
|
|
console.error('订单提交失败:', error)
|
|
|
- // ElMessage.error(error.value)
|
|
|
- }finally {
|
|
|
+ } finally {
|
|
|
proxy.$modal.closeLoading()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const getDefaultAddressFun = async () => {
|
|
|
+const getDefaultAddressFun = async () => {
|
|
|
try {
|
|
|
const response = await getDefaultAddress()
|
|
|
- if(response.code == 200){
|
|
|
+ if (response.code == 200) {
|
|
|
addressBookType.value = 'sender'
|
|
|
applyAddress(response.data)
|
|
|
- } else {
|
|
|
}
|
|
|
} catch (error) {
|
|
|
- console.error('订单提交失败:', error)
|
|
|
+ console.error('获取默认地址失败:', error)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 初始化加载
|
|
|
-onMounted(() => {
|
|
|
- console.log('快递下单页面已加载')
|
|
|
- console.log('省市区数据总数:', areaData.length)
|
|
|
+// ========== 生成默认上门时间(今天一小时内,与组件算法一致) ==========
|
|
|
+function getDefaultPickupTime() {
|
|
|
+ const now = new Date();
|
|
|
+ // 开始时间 = now + 30分钟
|
|
|
+ let start = new Date(now.getTime() + 3 * 60000);
|
|
|
+ // 分钟向上取整到10的倍数
|
|
|
+ let minutes = start.getMinutes();
|
|
|
+ let roundedMinutes = Math.ceil(minutes / 10) * 10;
|
|
|
+ start.setMinutes(roundedMinutes, 0, 0);
|
|
|
+ // 如果分钟进位导致小时增加,无需额外处理,setMinutes会自动处理
|
|
|
+
|
|
|
+ // 合规性处理:开始时间不能早于9:00,不能晚于19:00(保证结束不超20:00)
|
|
|
+ const startOfDay = new Date(now);
|
|
|
+ startOfDay.setHours(9, 0, 0, 0);
|
|
|
+ if (start < startOfDay) {
|
|
|
+ start = startOfDay;
|
|
|
+ }
|
|
|
+ const maxStart = new Date(now);
|
|
|
+ maxStart.setHours(19, 0, 0, 0);
|
|
|
+ if (start > maxStart) {
|
|
|
+ start = maxStart;
|
|
|
+ }
|
|
|
|
|
|
+ // 结束时间 = 开始 + 1小时
|
|
|
+ let end = new Date(start.getTime() + 60 * 60000);
|
|
|
+ const maxEnd = new Date(now);
|
|
|
+ maxEnd.setHours(20, 0, 0, 0);
|
|
|
+ if (end > maxEnd) {
|
|
|
+ start = new Date(maxEnd.getTime() - 60 * 60000);
|
|
|
+ end = maxEnd;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 日期字符串 YYYY-MM-DD
|
|
|
+ const year = start.getFullYear();
|
|
|
+ const month = String(start.getMonth() + 1).padStart(2, '0');
|
|
|
+ const day = String(start.getDate()).padStart(2, '0');
|
|
|
+ const dateStr = `${year}-${month}-${day}`;
|
|
|
+
|
|
|
+ // 时间范围 HH:MM-HH:MM
|
|
|
+ const startHour = String(start.getHours()).padStart(2, '0');
|
|
|
+ const startMin = String(start.getMinutes()).padStart(2, '0');
|
|
|
+ const endHour = String(end.getHours()).padStart(2, '0');
|
|
|
+ const endMin = String(end.getMinutes()).padStart(2, '0');
|
|
|
+ const timeRange = `${startHour}:${startMin}-${endHour}:${endMin}`;
|
|
|
+
|
|
|
+ return [dateStr, timeRange];
|
|
|
+}
|
|
|
+// =====================================================
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
productType.value = route.query.productType || '1';
|
|
|
- console.log("===productType=", productType.value)
|
|
|
- getDefaultAddressFun()
|
|
|
+ getDefaultAddressFun();
|
|
|
+
|
|
|
+ // 设置默认上门时间
|
|
|
+ deliveryForm.pickupTime = getDefaultPickupTime();
|
|
|
})
|
|
|
</script>
|
|
|
|