- 新增商品属性页(分类/品牌/单位)与商品表单的品牌/单位选择 - 新增订单状态页:状态分视图列表、新建/编辑弹窗、明细维护、审核/驳回/取消/作废/恢复/推送仓库等操作 - 导出任务按类型动态渲染筛选表单与任务进度;导出按钮/筛选组件抽为公共组件 - 旧地址 order-split / order-create / order-delivery 重定向到 /order,导航与多标签页适配新页面 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
877 lines
32 KiB
Vue
877 lines
32 KiB
Vue
<script setup lang="ts">
|
||
import { computed, reactive, ref, watch } from 'vue'
|
||
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
|
||
import DataTable from '@/components/DataTable.vue'
|
||
import ProductSelect from '@/components/ProductSelect.vue'
|
||
import { getExpressCompanyOptions, type ExpressCompanyOption } from '@/api/expressCompany'
|
||
import type { ProductSearchItem } from '@/api/product'
|
||
import type { DataItem } from 'element-china-area-data'
|
||
import {
|
||
createOrderStatus,
|
||
getOrderStatusDetail,
|
||
parseReceiverText,
|
||
updateOrderStatus,
|
||
type OrderItemLine,
|
||
type OrderStatusFilters,
|
||
type OrderStatusPayload,
|
||
} from '@/api/orderStatus'
|
||
|
||
/**
|
||
* 订单(发货单)新建 / 编辑弹窗
|
||
*
|
||
* 字段口径与老「发货单」一致:仓库 / 店铺 / 订单类型 / 收件人 12 项 / 金额 / 留言 / 物流 / 明细;
|
||
* 订单号留空时由后端生成(有来源订单号 → 「来源订单号-序号」,否则 → FH_{id})。
|
||
* 编辑模式仅待审核 / 异常可用,明细随表单一并保存(覆盖式)。
|
||
*/
|
||
const props = defineProps<{
|
||
modelValue: boolean
|
||
/** 编辑时的订单 id;不传为新建 */
|
||
orderId?: number | null
|
||
filters: OrderStatusFilters
|
||
/** 默认落到哪个单据(新建时用于刷新对应列表) */
|
||
defaultShopId?: number | null
|
||
}>()
|
||
|
||
const emit = defineEmits<{
|
||
'update:modelValue': [ value: boolean ]
|
||
saved: [ payload: { id: number; order_no: string; isEdit: boolean } ]
|
||
}>()
|
||
|
||
const visible = computed({
|
||
get: () => props.modelValue,
|
||
set: value => emit('update:modelValue', value),
|
||
})
|
||
|
||
const isEdit = computed(() => Boolean(props.orderId))
|
||
const submitting = ref(false)
|
||
const loading = ref(false)
|
||
const formRef = ref<FormInstance>()
|
||
|
||
const ORDER_TYPES = [
|
||
{ value: 'JYCK', label: 'JYCK 一般交易出库单' },
|
||
{ value: 'HHCK', label: 'HHCK 换货出库' },
|
||
{ value: 'BFCK', label: 'BFCK 补发出库' },
|
||
]
|
||
|
||
const form = reactive<OrderStatusPayload & { items: OrderItemLine[] }>({
|
||
parent_order_no: '',
|
||
order_no: '',
|
||
warehouse_id: null,
|
||
shop_id: null,
|
||
order_type: 'JYCK',
|
||
is_urgency: 'N',
|
||
invoice_flag: 'N',
|
||
receiver: '',
|
||
tel: '',
|
||
mobile: '',
|
||
email: '',
|
||
country_code: '',
|
||
province: '',
|
||
city: '',
|
||
area: '',
|
||
town: '',
|
||
detail_address: '',
|
||
zip_code: '',
|
||
oaid: '',
|
||
total_amount: null,
|
||
item_amount: null,
|
||
discount_amount: null,
|
||
freight: null,
|
||
ar_amount: null,
|
||
got_amount: null,
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
seller_message: '',
|
||
buyer_message: '',
|
||
remark: '',
|
||
items: [],
|
||
})
|
||
|
||
const rules: FormRules = {
|
||
warehouse_id: [ { required: true, message: '请选择仓库(推送仓库需要仓库编码与接口配置)', trigger: 'change' } ],
|
||
shop_id: [ { required: true, message: '请选择店铺(推送时 shopNick 取店铺名称匹配快递策略)', trigger: 'change' } ],
|
||
receiver: [ { required: true, message: '请输入收件人姓名', trigger: 'blur' } ],
|
||
// 省 / 市 / 区 由三级联动一次写入,校验挂在 province 上即可(city / area 不会再单独为空)
|
||
province: [ { required: true, message: '请选择省 / 市 / 区', trigger: 'change' } ],
|
||
town: [ { required: true, message: '请输入街道/镇', trigger: 'blur' } ],
|
||
logistics_code: [ { required: true, message: '请选择物流公司(推送仓库时随单下发 logisticsCode)', trigger: 'change' } ],
|
||
}
|
||
|
||
/** 明细行默认值 */
|
||
function emptyLine(): OrderItemLine {
|
||
return {
|
||
order_line_no: '',
|
||
item_id: null,
|
||
item_code: '',
|
||
item_name: '',
|
||
plan_qty: 1,
|
||
actual_price: 0,
|
||
retail_price: 0,
|
||
ext_code: '',
|
||
inventory_type: 'ZP',
|
||
}
|
||
}
|
||
|
||
function fillItems(items: OrderItemLine[] | undefined) {
|
||
form.items = (items || []).map(item => ({
|
||
...item,
|
||
plan_qty: Number(item.plan_qty || 0),
|
||
actual_price: item.actual_price === null || item.actual_price === undefined ? 0 : Number(item.actual_price),
|
||
}))
|
||
if (!form.items.length) form.items = [ emptyLine() ]
|
||
}
|
||
|
||
/** 默认仓库:取当前主体仓库列表第一个(与老发货单一致,减少手工选择) */
|
||
function defaultWarehouseId(): number | null {
|
||
const list = props.filters.warehouses || []
|
||
return list.length ? list[0].id : null
|
||
}
|
||
|
||
/** 默认店铺:优先父级入口指定的店铺,否则取店铺列表第一个 */
|
||
function defaultShopIdOf(): number | null {
|
||
if (props.defaultShopId) return props.defaultShopId
|
||
const list = props.filters.shops || []
|
||
return list.length ? list[0].id : null
|
||
}
|
||
|
||
function reset() {
|
||
Object.assign(form, {
|
||
parent_order_no: '',
|
||
order_no: '',
|
||
warehouse_id: defaultWarehouseId(),
|
||
shop_id: defaultShopIdOf(),
|
||
order_type: 'JYCK',
|
||
is_urgency: 'N',
|
||
invoice_flag: 'N',
|
||
receiver: '',
|
||
tel: '',
|
||
mobile: '',
|
||
email: '',
|
||
country_code: '',
|
||
province: '',
|
||
city: '',
|
||
area: '',
|
||
town: '',
|
||
detail_address: '',
|
||
zip_code: '',
|
||
oaid: '',
|
||
total_amount: null,
|
||
item_amount: null,
|
||
discount_amount: null,
|
||
freight: null,
|
||
ar_amount: null,
|
||
got_amount: null,
|
||
logistics_code: '',
|
||
logistics_name: '',
|
||
seller_message: '',
|
||
buyer_message: '',
|
||
remark: '',
|
||
})
|
||
fillItems([])
|
||
}
|
||
|
||
/** 编辑模式:载入现有单据与明细 */
|
||
async function loadDetail(id: number) {
|
||
loading.value = true
|
||
try {
|
||
const { order, items } = await getOrderStatusDetail(id)
|
||
Object.assign(form, {
|
||
parent_order_no: order.parent_order_no || '',
|
||
order_no: order.order_no,
|
||
warehouse_id: order.warehouse_id ?? null,
|
||
shop_id: order.shop_id ?? null,
|
||
order_type: order.order_type || 'JYCK',
|
||
is_urgency: order.is_urgency || 'N',
|
||
invoice_flag: order.invoice_flag || 'N',
|
||
receiver: order.receiver || '',
|
||
tel: order.tel || '',
|
||
mobile: order.mobile || '',
|
||
email: order.email || '',
|
||
country_code: order.country_code || '',
|
||
province: order.province || '',
|
||
city: order.city || '',
|
||
area: order.area || '',
|
||
town: order.town || '',
|
||
detail_address: order.detail_address || '',
|
||
zip_code: order.zip_code || '',
|
||
oaid: order.oaid || '',
|
||
total_amount: numOrNull(order.total_amount),
|
||
item_amount: numOrNull(order.item_amount),
|
||
discount_amount: numOrNull(order.discount_amount),
|
||
freight: numOrNull(order.freight),
|
||
ar_amount: numOrNull(order.ar_amount),
|
||
got_amount: numOrNull(order.got_amount),
|
||
logistics_code: order.logistics_code || '',
|
||
logistics_name: order.logistics_name || '',
|
||
seller_message: order.seller_message || '',
|
||
buyer_message: order.buyer_message || '',
|
||
remark: order.remark || '',
|
||
})
|
||
fillItems(items)
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function numOrNull(value: unknown): number | null {
|
||
if (value === null || value === undefined || value === '') return null
|
||
const num = Number(value)
|
||
return Number.isFinite(num) ? num : null
|
||
}
|
||
|
||
watch(
|
||
() => [ props.modelValue, props.orderId ] as const,
|
||
async ([ open, id ]) => {
|
||
if (!open) return
|
||
reset()
|
||
if (id) await loadDetail(Number(id))
|
||
else fillItems([])
|
||
},
|
||
{ immediate: true },
|
||
)
|
||
|
||
/* -------------------- 收件人智能识别 -------------------- */
|
||
const receiverText = ref('')
|
||
const parsing = ref(false)
|
||
async function handleParseReceiver() {
|
||
const text = receiverText.value.trim()
|
||
if (!text) {
|
||
ElMessage.warning('请先粘贴包含收件人信息的文本')
|
||
return
|
||
}
|
||
parsing.value = true
|
||
try {
|
||
const data = await parseReceiverText(text)
|
||
// 识别结果按同名字段回填(识别不到的不覆盖已有值)
|
||
const mapping: Record<string, keyof typeof form> = {
|
||
name: 'receiver',
|
||
tel: 'tel',
|
||
mobile: 'mobile',
|
||
province: 'province',
|
||
city: 'city',
|
||
area: 'area',
|
||
town: 'town',
|
||
detailAddress: 'detail_address',
|
||
detail_address: 'detail_address',
|
||
zipCode: 'zip_code',
|
||
zip_code: 'zip_code',
|
||
email: 'email',
|
||
}
|
||
let hit = 0
|
||
for (const [ key, value ] of Object.entries(data || {})) {
|
||
const field = mapping[key]
|
||
if (!field || value === null || value === undefined || value === '') continue
|
||
;(form as Record<string, unknown>)[field as string] = String(value)
|
||
hit += 1
|
||
}
|
||
ElMessage.success(hit ? `已识别并填充 ${hit} 项收件人信息` : '未识别到可用字段,请手工填写')
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
parsing.value = false
|
||
}
|
||
}
|
||
|
||
/* -------------------- 省 / 市 / 区 三级联动 -------------------- */
|
||
/** 省市区选项(element-china-area-data 的 pcaTextArr,值即文本,与库内 province/city/area 同口径) */
|
||
const areaOptions = ref<DataItem[]>([])
|
||
|
||
/** 三级路径(由 province/city/area 派生,识别回填 / 编辑回显都能同步) */
|
||
const areaPath = computed<string[]>(() =>
|
||
[ form.province, form.city, form.area ].map(part => String(part || '').trim()).filter(Boolean),
|
||
)
|
||
|
||
/** 选完三级后拆分回三个字段(后端仍按 province/city/area 三个列存) */
|
||
function handleAreaChange(path: string[] | null) {
|
||
const list = Array.isArray(path) ? path : []
|
||
form.province = list[0] || ''
|
||
form.city = list[1] || ''
|
||
form.area = list[2] || ''
|
||
}
|
||
|
||
/** 当前地区路径是否命中标准行政区划(未命中时下拉显示为空,需提示库内原值) */
|
||
const areaPathMatched = computed(() => {
|
||
const path = areaPath.value
|
||
if (!path.length) return true
|
||
let level: DataItem[] | undefined = areaOptions.value
|
||
for (const name of path) {
|
||
const hit: DataItem | undefined = (level || []).find(option => option.label === name)
|
||
if (!hit) return false
|
||
level = hit.children
|
||
}
|
||
return true
|
||
})
|
||
|
||
/* -------------------- 物流公司(快递公司字典) -------------------- */
|
||
const expressCompanies = ref<ExpressCompanyOption[]>([])
|
||
|
||
/** 下拉选项:字典项 + 当前值(WMS 可能回传字典外的自定义编码,避免显示为空) */
|
||
const expressOptions = computed<ExpressCompanyOption[]>(() => {
|
||
const list = [ ...expressCompanies.value ]
|
||
const code = String(form.logistics_code || '').trim()
|
||
if (code && !list.some(company => company.code === code)) {
|
||
list.unshift({ id: 0, code, name: String(form.logistics_name || code) })
|
||
}
|
||
return list
|
||
})
|
||
|
||
/** 选中物流公司后自动带出名称(与老发货单口径一致) */
|
||
function handleExpressChange(code: string | null) {
|
||
const company = expressCompanies.value.find(item => item.code === code)
|
||
form.logistics_name = company ? company.name : ''
|
||
}
|
||
|
||
watch(
|
||
() => props.modelValue,
|
||
async open => {
|
||
if (!open) return
|
||
try {
|
||
expressCompanies.value = await getExpressCompanyOptions()
|
||
} catch {
|
||
// 拦截器已提示
|
||
}
|
||
// 省市区数据较大,按需动态加载(单独 chunk,不进主包)
|
||
if (!areaOptions.value.length) {
|
||
try {
|
||
const { pcaTextArr } = await import('element-china-area-data')
|
||
areaOptions.value = pcaTextArr as DataItem[]
|
||
} catch {
|
||
// 可选依赖加载失败时降级为不做可选(省市区仍有智能识别与手工联动)
|
||
}
|
||
}
|
||
},
|
||
)
|
||
|
||
// 筛选项(仓库 / 店铺)异步到达时兜底回填默认值(新建场景)
|
||
watch(
|
||
() => props.filters,
|
||
() => {
|
||
if (!visible.value || isEdit.value) return
|
||
if (form.warehouse_id == null) form.warehouse_id = defaultWarehouseId()
|
||
if (form.shop_id == null) form.shop_id = defaultShopIdOf()
|
||
},
|
||
{ deep: true },
|
||
)
|
||
|
||
/* -------------------- 明细 -------------------- */
|
||
function addLine() {
|
||
form.items = [ ...form.items, emptyLine() ]
|
||
}
|
||
function removeLine(index: number) {
|
||
const list = [ ...form.items ]
|
||
list.splice(index, 1)
|
||
form.items = list.length ? list : [ emptyLine() ]
|
||
}
|
||
|
||
/** 选中商品后带出商品ID / 编码 / 名称(单价与数量由人工填写,与老发货单一致) */
|
||
function onLineProductSelect(index: number, product: ProductSearchItem) {
|
||
const line = form.items[index]
|
||
if (!line) return
|
||
line.item_id = product.id
|
||
line.item_code = product.item_code || ''
|
||
line.item_name = product.item_name || ''
|
||
}
|
||
|
||
function lineAmount(line: OrderItemLine): string {
|
||
const qty = Number(line.plan_qty || 0)
|
||
const price = Number(line.actual_price || 0)
|
||
if (!Number.isFinite(qty) || !Number.isFinite(price)) return '-'
|
||
return (qty * price).toFixed(2)
|
||
}
|
||
|
||
/** 汇总明细金额(商品总金额 item_amount 的唯一口径:Σ 数量 × 单价) */
|
||
const itemsAmount = computed(() =>
|
||
form.items.reduce((sum, line) => sum + Number(line.plan_qty || 0) * Number(line.actual_price || 0), 0),
|
||
)
|
||
|
||
/** 明细是否有实际内容(空行不计):有明细时商品总金额由明细派生,不允许手改 */
|
||
const hasRealItems = computed(() =>
|
||
form.items.some(line => String(line.item_code || '').trim() || Number(line.item_id || 0) > 0),
|
||
)
|
||
|
||
/** 商品总金额(两位小数) */
|
||
const derivedItemAmount = computed(() => Number(itemsAmount.value.toFixed(2)))
|
||
|
||
// 明细变化 → 自动回填商品总金额(对齐后端重算口径,避免表头与明细不一致)
|
||
watch(
|
||
() => form.items.map(line => `${line.item_code}|${line.plan_qty}|${line.actual_price}`).join(','),
|
||
() => {
|
||
if (hasRealItems.value) form.item_amount = derivedItemAmount.value
|
||
},
|
||
)
|
||
|
||
/** 提交前清理:空行剔除、行号补全、空串转 undefined */
|
||
function buildPayload(): OrderStatusPayload {
|
||
const items = form.items
|
||
.filter(line => (line.item_code && String(line.item_code).trim()) || (line.item_id && line.item_id > 0))
|
||
.map((line, index) => ({
|
||
order_line_no: String(line.order_line_no || index + 1),
|
||
item_id: line.item_id ?? null,
|
||
item_code: line.item_code ? String(line.item_code).trim() : null,
|
||
item_name: line.item_name ? String(line.item_name).trim() : null,
|
||
plan_qty: Number(line.plan_qty || 0),
|
||
actual_price: line.actual_price === null || line.actual_price === undefined ? 0 : Number(line.actual_price),
|
||
retail_price: line.retail_price === null || line.retail_price === undefined ? 0 : Number(line.retail_price),
|
||
ext_code: line.ext_code ? String(line.ext_code).trim() : null,
|
||
inventory_type: line.inventory_type || 'ZP',
|
||
}))
|
||
|
||
const text = (value: unknown) => {
|
||
const str = value === null || value === undefined ? '' : String(value).trim()
|
||
return str === '' ? undefined : str
|
||
}
|
||
|
||
// 金额类:空值不传(后端保留库内既有值 / 默认 0),避免显式 null 触发非空约束
|
||
const amount = (value: unknown) => {
|
||
const num = numOrNull(value)
|
||
return num === null ? undefined : num
|
||
}
|
||
|
||
return {
|
||
parent_order_no: text(form.parent_order_no),
|
||
order_no: isEdit.value ? undefined : text(form.order_no),
|
||
warehouse_id: form.warehouse_id ?? null,
|
||
shop_id: form.shop_id ?? null,
|
||
order_type: form.order_type || 'JYCK',
|
||
is_urgency: form.is_urgency || 'N',
|
||
invoice_flag: form.invoice_flag || 'N',
|
||
receiver: text(form.receiver),
|
||
tel: text(form.tel),
|
||
mobile: text(form.mobile),
|
||
email: text(form.email),
|
||
country_code: text(form.country_code),
|
||
province: text(form.province),
|
||
city: text(form.city),
|
||
area: text(form.area),
|
||
town: text(form.town),
|
||
detail_address: text(form.detail_address),
|
||
zip_code: text(form.zip_code),
|
||
oaid: text(form.oaid),
|
||
total_amount: amount(form.total_amount),
|
||
item_amount: hasRealItems.value ? derivedItemAmount.value : amount(form.item_amount),
|
||
discount_amount: amount(form.discount_amount),
|
||
freight: amount(form.freight),
|
||
ar_amount: amount(form.ar_amount),
|
||
got_amount: amount(form.got_amount),
|
||
logistics_code: text(form.logistics_code),
|
||
logistics_name: text(form.logistics_name),
|
||
seller_message: text(form.seller_message),
|
||
buyer_message: text(form.buyer_message),
|
||
remark: text(form.remark),
|
||
items: items.length ? items : undefined,
|
||
}
|
||
}
|
||
|
||
async function submit() {
|
||
if (!formRef.value) return
|
||
await formRef.value.validate(async valid => {
|
||
if (!valid) return
|
||
// 收件人电话与手机至少填一个(对齐后端与取号硬依赖)
|
||
if (!String(form.tel || '').trim() && !String(form.mobile || '').trim()) {
|
||
ElMessage.warning('收件人电话(tel)与手机(mobile)至少填写一个')
|
||
return
|
||
}
|
||
// 新建发货单必须有商品明细(单号、库存锁定与推送仓库均以明细为准)
|
||
if (!isEdit.value && !hasRealItems.value) {
|
||
ElMessage.warning('请至少填写一行商品明细(商品编码 + 数量 + 单价)')
|
||
return
|
||
}
|
||
submitting.value = true
|
||
try {
|
||
const payload = buildPayload()
|
||
if (isEdit.value && props.orderId) {
|
||
await updateOrderStatus(Number(props.orderId), payload)
|
||
ElMessage.success('订单已更新')
|
||
emit('saved', { id: Number(props.orderId), order_no: String(payload.order_no || ''), isEdit: true })
|
||
} else {
|
||
const result = await createOrderStatus(payload)
|
||
ElMessage.success(`已创建订单 ${result.order_no}`)
|
||
emit('saved', { id: result.id, order_no: result.order_no, isEdit: false })
|
||
}
|
||
visible.value = false
|
||
} catch {
|
||
// 拦截器已提示
|
||
} finally {
|
||
submitting.value = false
|
||
}
|
||
})
|
||
}
|
||
|
||
</script>
|
||
|
||
<template>
|
||
<el-dialog
|
||
v-model="visible"
|
||
:title="isEdit ? '编辑订单' : '新建订单(发货单)'"
|
||
width="980px"
|
||
top="6vh"
|
||
append-to-body
|
||
destroy-on-close
|
||
>
|
||
<el-form ref="formRef" :model="form" :rules="rules" label-width="96px" size="small" scroll-to-error v-loading="loading">
|
||
<div class="form-body">
|
||
<el-divider content-position="left">基础信息</el-divider>
|
||
<el-row :gutter="8">
|
||
<el-col :span="12">
|
||
<el-form-item label="来源订单号">
|
||
<el-input v-model="form.parent_order_no" placeholder="上游 / 平台订单号(可空)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="订单号">
|
||
<el-input
|
||
v-model="form.order_no"
|
||
:disabled="isEdit"
|
||
:placeholder="isEdit ? '订单号不可修改(驳回 / 恢复时系统换号)' : '留空自动生成'"
|
||
clearable
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="仓库" prop="warehouse_id">
|
||
<el-select v-model="form.warehouse_id" placeholder="请选择仓库" clearable filterable style="width: 100%">
|
||
<el-option
|
||
v-for="warehouse in props.filters.warehouses"
|
||
:key="warehouse.id"
|
||
:label="`${warehouse.name}(${warehouse.code})`"
|
||
:value="warehouse.id"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="店铺" prop="shop_id">
|
||
<el-select v-model="form.shop_id" placeholder="请选择店铺" clearable filterable style="width: 100%">
|
||
<el-option v-for="shop in props.filters.shops" :key="shop.id" :label="shop.name" :value="shop.id" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="订单类型">
|
||
<el-select v-model="form.order_type" style="width: 100%">
|
||
<el-option v-for="item in ORDER_TYPES" :key="item.value" :label="item.label" :value="item.value" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="是否紧急">
|
||
<el-select v-model="form.is_urgency" style="width: 100%">
|
||
<el-option label="否" value="N" />
|
||
<el-option label="是" value="Y" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="需要发票">
|
||
<el-select v-model="form.invoice_flag" style="width: 100%">
|
||
<el-option label="否" value="N" />
|
||
<el-option label="是" value="Y" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="24">
|
||
<el-form-item label="备注">
|
||
<el-input v-model="form.remark" placeholder="备注 / 异常原因" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-divider content-position="left">收件人</el-divider>
|
||
<div class="parse-bar">
|
||
<el-input
|
||
v-model="receiverText"
|
||
type="textarea"
|
||
:rows="2"
|
||
placeholder="粘贴「姓名 电话 地址」等文本,自动识别并填充下方字段"
|
||
/>
|
||
<el-button type="primary" size="small" :loading="parsing" @click="handleParseReceiver">智能识别</el-button>
|
||
</div>
|
||
<el-row :gutter="8">
|
||
<el-col :span="8">
|
||
<el-form-item label="收件人" prop="receiver">
|
||
<el-input v-model="form.receiver" placeholder="姓名" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="电话">
|
||
<el-input v-model="form.tel" placeholder="电话(与手机至少填一个)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="手机">
|
||
<el-input v-model="form.mobile" placeholder="手机" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="省/市/区" prop="province">
|
||
<div class="area-field">
|
||
<el-cascader
|
||
:model-value="areaPath"
|
||
:options="areaOptions"
|
||
:props="{ expandTrigger: 'hover' }"
|
||
placeholder="搜索或逐级选择省 / 市 / 区"
|
||
filterable
|
||
clearable
|
||
style="width: 100%"
|
||
@change="handleAreaChange"
|
||
/>
|
||
<span v-if="!areaPathMatched" class="field-hint">
|
||
库内地区:{{ areaPath.join(' / ') }}(不在标准行政区划内,重新选择将覆盖)
|
||
</span>
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="街道/镇" prop="town">
|
||
<el-input v-model="form.town" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="24">
|
||
<el-form-item label="详细地址">
|
||
<el-input v-model="form.detail_address" placeholder="门牌号 / 楼栋 / 村组等" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-collapse class="more-collapse">
|
||
<el-collapse-item title="更多收件人字段(选填:邮箱 / 国家编码 / 邮编 / OAID)" name="more-receiver">
|
||
<el-row :gutter="8">
|
||
<el-col :span="8">
|
||
<el-form-item label="邮箱">
|
||
<el-input v-model="form.email" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="国家编码">
|
||
<el-input v-model="form.country_code" placeholder="如 CN" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="邮编">
|
||
<el-input v-model="form.zip_code" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="OAID">
|
||
<el-input v-model="form.oaid" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-collapse-item>
|
||
</el-collapse>
|
||
|
||
<el-divider content-position="left">金额与物流</el-divider>
|
||
<el-row :gutter="8">
|
||
<el-col :span="6">
|
||
<el-form-item label="订单总金额">
|
||
<el-input-number v-model="form.total_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="商品总金额">
|
||
<div class="amount-field">
|
||
<el-input-number
|
||
v-model="form.item_amount"
|
||
:min="0"
|
||
:precision="2"
|
||
:controls="false"
|
||
:disabled="hasRealItems"
|
||
style="width: 100%"
|
||
/>
|
||
<span v-if="hasRealItems" class="field-hint">按明细自动计算</span>
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="折扣金额">
|
||
<el-input-number v-model="form.discount_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="快递费">
|
||
<el-input-number v-model="form.freight" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="应收金额">
|
||
<el-input-number v-model="form.ar_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="6">
|
||
<el-form-item label="已收金额">
|
||
<el-input-number v-model="form.got_amount" :min="0" :precision="2" :controls="false" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="物流公司" prop="logistics_code">
|
||
<el-select
|
||
v-model="form.logistics_code"
|
||
placeholder="请选择快递公司"
|
||
clearable
|
||
filterable
|
||
style="width: 100%"
|
||
@change="handleExpressChange"
|
||
>
|
||
<el-option
|
||
v-for="company in expressOptions"
|
||
:key="company.code"
|
||
:label="`${company.name}(${company.code})`"
|
||
:value="company.code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-collapse class="more-collapse">
|
||
<el-collapse-item title="更多(选填:卖家留言 / 买家留言)" name="more-amount">
|
||
<el-row :gutter="8">
|
||
<el-col :span="12">
|
||
<el-form-item label="卖家留言">
|
||
<el-input v-model="form.seller_message" type="textarea" :rows="2" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="买家留言">
|
||
<el-input v-model="form.buyer_message" type="textarea" :rows="2" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-collapse-item>
|
||
</el-collapse>
|
||
|
||
<el-divider content-position="left">商品明细</el-divider>
|
||
<DataTable :data="form.items" :stripe="true">
|
||
<el-table-column label="行号" width="70">
|
||
<template #default="{ row, $index }">
|
||
<el-input v-model="row.order_line_no" size="small" :placeholder="String($index + 1)" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品" min-width="220">
|
||
<template #default="{ row, $index }">
|
||
<ProductSelect
|
||
v-model="row.item_id"
|
||
:model-label="[ row.item_code, row.item_name ].filter(Boolean).join(' ')"
|
||
@select="(p: ProductSearchItem) => onLineProductSelect($index, p)"
|
||
/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品编码" width="140">
|
||
<template #default="{ row }">
|
||
<el-input v-model="row.item_code" size="small" placeholder="选商品后自动带出" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="商品名称" min-width="150">
|
||
<template #default="{ row }">
|
||
<el-input v-model="row.item_name" size="small" placeholder="选商品后自动带出" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="数量" width="100">
|
||
<template #default="{ row }">
|
||
<el-input-number v-model="row.plan_qty" :min="0" :precision="3" :controls="false" size="small" style="width: 100%" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="单价" width="100">
|
||
<template #default="{ row }">
|
||
<el-input-number v-model="row.actual_price" :min="0" :precision="2" :controls="false" size="small" style="width: 100%" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="库存类型" width="100">
|
||
<template #default="{ row }">
|
||
<el-select v-model="row.inventory_type" size="small">
|
||
<el-option label="正品" value="ZP" />
|
||
<el-option label="残次" value="CC" />
|
||
</el-select>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="外部编码" width="120">
|
||
<template #default="{ row }">
|
||
<el-input v-model="row.ext_code" size="small" />
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="金额" width="90" align="right">
|
||
<template #default="{ row }">{{ lineAmount(row) }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="70">
|
||
<template #default="{ $index }">
|
||
<el-button link type="danger" size="small" @click="removeLine($index)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</DataTable>
|
||
<div class="items-footer">
|
||
<el-button size="small" @click="addLine">添加商品行</el-button>
|
||
<span class="items-total">明细金额合计:{{ itemsAmount.toFixed(2) }}</span>
|
||
</div>
|
||
</div>
|
||
</el-form>
|
||
|
||
<template #footer>
|
||
<el-button size="small" @click="visible = false">取消</el-button>
|
||
<el-button type="primary" size="small" :loading="submitting" @click="submit">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.form-body {
|
||
max-height: 66vh;
|
||
overflow-y: auto;
|
||
padding-right: 4px;
|
||
}
|
||
.form-body :deep(.el-divider) {
|
||
margin: 4px 0 14px;
|
||
}
|
||
.form-body :deep(.el-divider__text) {
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
}
|
||
.more-collapse {
|
||
border-top: none;
|
||
}
|
||
.more-collapse :deep(.el-collapse-item__header) {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
height: 32px;
|
||
line-height: 32px;
|
||
border-bottom: none;
|
||
}
|
||
.more-collapse :deep(.el-collapse-item__wrap) {
|
||
border-bottom: none;
|
||
}
|
||
.parse-bar {
|
||
display: flex;
|
||
gap: 8px;
|
||
align-items: flex-start;
|
||
margin-bottom: 12px;
|
||
}
|
||
.parse-bar .el-button {
|
||
flex: 0 0 auto;
|
||
}
|
||
.items-footer {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-top: 8px;
|
||
}
|
||
.items-total {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
.amount-field {
|
||
width: 100%;
|
||
}
|
||
.area-field {
|
||
width: 100%;
|
||
}
|
||
.field-hint {
|
||
display: block;
|
||
margin-top: 2px;
|
||
font-size: 12px;
|
||
line-height: 16px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
:deep(.el-descriptions__label) {
|
||
width: 110px;
|
||
}
|
||
</style>
|