<template>
|
<div class="app-container">
|
<div class="header-section">
|
<div class="title-container">
|
<span class="blue-bar"></span>
|
<span class="title-text">项目类型</span>
|
</div>
|
<el-button type="primary" class="add-btn" @click="handleAdd">新增</el-button>
|
</div>
|
|
<div class="content-section" v-loading="loading">
|
<div class="card-list-scroll">
|
<div v-for="item in projectTypeList" :key="item.id" class="project-type-card">
|
<div class="card-header">
|
<div class="info-group">
|
<span class="label">类型名称:</span>
|
<span class="value">{{ item.name }}</span>
|
</div>
|
<div class="info-group">
|
<span class="label">备注:</span>
|
<span class="value">{{ item.description || '--' }}</span>
|
</div>
|
<div class="info-group">
|
<span class="label">附件:</span>
|
<div
|
class="attachment-info"
|
v-if="(item.attachmentList?.length || 0) > 0"
|
@click="handleExpand(item)"
|
>
|
{{ item.attachmentList[0]?.fileName || item.attachmentList[0]?.name }}
|
<span v-if="item.attachmentList.length > 1" class="file-count">
|
+{{ item.attachmentList.length - 1 }}
|
</span>
|
<span class="expand-link">{{ item.expanded ? '收起' : '展开' }}</span>
|
</div>
|
<span class="value" v-else>--</span>
|
</div>
|
<div class="actions">
|
<el-button link type="primary" @click="handleUpdate(item)">编辑</el-button>
|
<el-button link type="primary" @click="handleCopy(item)">复制</el-button>
|
<el-button link type="danger" @click="handleDelete(item)">删除</el-button>
|
</div>
|
</div>
|
|
<el-collapse-transition>
|
<div v-show="item.expanded" class="expanded-content">
|
<div class="attachment-list">
|
<div
|
v-for="att in (item.attachmentList || [])"
|
:key="att.id || att.url || att.fileUrl || att.fileName || att.name"
|
class="attachment-item"
|
>
|
<el-icon><Document /></el-icon>
|
<span class="attachment-name">{{ att.fileName || att.name || '--' }}</span>
|
<el-button link type="primary" size="small" @click="handleDownload(att)">下载</el-button>
|
</div>
|
</div>
|
</div>
|
</el-collapse-transition>
|
|
<div class="card-body">
|
<div class="workflow-container">
|
<div v-for="(step, index) in item.steps" :key="index" class="workflow-step">
|
<div class="step-main">
|
<div class="step-circle">{{ index + 1 }}</div>
|
<div v-if="index < item.steps.length - 1" class="step-line"></div>
|
</div>
|
<div class="step-label">{{ step.label }}</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
</div>
|
|
<div class="pagination-container">
|
<el-pagination
|
v-model:current-page="queryParams.current"
|
v-model:page-size="queryParams.size"
|
:page-sizes="[10, 20, 30, 50]"
|
layout="total, sizes, prev, pager, next, jumper"
|
:total="total"
|
@size-change="getList"
|
@current-change="getList"
|
/>
|
</div>
|
</div>
|
|
<!-- 添加或修改项目类型对话框 -->
|
<ProjectTypeDialog
|
v-model="open"
|
:title="title"
|
:data="editData"
|
@submit="handleDialogSubmit"
|
/>
|
</div>
|
</template>
|
|
<script setup name="ProjectType">
|
import { ref, reactive, onMounted, getCurrentInstance } from 'vue';
|
import { Document, Download, ArrowDown } from '@element-plus/icons-vue';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
import { listPlan, savePlan, deletePlan } from '@/api/projectManagement/projectType';
|
import ProjectTypeDialog from './components/ProjectTypeDialog.vue';
|
|
const { proxy } = getCurrentInstance();
|
|
// 遮罩层
|
const loading = ref(false);
|
// 总条数
|
const total = ref(0);
|
// 项目类型表格数据
|
const projectTypeList = ref([]);
|
// 弹出层标题
|
const title = ref("");
|
// 是否显示弹出层
|
const open = ref(false);
|
// 编辑数据
|
const editData = ref(null);
|
|
// 查询参数
|
const queryParams = reactive({
|
current: 1,
|
size: 10,
|
});
|
|
/** 查询项目类型列表 */
|
async function getList() {
|
loading.value = true;
|
try {
|
const res = await listPlan(queryParams);
|
if (res.code === 200) {
|
projectTypeList.value = res.data.records.map(item => ({
|
...item,
|
expanded: false,
|
attachmentList: Array.isArray(item.attachmentList) ? item.attachmentList : [],
|
// 后端返回的节点列表可能是 planNodeList 或 savePlanNodeList
|
steps: (item.planNodeList || item.savePlanNodeList || []).map(node => ({
|
label: node.name
|
}))
|
}));
|
total.value = res.data.total;
|
} else {
|
ElMessage.error(res.msg || "获取列表失败");
|
}
|
} catch (error) {
|
console.error("获取列表失败:", error);
|
// 如果接口不通,暂时保留模拟数据供演示
|
if (projectTypeList.value.length === 0) {
|
projectTypeList.value = [
|
{
|
id: 1,
|
name: 'A项目',
|
description: '',
|
attachmentList: [{ id: 1, fileName: 'precaution...' }],
|
steps: [{ label: '立项' }, { label: '设计' }, { label: '采购' }, { label: '生产' }, { label: '出货' }],
|
expanded: false
|
}
|
];
|
total.value = 1;
|
}
|
} finally {
|
loading.value = false;
|
}
|
}
|
|
/** 新增按钮操作 */
|
function handleAdd() {
|
editData.value = null;
|
open.value = true;
|
title.value = "添加项目类型";
|
}
|
|
/** 修改按钮操作 */
|
function handleUpdate(row) {
|
editData.value = row;
|
open.value = true;
|
title.value = "修改项目类型";
|
}
|
|
/** 弹窗提交处理 */
|
async function handleDialogSubmit(formData) {
|
try {
|
const res = await savePlan(formData);
|
if (res.code === 200) {
|
ElMessage.success(formData.id !== undefined ? "修改成功" : "新增成功");
|
open.value = false;
|
getList();
|
} else {
|
ElMessage.error(res.msg || "保存失败");
|
}
|
} catch (error) {
|
console.error("保存失败:", error);
|
}
|
}
|
|
/** 删除按钮操作 */
|
function handleDelete(row) {
|
ElMessageBox.confirm('是否确认删除项目类型编号为"' + row.id + '"的数据项?', "系统提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning"
|
}).then(async function() {
|
try {
|
const res = await deletePlan(row.id);
|
if (res.code === 200) {
|
ElMessage.success("删除成功");
|
getList();
|
} else {
|
ElMessage.error(res.msg || "删除失败");
|
}
|
} catch (error) {
|
console.error("删除失败:", error);
|
}
|
}).catch(() => {});
|
}
|
|
/** 复制按钮操作 */
|
async function handleCopy(row) {
|
const copyData = {
|
name: row.name + " - 副本",
|
description: row.description,
|
attachmentIds: Array.isArray(row.attachmentIds)
|
? row.attachmentIds
|
: (row.attachmentList || []).map(x => x.id).filter(Boolean),
|
savePlanNodeList: (row.planNodeList || row.savePlanNodeList || []).map(node => ({
|
name: node.name,
|
leaderId: node.leaderId,
|
leaderName: node.leaderName,
|
estimatedDuration: node.estimatedDuration,
|
hourlyRate: node.hourlyRate,
|
workContent: node.workContent
|
}))
|
};
|
try {
|
const res = await savePlan(copyData);
|
if (res.code === 200) {
|
ElMessage.success("复制成功");
|
getList();
|
} else {
|
ElMessage.error(res.msg || "复制失败");
|
}
|
} catch (error) {
|
console.error("复制失败:", error);
|
}
|
}
|
|
/** 展开/收起附件 */
|
function handleExpand(item) {
|
item.expanded = !item.expanded;
|
}
|
|
/** 下载附件 */
|
function handleDownload(attachment) {
|
const url = attachment?.url || attachment?.fileUrl || attachment?.tempPath || attachment?.fileName;
|
if (!url) {
|
ElMessage.warning("未找到可下载的文件地址");
|
return;
|
}
|
proxy.$download.name(url);
|
}
|
|
onMounted(() => {
|
getList();
|
});
|
</script>
|
|
<style scoped lang="scss">
|
.app-container {
|
background-color: #f5f7fa;
|
height: calc(100vh - 84px);
|
padding: 20px;
|
display: flex;
|
flex-direction: column;
|
overflow: hidden;
|
}
|
|
.header-section {
|
flex-shrink: 0;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
background-color: #fff;
|
padding: 15px 20px;
|
border-radius: 8px;
|
margin-bottom: 20px;
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
|
.title-container {
|
display: flex;
|
align-items: center;
|
|
.blue-bar {
|
width: 4px;
|
height: 18px;
|
background-color: #409eff;
|
margin-right: 10px;
|
border-radius: 2px;
|
}
|
|
.title-text {
|
font-size: 16px;
|
font-weight: bold;
|
color: #333;
|
}
|
}
|
|
.add-btn {
|
padding: 8px 20px;
|
}
|
}
|
|
.content-section{
|
flex: 1;
|
display: flex;
|
flex-direction: column;
|
overflow: hidden;
|
background: #fff;
|
border-radius: 8px;
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
}
|
|
.card-list-scroll {
|
flex: 1;
|
overflow-y: auto;
|
padding: 20px;
|
}
|
|
.project-type-card {
|
background-color: #fff;
|
border-radius: 8px;
|
padding: 20px;
|
margin-bottom: 20px;
|
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
border: 1px solid #ebeef5;
|
|
&:last-child {
|
margin-bottom: 0;
|
}
|
|
.card-header {
|
display: flex;
|
align-items: center;
|
margin-bottom: 25px;
|
position: relative;
|
|
.info-group {
|
margin-right: 40px;
|
display: flex;
|
align-items: center;
|
font-size: 14px;
|
|
.label {
|
color: #666;
|
margin-right: 8px;
|
}
|
|
.value {
|
color: #333;
|
}
|
|
.attachment-info {
|
display: flex;
|
align-items: center;
|
background-color: #f0f4ff;
|
padding: 4px 10px;
|
border-radius: 4px;
|
color: #409eff;
|
cursor: pointer;
|
|
.file-icon {
|
margin-right: 5px;
|
}
|
|
.file-name {
|
margin-right: 5px;
|
max-width: 100px;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
|
.file-count {
|
margin-right: 8px;
|
font-size: 12px;
|
color: #909399;
|
}
|
|
.download-icon {
|
font-size: 12px;
|
margin-right: 10px;
|
}
|
|
.expand-link {
|
color: #409eff;
|
margin-right: 5px;
|
}
|
|
.arrow-icon {
|
color: #409eff;
|
font-size: 12px;
|
}
|
}
|
}
|
|
.actions {
|
margin-left: auto;
|
}
|
}
|
|
.expanded-content {
|
padding: 0 20px 20px;
|
border-bottom: 1px dashed #ebeef5;
|
margin-bottom: 20px;
|
|
.attachment-list {
|
background-color: #f8f9fa;
|
padding: 15px;
|
border-radius: 4px;
|
|
.attachment-item {
|
display: flex;
|
align-items: center;
|
gap: 10px;
|
font-size: 14px;
|
color: #606266;
|
|
.el-icon {
|
font-size: 16px;
|
color: #409eff;
|
}
|
|
.attachment-name {
|
flex: 1;
|
overflow: hidden;
|
text-overflow: ellipsis;
|
white-space: nowrap;
|
}
|
}
|
}
|
}
|
|
.card-body {
|
.workflow-container {
|
display: flex;
|
align-items: flex-start;
|
padding: 10px 0;
|
overflow-x: auto;
|
|
.workflow-step {
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
min-width: 120px;
|
flex-shrink: 0;
|
|
.step-main {
|
display: flex;
|
align-items: center;
|
width: 100%;
|
position: relative;
|
|
.step-circle {
|
width: 24px;
|
height: 24px;
|
background-color: #409eff;
|
color: #fff;
|
border-radius: 50%;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
font-size: 12px;
|
font-weight: bold;
|
z-index: 2;
|
margin: 0 auto;
|
}
|
|
.step-line {
|
position: absolute;
|
height: 2px;
|
background-color: #d9e6ff;
|
left: calc(50% + 12px);
|
right: calc(-50% + 12px);
|
top: 50%;
|
transform: translateY(-50%);
|
z-index: 1;
|
}
|
}
|
|
.step-label {
|
margin-top: 10px;
|
font-size: 13px;
|
color: #333;
|
text-align: center;
|
}
|
}
|
}
|
}
|
}
|
|
.pagination-container {
|
flex-shrink: 0;
|
display: flex;
|
justify-content: flex-end;
|
padding: 10px 20px;
|
background-color: #fff;
|
border-top: 1px solid #ebeef5;
|
margin-top: 0;
|
}
|
|
.step-config-item {
|
display: flex;
|
align-items: center;
|
gap: 10px;
|
margin-bottom: 10px;
|
}
|
</style>
|