smart_archives_web/src/views/filesTransfer/apply/prop/applyForm.vue

374 lines
14 KiB
Vue
Raw Normal View History

2025-09-18 17:20:40 +08:00
<template>
<!-- 小型弹窗用于完成删除保存等操作 -->
<el-dialog class="l-dialog" :class="lDialog" :title="title" :visible.sync="dialogVisible" :showClose="true"
:closeOnClickModal="false" @close="handleClose" :append-to-body="true">
<div>
<el-form :model="form" :rules="rules" ref="ruleForm" label-width="110px">
<el-form-item label="项目" prop="proId">
2025-09-19 15:39:03 +08:00
<el-select class="form-item" v-model="form.proId" filterable clearable placeholder="请选择项目"
@change="handleProChange">
2025-09-18 17:20:40 +08:00
<el-option v-for="item in proList" :key="item.id" :label="item.name"
:value="item.id"></el-option>
</el-select>
</el-form-item>
2025-09-19 10:52:03 +08:00
<el-form-item label="选择移交档案" prop="checkTreeData">
<div>
2025-09-19 13:42:48 +08:00
<el-button plain type="primary" size="mini" icon="el-icon-plus"
@click="handleAddFile">选择</el-button>
2025-09-19 10:52:03 +08:00
<!-- 选中文件表格 -->
<div v-if="checkTreeData && checkTreeData.length > 0" style="margin-top: 10px;">
<el-table :data="checkTreeData" border size="mini" style="width: 100%">
<el-table-column prop="index" label="序号" width="60" align="center">
<template slot-scope="scope">
{{ scope.$index + 1 }}
</template>
</el-table-column>
2025-09-19 13:42:48 +08:00
<el-table-column prop="parParentName" label="所属分类" min-width="200">
2025-09-19 10:52:03 +08:00
<template slot-scope="scope">
2025-09-19 13:42:48 +08:00
{{ scope.row.parParentName || '' }}
2025-09-19 10:52:03 +08:00
</template>
</el-table-column>
2025-09-19 13:42:48 +08:00
<el-table-column prop="parentName" label="所属案卷" min-width="100">
2025-09-19 10:52:03 +08:00
<template slot-scope="scope">
2025-09-19 13:42:48 +08:00
{{ scope.row.parentName || '' }}
2025-09-19 10:52:03 +08:00
</template>
</el-table-column>
<el-table-column prop="fileName" label="文件名称" min-width="100">
<template slot-scope="scope">
{{ scope.row.fileName || '' }}
</template>
</el-table-column>
<el-table-column label="操作" width="80" align="center">
<template slot-scope="scope">
2025-09-19 13:42:48 +08:00
<el-button type="text" icon="el-icon-delete" size="mini" style="color: #f56c6c;"
2025-09-19 10:52:03 +08:00
@click="removeFile(scope.$index)">
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
2025-09-18 17:20:40 +08:00
</el-form-item>
<el-form-item label="接收组织" prop="deptId">
2025-09-19 13:42:48 +08:00
<treeselect v-model="form.deptId" :options="treeDataList" placeholder="请选择接收组织" value-key="id"
:disable-branch-nodes="true" noChildrenText="没有数据了" noOptionsText="没有数据了"
noResultsText="没有搜索结果" />
2025-09-18 17:20:40 +08:00
</el-form-item>
</el-form>
</div>
<span slot="footer" class="dialog-footer">
<el-button class="clear-btn" @click="handleClose" :disabled="disabled">取消</el-button>
<el-button type="primary" class="search-btn" :disabled="disabled"
@click="submitForm('ruleForm')">确认</el-button>
</span>
2025-09-19 13:42:48 +08:00
<FileTree v-if="isflag" :isAdd="isAdd" :rowData="fileTreeRow" :title="fileTreeTitle" @closeDialog="closeDialog"
@getTreeData="getTreeData" :dataForm="fileTreeRow" :width="600" />
2025-09-18 17:20:40 +08:00
</el-dialog>
</template>
<script>
import _ from 'lodash'
import {
saveTransferApplyApi,
editTransferApplyApi,
2025-09-19 13:42:48 +08:00
getProSelectApi,
2025-09-19 15:39:03 +08:00
getTransferApplyFilesApi,
2025-09-19 16:06:03 +08:00
getTransferApplyFilesByApplyIdApi
2025-09-18 17:20:40 +08:00
} from '@/api/filesTransfer/apply'
import { getDeptSelectApi } from '@/api/select'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
2025-09-18 17:40:18 +08:00
import FileTree from '@/views/common/fileTree.vue'
2025-09-18 17:20:40 +08:00
export default {
name: "ApplyForm",
props: ["width", "dataForm", "title", "disabled", "isAdd", "rowData"],
dicts: ['data_class_type'],
2025-09-19 13:42:48 +08:00
components: { Treeselect, FileTree },
2025-09-18 17:20:40 +08:00
data() {
return {
lDialog: this.width > 500 ? "w700" : "w500",
dialogVisible: true,
isDisabled: true,
form: {
proId: undefined,
deptId: undefined,
},
treeDataList: [],
proList: [],
2025-09-19 10:52:03 +08:00
checkTreeData: [],
2025-09-18 17:20:40 +08:00
loading: null,
rules: {
proId: [
{ required: true, message: '请选择项目', trigger: 'change' }
],
2025-09-19 10:52:03 +08:00
checkTreeData: [
2025-09-19 13:42:48 +08:00
{
2025-09-19 10:52:03 +08:00
validator: (rule, value, callback) => {
if (!this.checkTreeData || this.checkTreeData.length === 0) {
callback(new Error('请选择移交档案'));
} else {
callback();
}
2025-09-19 13:42:48 +08:00
},
trigger: 'change'
2025-09-19 10:52:03 +08:00
}
],
2025-09-18 17:20:40 +08:00
deptId: [
{ required: true, message: '请选择接收组织', trigger: 'change' }
],
},
2025-09-18 18:02:29 +08:00
fileTreeTitle: "",
isflag: false,
fileTreeRow: {},
2025-09-18 17:20:40 +08:00
};
},
created() {
this.initFormData();
},
methods: {
/** 初始化表单数据 */
async initFormData() {
await getDeptSelectApi().then(res => {
2025-09-18 17:40:18 +08:00
this.treeDataList = this.convertToVueTree(res.data);
2025-09-18 17:20:40 +08:00
});
await getProSelectApi().then(res => {
this.proList = res.data;
2025-09-28 15:14:32 +08:00
2025-09-18 17:20:40 +08:00
});
2025-09-19 18:23:07 +08:00
2025-09-19 15:39:03 +08:00
2025-09-18 17:20:40 +08:00
if (this.isAdd === 'edit' && this.rowData) {
// 编辑模式:填充表单数据
this.form = {
2025-09-19 10:52:03 +08:00
id: this.rowData.id || null,
2025-09-18 17:20:40 +08:00
proId: this.rowData.proId || undefined,
deptId: this.rowData.deptId || undefined,
};
2025-09-19 18:23:07 +08:00
const res = await getTransferApplyFilesByApplyIdApi({ id: this.rowData.id });
if (Array.isArray(res.data) && res.data.length > 0) {
res.data.map(item => {
const newFile = {
proFilesContentsId: item.id,
parParentName: item.parParentName,
parentName: item.parentName,
fileName: item.fileName,
proId: item.proId,
fileSourceId: item.fileId,
filePath: item.filePath
};
this.checkTreeData.push(newFile);
})
}
2025-09-18 17:20:40 +08:00
} else {
// 新增模式:重置表单
this.form = {
proId: undefined,
deptId: undefined,
};
}
},
2025-09-19 15:39:03 +08:00
handleProChange(value) {
2025-09-29 15:12:56 +08:00
// console.log(value);
2025-09-19 13:42:48 +08:00
this.checkTreeData = [];
},
2025-09-18 17:20:40 +08:00
// 选择移交档案
2025-09-19 13:42:48 +08:00
handleAddFile() {
if (!this.form.proId) {
2025-09-19 10:04:16 +08:00
return this.$modal.msgError('请选择项目');
}
const proId = this.form.proId;
2025-09-18 18:02:29 +08:00
this.fileTreeTitle = "选择";
2025-09-19 13:42:48 +08:00
this.fileTreeRow = { proId };
2025-09-18 18:02:29 +08:00
this.isflag = true;
},
closeDialog() {
this.isflag = false;
},
showColose() {
this.isflag = false;
2025-09-18 17:20:40 +08:00
},
/*关闭弹窗 */
handleClose() {
this.dialogVisible = false;
this.$emit("closeDialog");
2025-09-29 14:18:40 +08:00
/* setTimeout(() => {
2025-09-18 17:20:40 +08:00
this.dialogVisible = true;
2025-09-29 14:18:40 +08:00
}); */
2025-09-18 17:20:40 +08:00
},
/**确认弹窗 */
sureBtnClick() {
this.dialogVisible = false;
this.$emit("closeDialog");
2025-09-29 14:18:40 +08:00
/* setTimeout(() => {
2025-09-18 17:20:40 +08:00
this.dialogVisible = true;
2025-09-29 14:18:40 +08:00
}); */
2025-09-18 17:20:40 +08:00
},
/**重置表单*/
reset() {
this.form = {
id: null,
2025-09-19 10:52:03 +08:00
proId: undefined,
deptId: undefined
2025-09-18 17:20:40 +08:00
};
this.resetForm("ruleForm");
2025-09-19 18:23:07 +08:00
this.checkTreeData = [];
2025-09-18 17:20:40 +08:00
},
handleReuslt(res) {
this.$modal.msgSuccess(res.msg);
this.reset();
this.$emit('handleQuery');
this.handleClose();
},
/**验证 */
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
// 显示遮罩层
this.loading = this.$loading({
lock: true,
text: "数据提交中,请稍候...",
background: 'rgba(0,0,0,0.5)',
target: this.$el.querySelector('.el-dialog') || document.body
})
let params = _.cloneDeep(this.form);
2025-09-19 13:42:48 +08:00
// 获取单项工程名称
let proObj = this.proList.find(item => item.id === params.proId);
params.singleProName = proObj.name;
// 获取接收组织名称
const obj = this.findNodeById(this.treeDataList, this.form.deptId);
params.deptName = obj?.label || '';
params.transferFileDtos = this.checkTreeData;
2025-09-29 15:12:56 +08:00
// console.log(params);
2025-09-19 15:39:03 +08:00
2025-09-18 17:20:40 +08:00
if (this.isAdd === 'add') {
saveTransferApplyApi(params).then(res => {
this.loading.close();
if (res.code === 200) {
this.handleReuslt(res);
} else {
this.$modal.msgError(res.msg);
}
}).catch(error => {
this.loading.close();
// this.$modal.msgError('提交失败,请重试');
});
} else {
editTransferApplyApi(params).then(res => {
this.loading.close();
if (res.code === 200) {
this.handleReuslt(res);
} else {
this.$modal.msgError(res.msg);
}
}).catch(error => {
this.loading.close();
// this.$modal.msgError('提交失败,请重试');
});
}
}
});
2025-09-18 17:40:18 +08:00
},
// 树数据过滤 - 支持无限层级转换
2025-09-18 18:02:29 +08:00
convertToVueTree(data, level = 1) {
2025-09-18 17:40:18 +08:00
if (!data || !Array.isArray(data)) {
2025-09-18 18:02:29 +08:00
return []
2025-09-18 17:40:18 +08:00
}
return data.map(item => {
const node = {
id: item.deptId,
label: item.deptName,
2025-09-18 18:02:29 +08:00
}
2025-09-18 17:40:18 +08:00
if (item.children && Array.isArray(item.children) && item.children.length > 0) {
2025-09-18 18:02:29 +08:00
if (level < 3) {
const children = this.convertToVueTree(item.children, level + 1)
if (children.length > 0) node.children = children
2025-09-18 17:40:18 +08:00
}
}
2025-09-18 18:02:29 +08:00
return node
})
2025-09-18 17:40:18 +08:00
},
2025-09-19 13:42:48 +08:00
findNodeById(nodes, id) {
2025-09-19 15:39:03 +08:00
for (const node of nodes) {
if (node.id === id) return node;
if (node.children) {
const found = this.findNodeById(node.children, id);
if (found) return found;
}
2025-09-19 13:42:48 +08:00
}
2025-09-19 15:39:03 +08:00
return null;
2025-09-19 13:42:48 +08:00
},
2025-09-19 10:52:03 +08:00
// 获取选中的节点
2025-09-19 13:42:48 +08:00
async getTreeData(nodeId) {
2025-09-29 15:29:28 +08:00
// this.checkTreeData = [];
2025-09-19 15:39:03 +08:00
const res = await getTransferApplyFilesApi({ proId: this.form.proId, id: nodeId });
2025-09-19 13:42:48 +08:00
if (Array.isArray(res.data) && res.data.length > 0) {
res.data.map(item => {
const newFile = {
proFilesContentsId: item.id,
parParentName: item.parParentName,
parentName: item.parentName,
fileName: item.fileName,
proId: item.proId,
2025-09-19 15:39:03 +08:00
fileSourceId: item.fileId,
filePath: item.filePath
2025-09-19 13:42:48 +08:00
};
2025-09-29 15:29:28 +08:00
const exists = this.checkTreeData.some(f => f.proFilesContentsId === newFile.proFilesContentsId);
if (!exists) {
this.checkTreeData.push(newFile);
}
2025-09-19 13:42:48 +08:00
})
}
2025-09-22 13:45:55 +08:00
2025-09-19 10:52:03 +08:00
// 触发表单验证
this.$nextTick(() => {
this.$refs.ruleForm.validateField('checkTreeData');
});
},
// 删除文件
removeFile(index) {
this.checkTreeData.splice(index, 1);
// 触发表单验证
this.$nextTick(() => {
this.$refs.ruleForm.validateField('checkTreeData');
});
}
2025-09-18 17:20:40 +08:00
}
};
</script>
2025-09-22 11:13:52 +08:00
<style lang="scss" scoped>
.w700 ::v-deep .el-dialog {
2025-09-19 10:52:03 +08:00
width: 1100px;
2025-09-18 17:20:40 +08:00
}
2025-09-22 11:13:52 +08:00
.w500 ::v-deep .el-dialog {
2025-09-18 17:20:40 +08:00
width: 500px;
}
2025-09-22 11:13:52 +08:00
.w500 ::v-deep .el-dialog__header,
.w700 ::v-deep .el-dialog__header {
2025-09-18 17:20:40 +08:00
// background: #eeeeee;
.el-dialog__title {
font-size: 16px;
}
}
.yxq .el-range-separator {
margin-right: 7px !important;
}
.el-date-editor--daterange.el-input__inner {
width: 260px;
}
.form-item {
width: 100%;
}
.select-style {
display: flex;
justify-content: space-between;
}
</style>