|
@@ -0,0 +1,203 @@
|
|
|
+<template>
|
|
|
+ <el-card shadow="hover">
|
|
|
+ <template #header>
|
|
|
+ <el-row :gutter="10">
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="1.5">
|
|
|
+ <el-button type="danger" plain :disabled="multiple" icon="Delete" @click="handleDelete(null)"> 删除 </el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <el-table
|
|
|
+ v-loading="loading"
|
|
|
+ :default-sort="{ prop: 'startTime,endTime', order: 'descending' }"
|
|
|
+ :data="dataList"
|
|
|
+ @selection-change="handleSelectionChange"
|
|
|
+ >
|
|
|
+ <el-table-column type="selection" width="50" align="center" />
|
|
|
+ <el-table-column label="单位名称" width="200" align="center" prop="dept_name" :show-overflow-tooltip="true" />
|
|
|
+ <el-table-column label="职能说明" align="left" prop="content" :show-overflow-tooltip="true" />
|
|
|
+ <el-table-column label="操作" width="150" align="center">
|
|
|
+ <template #default="scope">
|
|
|
+ <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">编辑</el-button>
|
|
|
+ <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ <pagination
|
|
|
+ v-show="total > queryParams.pageSize"
|
|
|
+ v-model:page="queryParams.page"
|
|
|
+ v-model:limit="queryParams.pageSize"
|
|
|
+ :total="total"
|
|
|
+ @pagination="getList"
|
|
|
+ />
|
|
|
+ </el-card>
|
|
|
+ <!-- 添加或修改培训记录配置对话框 -->
|
|
|
+ <el-dialog ref="formDialogRef" v-model="visible" :title="title" width="500px" append-to-body>
|
|
|
+ <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
|
|
|
+ <el-form-item label="单位名称" prop="dept_id">
|
|
|
+ <el-select v-model="form.dept_id" placeholder="请选择单位">
|
|
|
+ <el-option v-for="item in depts" :key="item.deptId" :label="item.deptName" :value="item.deptId"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="职能说明" prop="content">
|
|
|
+ <el-input v-model="form.content" type="textarea" placeholder="请输入职能说明"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="排序" prop="dept_order">
|
|
|
+ <el-input v-model="form.dept_order" placeholder="请输入排序" />
|
|
|
+ </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>
|
|
|
+</template>
|
|
|
+<script setup lang="ts">
|
|
|
+import {listDept} from '@/api/system/dept';
|
|
|
+import {
|
|
|
+ getUnitList,
|
|
|
+ addUnit,
|
|
|
+ updateUnit,
|
|
|
+ getUnitDetail,
|
|
|
+ deleteUnit
|
|
|
+} from '@/api/riskPrevention/planManage';
|
|
|
+import { to } from 'await-to-js';
|
|
|
+import { ref } from 'vue';
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ id: String
|
|
|
+});
|
|
|
+
|
|
|
+const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
|
+const depts = ref([]);
|
|
|
+const formRef = ref<ElFormInstance>();
|
|
|
+const ids = ref<string[]>([]);
|
|
|
+const single = ref(true);
|
|
|
+const multiple = ref(true);
|
|
|
+const total = ref(0);
|
|
|
+const selectedRow = ref(null);
|
|
|
+const dataList = ref([]);
|
|
|
+const loading = ref(true);
|
|
|
+let visible = ref(false);
|
|
|
+let buttonLoading = ref(false);
|
|
|
+let title = ref('');
|
|
|
+
|
|
|
+const queryParams = reactive({
|
|
|
+ page: 1,
|
|
|
+ pageSize: 10
|
|
|
+});
|
|
|
+
|
|
|
+const form = ref({
|
|
|
+ id: '',
|
|
|
+ dept_id: '',
|
|
|
+ dept_name: '',
|
|
|
+ content: '',
|
|
|
+ dept_order: 0
|
|
|
+});
|
|
|
+
|
|
|
+const rules = reactive({
|
|
|
+ dept_id: [{ required: true, message: '单位名称不能为空', trigger: 'blur' }],
|
|
|
+ content: [{ required: true, message: '职能说明不能为空', trigger: 'blur' }]
|
|
|
+});
|
|
|
+
|
|
|
+// 获取列表数据
|
|
|
+const getList = async() => {
|
|
|
+ loading.value = true;
|
|
|
+ const res = await listDept();
|
|
|
+ depts.value = res.data;
|
|
|
+ getUnitList({ ...queryParams, plan_id: props.id })
|
|
|
+ .then((res) => {
|
|
|
+ dataList.value = res.data;
|
|
|
+ total.value = res.total;
|
|
|
+ })
|
|
|
+ .finally(() => {
|
|
|
+ loading.value = false;
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.id,
|
|
|
+ () => {
|
|
|
+ if (props.id) {
|
|
|
+ getList();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ {
|
|
|
+ immediate: true
|
|
|
+ }
|
|
|
+);
|
|
|
+
|
|
|
+/** 取消按钮 */
|
|
|
+const cancel = () => {
|
|
|
+ resetForm();
|
|
|
+ visible.value = false;
|
|
|
+};
|
|
|
+
|
|
|
+const resetForm = () => {
|
|
|
+ form.value = {
|
|
|
+ id: '',
|
|
|
+ dept_id: '',
|
|
|
+ dept_name: '',
|
|
|
+ content: '',
|
|
|
+ dept_order: 0
|
|
|
+ };
|
|
|
+ formRef.value?.resetFields();
|
|
|
+ formRef.value?.clearValidate();
|
|
|
+};
|
|
|
+
|
|
|
+const handleUpdate = async (row) => {
|
|
|
+ if (row) {
|
|
|
+ resetForm();
|
|
|
+ const res = await getUnitDetail(row.id);
|
|
|
+ form.value = res.data;
|
|
|
+ visible.value = true;
|
|
|
+ title.value = '修改单位职能记录';
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const handleAdd = () => {
|
|
|
+ resetForm();
|
|
|
+ visible.value = true;
|
|
|
+ title.value = '添加单位职能记录';
|
|
|
+};
|
|
|
+
|
|
|
+/**提交按钮 */
|
|
|
+const submitForm = () => {
|
|
|
+ formRef.value?.validate(async (valid) => {
|
|
|
+ if (valid) {
|
|
|
+ try {
|
|
|
+ buttonLoading.value = true;
|
|
|
+ form.value.id ? await updateUnit({ ...form.value, plan_id: props.id }) : await addUnit({ ...form.value, plan_id: props.id });
|
|
|
+ proxy?.$modal.msgSuccess(form.value.id ? '修改成功' : '新增成功');
|
|
|
+ visible.value = false;
|
|
|
+ getList();
|
|
|
+ } finally {
|
|
|
+ buttonLoading.value = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const handleSelectionChange = (selection) => {
|
|
|
+ ids.value = selection.map((item) => item.id);
|
|
|
+ selectedRow.value = selection.length === 1 ? selection[0] : null;
|
|
|
+ single.value = selection.length != 1;
|
|
|
+ multiple.value = !selection.length;
|
|
|
+};
|
|
|
+
|
|
|
+const handleDelete = async (row) => {
|
|
|
+ const deleteIds = row && row.id ? [row?.id] : ids.value;
|
|
|
+ const [err] = await to(proxy?.$modal.confirm('是否确认删除选择的单位职能记录?') as any);
|
|
|
+ if (!err) {
|
|
|
+ await deleteUnit({ids: deleteIds});
|
|
|
+ getList();
|
|
|
+ proxy?.$modal.msgSuccess('删除成功');
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|