合并
This commit is contained in:
@ -140,7 +140,7 @@
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
:label="index === 0 ? '名称' : ''"
|
||||
label="名称"
|
||||
:prop="`itemList.${index}.name`"
|
||||
:rules="[{ required: true, message: '名称不能为空', trigger: 'blur' }]"
|
||||
>
|
||||
@ -149,7 +149,7 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
:label="index === 0 ? '规格' : ''"
|
||||
label="规格"
|
||||
:prop="`itemList.${index}.specification`"
|
||||
:rules="[{ required: true, message: '规格不能为空', trigger: 'blur' }]"
|
||||
>
|
||||
@ -158,7 +158,7 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
:label="index === 0 ? '单位' : ''"
|
||||
label="单位"
|
||||
:prop="`itemList.${index}.unit`"
|
||||
:rules="[{ required: true, message: '单位不能为空', trigger: 'blur' }]"
|
||||
>
|
||||
@ -167,7 +167,7 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
:label="index === 0 ? '库存' : ''"
|
||||
label="库存"
|
||||
:prop="`itemList.${index}.stockQuantity`"
|
||||
:rules="[{ required: true, message: '库存不能为空', trigger: 'blur' }]"
|
||||
>
|
||||
@ -176,7 +176,7 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
:label="index === 0 ? '领取' : ''"
|
||||
label="领取"
|
||||
:prop="`itemList.${index}.issuedQuantity`"
|
||||
:rules="[{ required: true, message: '领取数量不能为空', trigger: 'blur' }]"
|
||||
>
|
||||
@ -185,7 +185,7 @@
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item
|
||||
:label="index === 0 ? '剩余' : ''"
|
||||
label="剩余"
|
||||
:prop="`itemList.${index}.remainingQuantity`"
|
||||
:rules="[{ required: true, message: '剩余数量不能为空', trigger: 'blur' }]"
|
||||
>
|
||||
@ -193,7 +193,7 @@
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item :label="index === 0 ? '备注' : ''" prop="remark">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="item.remark" placeholder="请输入内容" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
@ -54,31 +54,32 @@
|
||||
</tbody>
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="150">序号</th>
|
||||
<th width="150">名称</th>
|
||||
<th width="150">规格</th>
|
||||
<th width="150">单位</th>
|
||||
<th width="150">库存</th>
|
||||
<th width="150">领取</th>
|
||||
<th width="150">剩余</th>
|
||||
<th width="150">备注</th>
|
||||
<!-- 去掉重复的 width 属性,统一用 CSS 控制 -->
|
||||
<th style="width: 80px; word-wrap: break-word">序号</th>
|
||||
<th style="width: 120px; word-wrap: break-word">名称</th>
|
||||
<th style="width: 120px; word-wrap: break-word">规格</th>
|
||||
<th style="width: 80px; word-wrap: break-word">单位</th>
|
||||
<th style="width: 80px; word-wrap: break-word">库存</th>
|
||||
<th style="width: 80px; word-wrap: break-word">领取</th>
|
||||
<th style="width: 80px; word-wrap: break-word">剩余</th>
|
||||
<th style="width: 120px; word-wrap: break-word">备注</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, i) of formData.itemList" :key="i">
|
||||
<th width="150">{{ i + 1 }}</th>
|
||||
<th width="150">{{ item.name }}</th>
|
||||
<th width="150">{{ item.specification }}</th>
|
||||
<th width="150">{{ item.unit }}</th>
|
||||
<th width="150">{{ item.stockQuantity }}</th>
|
||||
<th width="150">{{ item.issuedQuantity }}</th>
|
||||
<th width="150">{{ item.remainingQuantity }}</th>
|
||||
<th width="150">{{ item.remark }}</th>
|
||||
<td width="150">{{ i + 1 }}</td>
|
||||
<td width="150">{{ item.name }}</td>
|
||||
<td width="150">{{ item.specification }}</td>
|
||||
<td width="150">{{ item.unit }}</td>
|
||||
<td width="150">{{ item.stockQuantity }}</td>
|
||||
<td width="150">{{ item.issuedQuantity }}</td>
|
||||
<td width="150">{{ item.remainingQuantity }}</td>
|
||||
<td width="150">{{ item.remark }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="7">
|
||||
<td colspan="7" style="word-wrap: break-word">
|
||||
<div style="margin-bottom: 10px">缺陷情况:</div>
|
||||
{{ formData.defectDescription }}
|
||||
</td>
|
||||
@ -296,5 +297,6 @@ tbody {
|
||||
box-shadow: 0px 0px 10px #ddd;
|
||||
padding: 20px;
|
||||
position: relative;
|
||||
/* overflow: auto; */
|
||||
}
|
||||
</style>
|
||||
|
327
src/views/materials/materialsUseRecord/index.vue
Normal file
327
src/views/materials/materialsUseRecord/index.vue
Normal file
@ -0,0 +1,327 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave"> </transition>
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
|
||||
<el-form-item label="使用部位" prop="usePart">
|
||||
<el-input v-model="queryParams.usePart" placeholder="请输入使用部位" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<!-- 外层表格:添加ref用于控制展开状态 -->
|
||||
<el-table ref="outerTableRef" v-loading="loading" :data="materialsUseInventoryList" @expand-change="handleExpandChange" border>
|
||||
<el-table-column type="expand">
|
||||
<template #default="props">
|
||||
<div style="margin-left: 60px">
|
||||
<el-table :data="materialsUseRecordList" border v-loading="loadingChild">
|
||||
<el-table-column label="序号" align="center" type="index" width="60" />
|
||||
<el-table-column label="使用数量" align="center" prop="useNumber" />
|
||||
<el-table-column label="剩余量" align="center" prop="residueNumber" />
|
||||
<el-table-column label="使用部位" align="center" prop="usePart" />
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
icon="delete"
|
||||
v-if="scope.row.ishow"
|
||||
@click="handleDelete(scope.row)"
|
||||
v-hasPermi="['materials:materialsUseRecord:remove']"
|
||||
>删除</el-button
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination
|
||||
v-show="totalChild > 0"
|
||||
:total="totalChild"
|
||||
v-model:page="queryParamsChild.pageNum"
|
||||
v-model:limit="queryParamsChild.pageSize"
|
||||
@pagination="getListChild"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="序号" align="center" type="index" width="60" />
|
||||
<el-table-column label="物资名称" align="center" prop="materialsName" />
|
||||
<el-table-column label="交接单位" align="center" prop="recipient" />
|
||||
<el-table-column label="计划数量" align="center" prop="quantityCount" />
|
||||
<el-table-column label="数量" align="center" prop="number" />
|
||||
<el-table-column label="出库人" align="center" prop="operator" />
|
||||
<el-table-column label="领用人" align="center" prop="shipper" />
|
||||
<el-table-column label="剩余量" align="center" prop="residue" />
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-button link type="primary" icon="Plus" @click="handleAdd(scope.row)" v-hasPermi="['materials:materialsUseRecord:add']"
|
||||
>添加登记</el-button
|
||||
>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
|
||||
</el-card>
|
||||
<!-- 添加或修改材料使用登记对话框 -->
|
||||
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
|
||||
<el-form ref="materialsUseRecordFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-form-item label="使用数量" prop="useNumber">
|
||||
<el-input v-model="form.useNumber" type="number" placeholder="请输入使用数量" />
|
||||
</el-form-item>
|
||||
<el-form-item label="使用部位" prop="usePart">
|
||||
<el-input v-model="form.usePart" type="textarea" placeholder="请输入内容" />
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" placeholder="请输入备注" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup name="MaterialsUseRecord" lang="ts">
|
||||
import {
|
||||
listMaterialsUseRecord,
|
||||
listMaterialsUseInventory,
|
||||
getMaterialsUseRecord,
|
||||
delMaterialsUseRecord,
|
||||
addMaterialsUseRecord,
|
||||
updateMaterialsUseRecord
|
||||
} from '@/api/materials/materialsUseRecord';
|
||||
import { MaterialsUseRecordVO, MaterialsUseRecordQuery, MaterialsUseRecordForm } from '@/api/materials/materialsUseRecord/types';
|
||||
import { getCurrentInstance, ComponentInternalInstance, onMounted, ref, reactive, toRefs, computed } from 'vue';
|
||||
import { ElFormInstance, ElTable } from 'element-plus';
|
||||
import useUserStore from '@/store/modules/user';
|
||||
import { get } from 'lodash';
|
||||
|
||||
// 类型定义补充(若项目中无全局DialogOption类型需添加)
|
||||
interface DialogOption {
|
||||
visible: boolean;
|
||||
title: string;
|
||||
}
|
||||
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const userStore = useUserStore();
|
||||
const currentProject = computed(() => userStore.selectedProject);
|
||||
|
||||
// 核心数据响应式定义
|
||||
const materialsUseRecordList = ref<MaterialsUseRecordVO[]>([]);
|
||||
const materialsUseInventoryList = ref<any[]>([]); // 外层列表数据类型可根据实际接口返回调整
|
||||
const buttonLoading = ref(false);
|
||||
const loading = ref(true);
|
||||
const loadingChild = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<string | number>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
const totalChild = ref(0);
|
||||
|
||||
// 组件Ref定义
|
||||
const queryFormRef = ref<ElFormInstance>();
|
||||
const materialsUseRecordFormRef = ref<ElFormInstance>();
|
||||
const outerTableRef = ref<InstanceType<typeof ElTable> | undefined>(undefined); // 外层表格Ref(控制展开)
|
||||
const currentExpandInventoryId = ref<number | undefined>(undefined); // 存储当前展开行的inventoryId
|
||||
|
||||
// 对话框与表单数据
|
||||
const dialog = reactive<DialogOption>({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const initFormData = {
|
||||
id: undefined,
|
||||
projectId: currentProject.value?.id,
|
||||
inventoryId: undefined,
|
||||
usePart: undefined,
|
||||
useNumber: undefined,
|
||||
residueNumber: undefined,
|
||||
remark: undefined
|
||||
};
|
||||
const data = reactive({
|
||||
form: { ...initFormData } as MaterialsUseRecordForm,
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
projectId: currentProject.value?.id,
|
||||
outPut: 1,
|
||||
usePart: undefined // 补充usePart字段(与表单prop对应)
|
||||
} as MaterialsUseRecordQuery & { outPut?: number; usePart?: string },
|
||||
queryParamsChild: {
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
inventoryId: undefined,
|
||||
usePart: undefined,
|
||||
useNumber: undefined,
|
||||
residueNumber: undefined
|
||||
} as MaterialsUseRecordQuery,
|
||||
rules: {
|
||||
id: [{ required: true, message: '主键ID不能为空', trigger: 'blur' }],
|
||||
projectId: [{ required: true, message: '项目ID不能为空', trigger: 'blur' }],
|
||||
inventoryId: [{ required: true, message: '库存ID不能为空', trigger: 'blur' }],
|
||||
usePart: [{ required: true, message: '使用部位不能为空', trigger: 'blur' }],
|
||||
useNumber: [{ required: true, message: '使用数量不能为空', trigger: 'blur' }],
|
||||
residueNumber: [{ required: true, message: '剩余量不能为空', trigger: 'blur' }]
|
||||
}
|
||||
});
|
||||
|
||||
const { queryParams, form, rules, queryParamsChild } = toRefs(data);
|
||||
|
||||
/** 查询材料使用登记列表(外层列表) */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const res = await listMaterialsUseInventory(queryParams.value);
|
||||
materialsUseInventoryList.value = res.rows;
|
||||
total.value = res.total;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 处理外层表格展开/折叠:记录当前展开行的inventoryId */
|
||||
const handleExpandChange = (row: any) => {
|
||||
currentExpandInventoryId.value = row.id; // 记录展开行ID
|
||||
queryParamsChild.value.inventoryId = row.id;
|
||||
getListChild();
|
||||
};
|
||||
|
||||
/** 查询材料子级登记列表(内层列表) */
|
||||
const getListChild = async () => {
|
||||
loadingChild.value = true;
|
||||
try {
|
||||
const res = await listMaterialsUseRecord(queryParamsChild.value);
|
||||
materialsUseRecordList.value = res.rows;
|
||||
// 控制首行删除按钮显示
|
||||
if (res.rows.length > 0) {
|
||||
materialsUseRecordList.value[0].ishow = true;
|
||||
}
|
||||
totalChild.value = res.total;
|
||||
} finally {
|
||||
loadingChild.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
reset();
|
||||
dialog.visible = false;
|
||||
};
|
||||
|
||||
/** 表单重置 */
|
||||
const reset = () => {
|
||||
form.value = { ...initFormData };
|
||||
materialsUseRecordFormRef.value?.resetFields();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value?.resetFields();
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 多选框选中数据(当前模板未使用,保留原逻辑) */
|
||||
const handleSelectionChange = (selection: MaterialsUseRecordVO[]) => {
|
||||
ids.value = selection.map((item) => item.id);
|
||||
single.value = selection.length !== 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = async (row: any) => {
|
||||
reset();
|
||||
form.value.inventoryId = row.id;
|
||||
dialog.visible = true;
|
||||
dialog.title = '添加材料使用登记';
|
||||
};
|
||||
|
||||
/** 修改按钮操作(当前模板未使用,保留原逻辑) */
|
||||
const handleUpdate = async (row?: MaterialsUseRecordVO) => {
|
||||
reset();
|
||||
const _id = row?.id || ids.value[0];
|
||||
const res = await getMaterialsUseRecord(_id);
|
||||
Object.assign(form.value, res.data);
|
||||
dialog.visible = true;
|
||||
dialog.title = '修改材料使用登记';
|
||||
};
|
||||
|
||||
/** 提交按钮:核心优化逻辑(刷新外层列表+保留展开状态) */
|
||||
const submitForm = () => {
|
||||
materialsUseRecordFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
buttonLoading.value = true;
|
||||
try {
|
||||
// 1. 执行添加/修改接口请求
|
||||
await addMaterialsUseRecord(form.value);
|
||||
// 2. 刷新外层列表(确保外层数据同步,如剩余量)
|
||||
await getList();
|
||||
// 3. 刷新当前展开行的子列表
|
||||
await getListChild();
|
||||
// 4. 恢复展开状态:根据记录的inventoryId重新展开行
|
||||
if (currentExpandInventoryId.value && outerTableRef.value) {
|
||||
const targetRow = materialsUseInventoryList.value.find((item) => item.id === currentExpandInventoryId.value);
|
||||
if (targetRow) {
|
||||
outerTableRef.value.toggleRowExpansion(targetRow, true);
|
||||
}
|
||||
}
|
||||
proxy?.$modal.msgSuccess('操作成功');
|
||||
dialog.visible = false;
|
||||
} finally {
|
||||
buttonLoading.value = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: MaterialsUseRecordVO) => {
|
||||
const _ids = row?.id || ids.value;
|
||||
try {
|
||||
await proxy?.$modal.confirm(`是否确认删除材料使用登记编号为"${_ids}"的数据项?`);
|
||||
await delMaterialsUseRecord(_ids);
|
||||
await getList();
|
||||
await getListChild();
|
||||
if (currentExpandInventoryId.value && outerTableRef.value) {
|
||||
const targetRow = materialsUseInventoryList.value.find((item) => item.id === currentExpandInventoryId.value);
|
||||
if (targetRow) {
|
||||
outerTableRef.value.toggleRowExpansion(targetRow, true);
|
||||
}
|
||||
}
|
||||
proxy?.$modal.msgSuccess('删除成功');
|
||||
await getListChild();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 导出按钮操作(保留原逻辑) */
|
||||
const handleExport = () => {
|
||||
proxy?.download('materials/materialsUseRecord/export', { ...queryParams.value }, `materialsUseRecord_${new Date().getTime()}.xlsx`);
|
||||
};
|
||||
|
||||
/** 页面挂载时加载外层列表 */
|
||||
onMounted(() => {
|
||||
getList();
|
||||
});
|
||||
</script>
|
Reference in New Issue
Block a user