feat: 维保发货

frontend_1.0.0
chenhao 2026-10-09 17:34:52 +08:00
parent 6f1bed50de
commit dce74b065b
2 changed files with 142 additions and 346 deletions

View File

@ -1,33 +1,11 @@
<template>
<el-dialog
title="维保发货"
:close-on-click-modal="false"
:visible.sync="visible"
width="80%"
top="5vh"
append-to-body
@close="handleCancel"
>
<div class="maintenance-head">
<div class="maintenance-head__title">要求发货时间: {{ requiredDeliveryTime || '-' }}</div>
<div class="maintenance-head__related">
<span>
关联项目:
<b>{{ relatedText }}</b>
</span>
<span class="maintenance-head__divider" />
<span>
可续用SN:
<b>{{ snList.length }}</b> 台
</span>
<span class="maintenance-head__divider" />
<span>
剩余应发:
<b>{{ remainText }}</b>
</span>
</div>
<el-dialog title="生成发货单" :close-on-click-modal="false" :visible.sync="visible" width="85%" top="5vh" append-to-body @close="handleCancel">
<div class="required-delivery-time">
要求发货时间: {{ requiredDeliveryTime }}
</div>
<div class="related-project">
关联项目: {{ relatedText }}(可续用SN {{ availableNum }} 台,本次应发 {{ remainQuantity }} 台)
</div>
<el-form :model="form" ref="form" label-width="100px" :rules="rules">
<el-row>
<el-col :span="6">
@ -38,24 +16,14 @@
<el-col :span="6">
<el-form-item label="发货方式" prop="deliveryType">
<el-select v-model="form.deliveryType" placeholder="请选择">
<el-option
v-for="dict in dict.type.delivery_type"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
<el-option v-for="dict in dict.type.delivery_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="物流公司" prop="logisticsCompany">
<el-select v-model="form.logisticsCompany" placeholder="请选择">
<el-option
v-for="dict in dict.type.logistics_company"
:key="dict.value"
:label="dict.label"
:value="dict.value"
></el-option>
<el-option v-for="dict in dict.type.logistics_company" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
</el-select>
</el-form-item>
</el-col>
@ -71,13 +39,7 @@
</el-col>
<el-col :span="6">
<el-form-item label="发货时间" prop="deliveryTime">
<el-date-picker
v-model="form.deliveryTime"
type="date"
value-format="yyyy-MM-dd"
placeholder="选择日期"
:disabled="form.deliveryTimeType === '0'"
></el-date-picker>
<el-date-picker v-model="form.deliveryTime" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" :disabled="form.deliveryTimeType === '0'"></el-date-picker>
</el-form-item>
</el-col>
<el-col :span="12">
@ -95,65 +57,42 @@
</el-row>
</el-form>
<div class="table-card">
<div class="table-card__toolbar">
<el-button type="primary" plain icon="el-icon-check" size="mini" @click="selectAll">全选可续用SN</el-button>
<el-button plain icon="el-icon-close" size="mini" @click="clearSelection">清空</el-button>
<div class="maintenance-count">已选: {{ selectedSnList.length }} (台)</div>
</div>
<el-table
ref="snTable"
v-loading="loading"
:data="snList"
row-key="productSn"
height="360"
@selection-change="handleSelectionChange"
>
<el-table-column type="selection" width="55" align="center" reserve-selection />
<el-table-column label="SN码" align="center" prop="productSn" min-width="200" />
<el-table-column label="来源发货单" align="center" prop="deliveryId" width="140" />
<el-table-column label="来源发货时间" align="center" prop="deliveryTime" width="180" />
<template slot="empty">
<div class="maintenance-empty">
关联项目下暂无该产品编码的已发货SN,请先确认订单的关联项目与产品配置
</div>
</template>
</el-table>
</div>
<el-row :gutter="10" class="mb8">
<el-col :span="24">
<div style="text-align: right;">已选: {{ selectedSnList.length }} (台)</div>
</el-col>
</el-row>
<el-table ref="snTable" :data="snList" @selection-change="handleSelectionChange" height="400px" row-key="productSn" v-loading="loading">
<el-table-column type="selection" width="55" align="center" :reserve-selection="true"/>
<el-table-column label="SN码" prop="productSn" />
<el-table-column label="产品编码" :formatter="productCodeFormatter" />
<el-table-column label="关联项目发货时间" prop="deliveryTime" width="200" />
</el-table>
<div slot="footer" class="dialog-footer">
<el-button type="primary" :loading="submitting" @click="submitForm">确 定</el-button>
<el-button type="primary" @click="submitForm">确 定</el-button>
<el-button @click="handleCancel">取 消</el-button>
</div>
</el-dialog>
</template>
<script>
/**
* 仅维保订单发货弹窗
*
* 与普通发货的区别:SN 不从本订单库存里挑,而是直接续用关联项目同产品编码的已发货SN。
* 后端 addDelivery 里 maintenanceOnly 分支只写发货单与发货明细,
* 不校验采购绑定、也不回写 SN 的库存状态/出库单号/订单归属,
* 因此这里只提交 productSnList(productSnDataList 保持为空)。
*/
import { addDelivery, maintenanceSn } from '@/api/inventory/delivery';
export default {
name: 'MaintenanceDeliveryForm',
name: "MaintenanceDeliveryForm",
dicts: ['delivery_type', 'logistics_company'],
data() {
return {
visible: false,
loading: false,
submitting: false,
requiredDeliveryTime: '',
productData: {},
outerData: {},
related: {
relatedOrderCode: '',
relatedProjectName: ''
},
relatedOrderCode: '',
relatedProjectName: '',
availableNum: 0,
snList: [],
selectedSnList: [],
form: {
@ -161,114 +100,87 @@ export default {
deliveryType: '',
logisticsCompany: '',
deliveryTimeType: '0',
deliveryTime: '',
deliveryTime: new Date(),
remark: '',
notifierAddress: ''
notifierAddress: '',
},
rules: {
logisticsCode: [{ required: true, message: '物流单号不能为空', trigger: 'blur' }],
deliveryType: [{ required: true, message: '发货方式不能为空', trigger: 'change' }]
}
logisticsCode: [{ required: true, message: "物流单号不能为空", trigger: "blur" }],
deliveryType: [{ required: true, message: "发货方式不能为空", trigger: "change" }],
},
};
},
computed: {
relatedText() {
const code = this.related.relatedOrderCode;
const name = this.related.relatedProjectName;
if (!code && !name) {
return '-';
}
return [code, name].filter(item => !!item).join(' / ');
},
// 剩余应发数量:取不到时返回 NaN,交由后端兜底校验
// 剩余应发数量:出库明细数量 - 已生成发货 - 已确认发货
remainQuantity() {
const quantity = Number(this.productData.quantity);
if (!this.productData.quantity || Number.isNaN(quantity)) {
return NaN;
if (Number.isNaN(quantity)) {
return 0;
}
return (
quantity -
Number(this.productData.deliveryGenerateQuantity || 0) -
Number(this.productData.deliveryConfirmQuantity || 0)
);
return quantity
- Number(this.productData.deliveryGenerateQuantity || 0)
- Number(this.productData.deliveryConfirmQuantity || 0);
},
relatedText() {
if (!this.relatedOrderCode) {
return '未配置关联项目';
}
return this.relatedProjectName
? this.relatedOrderCode + ' / ' + this.relatedProjectName
: this.relatedOrderCode;
},
remainText() {
return Number.isNaN(this.remainQuantity) ? '-' : `${this.remainQuantity} 台`;
}
},
watch: {
'form.deliveryTimeType'(val) {
if (val === '0') {
this.form.deliveryTime = this.today();
this.form.deliveryTime = new Date();
}
}
},
methods: {
today() {
return this.parseTime(new Date(), '{y}-{m}-{d}');
productCodeFormatter() {
return this.productData.productCode;
},
open(productRow, outerForm) {
this.reset();
this.productData = productRow || {};
this.outerData = outerForm || {};
this.requiredDeliveryTime = this.outerData.deliveryTime || '';
this.requiredDeliveryTime = this.outerData.deliveryTime;
this.form.notifierAddress = this.outerData.notifierAddress || '';
this.form.deliveryTime = this.today();
this.visible = true;
this.getSnList();
this.loadSnList();
},
getSnList() {
loadSnList() {
const orderCode = this.outerData.orderCode;
const productCode = this.productData.productCode;
if (!orderCode || !productCode) {
this.$message.error('缺少订单编码或产品编码,无法查询可续用的SN');
this.$message.error('订单编码或产品编码为空,无法查询可续用SN');
return;
}
this.loading = true;
maintenanceSn({ orderCode, productCode })
.then(response => {
const data = response.data || {};
this.related = {
relatedOrderCode: data.relatedOrderCode || '',
relatedProjectName: data.relatedProjectName || ''
};
this.snList = data.snList || [];
if (this.snList.length === 0) {
this.$message.warning('关联项目下没有可续用的SN,请先确认关联项目配置');
}
this.$nextTick(() => this.preselect());
})
.catch(() => {
this.snList = [];
})
.finally(() => {
this.loading = false;
maintenanceSn({ orderCode, productCode }).then(response => {
const data = response.data || {};
this.relatedOrderCode = data.relatedOrderCode || '';
this.relatedProjectName = data.relatedProjectName || '';
this.availableNum = data.availableNum || 0;
this.snList = data.snList || [];
if (this.snList.length < this.remainQuantity) {
this.$message.error(`关联项目可续用SN(${this.snList.length}台)少于本次应发数量(${this.remainQuantity}台),请先在关联项目完成发货`);
return;
}
// 默认勾选前 N 个(N = 剩余应发数量),可按需增删
this.$nextTick(() => {
this.$refs.snTable.clearSelection();
this.snList.slice(0, this.remainQuantity).forEach(row => {
this.$refs.snTable.toggleRowSelection(row, true);
});
});
}).finally(() => {
this.loading = false;
});
},
// 默认按剩余应发数量勾选(后端按发货时间倒序返回,取前面的即可)
preselect() {
const table = this.$refs.snTable;
if (!table) {
return;
}
table.clearSelection();
const target = Number.isNaN(this.remainQuantity) ? this.snList.length : this.remainQuantity;
this.snList.slice(0, Math.max(target, 0)).forEach(row => table.toggleRowSelection(row, true));
},
selectAll() {
const table = this.$refs.snTable;
if (!table) {
return;
}
this.snList.forEach(row => table.toggleRowSelection(row, true));
},
clearSelection() {
if (this.$refs.snTable) {
this.$refs.snTable.clearSelection();
}
},
handleSelectionChange(rows) {
this.selectedSnList = rows;
handleSelectionChange(selection) {
this.selectedSnList = selection;
},
submitForm() {
this.$refs.form.validate(valid => {
@ -276,115 +188,64 @@ export default {
return;
}
if (this.selectedSnList.length === 0) {
this.$message.error('请选择发货SN');
this.$message.error("应发货数量应该大于0");
return;
}
const remain = this.remainQuantity;
// 与普通发货同一口径:必须一次发满剩余应发数量
if (!Number.isNaN(remain) && this.selectedSnList.length !== remain) {
this.$message.error(
`发货必须一次发满剩余应发数量(剩余 ${remain} 台,当前已选 ${this.selectedSnList.length} 台)`
);
// 与其他发货方式一致:必须一次发满剩余应发数量
if (this.remainQuantity > 0 && this.selectedSnList.length !== this.remainQuantity) {
this.$message.error(`发货必须一次发满剩余应发数量(剩余 ${this.remainQuantity} 台,当前已选 ${this.selectedSnList.length} 台)`);
return;
}
if (this.selectedSnList.length > this.snList.length) {
this.$message.error('所选SN数量超过可续用SN数量');
return;
}
const data = {
...this.form,
productSnList: this.selectedSnList.map(item => item.productSn),
// 仅维保不回写SN库存信息,明细由后端按 productSnList 生成
productSnDataList: [],
productCode: this.productData.productCode,
quantity: this.selectedSnList.length,
warehouseId: this.productData.warehouseId,
outerCode: this.outerData.outerCode,
detailId: this.productData.id,
orderCode: this.outerData.orderCode
orderCode: this.outerData.orderCode,
};
this.submitting = true;
addDelivery(data)
.then(() => {
this.$message.success('生成发货单成功');
this.visible = false;
this.$emit('success');
})
.finally(() => {
this.submitting = false;
});
addDelivery(data).then(() => {
this.$message.success('生成发货单成功');
this.visible = false;
this.$emit('success');
});
});
},
handleCancel() {
this.visible = false;
this.reset();
},
reset() {
this.productData = {};
this.outerData = {};
this.requiredDeliveryTime = '';
this.related = { relatedOrderCode: '', relatedProjectName: '' };
this.snList = [];
this.selectedSnList = [];
this.form = {
logisticsCode: '',
deliveryType: '',
logisticsCompany: '',
deliveryTimeType: '0',
deliveryTime: this.today(),
deliveryTime: new Date(),
remark: '',
notifierAddress: ''
notifierAddress: '',
};
this.$nextTick(() => {
if (this.$refs.form) {
this.$refs.form.clearValidate();
}
if (this.$refs.snTable) {
this.$refs.snTable.clearSelection();
}
});
this.resetForm("form");
this.relatedOrderCode = '';
this.relatedProjectName = '';
this.availableNum = 0;
this.snList = [];
this.selectedSnList = [];
}
}
};
</script>
<style lang="scss" scoped>
.maintenance-head {
margin-bottom: 16px;
&__title {
margin-bottom: 6px;
font-size: 18px;
font-weight: 700;
text-align: right;
}
&__related {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
font-size: 13px;
}
&__divider {
width: 1px;
height: 12px;
background: #e2e8f0;
}
<style scoped>
.required-delivery-time {
font-weight: bold;
font-size: 18px;
text-align: right;
margin-bottom: 15px;
}
.maintenance-count {
margin-left: auto;
font-size: 13px;
}
.maintenance-empty {
padding: 24px 0;
font-size: 13px;
color: #94a3b8;
.related-project {
font-weight: bold;
margin-bottom: 15px;
}
</style>

View File

@ -1,93 +1,50 @@
<template>
<el-dialog
title="选择关联项目"
:close-on-click-modal="false"
:visible.sync="dialogVisible"
width="70%"
append-to-body
@close="handleClose"
>
<el-dialog title="选择关联项目" :visible.sync="dialogVisible" width="70%" append-to-body @close="handleClose">
<div class="app-container">
<div class="filter-card">
<el-form :model="queryParams" ref="queryForm" :inline="true" size="small" label-width="80px">
<el-form-item label="项目编号" prop="projectCode">
<el-input
v-model="queryParams.projectCode"
placeholder="请输入项目编号"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="项目名称" prop="projectName">
<el-input
v-model="queryParams.projectName"
placeholder="请输入项目名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</div>
<el-form :model="queryParams" ref="queryForm" :inline="true" label-width="80px">
<el-form-item label="项目编码" prop="projectCode">
<el-input v-model="queryParams.projectCode" placeholder="请输入项目编码" clearable size="small" @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item label="项目名称" prop="projectName">
<el-input v-model="queryParams.projectName" placeholder="请输入项目名称" clearable size="small" @keyup.enter.native="handleQuery"/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="table-card">
<el-table v-loading="loading" :data="orderList" @row-click="handleSelect">
<el-table-column label="项目编号" align="center" prop="projectCode" width="130" :show-overflow-tooltip="true" />
<el-table-column label="项目名称" align="center" prop="projectName" min-width="180" :show-overflow-tooltip="true" />
<el-table-column label="订单编号" align="center" prop="orderCode" width="150" :show-overflow-tooltip="true" />
<el-table-column label="最终客户" align="center" prop="customerName" min-width="150" :show-overflow-tooltip="true" />
<el-table-column label="金额(¥)" align="center" prop="shipmentAmount" width="120">
<template slot-scope="scope">{{ formatAmount(scope.row.shipmentAmount) }}</template>
</el-table-column>
<el-table-column label="审批完成时间" align="center" prop="approveTime" width="180">
<template slot-scope="scope">{{ scope.row.approveTime || '-' }}</template>
</el-table-column>
<el-table-column label="操作" align="center" width="80">
<template slot-scope="scope">
<el-button type="text" size="mini" @click.stop="handleSelect(scope.row)">选择</el-button>
</template>
</el-table-column>
<template slot="empty">
<div class="related-empty">暂无可选订单:仅展示已审批完成的正常订单,且不含当前订单</div>
</template>
</el-table>
<div class="table-card__footer">
<ui-pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</div>
</div>
<el-table
v-loading="loading"
:data="orderList"
highlight-current-row
@current-change="handleRowSelect"
>
<el-table-column label="项目编码" align="center" prop="projectCode" :show-overflow-tooltip="true"/>
<el-table-column label="项目名称" align="center" prop="projectName" :show-overflow-tooltip="true"/>
<el-table-column label="最终客户" align="center" prop="customerName" :show-overflow-tooltip="true"/>
</el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
</div>
</el-dialog>
</template>
<script>
/**
* 仅维保订单「关联项目」选择弹窗
*
* 候选口径由后端 /project/order/vue/relatedCandidateList 决定:
* 只返回已审批完成(order_status=2)的正常订单(order_type=1),并排除当前订单自身。
* 选中后向父组件抛出整行(含 id / orderCode / projectId / projectName)。
*/
import { relatedCandidateList } from '@/api/project/order';
import { relatedCandidateList } from "@/api/project/order";
export default {
name: 'RelatedOrderSelectDialog',
name: "RelatedOrderSelectDialog",
props: {
visible: {
type: Boolean,
default: false
},
// 当前订单id:避免把自己列为关联项目候选
excludeOrderId: {
type: [Number, String],
type: Number,
default: null
}
},
@ -124,21 +81,14 @@ export default {
methods: {
getList() {
this.loading = true;
// excludeOrderId 为空时不能传空串,后端是 Long 类型入参
return relatedCandidateList(
Object.assign({}, this.queryParams, { excludeOrderId: this.excludeOrderId || null })
)
.then(response => {
this.orderList = response.rows || [];
this.total = response.total || 0;
})
.catch(() => {
this.orderList = [];
this.total = 0;
})
.finally(() => {
this.loading = false;
});
const params = Object.assign({}, this.queryParams, { excludeOrderId: this.excludeOrderId });
relatedCandidateList(params).then(response => {
this.orderList = response.rows || [];
this.total = response.total || 0;
this.loading = false;
}).catch(() => {
this.loading = false;
});
},
handleQuery() {
this.queryParams.pageNum = 1;
@ -149,7 +99,8 @@ export default {
this.queryParams.projectName = null;
this.handleQuery();
},
handleSelect(row) {
// 单击行即选中并回填关闭,无需再次确认
handleRowSelect(row) {
if (!row) {
return;
}
@ -159,24 +110,8 @@ export default {
handleClose() {
this.queryParams.projectCode = null;
this.queryParams.projectName = null;
},
formatAmount(value) {
if (value === null || value === undefined || value === '') {
return '0.00';
}
return Number(value).toLocaleString('en-US', {
minimumFractionDigits: 2,
maximumFractionDigits: 2
});
this.queryParams.pageNum = 1;
}
}
};
</script>
<style lang="scss" scoped>
.related-empty {
padding: 24px 0;
font-size: 13px;
color: #94a3b8;
}
</style>