采购员任命

This commit is contained in:
Teo
2025-08-13 19:10:35 +08:00
parent fbe1dae085
commit b90b0a457c
12 changed files with 1210 additions and 286 deletions

View File

@ -7,7 +7,7 @@
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5" :offset="0"
><el-button type="primary" size="default" @click="addBatch" icon="FolderAdd" plain>新增</el-button></el-col
><el-button type="primary" size="default" @click="handleAdd" icon="FolderAdd" plain>新增</el-button></el-col
>
<el-col :span="1.5" :offset="0"
><el-button type="danger" size="default" @click="handleDeleteBatch" icon="FolderDelete" plain>删除</el-button></el-col
@ -19,27 +19,27 @@
<el-tree
ref="batchTreeRef"
class="mt-2"
node-key="batchNumber"
node-key="id"
:data="batchOptions"
:props="{ label: 'batchNumber', children: 'children' }"
:props="{ label: 'planCode', children: 'children' }"
:expand-on-click-node="false"
highlight-current
default-expand-all
@node-click="handleNodeClick"
>
<template #default="{ node, data }">
<template #default="{ node, data }">
<div class="custom-tree-node">
{{node.label }}
<dict-tag :options="wf_business_status" :value="data.approvalProject" />
{{ node.label }}
<dict-tag :options="wf_business_status" :value="data.status" />
</div>
</template>
</el-tree>
<pagination
v-show="total > 0"
:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="getBatchList"
v-model:page="queryParams.batchData.pageNum"
v-model:limit="queryParams.batchData.pageSize"
@pagination="getList"
layout="prev, pager, next,jumper"
/>
</el-card>
@ -48,11 +48,8 @@
<el-card shadow="never">
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5" v-if="form.approvalProject == 'draft'">
<el-button type="primary" plain icon="SemiSelect" @click="handleAdd" v-hasPermi="['cailiaoshebei:cailiaoshebei:add']">选择</el-button>
</el-col>
<el-col :span="1.5" v-if="form.approvalProject == 'draft'">
<el-button type="success" plain icon="Check" @click="submitForm" v-hasPermi="['cailiaoshebei:cailiaoshebei:delete']">保存</el-button>
<el-col :span="1.5" v-if="form.mrpBaseBo.status == 'draft'">
<el-button type="primary" plain icon="Edit" @click="handleUpdata" v-hasPermi="['cailiaoshebei:cailiaoshebei:add']">修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button plain type="warning" icon="Finished" @click="handleAudit()" v-hasPermi="['out:monthPlan:remove']">审核</el-button>
@ -63,49 +60,98 @@
</template>
<el-table v-loading="loading" :data="cailiaoshebeiList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<!-- <el-table-column type="selection" width="55" align="center" /> -->
<!-- <el-table-column label="供货商ID" align="center" prop="supplierId" /> -->
<el-table-column label="供货商" align="center" prop="supplierCompany" />
<el-table-column label="设备材料名称" align="center" prop="name" />
<el-table-column label="物资名称" align="center" prop="name" />
<el-table-column label="质量标准" align="center" prop="qs" />
<el-table-column label="规格型号" align="center" prop="specification" />
<el-table-column label="物料编码" align="center" prop="materialCode" width="200" />
<el-table-column label="计量单位" align="center" prop="unit" width="80" />
<el-table-column label="供应周期(天)" align="center" prop="estimatedCycle" />
<el-table-column label="需求数量" align="center" prop="demandQuantity">
<template #default="scope">
<el-input v-model="scope.row.demandQuantity" type="number" :disabled="form.approvalProject != 'draft'"/>
</template>
</el-table-column>
<el-table-column label="计划到场时间" align="center" prop="arrivalTime" width="250">
<template #default="scope">
<div class="flex justify-center w100%">
<el-date-picker v-model="scope.row.arrivalTime" type="date" value-format="YYYY-MM-DD" :disabled="form.approvalProject != 'draft'" />
</div>
</template>
</el-table-column>
<el-table-column label="需求数量" align="center" prop="demandQuantity" />
<el-table-column label="需求到货时间" align="center" prop="arrivalTime" width="250" />
<el-table-column label="备注" align="center" prop="remark" />
</el-table>
<pagination
v-show="mainTotal > 0"
:total="mainTotal"
v-model:page="queryParams.mainData.pageNum"
v-model:limit="queryParams.mainData.pageSize"
@pagination="getMainList"
/>
</el-card>
</el-col>
</el-row>
<!-- 添加或修改物资-材料设备对话框 -->
<el-dialog :title="dialog.title" v-model="dialog.visible" width="650px" append-to-body>
<el-transfer
v-model="cailiaoshebeiSelectedList"
filterable
:data="cailiaoshebeiAllList"
:props="{
label: 'name',
key: 'cailiaoshebeiId'
}"
><template #default="{ option }">
{{ `${option.specification || ''} ${option.name || ''}` }}1
</template>
</el-transfer>
<el-dialog :title="dialog.title" v-model="dialog.visible" width="1250px" append-to-body>
<el-form :model="form" ref="cailiaoshebeiFormRef" :rules="rules" label-width="80px" :inline="false">
<el-divider>基础信息</el-divider>
<el-row :gutter="20">
<el-col :span="8" :offset="0">
<el-form-item label="物资类别" prop="mrpBaseBo.matCat">
<el-input v-model="form.mrpBaseBo.matCat" placeholder="请输入物资类别" />
</el-form-item>
</el-col>
<el-col :span="8" :offset="0">
<el-form-item label="编制日期" prop="mrpBaseBo.preparedDate">
<el-date-picker v-model="form.mrpBaseBo.preparedDate" type="date" value-format="YYYY-MM-DD" placeholder="请选择编制日期" />
</el-form-item>
</el-col>
<el-col :span="8" :offset="0">
<el-form-item label="计划编号" prop="mrpBaseBo.planCode">
<el-input v-model="form.mrpBaseBo.planCode" placeholder="请输入计划编号" />
</el-form-item>
</el-col>
</el-row>
<el-divider>主要信息</el-divider>
<el-table :data="form.planList">
<el-table-column prop="name" align="center" label="物资名称">
<template #default="scope">
<el-input v-model="scope.row.name" placeholder="请输入物资" />
</template>
</el-table-column>
<el-table-column prop="specification" align="center" label="规格型号" width="150">
<template #default="scope">
<el-input v-model="scope.row.specification" placeholder="请输入规格型号" />
</template>
</el-table-column>
<el-table-column prop="unit" align="center" label="单位" width="130">
<template #default="scope">
<el-input v-model="scope.row.unit" placeholder="请输入单位" />
</template>
</el-table-column>
<el-table-column prop="demandQuantity" align="center" label="数量" width="130">
<template #default="scope">
<el-input v-model="scope.row.demandQuantity" placeholder="请输入数量" type="number" min="0" />
</template>
</el-table-column>
<el-table-column prop="qs" align="center" label="质量标准" width="150">
<template #default="scope">
<el-input v-model="scope.row.qs" placeholder="请输入质量标准" />
</template>
</el-table-column>
<el-table-column prop="arrivalTime" align="center" label="需求到货时间">
<template #default="scope">
<el-date-picker v-model="scope.row.arrivalTime" type="date" value-format="YYYY-MM-DD" placeholder="请选择" style="width: 140px" />
</template>
</el-table-column>
<el-table-column prop="remark" align="center" label="备注" width="150">
<template #default="scope">
<el-input v-model="scope.row.remark" placeholder="请输入备注" />
</template>
</el-table-column>
<el-table-column prop="remark" align="center" label="操作" width="150">
<template #default="scope">
<el-button @click="addRow" type="success" icon="Plus" circle size="small" />
<el-button @click="delRow(scope.$index)" type="danger" icon="Delete" circle size="small" />
</template>
</el-table-column>
</el-table>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button :loading="buttonLoading" type="primary" @click="submitTransferForm"> </el-button>
<el-button @click="cancel"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</template>
</el-dialog>
@ -125,20 +171,15 @@ import {
listSelectCailiaoshebei
} from '@/api/materials/batchPlan';
import { CailiaoshebeiVO, CailiaoshebeiQuery, CailiaoshebeiForm } from '@/api/materials/batchPlan/types';
import { listContractor } from '@/api/project/contractor';
import { useUserStoreHook } from '@/store/modules/user';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { supply } = toRefs<any>(proxy?.useDict('supply'));
// 获取用户 store
const userStore = useUserStoreHook();
// 从 store 中获取项目列表和当前选中的项目
const currentProject = computed(() => userStore.selectedProject);
const batchTreeRef = ref<any>(null);
const cailiaoshebeiList = ref<CailiaoshebeiVO[]>([]);
const cailiaoshebeiAllList = ref<CailiaoshebeiVO[]>([]);
const cailiaoshebeiSelectedList = ref([]);
const buttonLoading = ref(false);
const loading = ref(false);
const showSearch = ref(true);
@ -146,6 +187,7 @@ const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const mainTotal = ref(0);
const batchOptions = ref<any[]>([]);
const { wf_business_status } = toRefs<any>(proxy?.useDict('wf_business_status'));
@ -157,99 +199,110 @@ const dialog = reactive<DialogOption>({
title: ''
});
const initFormData: CailiaoshebeiForm = {
id: undefined,
batchNumber: undefined,
supplierId: undefined,
addDataList: [],
const initFormData: any = {
mrpBaseBo: {
id: undefined,
preparedDate: undefined,
planCode: undefined,
matCat: undefined,
status: undefined,
projectId: currentProject.value.id
},
supplier: undefined,
name: undefined,
supply: undefined,
specification: undefined,
signalment: undefined,
materialCode: undefined,
arrivalTime: undefined,
approvalProject: undefined,
finishTime: undefined,
unit: undefined,
plan: undefined,
realQuantity: undefined,
projectId: currentProject.value.id,
remark: undefined
planList: [
{
id: undefined,
name: undefined,
specification: undefined,
unit: undefined,
demandQuantity: undefined,
qs: undefined,
arrivalTime: undefined,
remark: undefined
}
]
};
const data = reactive<PageData<CailiaoshebeiForm, CailiaoshebeiQuery>>({
const data = reactive({
form: { ...initFormData },
queryParams: {
pageNum: 1,
pageSize: 10,
batchNumber: undefined,
supplierId: undefined,
supplier: undefined,
name: undefined,
projectId: currentProject.value.id,
supply: undefined,
specification: undefined,
signalment: undefined,
materialCode: undefined,
arrivalTime: undefined,
finishTime: undefined,
unit: undefined,
plan: undefined,
realQuantity: undefined,
params: {}
batchData: {
pageNum: 1,
pageSize: 10,
planCode: undefined,
projectId: currentProject.value.id
},
mainData: {
pageNum: 1,
pageSize: 10,
mrpBaseId: undefined,
projectId: currentProject.value.id
}
},
rules: {
id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }]
id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
'mrpBaseBo.preparedDate': [{ required: true, message: '计划日期不能为空', trigger: 'blur' }],
'mrpBaseBo.planCode': [{ required: true, message: '计划编码不能为空', trigger: 'blur' }],
'mrpBaseBo.matCat': [{ required: true, message: '物资分类不能为空', trigger: 'blur' }]
}
});
const batchNumber = ref('');
const { queryParams, form, rules } = toRefs(data);
/** 查询物资-材料设备列表 */
const getList = async () => {
if (!queryParams.value.batchNumber) return;
const getList = async (type: string) => {
loading.value = true;
const res = await listCailiaoshebei(queryParams.value);
cailiaoshebeiList.value = res.rows;
loading.value = false;
};
//查询批次列表
const getBatchList = async () => {
const res = await listBatch(queryParams.value);
const res = await listBatch(queryParams.value.batchData);
batchOptions.value = res.rows;
total.value = res.total;
try {
queryParams.value.batchNumber = res.rows[0].batchNumber;
batchTreeRef.value.setCurrentKey(res.rows[0].batchNumber);
form.value.batchNumber = res.rows[0].batchNumber;
form.value.approvalProject = res.rows[0].approvalProject;
} catch (error) {
form.value.batchNumber = '';
queryParams.value.batchNumber = '';
if (res.rows && res.rows.length > 0 && !queryParams.value.mainData.mrpBaseId) {
batchTreeRef.value.setCurrentKey(res.rows[0].id);
queryParams.value.mainData.mrpBaseId = res.rows[0].id;
form.value.mrpBaseBo.status = res.rows[0].status;
}
getList();
total.value = res.total;
loading.value = false;
if (type === 'search') return;
getMainList();
};
/** 节点单击事件 */
const handleNodeClick = (data: any) => {
queryParams.value.batchNumber = data.batchNumber;
form.value.batchNumber = data.batchNumber;
form.value.approvalProject = data.approvalProject;
queryParams.value.mainData.mrpBaseId = data.id;
form.value.mrpBaseBo.status = data.status;
console.log('🚀 ~ handleNodeClick ~ form.value:', form.value);
if (data.batchNumber === '0') {
queryParams.value.batchNumber = '';
}
getList();
getMainList();
};
const getMainList = async () => {
if (!queryParams.value.mainData.mrpBaseId) return;
const res = await getBatch(queryParams.value.mainData);
cailiaoshebeiList.value = res.rows;
mainTotal.value = res.total;
};
const searchBatchList = async () => {
queryParams.value.batchNumber = batchNumber.value;
getBatchList();
queryParams.value.batchData.planCode = batchNumber.value;
getList('search');
};
//删除
const delRow = (index: number) => {
if (form.value.planList.length <= 1) return proxy?.$modal.msgWarning('请至少保留一项');
form.value.planList.splice(index, 1);
};
//新增
const addRow = () => {
form.value.planList.push({
name: undefined,
specification: undefined,
unit: undefined,
demandQuantity: undefined,
qs: undefined,
arrivalTime: undefined,
remark: undefined
});
};
/** 取消按钮 */
@ -260,23 +313,34 @@ const cancel = () => {
/** 表单重置 */
const reset = () => {
const preservedBatchId = form.value.batchNumber; // 先保存当前的 batchNumber
const status=form.value.approvalProject
form.value = { ...initFormData, batchNumber: preservedBatchId,approvalProject:status }; // 重置但保留
const status = form.value.mrpBaseBo.status;
form.value = { ...initFormData, status }; // 重置但保留
cailiaoshebeiFormRef.value?.resetFields();
form.value.mrpBaseBo.projectId = currentProject.value.id;
form.value.planList = [
{
name: undefined,
specification: undefined,
unit: undefined,
demandQuantity: undefined,
qs: undefined,
arrivalTime: undefined,
remark: undefined
}
];
};
/** 搜索按钮操作 */
const handleQuery = () => {
queryParams.value.pageNum = 1;
getList();
};
// /** 搜索按钮操作 */
// const handleQuery = () => {
// queryParams.value.pageNum = 1;
// getList();
// };
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
};
// /** 重置按钮操作 */
// const resetQuery = () => {
// queryFormRef.value?.resetFields();
// handleQuery();
// };
/** 多选框选中数据 */
const handleSelectionChange = (selection: CailiaoshebeiVO[]) => {
@ -288,15 +352,26 @@ const handleSelectionChange = (selection: CailiaoshebeiVO[]) => {
/** 新增按钮操作 */
const handleAdd = () => {
reset();
listSelectCailiaoshebei({
projectId: currentProject.value.id
}).then((res) => {
cailiaoshebeiAllList.value = res.rows;
});
dialog.visible = true;
dialog.title = '选择物资-材料设备';
dialog.title = '新增物资-需求';
};
const handleUpdata = () => {
reset();
getCailiaoshebei(queryParams.value.mainData.mrpBaseId).then((res: any) => {
form.value.mrpBaseBo = res.data.mrpBaseBo;
const allowedKeys = Object.keys(initFormData.planList[0]);
form.value.planList = res.data.planList.map((item) => {
return allowedKeys.reduce((obj, key) => {
obj[key] = item[key] ?? undefined;
return obj;
}, {});
});
console.log(form.value);
});
dialog.visible = true;
dialog.title = '修改物资-需求';
};
/** 提交按钮 */
@ -307,30 +382,32 @@ const submitForm = async () => {
delete item.id;
}
});
await addCailiaoshebei({ addDataList: cailiaoshebeiList.value,batchNumber:form.value.batchNumber,projectId:currentProject.value.id } as any).finally(() => (buttonLoading.value = false));
await addCailiaoshebei({
addDataList: cailiaoshebeiList.value,
batchNumber: form.value.batchNumber,
projectId: currentProject.value.id
} as any).finally(() => (buttonLoading.value = false));
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
};
/** 提交穿梭框数据 */
/** 提交数据 */
const submitTransferForm = async () => {
cailiaoshebeiList.value = cailiaoshebeiSelectedList.value.map((id) => {
const item = cailiaoshebeiAllList.value.find((option) => option.cailiaoshebeiId === id);
return item;
const result = validateAndClean(form.value.planList);
if (!result.valid) {
proxy?.$modal.msgError('验证失败,主要信息存在部分字段缺失的数据项');
return;
}
cailiaoshebeiFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
buttonLoading.value = true;
form.value.planList = result.data;
await updateCailiaoshebei(form.value).finally(() => (buttonLoading.value = false));
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
await getList();
}
});
dialog.visible = false;
};
/** 新增批次 */
const addBatch = async () => {
await proxy?.$modal.confirm('是否确认新增批次?').finally(() => (loading.value = false));
await getBatch({ projectId: currentProject.value.id });
queryParams.value.batchNumber = '';
await getBatchList();
proxy?.$modal.msgSuccess('新增成功');
};
/** 删除批次 */
@ -339,58 +416,63 @@ const handleDeleteBatch = async () => {
await proxy?.$modal.confirm('是否确认删除批次编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
await delBatch(_ids);
proxy?.$modal.msgSuccess('删除成功');
queryParams.value.batchNumber = '';
await getBatchList();
};
/** 删除按钮操作 */
const handleDelete = async (row?: CailiaoshebeiVO) => {
const _ids = row?.id || ids.value;
await proxy?.$modal.confirm('是否确认删除物资-材料设备编号为"' + _ids + '"的数据项?').finally(() => (loading.value = false));
await delCailiaoshebei(_ids);
proxy?.$modal.msgSuccess('删除成功');
queryParams.value.mainData.mrpBaseId = undefined;
await getList();
};
//检测主要信息填写状况
function validateAndClean(arr) {
// 过滤掉全空的数据项
const cleanedArr = arr.filter((item) => !Object.values(item).every((v) => v === '' || v == null));
let hasFullItem = false; // 是否有一条全填数据
for (const item of cleanedArr) {
const keys = Object.keys(item).filter((k) => k !== 'remark' && k !== 'id');
const allFilled = keys.every((k) => item[k] !== '' && item[k] != null);
if (allFilled) {
hasFullItem = true; // 有一条全填
}
const allEmpty = Object.values(item).every((v) => v === '' || v == null);
// 如果不是全填,也不是全空(部分填) → 直接返回失败
if (!allFilled && !allEmpty) {
return { valid: false, data: cleanedArr };
}
}
// 如果没有至少一条全填,返回失败
if (!hasFullItem) {
return { valid: false, data: cleanedArr };
}
return { valid: true, data: cleanedArr };
}
/** 审核按钮操作 */
const handleAudit = async () => {
if (!form.value.approvalProject) {
if (!form.value.mrpBaseBo.status) {
proxy?.$modal.msgError('请选择批次号');
return;
}
proxy?.$tab.closePage(proxy.$route);
proxy?.$tab.openPage('/materials-management/batchPlan/indexEdit', '审核物资设备批次需求计划', {
id: form.value.batchNumber,
approvalProject: form.value.approvalProject + '_batchRequirements',
id: queryParams.value.mainData.mrpBaseId,
status: form.value.mrpBaseBo.status + '_batchRequirements',
type: 'update'
});
};
/** 查询供货商列表 */
const supplierOptions = ref([]);
const getSupplierList = async () => {
const res = await listContractor({
projectId: currentProject.value.id,
pageNum: 1,
pageSize: 10000
});
supplierOptions.value = res.rows;
};
onMounted(() => {
getBatchList();
getSupplierList();
getList();
// getSupplierList();
});
//监听项目id刷新数据
const listeningProject = watch(
() => currentProject.value.id,
(nid, oid) => {
queryParams.value.projectId = nid;
form.value.projectId = nid;
getBatchList();
getSupplierList();
queryParams.value.mainData.projectId = nid;
form.value.mrpBaseBo.projectId = nid;
getList();
}
);
@ -406,6 +488,5 @@ onUnmounted(() => {
justify-content: space-between;
font-size: 14px;
padding-right: 8px;
}
</style
}
</style>