采购员任命

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

@ -0,0 +1,313 @@
<template>
<div class="p-6 bg-gray-50">
<div class="appWidth mx-auto bg-white rounded-xl shadow-sm overflow-hidden transition-all duration-300 hover:shadow-md">
<!-- 表单标题区域 -->
<div class="bg-gradient-to-r from-blue-500 to-blue-600 text-white p-6">
<h2 class="text-2xl font-bold flex items-center"><i class="el-icon-user-circle mr-3"></i>人员配置</h2>
<p class="text-blue-100 mt-2 opacity-90">请配置采购专员信息</p>
<!-- <span class="text-red-300">*</span> 为必填项 -->
</div>
<!-- 表单内容区域 -->
<el-form ref="leaveFormRef" :model="form" :rules="rules" label-width="120px" class="p-6 space-y-6">
<!-- 设计负责人 -->
<div class="fonts">
<el-form-item label="采购专员" prop="userId" class="mb-4">
<el-select
v-model="form.userId"
placeholder="请选择采购专员"
class="w-full transition-all duration-300 border-gray-300 focus:border-blue-400 focus:ring-1 focus:ring-blue-400"
>
<el-option v-for="item in userList" :key="item.userId" :label="item.nickName" :value="item.userId" />
</el-select>
</el-form-item>
</div>
<!-- 提交按钮区域 -->
<div class="flex justify-center space-x-6 mt-8 pt-6 border-t border-gray-100">
<el-button
type="primary"
@click="submitForm"
icon="Check"
class="px-8 py-2.5 transition-all duration-300 transform hover:scale-105 bg-blue-500 hover:bg-blue-600 text-white font-medium"
>
确认提交
</el-button>
<el-button @click="resetForm" icon="Refresh" class="px-8 py-2.5 transition-all duration-300 border-gray-300 hover:bg-gray-100 font-medium">
重置
</el-button>
</div>
</el-form>
</div>
</div>
</template>
<script setup name="PersonnelForm" lang="ts">
import { ref, reactive, computed, onMounted, toRefs } from 'vue';
import { getCurrentInstance } from 'vue';
import type { ComponentInternalInstance } from 'vue';
import { useUserStoreHook } from '@/store/modules/user';
import { listUserByDeptId } from '@/api/system/user';
import { ElMessage, ElLoading } from 'element-plus';
import { Delete } from '@element-plus/icons-vue';
import { designUserAdd, designUserDetail, systemUserList } from '@/api/materials/appointment';
// 获取当前实例
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
// 获取用户 store
const userStore = useUserStoreHook();
// 从 store 中获取当前选中的项目
const currentProject = computed(() => userStore.selectedProject);
// 专业字典数据
const { des_user_major } = toRefs<any>(proxy?.useDict('des_user_major'));
// 表单数据
const form = reactive({
id: null,
projectId: currentProject.value?.id,
userId: null // 设计负责人
});
// 表单验证规则
const rules = reactive({
userId: [{ required: true, message: '请选择采购专员', trigger: 'change' }]
});
// 用户列表
const userList = ref([]);
// 表单引用
const leaveFormRef = ref();
/** 查询当前部门的所有用户 */
const getDeptAllUser = async (deptId: any) => {
try {
const res = await systemUserList({ deptId });
// 实际项目中使用接口返回的数据
userList.value = res.rows;
} catch (error) {
ElMessage.error('获取用户列表失败');
} finally {
}
};
/** 查询当前表单数据并回显 */
const designUser = async () => {
if (!currentProject.value?.id) return;
const loading = ElLoading.service({
lock: true,
text: '加载配置数据中...',
background: 'rgba(255, 255, 255, 0.7)'
});
try {
const res = await designUserDetail(currentProject.value?.id);
if (res.code == 200) {
if (!res.data) {
resetForm();
form.id = null;
return;
}
Object.assign(form, res.data);
}
} catch (error) {
ElMessage.error('获取配置数据失败');
// 添加默认空项
} finally {
loading.close();
}
};
/** 提交表单 */
const submitForm = async () => {
if (!leaveFormRef.value) return;
try {
// 表单验证
await leaveFormRef.value.validate();
let userName = userList.value.find((item) => item.userId === form.userId)?.nickName;
const data = {
projectId: currentProject.value?.id,
userId: form.userId,
userName,
id: form.id
};
// 提交到后端
const res = await designUserAdd(data);
if (res.code === 200) {
ElMessage.success('提交成功');
} else {
ElMessage.error(res.msg || '提交失败');
}
} catch (error) {
ElMessage.error('请完善表单信息后再提交');
} finally {
// 关闭加载状态
ElLoading.service().close();
}
};
/** 重置表单 */
const resetForm = () => {
if (leaveFormRef.value) {
leaveFormRef.value.resetFields();
}
};
// 页面挂载时初始化数据
onMounted(() => {
console.log(userStore.deptId);
// 先获取用户列表,再加载表单数据
getDeptAllUser(userStore.deptId).then(() => {
designUser();
});
});
//监听项目id刷新数据
const listeningProject = watch(
() => currentProject.value.id,
(nid, oid) => {
getDeptAllUser(userStore.deptId).then(() => {
designUser();
});
}
);
onUnmounted(() => {
listeningProject();
});
</script>
<style lang="scss">
.appWidth {
width: 50vw;
max-width: 1200px;
.el-select__wrapper {
width: 16vw !important;
}
.el-button--small {
margin-bottom: 10px;
}
.fonts {
.el-form-item--default .el-form-item__label {
font-size: 18px !important;
}
}
}
// 自定义动画
@keyframes fadeIn {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.animate-fadeIn {
animation: fadeIn 0.3s ease-out forwards;
}
// 表单样式优化
::v-deep .el-form {
--el-form-item-margin-bottom: 0;
}
::v-deep .el-form-item {
margin-bottom: 0;
&__label {
font-weight: 500;
color: #4e5969;
padding: 0 0 8px 0;
}
&__content {
padding: 0;
}
}
::v-deep .el-select {
width: 100%;
.el-input__inner {
border-radius: 6px;
transition: all 0.3s ease;
}
&:hover .el-input__inner {
border-color: #66b1ff;
}
&.el-select-focus .el-input__inner {
border-color: #409eff;
box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}
}
::v-deep .el-button {
border-radius: 6px;
padding: 8px 16px;
&--primary {
background-color: #409eff;
border-color: #409eff;
&:hover {
background-color: #66b1ff;
border-color: #66b1ff;
}
}
&--danger {
background-color: #f56c6c;
border-color: #f56c6c;
&:hover {
background-color: #f78989;
border-color: #f78989;
}
&:disabled {
background-color: #ffcccc;
border-color: #ffbbbb;
cursor: not-allowed;
}
}
}
// 响应式网格布局
.grid {
display: grid;
}
.grid-cols-1 {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
.md\:grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.gap-4 {
gap: 1rem;
}
// 适配小屏幕
@media (max-width: 768px) {
.appWidth {
width: 95vw;
}
::v-deep .el-form {
padding: 4px;
}
::v-deep .el-form-item__label {
width: 100px;
}
}
</style>

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>

View File

@ -8,8 +8,8 @@
@approvalVerifyOpen="approvalVerifyOpen"
@handleApprovalRecord="handleApprovalRecord"
:buttonLoading="buttonLoading"
:id="form.id"
:status="form.approvalProject"
:id="form.mrpBaseBo.id"
:status="form.mrpBaseBo.status"
:pageType="routeParams.type"
/>
</el-card>
@ -17,17 +17,36 @@
<el-card class="rounded-lg shadow-sm bg-white border border-gray-100 transition-all hover:shadow-md overflow-hidden">
<div class="p-4 bg-gradient-to-r from-blue-50 to-indigo-50 border-b border-gray-100">
<h3 class="text-lg font-semibold text-gray-800">物资设备批次需求计划</h3>
<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="请输入物资类别" disabled />
</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" disabled 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="请输入计划编号" disabled />
</el-form-item>
</el-col>
</el-row>
</div>
<div class="p-6">
<el-table v-loading="loading" :data="cailiaoshebeiList">
<el-table-column label="供货商" align="center" prop="supplierCompany" />
<el-table-column label="设备材料名称" align="center" prop="name" />
<!-- <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="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" />
<el-table-column label="计划到场时间" align="center" prop="arrivalTime" width="250" />
<el-table-column label="需求到货时间" align="center" prop="arrivalTime" width="250" />
<el-table-column label="备注" align="center" prop="remark" />
</el-table>
</div>
</el-card>
@ -77,7 +96,7 @@ const { design_change_reason_type } = toRefs<any>(proxy?.useDict('design_change_
import { getKnowledgeDocument } from '@/api/design/technicalStandard';
import { getConstructionValue } from '@/api/out/constructionValue';
import { workScheduleListDetail } from '@/api/progress/plan';
import { getCailiaoshebei } from '@/api/materials/suppliesprice';
import { getCailiaoshebei } from '@/api/materials/batchPlan';
import { getPcDetail, listCailiaoshebei } from '@/api/materials/batchPlan';
import { CailiaoshebeiVO } from '@/api/materials/batchPlan/types';
// 获取用户 store
@ -101,7 +120,7 @@ const approvalRecordRef = ref<InstanceType<typeof ApprovalRecord>>();
//按钮组件
const flowCodeOptions = [
{
value: currentProject.value?.id + '_batchRequirements',
value: currentProject.value?.id + '_mrp',
label: '物资供应总计划审批'
}
];
@ -121,9 +140,28 @@ const taskVariables = ref<Record<string, any>>({});
const selectValue = ref<string[]>([]);
const cailiaoshebeiList = ref<CailiaoshebeiVO[]>([]);
const initFormData = {
id: undefined,
approvalProject: undefined
const initFormData: any = {
mrpBaseBo: {
id: undefined,
preparedDate: undefined,
planCode: undefined,
matCat: undefined,
status: undefined,
projectId: currentProject.value.id
},
planList: [
{
id: undefined,
name: undefined,
specification: undefined,
unit: undefined,
demandQuantity: undefined,
qs: undefined,
arrivalTime: undefined,
remark: undefined
}
]
};
const data = reactive({
form: { ...initFormData },
@ -148,18 +186,11 @@ const getInfo = () => {
loading.value = true;
buttonLoading.value = false;
nextTick(async () => {
const id = routeParams.value.id.split('_')[0];
const res = await listCailiaoshebei({ pageNum: 1, pageSize: 10, batchNumber: id });
cailiaoshebeiList.value = res.rows;
if (!form.value.approvalProject) {
const res = await getPcDetail(id);
form.value.approvalProject = res.data.approvalProject;
} else {
form.value.approvalProject = routeParams.value.approvalProject;
}
console.log('🚀 ~ getInfo ~ form.value.approvalProject:', form.value.approvalProject);
form.value.id = routeParams.value.id;
const id = routeParams.value.id;
const res: any = await getCailiaoshebei(id);
cailiaoshebeiList.value = res.data.planList;
Object.assign(form.value, res.data);
console.log('🚀 ~ getInfo ~ form.value:', form.value);
loading.value = false;
buttonLoading.value = false;
@ -177,10 +208,10 @@ const submitFlow = async () => {
dialogVisible.visible = false;
};
//提交申请
const handleStartWorkFlow = async (data: LeaveForm) => {
const handleStartWorkFlow = async (data: any) => {
try {
submitFormData.value.flowCode = flowCode.value;
submitFormData.value.businessId = data.id;
submitFormData.value.businessId = data.mrpBaseBo.id;
//流程变量
taskVariables.value = {
// leave4/5 使用的流程变量
@ -198,7 +229,7 @@ const handleStartWorkFlow = async (data: LeaveForm) => {
};
//审批记录
const handleApprovalRecord = () => {
approvalRecordRef.value.init(form.value.id);
approvalRecordRef.value.init(form.value.mrpBaseBo.id);
};
//提交回调
const submitCallback = async () => {
@ -218,7 +249,7 @@ const submit = async (status, data) => {
proxy.$tab.closePage(proxy.$route);
proxy.$router.go(-1);
} else {
if ((form.value.approvalProject === 'draft' && (flowCode.value === '' || flowCode.value === null)) || routeParams.value.type === 'add') {
if ((form.value.mrpBaseBo.status === 'draft' && (flowCode.value === '' || flowCode.value === null)) || routeParams.value.type === 'add') {
flowCode.value = flowCodeOptions[0].value;
dialogVisible.visible = true;
return;