411 lines
13 KiB
Vue
411 lines
13 KiB
Vue
<script setup>
|
||
import { computed, reactive, ref, onMounted, nextTick } from "vue";
|
||
import { getToken } from "@/utils/auth";
|
||
import { queryComDictListService, addComDictService, updateComDictService, delComDictService } from "../../../api/liswork/dict/ComDict.js";
|
||
|
||
|
||
const { proxy } = getCurrentInstance();
|
||
|
||
const data = reactive({
|
||
form: {},
|
||
queryParams: {
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
zdmc: undefined,
|
||
zdlb: '00',
|
||
zddh: undefined,
|
||
yljg: '1'
|
||
},
|
||
rules: {
|
||
dictName: [{ required: true, message: "字典名称不能为空", trigger: "blur" }],
|
||
dictType: [{ required: true, message: "字典类型不能为空", trigger: "blur" }]
|
||
},
|
||
});
|
||
|
||
const { queryParams, form, rules } = toRefs(data);
|
||
const single = ref(true);
|
||
const multiple = ref(true);
|
||
const loading = ref(true);
|
||
const typeList = ref([])
|
||
const typeDetail = ref([])
|
||
const total = ref(0);
|
||
const zdlbmc = ref('');
|
||
const open = ref(false);
|
||
const title = ref('');
|
||
// const zdlbmcComputed = computed(() => {
|
||
// return typeDetail.value.map(item => {
|
||
// return item.zddh+'('+item.zdmc+')';
|
||
// });
|
||
// });
|
||
/*** 用户导入参数 */
|
||
const upload = reactive({
|
||
// 是否显示弹出层(用户导入)
|
||
open: false,
|
||
// 弹出层标题(用户导入)
|
||
title: "",
|
||
// 是否禁用上传
|
||
isUploading: false,
|
||
// 是否更新已经存在的用户数据
|
||
updateSupport: 0,
|
||
// 设置上传的请求头部
|
||
headers: { Authorization: "Bearer " + getToken() },
|
||
// 上传的地址
|
||
url: import.meta.env.VITE_APP_BASE_API + "/comdict/importData"
|
||
});
|
||
const treeRef = ref(null)
|
||
const defaultProps = {
|
||
children: 'children',
|
||
label: 'zdmc',
|
||
id: 'zddh'
|
||
}
|
||
|
||
const info = ref({})
|
||
watch(zdlbmc, (val) => {
|
||
console.log(ref(treeRef.value));
|
||
|
||
treeRef.value?.filter(val)
|
||
})
|
||
|
||
const filterNode = (value, data) => {
|
||
console.log(value, data);
|
||
|
||
if (!value) return true
|
||
return data.zdmc.includes(value)
|
||
}
|
||
|
||
const nodeHandle = (data) => {
|
||
queryParams.value.pageNum = 1
|
||
queryParams.value.zdlb = data.zddh;
|
||
getList()
|
||
// resetData(data.zdlb)
|
||
}
|
||
function resetData(zdlb) {
|
||
queryParams.value = {
|
||
pageNum: 1,
|
||
pageSize: 15,
|
||
zdmc: undefined,
|
||
zdlb: zdlb,
|
||
zddh: undefined,
|
||
yljg: '1'
|
||
}
|
||
}
|
||
function getTypeList() {
|
||
loading.value = true;
|
||
queryParams.value.pageSize = 1000;
|
||
queryParams.value.zdlb = '00'
|
||
queryComDictListService(queryParams.value).then(response => {
|
||
typeList.value = response.rows;
|
||
total.value = response.total;
|
||
loading.value = false;
|
||
resetData()
|
||
queryParams.value.zdlb = response.rows[1].zddh
|
||
getList()
|
||
});
|
||
}
|
||
|
||
|
||
|
||
/** 查询字典明细列表 */
|
||
function getList() {
|
||
loading.value = true;
|
||
queryComDictListService(queryParams.value).then(response => {
|
||
typeDetail.value = response.rows;
|
||
total.value = response.total;
|
||
loading.value = false;
|
||
});
|
||
//resetData()
|
||
}
|
||
|
||
//查询
|
||
function handleQuery() {
|
||
queryParams.value.pageNum = 1;
|
||
getList();
|
||
}
|
||
|
||
/** 表单重置 */
|
||
function reset() {
|
||
form.value = {
|
||
zdlb: '',
|
||
zdmc: '',
|
||
zddh: '',
|
||
bz: ''
|
||
};
|
||
proxy.resetForm("dictRef");
|
||
}
|
||
//重置
|
||
function resetQuery() {
|
||
queryParams.value.zdmc = ''
|
||
queryParams.value.zddh = ''
|
||
proxy.resetForm("queryRef");
|
||
handleQuery();
|
||
}
|
||
|
||
//新增
|
||
function handleAdd() {
|
||
if (queryParams.value.zdlb === undefined || queryParams.value.zdlb === '') {
|
||
proxy.$modal.msgWarning("请先选择字典大类");
|
||
return;
|
||
}
|
||
reset();
|
||
open.value = true;
|
||
title.value = '新增字典';
|
||
}
|
||
|
||
//修改
|
||
function handleUpdate(row) {
|
||
reset()
|
||
form.value = row.zdlb ? row : info.value
|
||
open.value = true;
|
||
}
|
||
|
||
//删除
|
||
function handleDelete(row) {
|
||
proxy.$modal.confirm('是否确认删除字典名称为"' + row.zdmc + '"的数据项?').then(function () {
|
||
return delComDictService(row);
|
||
}).then(() => {
|
||
getList();
|
||
proxy.$modal.msgSuccess("删除成功");
|
||
}).catch(() => { });
|
||
}
|
||
/** 导入按钮操作 */
|
||
function handleImport() {
|
||
upload.title = "字典导入";
|
||
upload.open = true;
|
||
};
|
||
/** 导出按钮操作 */
|
||
function handleExport() {
|
||
proxy.download("comdict/export", {
|
||
...queryParams.value,
|
||
}, `user_${new Date().getTime()}.xlsx`);
|
||
};
|
||
/** 下载模板操作 */
|
||
function importTemplate() {
|
||
proxy.download("comdict/importTemplate", {
|
||
}, `user_template_${new Date().getTime()}.xlsx`);
|
||
};
|
||
/** 提交上传文件 */
|
||
function submitFileForm() {
|
||
proxy.$refs["uploadRef"].submit();
|
||
};
|
||
/**文件上传中处理 */
|
||
const handleFileUploadProgress = (event, file, fileList) => {
|
||
upload.isUploading = true;
|
||
};
|
||
/** 文件上传成功处理 */
|
||
const handleFileSuccess = (response, file, fileList) => {
|
||
upload.open = false;
|
||
upload.isUploading = false;
|
||
proxy.$refs["uploadRef"].handleRemove(file);
|
||
proxy.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
|
||
handleQuery()
|
||
};
|
||
|
||
|
||
//多选框选中数据
|
||
function handleSelectionChange(selection) {
|
||
info.value = selection[0]
|
||
single.value = selection.length != 1;
|
||
}
|
||
|
||
//查询字典大类
|
||
function handleQueryDetail() {
|
||
queryParams.value.zdmc = zdlbmc.value
|
||
getTypeList()
|
||
resetData()
|
||
}
|
||
|
||
//提交表单数据
|
||
function submitForm() {
|
||
proxy.$refs["dictRef"].validate(valid => {
|
||
if (valid) {
|
||
if (form.value.zdlb != undefined && form.value.zdlb != '') {
|
||
updateComDictService(form.value).then(response => {
|
||
if (response.code == 0) {
|
||
proxy.$modal.msgSuccess("修改成功");
|
||
open.value = false;
|
||
getList();
|
||
}
|
||
})
|
||
} else {
|
||
form.value.zdlb = queryParams.value.zdlb;
|
||
form.value.yljg = 1;
|
||
addComDictService(form.value).then(response => {
|
||
if (response.code == 0) {
|
||
proxy.$modal.msgSuccess("新增成功");
|
||
open.value = false;
|
||
getList();
|
||
}
|
||
})
|
||
}
|
||
}
|
||
});
|
||
}
|
||
|
||
function cancel() {
|
||
open.value = false;
|
||
reset();
|
||
}
|
||
|
||
|
||
onMounted(() => {
|
||
getTypeList()
|
||
})
|
||
|
||
|
||
|
||
</script>
|
||
|
||
<template>
|
||
<div class="app-container">
|
||
<el-row :gutter="20">
|
||
<el-col :span="4" :xs="24">
|
||
<div class="head-container">
|
||
<el-input v-model="zdlbmc" clearable placeholder="请输入字典名称" prefix-icon="Search" style="margin-bottom: 20px" />
|
||
</div>
|
||
<div class="head-container">
|
||
<div class="card-content">
|
||
<el-tree ref="treeRef" class="filter-tree" :data="typeList" :props="defaultProps" default-expand-all
|
||
:filter-node-method="filterNode" @node-click="nodeHandle" highlight-current />
|
||
</div>
|
||
</div>
|
||
</el-col>
|
||
<!-- 字典明细-->
|
||
<el-col :span="20" :xs="24">
|
||
<!-- 表单区域-->
|
||
<el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
|
||
<el-form-item class="cus-el-form-item" label="名称" prop="dictName">
|
||
<el-input v-model="queryParams.zdmc" placeholder="请输入名称" clearable style="width: 240px"
|
||
@keyup.enter="handleQuery" />
|
||
</el-form-item>
|
||
<el-form-item class="cus-el-form-item" label="明细代号" prop="status">
|
||
<el-input v-model="queryParams.zddh" placeholder="请输入明细代号" clearable style="width: 240px"
|
||
@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>
|
||
|
||
<el-row :gutter="10" class="mb8">
|
||
<el-col :span="1.5">
|
||
<el-button type="primary" plain icon="Plus" @click="handleAdd"
|
||
v-hasPermi="['system:dict:add']">新增</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
|
||
v-hasPermi="['system:dict:edit']">修改</el-button>
|
||
</el-col>
|
||
<!-- <el-col :span="1.5">
|
||
<el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
|
||
v-hasPermi="['system:dict:remove']">删除</el-button>
|
||
</el-col> -->
|
||
<el-col :span="1.5">
|
||
<el-button type="info" plain icon="Upload" @click="handleImport"
|
||
v-hasPermi="['system:dict:import']">导入</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button type="warning" plain icon="Download" @click="handleExport"
|
||
v-hasPermi="['system:dict:export']">导出</el-button>
|
||
</el-col>
|
||
</el-row>
|
||
<!-- 表格区域-->
|
||
<el-table v-loading="loading" :data="typeDetail" @selection-change="handleSelectionChange" height="65vh">
|
||
<el-table-column type="selection" width="55" align="center" />
|
||
<el-table-column label='字典类型' align="center" prop="zdlb" :show-overflow-tooltip="true" />
|
||
<el-table-column label="明细代号" align="center" prop="zddh" />
|
||
<el-table-column label="名称" align="center" prop="zdmc" :show-overflow-tooltip="true" />
|
||
<el-table-column label="备注" align="center" prop="bz" :show-overflow-tooltip="true" />
|
||
<el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" icon="Edit" @click="handleUpdate(row)"
|
||
v-hasPermi="['system:dict:edit']">修改</el-button>
|
||
<el-button link type="primary" icon="Delete" @click="handleDelete(row)"
|
||
v-hasPermi="['system:dict:remove']">删除</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-col>
|
||
</el-row>
|
||
|
||
<!-- 添加或修改参数配置对话框 -->
|
||
<el-dialog :title="title" v-model="open" width="500px" append-to-body>
|
||
<el-form ref="dictRef" :model="form" :rules="rules" label-width="80px">
|
||
<el-form-item label="字典类别" prop="zdlb">
|
||
<el-input v-model="form.zdlb" disabled></el-input>
|
||
</el-form-item>
|
||
<el-form-item label="字典代号" prop="zddh">
|
||
<el-input v-model="form.zddh" placeholder="请输入字典代号" />
|
||
</el-form-item>
|
||
<el-form-item label="字典名称" prop="zdmc">
|
||
<el-input v-model="form.zdmc" placeholder="请输入字典名称" />
|
||
</el-form-item>
|
||
<el-form-item label="备注" prop="bz">
|
||
<el-input v-model="form.bz" placeholder="请输入内容"></el-input>
|
||
</el-form-item>
|
||
</el-form>
|
||
<template #footer>
|
||
<div class="dialog-footer">
|
||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||
<el-button @click="cancel">取 消</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
<!-- 用户导入对话框 -->
|
||
<el-dialog :title="upload.title" v-model="upload.open" width="400px" append-to-body>
|
||
<el-upload ref="uploadRef" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
|
||
:action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
|
||
:on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
|
||
<el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||
<template #tip>
|
||
<div class="el-upload__tip text-center">
|
||
<div class="el-upload__tip">
|
||
<el-checkbox v-model="upload.updateSupport" />是否覆盖已经存在的字典数据
|
||
</div>
|
||
<span>仅允许导入xls、xlsx格式文件。</span>
|
||
<el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;"
|
||
@click="importTemplate">下载模板</el-link>
|
||
</div>
|
||
</template>
|
||
</el-upload>
|
||
<template #footer>
|
||
<div class="dialog-footer">
|
||
<el-button type="primary" @click="submitFileForm">确 定</el-button>
|
||
<el-button @click="upload.open = false">取 消</el-button>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<style scoped lang="scss">
|
||
.card-content {
|
||
.card-content {
|
||
max-height: 450px;
|
||
/* 设置最大高度 */
|
||
overflow-y: auto;
|
||
/* 超出高度时显示垂直滚动条 */
|
||
padding: 16px;
|
||
/* 保持与卡片默认一致的内边距 */
|
||
}
|
||
|
||
.clickable:hover {
|
||
cursor: pointer;
|
||
/* 鼠标悬停时显示手型 */
|
||
transition: all 0.3s;
|
||
/* 平滑过渡效果 */
|
||
color: blue;
|
||
|
||
}
|
||
}
|
||
|
||
.filter-tree {
|
||
max-height: 70vh;
|
||
overflow-y: auto;
|
||
}
|
||
</style> |