feat: 新增合同配置页面,优化多页面合同关联逻辑

1.  新增crm/contract/selectConfig页面,支持本地配置可选合同列表,区分手动/接口同步来源
2.  优化ContractSelect组件,新增上次选中合同置顶、本地存储选中记录功能
3.  为合卷、分条、退火计划、钢卷编辑页面添加合同必填校验与自动关联逻辑
4.  移除各业务页面冗余的合同关系手动调用代码,统一关联逻辑
This commit is contained in:
2026-06-18 13:49:52 +08:00
parent 7f1a89eb61
commit ee49fbdcc0
7 changed files with 392 additions and 63 deletions

View File

@@ -134,12 +134,14 @@ export default {
},
set(val) {
this.$emit('input', val);
if (val) {
localStorage.setItem('lastSelectedContractId', val);
}
}
}
},
mounted() {
if (this.mode == "today") {
// 从localstorage中获取合同列表
this.loadFromLocalStorage();
} else {
this.loadContractList();
@@ -197,10 +199,23 @@ export default {
this.contractList = this.contractList.filter((item, index, self) =>
index === self.findIndex(t => t.orderId === item.orderId)
);
// 上一次选择的合同放在列表第一位
this.sortLastSelectedToFirst();
// 保存到localStorage
this.saveToLocalStorage();
}
},
// 将上一次选择的合同排到列表第一位
sortLastSelectedToFirst() {
const lastId = localStorage.getItem('lastSelectedContractId');
if (!lastId) return;
const index = this.contractList.findIndex(item => String(item.orderId) === String(lastId));
if (index > 0) {
const [item] = this.contractList.splice(index, 1);
this.contractList.unshift(item);
}
},
// 打开选择弹窗
async openSelectDialog() {
this.dialogVisible = true;

View File

@@ -0,0 +1,341 @@
<template>
<div class="select-config-page">
<div class="page-header">
<h3>可选合同配置</h3>
<div class="header-stats">
<span class="stat-item">
<span class="stat-label">已配置</span>
<span class="stat-value">{{ contractList.length }}</span>
</span>
<span class="stat-item">
<span class="stat-label">手动添加</span>
<span class="stat-value manual">{{contractList.filter(i => i.isManual).length}}</span>
</span>
<span class="stat-item">
<span class="stat-label">接口同步</span>
<span class="stat-value api">{{contractList.filter(i => !i.isManual).length}}</span>
</span>
</div>
</div>
<div class="content-card">
<el-tabs v-model="activeTab" @tab-click="handleTabClick">
<el-tab-pane label="可选合同" name="configured">
<div v-if="contractList.length === 0" class="empty-state">
<i class="el-icon-document"></i>
<p>暂无已配置合同</p>
<span>切换至"所有合同"标签页添加合同</span>
</div>
<el-table v-else v-loading="configLoading" :data="contractList" style="width: 100%" size="small" stripe
max-height="calc(100vh - 280px)">
<el-table-column prop="contractCode" label="合同编号" width="160" />
<el-table-column prop="contractName" label="合同名称" min-width="180" show-overflow-tooltip />
<el-table-column prop="customer" label="客户" width="140" />
<el-table-column prop="salesman" label="销售人员" width="100" />
<el-table-column prop="deliveryDate" label="交付日期" width="110">
<template slot-scope="scope">
<span :class="{ 'text-muted': !scope.row.deliveryDate }">
{{ scope.row.deliveryDate || '-' }}
</span>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip>
<template slot-scope="scope">
<span :class="{ 'text-muted': !scope.row.remark }">
{{ scope.row.remark || '-' }}
</span>
</template>
</el-table-column>
<el-table-column label="添加方式" width="90" align="center">
<template slot-scope="scope">
<el-tag v-if="scope.row.isManual" type="success" size="small">手动</el-tag>
<el-tag v-else type="info" size="small">接口</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="80" align="center">
<template slot-scope="scope">
<el-button type="text" size="small" @click="removeContract(scope.row.orderId)" style="color: #f56c6c;">
移除
</el-button>
</template>
</el-table-column>
</el-table>
</el-tab-pane>
<el-tab-pane label="所有合同" v-loading="allLoading" name="all">
<div class="search-bar">
<el-input v-model="searchKeyword" placeholder="搜索合同编号 / 名称 / 客户" @input="handleSearch" clearable
size="small" class="search-input">
<i slot="prefix" class="el-input__icon el-icon-search"></i>
</el-input>
</div>
<div v-if="allContracts.length === 0" class="empty-state">
<i class="el-icon-folder-opened"></i>
<p>暂无合同数据</p>
</div>
<el-table v-else :data="allContracts" size="small" stripe height="calc(100vh - 320px)">
<el-table-column prop="contractCode" label="合同编号" width="160" />
<el-table-column prop="contractName" label="合同名称" min-width="180" show-overflow-tooltip />
<el-table-column prop="customer" label="客户" width="140" />
<el-table-column prop="salesman" label="销售人员" width="100" />
<el-table-column prop="deliveryDate" label="交付日期" width="110">
<template slot-scope="scope">
<span :class="{ 'text-muted': !scope.row.deliveryDate }">
{{ scope.row.deliveryDate || '-' }}
</span>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="140" show-overflow-tooltip>
<template slot-scope="scope">
<span :class="{ 'text-muted': !scope.row.remark }">
{{ scope.row.remark || '-' }}
</span>
</template>
</el-table-column>
<el-table-column label="状态" width="80" align="center">
<template slot-scope="scope">
<el-tag v-if="isContractInList(scope.row.orderId)" type="success" size="small">已添加</el-tag>
<el-tag v-else type="info" size="small">未添加</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="80" align="center">
<template slot-scope="scope">
<el-button v-if="!isContractInList(scope.row.orderId)" type="primary" size="mini"
@click="addContract(scope.row)" plain>
添加
</el-button>
<el-button v-else type="text" size="small" @click="removeContract(scope.row.orderId)"
style="color: #f56c6c;">
移除
</el-button>
</template>
</el-table-column>
</el-table>
<div v-if="allContracts.length > 0" class="table-footer">
{{ allContracts.length }} 条记录
</div>
</el-tab-pane>
</el-tabs>
</div>
</div>
</template>
<script>
import { listOrder, listTodayOrder } from '@/api/crm/order';
export default {
name: "SelectConfig",
data() {
return {
contractList: [],
configLoading: false,
searchKeyword: '',
allContracts: [],
allLoading: false,
activeTab: 'configured',
}
},
mounted() {
this.loadFromLocalStorage();
},
methods: {
handleTabClick(tab) {
if (tab.name === 'all' && this.allContracts.length === 0) {
this.loadAllContracts();
}
},
loadFromLocalStorage() {
try {
const storedContracts = localStorage.getItem('todayContracts');
if (storedContracts) {
this.contractList = JSON.parse(storedContracts);
}
this.loadContractList();
} catch (error) {
console.error('Failed to load contracts from localStorage:', error);
this.loadContractList();
}
},
saveToLocalStorage() {
try {
localStorage.setItem('todayContracts', JSON.stringify(this.contractList));
} catch (error) {
console.error('Failed to save contracts to localStorage:', error);
}
},
async loadContractList() {
this.configLoading = true;
try {
const res = await listTodayOrder();
const existingManualContracts = this.contractList.filter(item => item.isManual);
const apiContracts = (res.data || []).map(item => ({
...item,
isManual: false
}));
this.contractList = [...apiContracts, ...existingManualContracts];
this.contractList = this.contractList.filter((item, index, self) =>
index === self.findIndex(t => t.orderId === item.orderId)
);
this.saveToLocalStorage();
} finally {
this.configLoading = false;
}
},
async loadAllContracts() {
this.allLoading = true;
try {
const res = await listOrder({
pageNum: 1,
pageSize: 10000,
keyword: this.searchKeyword || undefined,
});
const existingContracts = this.contractList;
this.allContracts = [...(res.rows || []), ...existingContracts].filter((item, index, self) =>
index === self.findIndex(t => t.orderId === item.orderId)
);
} catch (error) {
console.error('Failed to load all contracts:', error);
this.allContracts = [];
} finally {
this.allLoading = false;
}
},
handleSearch() {
this.loadAllContracts();
},
isContractInList(orderId) {
return this.contractList.some(item => item.orderId === orderId);
},
addContract(contract) {
if (!this.isContractInList(contract.orderId)) {
this.contractList.push({
...contract,
isManual: true
});
this.saveToLocalStorage();
}
},
removeContract(orderId) {
this.contractList = this.contractList.filter(item => item.orderId !== orderId);
this.saveToLocalStorage();
},
}
}
</script>
<style scoped>
.select-config-page {
padding: 16px;
min-height: 100%;
background: #f5f7fa;
}
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 16px;
padding: 16px 20px;
background: #fff;
border-radius: 6px;
border: 1px solid #ebeef5;
}
.page-header h3 {
margin: 0;
font-size: 16px;
color: #303133;
font-weight: 600;
}
.header-stats {
display: flex;
gap: 24px;
}
.stat-item {
display: flex;
align-items: center;
gap: 6px;
}
.stat-label {
font-size: 13px;
color: #909399;
}
.stat-value {
font-size: 18px;
font-weight: 600;
color: #303133;
}
.stat-value.manual {
color: #67c23a;
}
.stat-value.api {
color: #909399;
}
.content-card {
background: #fff;
border-radius: 6px;
border: 1px solid #ebeef5;
padding: 0 16px 16px;
}
.content-card ::v-deep .el-tabs__header {
margin-bottom: 16px;
}
.search-bar {
margin-bottom: 16px;
}
.search-input {
width: 320px;
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: #c0c4cc;
}
.empty-state i {
font-size: 48px;
margin-bottom: 12px;
}
.empty-state p {
margin: 0 0 8px;
font-size: 14px;
color: #909399;
}
.empty-state span {
font-size: 12px;
color: #c0c4cc;
}
.text-muted {
color: #c0c4cc;
}
.table-footer {
text-align: center;
padding: 12px;
font-size: 13px;
color: #909399;
}
</style>

View File

@@ -159,7 +159,7 @@
</el-row>
<el-dialog title="完成退火" :visible.sync="completeOpen" width="720px" append-to-body>
<div class="complete-tip">请为每条钢卷分配逻辑库区去向未分配将无法完成</div>
<div class="complete-tip">请为每条钢卷分配逻辑库区去向和关联合同未分配将无法完成</div>
<el-table :data="completeCoils" v-loading="completeLoading" height="360px">
<el-table-column label="入场钢卷号" prop="enterCoilNo" align="center" />
<el-table-column label="钢卷去向" align="center" width="240">
@@ -170,6 +170,11 @@
</el-select>
</template>
</el-table-column>
<el-table-column label="关联合同" align="center" width="240">
<template slot-scope="scope">
<ContractSelect v-model="scope.row.contractId" placeholder="请选择合同" />
</template>
</el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitComplete"> </el-button>
@@ -234,11 +239,13 @@ import { listMaterialCoil } from "@/api/wms/coil";
import { listWarehouse } from '@/api/wms/warehouse'
import WarehouseSelect from "@/components/KLPService/WarehouseSelect";
import { addAnnealOperateEvent } from "@/api/wms/annealOperateEvent";
import ContractSelect from "@/components/KLPService/ContractSelect";
export default {
name: "AnnealPlan",
components: {
WarehouseSelect
WarehouseSelect,
ContractSelect
},
data() {
return {
@@ -563,17 +570,18 @@ export default {
submitComplete() {
const locations = (this.completeCoils || []).map(item => ({
coilId: item.coilId,
warehouseId: item.warehouseId
warehouseId: item.warehouseId,
contractId: item.contractId,
}));
const missing = locations.filter(item => !item.warehouseId);
const missing = locations.filter(item => !item.warehouseId || !item.contractId);
if (missing.length > 0) {
this.$message.warning('请先为所有钢卷分配实际库位');
this.$message.warning('请先为所有钢卷分配实际库位和关联合同');
return;
}
this.completeLoading = true;
completeAnnealPlan({
planId: this.completePlanId,
locations: locations
locations: locations,
}).then(() => {
// anneal-todo: 新增操作事件
const targetFurnaceName = this.furnaceOptions.find(item => item.furnaceId === this.currentPlan.targetFurnaceId)?.furnaceName || '';

View File

@@ -375,7 +375,6 @@ import AbnormalForm from './components/AbnormalForm';
import PlanSheetViewer from './components/PlanSheetViewer.vue';
import { generateCoilNoPrefix } from "@/utils/coil/coilNo";
import ContractSelect from "@/components/KLPService/ContractSelect";
import { addCoilContractRel } from "@/api/wms/coilContractRel";
export default {
name: 'MergeCoil',
@@ -827,6 +826,12 @@ export default {
return;
}
// 验证合同
if (!this.targetCoil.contractId) {
this.$message.error('请选择合同');
return;
}
let loadingInstance = null;
try {
this.loading = true;
@@ -840,6 +845,7 @@ export default {
const mergeData = {
...this.targetCoil,
contractId: this.targetCoil.contractId || '',
enterCoilNo: enterCoilNos, // 拼接的入场钢卷号
hasMergeSplit: 2, // 2表示合卷
abnormals: this.abnormals,
@@ -859,16 +865,8 @@ export default {
background: 'rgba(0, 0, 0, 0.7)'
});
const response = await mergeMaterialCoil(mergeData);
await mergeMaterialCoil(mergeData);
const coilId = response.data;
if (this.targetCoil.contractId) {
addCoilContractRel({
coilId: coilId,
contractId: this.targetCoil.contractId,
})
}
this.$message.success('合卷保存成功');
// 延迟返回,让用户看到成功提示

View File

@@ -393,7 +393,6 @@ import { generateCoilNoPrefix } from '@/utils/coil/coilNo'
import ProductInfo from '@/components/KLPService/Renderer/ProductInfo'
import RawMaterialInfo from '@/components/KLPService/Renderer/RawMaterialInfo'
import ContractSelect from '@/components/KLPService/ContractSelect'
import { addCoilContractRel } from '@/api/wms/coilContractRel'
export default {
name: 'StepSplit',
@@ -491,7 +490,8 @@ export default {
materialType: [{ required: true, message: '请选择材料类型', trigger: 'change' }],
itemId: [{ required: true, message: '请选择成品/原料', trigger: 'change' }],
netWeight: [{ required: true, message: '请输入净重', trigger: 'blur' }],
warehouseId: [{ required: true, message: '请选择所在库位', trigger: 'change' }]
warehouseId: [{ required: true, message: '请选择所在库位', trigger: 'change' }],
contractId: [{ required: true, message: '请选择合同', trigger: 'change' }]
},
buttonLoading: false,
currentAction: {},
@@ -872,13 +872,6 @@ export default {
} else {
// 新增分条:调用创建接口
res = await createSpecialChild(this.coilId, this.actionId, splitData)
// 新增分条后,需要添加分条的合同关系
if (this.splitForm.contractId) {
addCoilContractRel({
coilId: res.data.coilId,
contractId: this.splitForm.contractId
})
}
}
this.$message.success(this.splitForm.coilId ? '编辑分条成功' : '新增分条成功')

View File

@@ -378,7 +378,6 @@ import AbnormalForm from './components/AbnormalForm';
import PlanSheetViewer from './components/PlanSheetViewer.vue';
import { generateCoilNoPrefix } from "@/utils/coil/coilNo";
import ContractSelect from "@/components/KLPService/ContractSelect";
import { addCoilContractRel } from "@/api/wms/coilContractRel";
export default {
name: 'SplitCoil',
@@ -748,6 +747,10 @@ export default {
this.$message.error(`${i + 1}个子卷的目标库区不能为空`);
return;
}
if (!item.contractId) {
this.$message.error(`${i + 1}个子卷的合同不能为空`);
return;
}
}
const loadingInstance = this.$loading({
@@ -768,9 +771,10 @@ export default {
hasMergeSplit: 1, // 1表示分条
newCoils: this.splitList.map(item => ({
...item,
itemType: item.itemType || this.motherCoil.itemType,
itemId: item.itemId || this.motherCoil.itemId,
hasMergeSplit: 1
itemType: item.itemType,
itemId: item.itemId,
hasMergeSplit: 1,
contractId: item.contractId,
}))
};
@@ -778,24 +782,6 @@ export default {
if (response.code === 200) {
this.$message.success('分条保存成功');
// 拿到多个子卷的coilId
const newCoilIds = response.msg.split(',');
// 先构建所有的请求体,并移除合同为空为空的项
const requests = newCoilIds.map((coilId, index) => ({
coilId,
contractId: this.splitList[index].contractId
}))
.filter(req => req.contractId);
// 为每个子卷添加合同关联
Promise.all(requests.map(async (req, index) => {
addCoilContractRel(req);
}));
// 如果是从待操作列表进来的,标记操作为完成
// if (this.actionId) {
// await completeAction(this.actionId, response.msg);
// }
// 延迟返回,让用户看到成功提示
setTimeout(() => {
this.$router.back();

View File

@@ -400,7 +400,6 @@ import WarehouseSelect from "@/components/KLPService/WarehouseSelect";
import TimeInput from "@/components/TimeInput";
import AbnormalForm from './components/AbnormalForm';
import { generateCoilNoPrefix } from "@/utils/coil/coilNo";
import { addCoilContractRel } from "@/api/wms/coilContractRel";
import ContractSelect from "@/components/KLPService/ContractSelect";
import L2MatchPanel from './panels/L2MatchPanel.vue'
import DrMatchPanel from './panels/DrMatchPanel.vue';
@@ -522,6 +521,7 @@ export default {
warehouseId: [
{ required: true, message: '请选择逻辑库区', trigger: 'change' }
],
contractId: [{ required: true, message: '请选择合同', trigger: 'change' }]
},
actionId: null,
actionType: null, // 待操作类型504/524 = 双机架
@@ -869,6 +869,8 @@ export default {
// 构造更新数据使用标准update接口直接更新原记录
const updateData = {
...this.updateForm,
contractId: this.updateForm.contractId,
// 其他字段...
coilId: this.currentInfo.coilId,
enterCoilNo: this.currentInfo.enterCoilNo,
supplierCoilNo: this.currentInfo.supplierCoilNo,
@@ -877,23 +879,9 @@ export default {
const response = await updateMaterialCoil({ ...updateData, actionId: this.actionId });
// 更新完成后如果选定了合同,需要增加与合同的绑定关系
const coilId = response.msg;
if (this.updateForm.contractId) {
await addCoilContractRel({
coilId: coilId,
contractId: this.updateForm.contractId,
});
}
if (response.code === 200) {
this.$message.success('钢卷信息更新成功');
// 如果是从待操作列表进来的,标记操作为完成
// if (this.actionId) {
// await completeAction(this.actionId, response.msg);
// }
// 延迟返回
setTimeout(() => {
this.$router.back();