修改bug

This commit is contained in:
2026-02-02 10:56:40 +08:00
parent 4d4ec340a5
commit 21562e57a6
7 changed files with 2939 additions and 832 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2018-2025, cyweb All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the pig4cloud.com developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
*/
import request from '/@/utils/request';
/**
* 分页查询
* @param params 查询参数
*/
export function getPage(params?: any) {
return request({
url: '/purchase/purchasingSchoolLeader/page',
method: 'get',
params
});
}
/**
* 通过id查询
* @param id ID
*/
export function getObj(id: string | number) {
return request({
url: '/purchase/purchasingSchoolLeader/details',
method: 'get',
params: { id }
});
}
/**
* 新增校领导(党委)
* @param obj 对象数据
*/
export function addObj(obj: any) {
return request({
url: '/purchase/purchasingSchoolLeader',
method: 'post',
data: obj
});
}
/**
* 修改校领导(党委)
* @param obj 对象数据
*/
export function editObj(obj: any) {
return request({
url: '/purchase/purchasingSchoolLeader',
method: 'put',
data: obj
});
}
/**
* 删除校领导(党委)
* @param ids ID数组
*/
export function delObj(ids: string[] | number[]) {
return request({
url: '/purchase/purchasingSchoolLeader',
method: 'delete',
data: ids
});
}

View File

@@ -808,7 +808,7 @@ const isGoodsCategory = computed(() => {
const isSpecialServiceCategory = computed(() => { const isSpecialServiceCategory = computed(() => {
const category = getCategoryInfo(); const category = getCategoryInfo();
if (!category) return false; if (!category) return false;
return category.isMallService === 1 && category.isProjectService === 1; return Number(category.isMallService) === 1 || Number(category.isProjectService) === 1;
}); });
// 判断是否自动选择网上商城采购方式5万<=金额<40万服务类目特殊服务类目 // 判断是否自动选择网上商城采购方式5万<=金额<40万服务类目特殊服务类目

View File

@@ -1,142 +1,227 @@
<template> <template>
<el-dialog :title="form.id ? '编辑' : '新增'" v-model="visible" <el-dialog
:close-on-click-modal="false" draggable> :title="form.id ? '编辑' : '新增'"
<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading"> v-model="visible"
<el-row :gutter="24"> width="700px"
<el-col :span="12" class="mb20"> :close-on-click-modal="false"
<el-form-item label="备注" prop="remark"> draggable>
<el-input v-model="form.remark" placeholder="请输入备注"/> <el-form
ref="dataFormRef"
:model="form"
:rules="dataRules"
label-width="120px"
v-loading="loading">
<el-form-item label="部门" prop="deptId">
<org-selector
v-model:orgList="deptList"
type="dept"
:multiple="false"
@update:orgList="handleDeptChange" />
</el-form-item> </el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="部门ID" prop="deptId">
<el-input v-model="form.deptId" placeholder="请输入部门ID"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="部门名称" prop="deptName"> <el-form-item label="部门名称" prop="deptName">
<el-input v-model="form.deptName" placeholder="请输入部门名称"/> <el-input
v-model="form.deptName"
placeholder="请选择部门后自动填充"
readonly />
</el-form-item> </el-form-item>
</el-col> <el-form-item label="分管负责人" prop="userId">
<el-col :span="12" class="mb20"> <org-selector
<el-form-item label="分管负责人ID" prop="userId"> v-model:orgList="userList"
<el-input v-model="form.userId" placeholder="请输入分管负责人ID"/> type="user"
:multiple="false"
@update:orgList="handleUserChange" />
</el-form-item> </el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="分管负责人工号" prop="username">
<el-input v-model="form.username" placeholder="请输入分管负责人工号"/>
</el-form-item>
</el-col>
<el-col :span="12" class="mb20">
<el-form-item label="姓名" prop="name"> <el-form-item label="姓名" prop="name">
<el-input v-model="form.name" placeholder="请输入姓名"/> <el-input
v-model="form.name"
placeholder="请选择用户后自动填充"
readonly />
</el-form-item>
<el-form-item label="用户工号" prop="username">
<el-input
v-model="form.username"
placeholder="请选择用户后自动填充"
readonly />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input
v-model="form.remark"
type="textarea"
:rows="3"
placeholder="请输入备注"
clearable />
</el-form-item> </el-form-item>
</el-col>
</el-row>
</el-form> </el-form>
<template #footer> <template #footer>
<span class="dialog-footer"> <span class="dialog-footer">
<el-button @click="visible = false"> </el-button> <el-button @click="visible = false"> </el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading"> </el-button> <el-button type="primary" @click="onSubmit" :disabled="loading"> </el-button>
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
</template> </template>
<script setup lang="ts" name="PurchasingBusinessDeptDialog"> <script setup lang="ts" name="PurchasingBusinessDeptForm">
// ========== 1. 导入语句 ========== import { reactive, ref, nextTick } from 'vue'
import { useDict } from '/@/hooks/dict'; import { getObj, addObj, putObj } from '/@/api/purchase/purchasingBusinessDept';
import { rule } from '/@/utils/validate'; import { useMessage } from '/@/hooks/message';
import { useMessage } from "/@/hooks/message"; import orgSelector from '/@/components/OrgSelector/index.vue';
import { getObj, addObj, putObj, validateExist } from '/@/api/purchase/purchasingBusinessDept';
// ========== 2. 组件定义 ========== // 定义子组件向父组件传值/事件
// 定义组件事件
const emit = defineEmits(['refresh']); const emit = defineEmits(['refresh']);
// ========== 3. 响应式数据定义 ========== // 定义变量内容
// 基础响应式变量 const dataFormRef = ref();
const dataFormRef = ref(); // 表单引用 const deptList = ref<any[]>([]);
const visible = ref(false); // 弹窗显示状态 const userList = ref<any[]>([]);
const loading = ref(false); // 加载状态 const dataForm = reactive({
id: '',
// 表单数据对象 deptId: '',
const form = reactive({ deptName: '',
id: '', // 主键 userId: '',
remark: '', // 备注 username: '',
deptId: '', // 部门ID name: '',
deptName: '', // 部门名称 remark: '',
userId: '', // 分管负责人ID
username: '', // 分管负责人工号
name: '', // 姓名
}); });
const visible = ref(false);
const loading = ref(false);
// ========== 4. 字典数据处理 ==========
// ========== 5. 表单校验规则 ==========
const dataRules = ref({ const dataRules = ref({
deptId: [
{ required: true, message: '请选择部门', trigger: 'change' }
],
userId: [
{ required: true, message: '请选择分管负责人', trigger: 'change' }
],
name: [
{ required: true, message: '姓名不能为空', trigger: 'blur' }
],
username: [
{ required: true, message: '用户工号不能为空', trigger: 'blur' }
],
}); });
// ========== 6. 方法定义 ========== // 处理部门选择变化
// 获取详情数据 const handleDeptChange = (list: any[]) => {
const getPurchasingBusinessDeptData = async (id: string) => { if (list && list.length > 0) {
try { const dept = list[0];
loading.value = true; dataForm.deptId = dept.deptId || dept.id || '';
const { data } = await getObj({ id: id }); dataForm.deptName = dept.name || dept.deptName || '';
// 直接将第一条数据赋值给表单 } else {
Object.assign(form, data[0]); dataForm.deptId = '';
} catch (error) { dataForm.deptName = '';
useMessage().error('获取数据失败');
} finally {
loading.value = false;
} }
}; };
// 打开弹窗方法 // 处理用户选择变化
const openDialog = (id: string) => { const handleUserChange = (list: any[]) => {
visible.value = true; if (list && list.length > 0) {
form.id = ''; const user = list[0];
dataForm.userId = user.userId || user.id || '';
dataForm.username = user.username || user.userName || '';
dataForm.name = user.name || user.realName || '';
} else {
dataForm.userId = '';
dataForm.username = '';
dataForm.name = '';
}
};
// 打开弹窗
const openDialog = async (id?: string) => {
visible.value = true;
dataForm.id = '';
dataForm.deptId = '';
dataForm.deptName = '';
dataForm.userId = '';
dataForm.username = '';
dataForm.name = '';
dataForm.remark = '';
deptList.value = [];
userList.value = [];
// 重置表单数据
nextTick(() => { nextTick(() => {
dataFormRef.value?.resetFields(); dataFormRef.value?.resetFields();
});
// 获取PurchasingBusinessDept信息
if (id) { if (id) {
form.id = id; // 编辑时,先获取详情数据
getPurchasingBusinessDeptData(id); loading.value = true;
getObj({ id }).then((res: any) => {
if (res.data && res.data.length > 0) {
const data = res.data[0];
Object.assign(dataForm, {
id: data.id || '',
deptId: data.deptId || '',
deptName: data.deptName || '',
userId: data.userId || '',
username: data.username || '',
name: data.name || '',
remark: data.remark || '',
});
// 设置部门列表用于回显
if (data.deptId) {
deptList.value = [{
deptId: data.deptId,
name: data.deptName,
id: data.deptId,
type: 'dept',
}];
} }
// 设置用户列表用于回显
if (data.userId) {
userList.value = [{
userId: data.userId,
username: data.username,
name: data.name,
id: data.userId,
userName: data.username,
realName: data.name,
type: 'user',
}];
}
}
loading.value = false;
}).catch((err: any) => {
useMessage().error(err.msg || '获取详情失败');
loading.value = false;
});
}
});
}; };
// 提交表单方法 // 提交
const onSubmit = async () => { const onSubmit = async () => {
loading.value = true; // 防止重复提交 // 立即设置 loading防止重复点击
if (loading.value) return;
loading.value = true;
// 表单校验 try {
const valid = await dataFormRef.value.validate().catch(() => {}); const valid = await dataFormRef.value.validate().catch(() => {});
if (!valid) { if (!valid) {
loading.value = false; loading.value = false;
return false; return false;
} }
try { if (dataForm.id) {
// 根据是否有ID判断是新增还是修改 await putObj(dataForm);
form.id ? await putObj(form) : await addObj(form); useMessage().success('编辑成功');
useMessage().success(form.id ? '修改成功' : '添加成功'); } else {
await addObj(dataForm);
useMessage().success('新增成功');
}
visible.value = false; visible.value = false;
emit('refresh'); // 通知父组件刷新列表 emit('refresh');
} catch (err: any) { } catch (err: any) {
useMessage().error(err.msg); useMessage().error(err.msg || (dataForm.id ? '编辑失败' : '新增失败'));
} finally { } finally {
loading.value = false; loading.value = false;
} }
}; };
// ========== 7. 对外暴露 ========== // 暴露变量
// 暴露方法给父组件
defineExpose({ defineExpose({
openDialog openDialog,
}); });
</script> </script>
<style scoped>
</style>

View File

@@ -1,27 +1,68 @@
<template> <template>
<div class="layout-padding"> <div class="modern-page-container">
<div class="layout-padding-auto layout-padding-view"> <div class="page-wrapper">
<!-- 搜索表单卡片 -->
<el-card v-show="showSearch" class="search-card" shadow="never">
<template #header>
<div class="card-header">
<span class="card-title">
<el-icon class="title-icon"><Search /></el-icon>
筛选条件
</span>
</div>
</template>
<el-form :model="state.queryForm" ref="queryRef" :inline="true" @keyup.enter="getDataList" class="search-form">
<el-form-item label="部门名称" prop="deptName">
<el-input
v-model="state.queryForm.deptName"
placeholder="请输入部门名称"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item label="用户工号" prop="username">
<el-input
v-model="state.queryForm.username"
placeholder="请输入用户工号"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item label="姓名" prop="name">
<el-input
v-model="state.queryForm.name"
placeholder="请输入姓名"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="getDataList">查询</el-button>
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<!-- 操作按钮区域 --> <!-- 内容卡片 -->
<el-row> <el-card class="content-card" shadow="never">
<div class="mb8" style="width: 100%"> <template #header>
<div class="card-header">
<span class="card-title">
<el-icon class="title-icon"><Document /></el-icon>
业务分管管理
</span>
<div class="header-actions">
<el-button <el-button
icon="folder-add" icon="FolderAdd"
type="primary" type="primary"
class="ml10"
@click="formDialogRef.openDialog()" @click="formDialogRef.openDialog()"
v-auth="'purchase_purchasingBusinessDept_add'" v-auth="'purchase_purchasingBusinessDept_add'">
>
新增 新增
</el-button> </el-button>
<el-button <el-button
plain plain
icon="upload-filled" icon="UploadFilled"
type="primary" type="primary"
class="ml10" class="ml10"
@click="excelUploadRef.show()" @click="excelUploadRef.show()"
v-auth="'purchase_purchasingBusinessDept_add'" v-auth="'purchase_purchasingBusinessDept_add'">
>
导入 导入
</el-button> </el-button>
<el-button <el-button
@@ -29,101 +70,108 @@
:disabled="multiple" :disabled="multiple"
icon="Delete" icon="Delete"
type="primary" type="primary"
class="ml10"
v-auth="'purchase_purchasingBusinessDept_del'" v-auth="'purchase_purchasingBusinessDept_del'"
@click="handleDelete(selectObjs)" @click="handleDelete(selectObjs)">
>
删除 删除
</el-button> </el-button>
<right-toolbar <right-toolbar
v-model:showSearch="showSearch" v-model:showSearch="showSearch"
:export="'purchase_purchasingBusinessDept_export'" :export="'purchase_purchasingBusinessDept_export'"
@exportExcel="exportExcel" @exportExcel="exportExcel"
class="ml10 mr20" class="ml10"
style="float: right;" @queryTable="getDataList" />
@queryTable="getDataList"
/>
</div> </div>
</el-row> </div>
</template>
<!-- 数据表格区域 --> <!-- 表格 -->
<el-table <el-table
ref="tableRef"
:data="state.dataList" :data="state.dataList"
v-loading="state.loading" v-loading="state.loading"
border stripe
:cell-style="tableStyle.cellStyle" :cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle" :header-cell-style="tableStyle.headerCellStyle"
@selection-change="selectionChangHandle" @selection-change="selectionChangHandle"
@sort-change="sortChangeHandle" @sort-change="sortChangeHandle"
> class="modern-table">
<el-table-column type="selection" width="40" align="center" /> <el-table-column type="selection" width="55" align="center" />
<el-table-column type="index" label="#" width="40" /> <el-table-column type="index" label="序号" width="70" align="center">
<el-table-column <template #header>
prop="remark" <el-icon><List /></el-icon>
label="备注" </template>
show-overflow-tooltip </el-table-column>
/> <el-table-column prop="deptName" label="部门名称" min-width="200" show-overflow-tooltip>
<el-table-column <template #header>
prop="deptId" <el-icon><OfficeBuilding /></el-icon>
label="部门ID" <span style="margin-left: 4px">部门名称</span>
show-overflow-tooltip </template>
/> </el-table-column>
<el-table-column <el-table-column prop="name" label="姓名" min-width="120" show-overflow-tooltip>
prop="deptName" <template #header>
label="部门名称" <el-icon><User /></el-icon>
show-overflow-tooltip <span style="margin-left: 4px">姓名</span>
/> </template>
<el-table-column </el-table-column>
prop="userId" <el-table-column prop="username" label="用户工号" min-width="150" show-overflow-tooltip>
label="分管负责人ID" <template #header>
show-overflow-tooltip <el-icon><UserFilled /></el-icon>
/> <span style="margin-left: 4px">用户工号</span>
<el-table-column </template>
prop="username" </el-table-column>
label="分管负责人工号" <el-table-column prop="remark" label="备注" min-width="300" show-overflow-tooltip>
show-overflow-tooltip <template #header>
/> <el-icon><EditPen /></el-icon>
<el-table-column <span style="margin-left: 4px">备注</span>
prop="name" </template>
label="姓名" </el-table-column>
show-overflow-tooltip <el-table-column prop="createTime" label="创建时间" width="180" show-overflow-tooltip>
/> <template #header>
<el-table-column label="操作" width="150"> <el-icon><Clock /></el-icon>
<span style="margin-left: 4px">创建时间</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="150">
<template #default="scope"> <template #default="scope">
<el-button <el-button
icon="edit-pen" icon="Edit"
text link
type="primary" type="primary"
v-auth="'purchase_purchasingBusinessDept_edit'" v-auth="'purchase_purchasingBusinessDept_edit'"
@click="formDialogRef.openDialog(scope.row.id)" @click="formDialogRef.openDialog(scope.row.id)">
>
编辑 编辑
</el-button> </el-button>
<el-button <el-button
icon="delete" icon="Delete"
text link
type="primary" type="danger"
v-auth="'purchase_purchasingBusinessDept_del'" v-auth="'purchase_purchasingBusinessDept_del'"
@click="handleDelete([scope.row.id])" @click="handleDelete([scope.row.id])">
>
删除 删除
</el-button> </el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<!-- 分页组件 --> <!-- 分页 -->
<pagination <pagination
v-if="state.pagination"
v-show="state.pagination.total && state.pagination.total > 0"
:total="state.pagination.total"
:current="state.pagination.current"
:size="state.pagination.size"
@size-change="sizeChangeHandle" @size-change="sizeChangeHandle"
@current-change="currentChangeHandle" @current-change="currentChangeHandle"
v-bind="state.pagination"
/> />
</el-card>
</div> </div>
<!-- 编辑新增弹窗 --> <!-- 编辑新增表单对话框 -->
<form-dialog ref="formDialogRef" @refresh="getDataList(false)" /> <form-dialog ref="formDialogRef" @refresh="getDataList" />
<!-- 导入excel弹窗 (需要在 upms-biz/resources/file 下维护模板) --> <!-- 导入excel弹窗 -->
<upload-excel <uploadExcel
ref="excelUploadRef" ref="excelUploadRef"
title="导入" title="导入"
url="/purchase/purchasingBusinessDept/import" url="/purchase/purchasingBusinessDept/import"
@@ -133,37 +181,41 @@
</div> </div>
</template> </template>
<script setup lang="ts" name="systemPurchasingBusinessDept"> <script setup lang="ts" name="PurchasingBusinessDept">
// ========== 导入声明 ========== import { ref, reactive, defineAsyncComponent } from 'vue'
import { BasicTableProps, useTable } from "/@/hooks/table"; import { BasicTableProps, useTable } from "/@/hooks/table";
import { fetchList, delObjs } from "/@/api/purchase/purchasingBusinessDept"; import { fetchList, delObjs } from "/@/api/purchase/purchasingBusinessDept";
import { useMessage, useMessageBox } from "/@/hooks/message"; import { useMessage, useMessageBox } from "/@/hooks/message";
import { useDict } from '/@/hooks/dict'; import { List, Document, User, UserFilled, EditPen, Clock, Search, OfficeBuilding } from '@element-plus/icons-vue'
// ========== 组件声明 ========== // 引入组件
// 异步加载表单弹窗组件
const FormDialog = defineAsyncComponent(() => import('./form.vue')); const FormDialog = defineAsyncComponent(() => import('./form.vue'));
// ========== 字典数据 ========== // 定义变量内容
const tableRef = ref()
const formDialogRef = ref()
const excelUploadRef = ref()
const queryRef = ref()
const showSearch = ref(true)
const selectObjs = ref([]) as any
const multiple = ref(true)
// ========== 组件引用 ========== /**
const formDialogRef = ref(); // 表单弹窗引用 * 定义响应式表格数据
const excelUploadRef = ref(); // Excel上传弹窗引用 */
const queryRef = ref(); // 查询表单引用
// ========== 响应式数据 ==========
const showSearch = ref(true); // 是否显示搜索区域
const selectObjs = ref([]) as any; // 表格多选数据
const multiple = ref(true); // 是否多选
// ========== 表格状态 ==========
const state: BasicTableProps = reactive<BasicTableProps>({ const state: BasicTableProps = reactive<BasicTableProps>({
queryForm: {}, // 查询参数 pageList: fetchList,
pageList: fetchList // 分页查询方法 queryForm: {
deptName: '',
username: '',
name: '',
},
createdIsNeed: true
}); });
// ========== Hook引用 ========== /**
// 表格相关Hook * 使用 useTable 定义表格相关操作
*/
const { const {
getDataList, getDataList,
currentChangeHandle, currentChangeHandle,
@@ -173,16 +225,13 @@ const {
tableStyle tableStyle
} = useTable(state); } = useTable(state);
// ========== 方法定义 ==========
/** /**
* 重置查询条件 * 重置搜索表单
*/ */
const resetQuery = () => { const resetQuery = () => {
// 清空搜索条件
queryRef.value?.resetFields(); queryRef.value?.resetFields();
// 清空多选
selectObjs.value = []; selectObjs.value = [];
// 重新查询 multiple.value = true;
getDataList(); getDataList();
}; };
@@ -192,7 +241,7 @@ const resetQuery = () => {
const exportExcel = () => { const exportExcel = () => {
downBlobFile( downBlobFile(
'/purchase/purchasingBusinessDept/export', '/purchase/purchasingBusinessDept/export',
Object.assign(state.queryForm, { ids: selectObjs }), Object.assign(state.queryForm, { ids: selectObjs.value }),
'purchasingBusinessDept.xlsx' 'purchasingBusinessDept.xlsx'
); );
}; };
@@ -207,22 +256,26 @@ const selectionChangHandle = (objs: { id: string }[]) => {
}; };
/** /**
* 删除数据处理 * 删除当前行
* @param ids 要删除的数据ID数组 * @param ids - 要删除的ID数组
*/ */
const handleDelete = async (ids: string[]) => { const handleDelete = async (ids: string[]) => {
try { try {
await useMessageBox().confirm('此操作将永久删除'); await useMessageBox().confirm('确定要删除该记录吗?');
} catch { } catch {
return; return;
} }
try { try {
await delObjs(ids); await delObjs(ids);
getDataList();
useMessage().success('删除成功'); useMessage().success('删除成功');
getDataList();
} catch (err: any) { } catch (err: any) {
useMessage().error(err.msg); useMessage().error(err.msg || '删除失败');
} }
}; };
</script> </script>
<style scoped lang="scss">
@import '/@/assets/styles/modern-page.scss';
</style>

View File

@@ -0,0 +1,181 @@
<template>
<el-dialog
:title="dataForm.id ? '编辑' : '新增'"
v-model="visible"
width="600px"
:close-on-click-modal="false"
draggable>
<el-form
ref="formRef"
:model="dataForm"
:rules="dataRules"
label-width="100px"
v-loading="loading">
<el-form-item label="用户" prop="userId">
<org-selector
v-model:orgList="userList"
type="user"
:multiple="false"
@update:orgList="handleUserChange" />
</el-form-item>
<el-form-item label="姓名" prop="name">
<el-input
v-model="dataForm.name"
placeholder="请选择用户后自动填充"
readonly />
</el-form-item>
<el-form-item label="用户工号" prop="username">
<el-input
v-model="dataForm.username"
placeholder="请选择用户后自动填充"
readonly />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input
v-model="dataForm.remark"
type="textarea"
:rows="3"
placeholder="请输入备注"
clearable />
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="visible = false"> </el-button>
<el-button type="primary" @click="onSubmit" :disabled="loading"> </el-button>
</span>
</template>
</el-dialog>
</template>
<script setup lang="ts" name="PurchasingSchoolLeaderForm">
import { reactive, ref, nextTick } from 'vue'
import { getObj, addObj, editObj } from '/@/api/finance/purchasingschoolleader';
import { useMessage } from '/@/hooks/message';
import orgSelector from '/@/components/OrgSelector/index.vue';
// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh']);
// 定义变量内容
const formRef = ref();
const userList = ref<any[]>([]);
const dataForm = reactive({
id: '',
userId: '',
username: '',
name: '',
remark: '',
});
const visible = ref(false);
const loading = ref(false);
const dataRules = ref({
userId: [
{ required: true, message: '请选择用户', trigger: 'change' }
],
name: [
{ required: true, message: '姓名不能为空', trigger: 'blur' }
],
username: [
{ required: true, message: '用户工号不能为空', trigger: 'blur' }
],
});
// 处理用户选择变化
const handleUserChange = (list: any[]) => {
if (list && list.length > 0) {
const user = list[0];
dataForm.userId = user.userId || user.id || '';
dataForm.username = user.username || user.userName || '';
dataForm.name = user.name || user.realName || '';
} else {
dataForm.userId = '';
dataForm.username = '';
dataForm.name = '';
}
};
// 打开弹窗
const openDialog = async (type: string, rowData?: any) => {
visible.value = true;
dataForm.id = '';
dataForm.userId = '';
dataForm.username = '';
dataForm.name = '';
dataForm.remark = '';
userList.value = [];
nextTick(() => {
formRef.value?.resetFields();
if (type === 'edit' && rowData?.id) {
// 编辑时,先获取详情数据
loading.value = true;
getObj(rowData.id).then((res: any) => {
if (res.data) {
Object.assign(dataForm, {
id: res.data.id || '',
userId: res.data.userId || '',
username: res.data.username || '',
name: res.data.name || '',
remark: res.data.remark || '',
});
// 设置用户列表用于回显
if (res.data.userId) {
userList.value = [{
userId: res.data.userId,
username: res.data.username,
name: res.data.name,
id: res.data.userId,
userName: res.data.username,
realName: res.data.name,
}];
}
}
loading.value = false;
}).catch((err: any) => {
useMessage().error(err.msg || '获取详情失败');
loading.value = false;
});
}
});
};
// 提交
const onSubmit = async () => {
// 立即设置 loading防止重复点击
if (loading.value) return;
loading.value = true;
try {
const valid = await formRef.value.validate().catch(() => {});
if (!valid) {
loading.value = false;
return false;
}
if (dataForm.id) {
await editObj(dataForm);
useMessage().success('编辑成功');
} else {
await addObj(dataForm);
useMessage().success('新增成功');
}
visible.value = false;
emit('refresh');
} catch (err: any) {
useMessage().error(err.msg || (dataForm.id ? '编辑失败' : '新增失败'));
} finally {
loading.value = false;
}
};
// 暴露变量
defineExpose({
openDialog,
});
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,197 @@
<template>
<div class="modern-page-container">
<div class="page-wrapper">
<!-- 搜索表单卡片 -->
<el-card v-show="showSearch" class="search-card" shadow="never">
<template #header>
<div class="card-header">
<span class="card-title">
<el-icon class="title-icon"><Search /></el-icon>
筛选条件
</span>
</div>
</template>
<el-form :model="state.queryForm" ref="searchFormRef" :inline="true" @keyup.enter="getDataList" class="search-form">
<el-form-item label="姓名" prop="name">
<el-input
v-model="state.queryForm.name"
placeholder="请输入姓名"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item label="用户工号" prop="username">
<el-input
v-model="state.queryForm.username"
placeholder="请输入用户工号"
clearable
style="width: 200px" />
</el-form-item>
<el-form-item>
<el-button type="primary" icon="Search" @click="getDataList">查询</el-button>
<el-button icon="Refresh" @click="handleReset">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<!-- 内容卡片 -->
<el-card class="content-card" shadow="never">
<template #header>
<div class="card-header">
<span class="card-title">
<el-icon class="title-icon"><User /></el-icon>
校领导党委管理
</span>
<div class="header-actions">
<el-button
icon="FolderAdd"
type="primary"
@click="formDialogRef.openDialog('add')">
新增
</el-button>
<right-toolbar v-model:showSearch="showSearch" class="ml10" @queryTable="getDataList" />
</div>
</div>
</template>
<!-- 表格 -->
<el-table
ref="tableRef"
:data="state.dataList"
v-loading="state.loading"
stripe
:cell-style="tableStyle.cellStyle"
:header-cell-style="tableStyle.headerCellStyle"
class="modern-table">
<el-table-column type="index" label="序号" width="70" align="center">
<template #header>
<el-icon><List /></el-icon>
</template>
</el-table-column>
<el-table-column prop="name" label="姓名" min-width="120" show-overflow-tooltip>
<template #header>
<el-icon><User /></el-icon>
<span style="margin-left: 4px">姓名</span>
</template>
</el-table-column>
<el-table-column prop="username" label="用户工号" min-width="150" show-overflow-tooltip>
<template #header>
<el-icon><UserFilled /></el-icon>
<span style="margin-left: 4px">用户工号</span>
</template>
</el-table-column>
<el-table-column prop="remark" label="备注" min-width="300" show-overflow-tooltip>
<template #header>
<el-icon><EditPen /></el-icon>
<span style="margin-left: 4px">备注</span>
</template>
</el-table-column>
<el-table-column prop="createTime" label="创建时间" width="180" show-overflow-tooltip>
<template #header>
<el-icon><Clock /></el-icon>
<span style="margin-left: 4px">创建时间</span>
</template>
</el-table-column>
<el-table-column label="操作" align="center" fixed="right" width="150">
<template #default="scope">
<el-button
icon="Edit"
link
type="primary"
@click="formDialogRef.openDialog('edit', scope.row)">
编辑
</el-button>
<el-button
icon="Delete"
link
type="danger"
@click="handleDelete(scope.row)">
删除
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<pagination
v-if="state.pagination"
v-show="state.pagination.total && state.pagination.total > 0"
:total="state.pagination.total"
:current="state.pagination.current"
:size="state.pagination.size"
@size-change="sizeChangeHandle"
@current-change="currentChangeHandle"
/>
</el-card>
</div>
<!-- 编辑新增表单对话框 -->
<FormDialog ref="formDialogRef" @refresh="getDataList" />
</div>
</template>
<script setup lang="ts" name="PurchasingSchoolLeader">
import { ref, reactive, defineAsyncComponent } from 'vue'
import { BasicTableProps, useTable } from "/@/hooks/table";
import { getPage, delObj } from "/@/api/finance/purchasingschoolleader";
import { useMessage, useMessageBox } from "/@/hooks/message";
import { List, User, UserFilled, EditPen, Clock, Search } from '@element-plus/icons-vue'
// 引入组件
const FormDialog = defineAsyncComponent(() => import('./form.vue'));
// 定义变量内容
const tableRef = ref()
const formDialogRef = ref()
const searchFormRef = ref()
const showSearch = ref(true)
/**
* 定义响应式表格数据
*/
const state: BasicTableProps = reactive<BasicTableProps>({
pageList: getPage,
queryForm: {
name: '',
username: '',
},
createdIsNeed: true
});
/**
* 使用 useTable 定义表格相关操作
*/
const { getDataList, tableStyle, sizeChangeHandle, currentChangeHandle } = useTable(state);
/**
* 重置搜索表单
*/
const handleReset = () => {
searchFormRef.value?.resetFields();
getDataList();
};
/**
* 删除当前行
* @param row - 当前行数据
*/
const handleDelete = async (row: any) => {
try {
await useMessageBox().confirm('确定要删除该记录吗?');
} catch {
return;
}
try {
await delObj([row.id]);
useMessage().success('删除成功');
getDataList();
} catch (err: any) {
useMessage().error(err.msg || '删除失败');
}
};
</script>
<style scoped lang="scss">
@import '/@/assets/styles/modern-page.scss';
</style>