进度管理产值管理

This commit is contained in:
Teo
2025-08-01 20:09:57 +08:00
parent bbc927edba
commit 4a5856f614
21 changed files with 2748 additions and 211 deletions

View File

@ -0,0 +1,371 @@
<template>
<div class="p-2">
<transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
<div v-show="showSearch" class="mb-[10px]">
<el-card shadow="hover">
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
<el-form-item label="请选择方阵:" prop="pid" label-width="100">
<!-- <el-input v-model="queryParams.pid" placeholder="请选择" clearable /> -->
<el-cascader
:options="matrixOptions"
placeholder="请选择"
@change="handleChange"
:props="{ value: 'matrixId', label: 'name' }"
v-model="queryParams.matrixId"
clearable
/>
<!-- <el-select v-model="matrixValue" placeholder="请选择" @change="handleChange" clearable>
<el-option v-for="item in matrixOptions" :key="item.id" :label="item.matrixName" :value="item.id" />
</el-select> -->
</el-form-item>
</el-form>
</el-card>
</div>
</transition>
<el-card shadow="never">
<template #header>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button type="info" plain icon="Sort" @click="handleToggleExpandAll">展开/折叠</el-button>
</el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
</template>
<el-table
ref="progressCategoryTableRef"
v-loading="loading"
:data="progressCategoryList"
row-key="id"
:default-expand-all="isExpandAll"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<!-- <el-table-column label="父类别id" prop="parentId" /> -->
<el-table-column label="类别名称" prop="name" />
<el-table-column label="计量方式" align="center" prop="unitType">
<template #default="{ row }">
<dict-tag :options="progress_unit_type" :value="row.unitType" v-if="row.parentId != 0" />
<span v-else></span>
</template>
</el-table-column>
<el-table-column label="计量单位" align="center" prop="unit">
<template #default="{ row }">
{{ row.parentId == 0 ? '' : row.unit }}
</template>
</el-table-column>
<el-table-column label="综合单价" align="center" prop="unitPrice">
<template #default="{ row }">
{{ row.parentId == 0 ? '' : row.unitPrice }}
</template>
</el-table-column>
<el-table-column label="产值金额" align="center" prop="outputValue">
<template #default="{ row }">
{{ row.parentId == 0 ? '' : row.outputValue }}
</template>
</el-table-column>
<el-table-column label="总数量/百分比" align="center" prop="total">
<template #default="{ row }">
{{ row.parentId == 0 ? '' : row.total }}
</template>
</el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template #default="scope">
<div v-if="scope.row.parentId">
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['progress:progressCategory:edit']">
修改
</el-button>
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['progress:progressCategory:remove']">
删除
</el-button>
</div>
</template>
</el-table-column>
</el-table>
</el-card>
<!-- 添加或修改分项工程单价对话框 -->
<el-dialog :title="dialog.title" v-model="dialog.visible" width="500px" append-to-body>
<el-form ref="progressCategoryFormRef" :model="form" :rules="rules" label-width="80px">
<el-form-item label="类别名称" prop="name">
<el-input v-model="form.name" placeholder="请输入类别名称" disabled />
</el-form-item>
<el-form-item label="计量单位" prop="unit">
<el-input v-model="form.unit" placeholder="请输入计量单位" />
</el-form-item>
<el-form-item label="综合单价" prop="unitPrice">
<el-input v-model="form.unitPrice" placeholder="请输入综合单价" />
</el-form-item>
<!-- <el-form-item label="总数量/百分比" prop="total">
<el-input v-model="form.total" 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="ProgressCategory" lang="ts">
import { getProjectSquare } from '@/api/progress/plan';
import {
listProgressCategory,
getProgressCategory,
delProgressCategory,
addProgressCategory,
updateProgressCategory
} from '@/api/progress/progressCategory';
import { ProgressCategoryVO, ProgressCategoryQuery, ProgressCategoryForm } from '@/api/progress/progressCategory/types';
import { useUserStoreHook } from '@/store/modules/user';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { progress_unit_type, progress_status } = toRefs<any>(proxy?.useDict('progress_unit_type', 'progress_status'));
// 获取用户 store
const userStore = useUserStoreHook();
// 从 store 中获取项目列表和当前选中的项目
const currentProject = computed(() => userStore.selectedProject);
type ProgressCategoryOption = {
id: number;
name: string;
children?: ProgressCategoryOption[];
};
const matrixOptions = ref([]);
const progressCategoryList = ref<ProgressCategoryVO[]>([]);
const progressCategoryOptions = ref<ProgressCategoryOption[]>([]);
const buttonLoading = ref(false);
const showSearch = ref(true);
const isExpandAll = ref(true);
const loading = ref(false);
const queryFormRef = ref<ElFormInstance>();
const progressCategoryFormRef = ref<ElFormInstance>();
const progressCategoryTableRef = ref<ElTableInstance>();
const dialog = reactive<DialogOption>({
visible: false,
title: ''
});
const initFormData: ProgressCategoryForm = {
id: undefined,
parentId: undefined,
projectId: currentProject.value.id,
matrixId: undefined,
matrixName: undefined,
name: undefined,
unitType: undefined,
unit: undefined,
unitPrice: undefined,
outputValue: undefined,
total: undefined,
completed: undefined,
planTotal: undefined,
isDelay: undefined,
workType: undefined,
status: undefined,
remark: undefined
};
const data = reactive<PageData<ProgressCategoryForm, ProgressCategoryQuery>>({
form: { ...initFormData },
queryParams: {
parentId: undefined,
projectId: currentProject.value.id,
matrixId: undefined,
matrixName: undefined,
name: undefined,
unitType: undefined,
unit: undefined,
unitPrice: undefined,
outputValue: undefined,
total: undefined,
completed: undefined,
planTotal: undefined,
isDelay: undefined,
workType: undefined,
status: undefined,
params: {}
},
rules: {
id: [{ required: true, message: '主键id不能为空', trigger: 'blur' }],
parentId: [{ required: true, message: '父类别id不能为空', trigger: 'blur' }],
projectId: [{ required: true, message: '项目id不能为空', trigger: 'blur' }],
matrixId: [{ required: true, message: '方阵id不能为空', trigger: 'blur' }],
name: [{ required: true, message: '类别名称不能为空', trigger: 'blur' }],
unitType: [{ required: true, message: '计量方式不能为空', trigger: 'change' }],
unitPrice: [{ required: true, message: '综合单价不能为空', trigger: 'blur' }],
outputValue: [{ required: true, message: '产值金额不能为空', trigger: 'blur' }],
isDelay: [{ required: true, message: '是否超期不能为空', trigger: 'blur' }],
status: [{ required: true, message: '完成状态不能为空', trigger: 'change' }]
}
});
const { queryParams, form, rules } = toRefs(data);
/** 查询分项工程单价列表 */
const getList = async () => {
if (!queryParams.value.matrixId) {
const res = await getProjectSquare(currentProject.value.id);
if (res.data.length === 0) {
proxy?.$modal.msgWarning('当前项目下没有方阵,请先创建方阵');
} else {
let matrixList = res.data.map((item) => {
return {
...item,
matrixId: item.projectId
};
});
if (!matrixValue.value) matrixValue.value = matrixList[0].id;
matrixOptions.value = matrixList;
queryParams.value.matrixId = matrixList[0].children[0].matrixId;
}
}
loading.value = true;
try {
const res = await listProgressCategory(queryParams.value);
const data = proxy?.handleTree<ProgressCategoryVO>(res.data, 'id', 'parentId');
if (data) {
progressCategoryList.value = data;
loading.value = false;
}
} finally {
loading.value = false;
}
};
/** 查询分项工程单价下拉树结构 */
const getTreeselect = async () => {
const res = await listProgressCategory(queryParams.value);
progressCategoryOptions.value = [];
const data: ProgressCategoryOption = { id: 0, name: '顶级节点', children: [] };
data.children = proxy?.handleTree<ProgressCategoryOption>(res.data, 'id', 'parentId');
progressCategoryOptions.value.push(data);
};
// 取消按钮
const cancel = () => {
reset();
dialog.visible = false;
};
// 表单重置
const reset = () => {
form.value = { ...initFormData };
progressCategoryFormRef.value?.resetFields();
};
/** 级联选择器改变事件 */
const handleChange = (value: number) => {
queryParams.value.matrixId = value[1];
getList();
};
/** 搜索按钮操作 */
const handleQuery = () => {
getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
queryFormRef.value?.resetFields();
handleQuery();
};
/** 新增按钮操作 */
const handleAdd = (row?: ProgressCategoryVO) => {
reset();
getTreeselect();
if (row != null && row.id) {
form.value.parentId = row.id;
} else {
form.value.parentId = 0;
}
dialog.visible = true;
dialog.title = '添加分项工程单价';
};
/** 展开/折叠操作 */
const handleToggleExpandAll = () => {
isExpandAll.value = !isExpandAll.value;
toggleExpandAll(progressCategoryList.value, isExpandAll.value);
};
/** 展开/折叠操作 */
const toggleExpandAll = (data: ProgressCategoryVO[], status: boolean) => {
data.forEach((item) => {
progressCategoryTableRef.value?.toggleRowExpansion(item, status);
if (item.children && item.children.length > 0) toggleExpandAll(item.children, status);
});
};
/** 修改按钮操作 */
const handleUpdate = async (row: ProgressCategoryVO) => {
reset();
await getTreeselect();
if (row != null) {
form.value.parentId = row.parentId;
}
const res = await getProgressCategory(row.id);
Object.assign(form.value, res.data);
dialog.visible = true;
dialog.title = '修改分项工程单价';
};
/** 提交按钮 */
const submitForm = () => {
progressCategoryFormRef.value?.validate(async (valid: boolean) => {
if (valid) {
buttonLoading.value = true;
if (form.value.id) {
await updateProgressCategory(form.value).finally(() => (buttonLoading.value = false));
} else {
await addProgressCategory(form.value).finally(() => (buttonLoading.value = false));
}
proxy?.$modal.msgSuccess('操作成功');
dialog.visible = false;
getList();
}
});
};
//切换项目重置方阵
const matrixValue = ref<number | undefined>(matrixOptions.value.length > 0 ? matrixOptions.value[0].id : undefined);
const resetMatrix = () => {
matrixValue.value = undefined;
queryParams.value.matrixId = undefined;
matrixOptions.value = [];
};
/** 删除按钮操作 */
const handleDelete = async (row: ProgressCategoryVO) => {
await proxy?.$modal.confirm('是否确认删除分项工程单价编号为"' + row.id + '"的数据项?');
loading.value = true;
await delProgressCategory(row.id).finally(() => (loading.value = false));
await getList();
proxy?.$modal.msgSuccess('删除成功');
};
onMounted(() => {
getList();
});
//监听项目id刷新数据
const listeningProject = watch(
() => currentProject.value.id,
(nid, oid) => {
queryParams.value.projectId = nid;
form.value.projectId = nid;
resetMatrix();
getList();
}
);
onUnmounted(() => {
listeningProject();
});
</script>