This commit is contained in:
parent
95d0223133
commit
c423f31490
|
|
@ -8,7 +8,6 @@
|
||||||
:close-on-click-modal="false"
|
:close-on-click-modal="false"
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
append-to-body
|
append-to-body
|
||||||
width="auto"
|
|
||||||
>
|
>
|
||||||
<el-form
|
<el-form
|
||||||
ref="ruleFormRef"
|
ref="ruleFormRef"
|
||||||
|
|
@ -73,7 +72,7 @@
|
||||||
</div>
|
</div>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item label="接收组织" prop="deptId">
|
<el-form-item label="接收组织">
|
||||||
<el-tree-select
|
<el-tree-select
|
||||||
v-model="form.deptId"
|
v-model="form.deptId"
|
||||||
:data="treeDataList"
|
:data="treeDataList"
|
||||||
|
|
@ -115,10 +114,10 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
import { ref, computed, onMounted, nextTick } from 'vue';
|
||||||
import { ElMessage, ElLoading } from 'element-plus'
|
import { ElMessage, ElLoading } from 'element-plus';
|
||||||
import { Delete, Plus } from '@element-plus/icons-vue'
|
import { Delete, Plus } from '@element-plus/icons-vue';
|
||||||
import _ from 'lodash-es'
|
import _ from 'lodash-es';
|
||||||
|
|
||||||
// API
|
// API
|
||||||
import {
|
import {
|
||||||
|
|
@ -126,12 +125,13 @@ import {
|
||||||
editTransferApplyApi,
|
editTransferApplyApi,
|
||||||
getProSelectApi,
|
getProSelectApi,
|
||||||
getTransferApplyFilesApi,
|
getTransferApplyFilesApi,
|
||||||
getTransferApplyFilesByApplyIdApi,
|
getTransferApplyFilesByApplyIdApi
|
||||||
} from '@/api/filesTransfer/apply'
|
} from '@/api/filesTransfer/apply';
|
||||||
import { getDeptSelectApi, getDictDataByTypeApi } from '@/api/select'
|
import { getDeptSelectApi, getDictDataByTypeApi } from '@/api/select';
|
||||||
|
import { getDeptTree } from '@/api/system/dept';
|
||||||
|
|
||||||
// 子组件
|
// 子组件
|
||||||
import FileTree from '@/views/common/fileTree.vue'
|
import FileTree from '@/views/common/fileTree.vue';
|
||||||
|
|
||||||
// Props
|
// Props
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
|
|
@ -140,31 +140,31 @@ const props = defineProps({
|
||||||
title: String,
|
title: String,
|
||||||
disabled: Boolean,
|
disabled: Boolean,
|
||||||
isAdd: String, // 'add' | 'edit'
|
isAdd: String, // 'add' | 'edit'
|
||||||
rowData: Object,
|
rowData: Object
|
||||||
})
|
});
|
||||||
|
|
||||||
const emit = defineEmits(['closeDialog', 'handleQuery'])
|
const emit = defineEmits(['closeDialog', 'handleQuery']);
|
||||||
|
|
||||||
// ================== Reactive Data ==================
|
// ================== Reactive Data ==================
|
||||||
const dialogVisible = ref(true)
|
const dialogVisible = ref(true);
|
||||||
const form = ref({
|
const form = ref({
|
||||||
id: null,
|
id: null,
|
||||||
proId: undefined,
|
proId: undefined,
|
||||||
deptId: undefined,
|
deptId: undefined
|
||||||
})
|
});
|
||||||
const treeDataList = ref([])
|
const treeDataList = ref([]);
|
||||||
const proList = ref([])
|
const proList = ref([]);
|
||||||
const checkTreeData = ref([])
|
const checkTreeData = ref([]);
|
||||||
|
|
||||||
const ruleFormRef = ref()
|
const ruleFormRef = ref();
|
||||||
const loadingInstance = ref(null)
|
const loadingInstance = ref(null);
|
||||||
|
|
||||||
const fileTreeTitle = ref('')
|
const fileTreeTitle = ref('');
|
||||||
const isflag = ref(false)
|
const isflag = ref(false);
|
||||||
const fileTreeRow = ref({})
|
const fileTreeRow = ref({});
|
||||||
|
|
||||||
// 动态 class
|
// 动态 class
|
||||||
const lDialog = computed(() => (props.width > 500 ? 'w700' : 'w500'))
|
const lDialog = computed(() => (props.width > 500 ? 'w700' : 'w500'));
|
||||||
|
|
||||||
// ================== Rules ==================
|
// ================== Rules ==================
|
||||||
const rules = {
|
const rules = {
|
||||||
|
|
@ -173,70 +173,70 @@ const rules = {
|
||||||
{
|
{
|
||||||
validator: (rule, value, callback) => {
|
validator: (rule, value, callback) => {
|
||||||
if (!checkTreeData.value || checkTreeData.value.length === 0) {
|
if (!checkTreeData.value || checkTreeData.value.length === 0) {
|
||||||
callback(new Error('请选择移交档案'))
|
callback(new Error('请选择移交档案'));
|
||||||
} else {
|
} else {
|
||||||
callback()
|
callback();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
trigger: 'change',
|
trigger: 'change'
|
||||||
},
|
}
|
||||||
],
|
],
|
||||||
deptId: [{ required: true, message: '请选择接收组织', trigger: 'change' }],
|
deptId: [{ required: true, message: '请选择接收组织', trigger: 'change' }]
|
||||||
}
|
};
|
||||||
|
|
||||||
// ================== Methods ==================
|
// ================== Methods ==================
|
||||||
const convertToVueTree = (data, level = 1) => {
|
const convertToVueTree = (data) => {
|
||||||
if (!data || !Array.isArray(data)) return []
|
if (!data || !Array.isArray(data)) return [];
|
||||||
return data.map((item) => {
|
return data.map((item) => {
|
||||||
const node = {
|
const node = {
|
||||||
id: item.deptId,
|
id: item.id,
|
||||||
label: item.deptName,
|
label: item.title
|
||||||
}
|
};
|
||||||
if (item.children && Array.isArray(item.children) && item.children.length > 0) {
|
if (item.children && Array.isArray(item.children) && item.children.length > 0) {
|
||||||
if (level < 3) {
|
const children = convertToVueTree(item.children);
|
||||||
const children = convertToVueTree(item.children, level + 1)
|
if (children.length > 0) node.children = children;
|
||||||
if (children.length > 0) node.children = children
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return node
|
return node;
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const findNodeById = (nodes, id) => {
|
const findNodeById = (nodes, id) => {
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
if (node.id === id) return node
|
if (node.id === id) return node;
|
||||||
if (node.children) {
|
if (node.children) {
|
||||||
const found = findNodeById(node.children, id)
|
const found = findNodeById(node.children, id);
|
||||||
if (found) return found
|
if (found) return found;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null;
|
||||||
}
|
};
|
||||||
|
|
||||||
const initFormData = async () => {
|
const initFormData = async () => {
|
||||||
// 加载字典(预留)
|
// 加载字典(预留)
|
||||||
await getDictDataByTypeApi( { dictType: 'data_class_type' }).catch(() => {})
|
await getDictDataByTypeApi({ dictType: 'data_class_type' }).catch(() => {
|
||||||
|
});
|
||||||
|
|
||||||
// 加载部门树
|
// 加载部门树
|
||||||
const deptRes = await getDeptSelectApi()
|
const deptRes = await getDeptTree();
|
||||||
treeDataList.value = convertToVueTree(deptRes.data.data)
|
treeDataList.value = convertToVueTree(deptRes.data.data);
|
||||||
|
|
||||||
// 加载项目列表
|
// 加载项目列表
|
||||||
const proRes = await getProSelectApi()
|
const proRes = await getProSelectApi();
|
||||||
proList.value = proRes.data.data
|
proList.value = proRes.data.data;
|
||||||
|
|
||||||
// 编辑模式回显
|
// 编辑模式回显
|
||||||
if (props.isAdd === 'edit' && props.rowData) {
|
if (props.isAdd === 'edit' && props.rowData) {
|
||||||
form.value = {
|
form.value = {
|
||||||
id: props.rowData.id || null,
|
id: props.rowData.id || null,
|
||||||
proId: props.rowData.proId || undefined,
|
proId: props.rowData.proId || undefined,
|
||||||
deptId: props.rowData.deptId || undefined,
|
deptId: props.rowData.deptId || undefined
|
||||||
}
|
};
|
||||||
|
|
||||||
const res = await getTransferApplyFilesByApplyIdApi({
|
const res = await getTransferApplyFilesByApplyIdApi({
|
||||||
id: props.rowData.id,
|
id: props.rowData.id,
|
||||||
proId: props.rowData.proId,
|
proId: props.rowData.proId
|
||||||
})
|
});
|
||||||
|
|
||||||
if (Array.isArray(res.data.data)) {
|
if (Array.isArray(res.data.data)) {
|
||||||
checkTreeData.value = res.data.data.map((item) => ({
|
checkTreeData.value = res.data.data.map((item) => ({
|
||||||
|
|
@ -246,111 +246,111 @@ const initFormData = async () => {
|
||||||
fileName: item.fileName,
|
fileName: item.fileName,
|
||||||
proId: item.proId,
|
proId: item.proId,
|
||||||
fileSourceId: item.fileId,
|
fileSourceId: item.fileId,
|
||||||
filePath: item.filePath,
|
filePath: item.filePath
|
||||||
}))
|
}));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 新增模式重置
|
// 新增模式重置
|
||||||
form.value = {
|
form.value = {
|
||||||
id: null,
|
id: null,
|
||||||
proId: undefined,
|
proId: undefined,
|
||||||
deptId: undefined,
|
deptId: undefined
|
||||||
}
|
};
|
||||||
checkTreeData.value = []
|
checkTreeData.value = [];
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleProChange = (value) => {
|
const handleProChange = (value) => {
|
||||||
checkTreeData.value = []
|
checkTreeData.value = [];
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleAddFile = () => {
|
const handleAddFile = () => {
|
||||||
if (!form.value.proId) {
|
if (!form.value.proId) {
|
||||||
ElMessage.error('请选择项目')
|
ElMessage.error('请选择项目');
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
fileTreeTitle.value = '选择'
|
fileTreeTitle.value = '选择';
|
||||||
fileTreeRow.value = { proId: form.value.proId }
|
fileTreeRow.value = { proId: form.value.proId };
|
||||||
isflag.value = true
|
isflag.value = true;
|
||||||
}
|
};
|
||||||
|
|
||||||
const closeDialog = () => {
|
const closeDialog = () => {
|
||||||
isflag.value = false
|
isflag.value = false;
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
dialogVisible.value = false
|
dialogVisible.value = false;
|
||||||
emit('closeDialog')
|
emit('closeDialog');
|
||||||
}
|
};
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
form.value = {
|
form.value = {
|
||||||
id: null,
|
id: null,
|
||||||
proId: undefined,
|
proId: undefined,
|
||||||
deptId: undefined,
|
deptId: undefined
|
||||||
}
|
};
|
||||||
checkTreeData.value = []
|
checkTreeData.value = [];
|
||||||
if (ruleFormRef.value) ruleFormRef.value.clearValidate()
|
if (ruleFormRef.value) ruleFormRef.value.clearValidate();
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleResult = (res) => {
|
const handleResult = (res) => {
|
||||||
ElMessage.success(res.data.msg)
|
ElMessage.success(res.data.msg);
|
||||||
reset()
|
reset();
|
||||||
emit('handleQuery')
|
emit('handleQuery');
|
||||||
handleClose()
|
handleClose();
|
||||||
}
|
};
|
||||||
|
|
||||||
const submitForm = async () => {
|
const submitForm = async () => {
|
||||||
try {
|
try {
|
||||||
await ruleFormRef.value.validate()
|
await ruleFormRef.value.validate();
|
||||||
} catch {
|
} catch {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingInstance.value = ElLoading.service({
|
loadingInstance.value = ElLoading.service({
|
||||||
lock: true,
|
lock: true,
|
||||||
text: '数据提交中,请稍候...',
|
text: '数据提交中,请稍候...',
|
||||||
background: 'rgba(0,0,0,0.5)',
|
background: 'rgba(0,0,0,0.5)',
|
||||||
target: document.querySelector('.el-dialog') || document.body,
|
target: document.querySelector('.el-dialog') || document.body
|
||||||
})
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const params = _.cloneDeep(form.value)
|
const params = _.cloneDeep(form.value);
|
||||||
|
|
||||||
// 补充名称
|
// 补充名称
|
||||||
const proObj = proList.value.find((item) => item.id === params.proId)
|
const proObj = proList.value.find((item) => item.id === params.proId);
|
||||||
params.singleProName = proObj?.name || ''
|
params.singleProName = proObj?.name || '';
|
||||||
|
|
||||||
const deptNode = findNodeById(treeDataList.value, params.deptId)
|
const deptNode = findNodeById(treeDataList.value, params.deptId);
|
||||||
params.deptName = deptNode?.label || ''
|
params.deptName = deptNode?.label || '';
|
||||||
|
|
||||||
params.transferFileDtos = checkTreeData.value
|
params.transferFileDtos = checkTreeData.value;
|
||||||
|
|
||||||
let res
|
let res;
|
||||||
if (props.isAdd === 'add') {
|
if (props.isAdd === 'add') {
|
||||||
res = await saveTransferApplyApi(params)
|
res = await saveTransferApplyApi(params);
|
||||||
} else {
|
} else {
|
||||||
res = await editTransferApplyApi(params)
|
res = await editTransferApplyApi(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingInstance.value.close()
|
loadingInstance.value.close();
|
||||||
|
|
||||||
if (res.data.code === 200) {
|
if (res.data.code === 200) {
|
||||||
handleResult(res)
|
handleResult(res);
|
||||||
} else {
|
} else {
|
||||||
ElMessage.error(res.data.msg)
|
ElMessage.error(res.data.msg);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
loadingInstance.value.close()
|
loadingInstance.value.close();
|
||||||
ElMessage.error(error.message || '操作失败')
|
ElMessage.error(error.message || '操作失败');
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const getTreeData = async (nodeId) => {
|
const getTreeData = async (nodeId) => {
|
||||||
const res = await getTransferApplyFilesApi({
|
const res = await getTransferApplyFilesApi({
|
||||||
proId: form.value.proId,
|
proId: form.value.proId,
|
||||||
id: nodeId,
|
id: nodeId
|
||||||
})
|
});
|
||||||
|
|
||||||
if (Array.isArray(res.data.data)) {
|
if (Array.isArray(res.data.data)) {
|
||||||
for (const item of res.data.data) {
|
for (const item of res.data.data) {
|
||||||
|
|
@ -361,50 +361,53 @@ const getTreeData = async (nodeId) => {
|
||||||
fileName: item.fileName,
|
fileName: item.fileName,
|
||||||
proId: item.proId,
|
proId: item.proId,
|
||||||
fileSourceId: item.fileId,
|
fileSourceId: item.fileId,
|
||||||
filePath: item.filePath,
|
filePath: item.filePath
|
||||||
}
|
};
|
||||||
|
|
||||||
const exists = checkTreeData.value.some(
|
const exists = checkTreeData.value.some(
|
||||||
(f) => f.proFilesContentsId === newFile.proFilesContentsId
|
(f) => f.proFilesContentsId === newFile.proFilesContentsId
|
||||||
)
|
);
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
checkTreeData.value.push(newFile)
|
checkTreeData.value.push(newFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 触发校验
|
// 触发校验
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
ruleFormRef.value?.validateField('checkTreeData')
|
ruleFormRef.value?.validateField('checkTreeData');
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const removeFile = (index) => {
|
const removeFile = (index) => {
|
||||||
checkTreeData.value.splice(index, 1)
|
checkTreeData.value.splice(index, 1);
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
ruleFormRef.value?.validateField('checkTreeData')
|
ruleFormRef.value?.validateField('checkTreeData');
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
// ================== Lifecycle ==================
|
// ================== Lifecycle ==================
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initFormData()
|
initFormData();
|
||||||
})
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.w700 ::v-deep(.el-dialog) {
|
.w700 ::v-deep(.el-dialog) {
|
||||||
width: 1100px;
|
width: 1100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w500 ::v-deep(.el-dialog) {
|
.w500 ::v-deep(.el-dialog) {
|
||||||
width: 500px;
|
width: 500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.w500 ::v-deep(.el-dialog__header),
|
.w500 ::v-deep(.el-dialog__header),
|
||||||
.w700 ::v-deep(.el-dialog__header) {
|
.w700 ::v-deep(.el-dialog__header) {
|
||||||
.el-dialog__title {
|
.el-dialog__title {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-item {
|
.form-item {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue