index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div class="p-2">
  3. <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
  4. <div v-show="showSearch" class="mb-[10px]">
  5. <el-card shadow="hover">
  6. <el-form ref="queryFormRef" :model="queryParams" :inline="true">
  7. <el-form-item label="姓名" prop="staffName">
  8. <el-input v-model="queryParams.staffName" placeholder="请输入姓名" clearable @keyup.enter="handleQuery" />
  9. </el-form-item>
  10. <el-form-item label="所属部门" prop="deptId">
  11. <el-tree-select
  12. v-model="queryParams.deptId"
  13. :data="deptList"
  14. node-key="deptId"
  15. :props="{ value: 'deptId', label: 'deptName', children: 'children' }"
  16. placeholder="请选择部门"
  17. clearable
  18. />
  19. </el-form-item>
  20. <el-form-item label="所属岗位" prop="postId">
  21. <el-select v-model="queryParams.postId" placeholder="请选择岗位" clearable>
  22. <el-option v-for="post in postList" :key="post.postId" :label="post.postName" :value="post.postId" />
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  27. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </el-card>
  31. </div>
  32. </transition>
  33. <el-card shadow="never">
  34. <template #header>
  35. <el-row :gutter="10" class="mb8">
  36. <el-col :span="20"><span>岗位设定信息列表</span> </el-col>
  37. <el-col :span="1.5">
  38. <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['system:comStaff:add']">新增</el-button>
  39. </el-col>
  40. </el-row>
  41. </template>
  42. <el-table v-loading="loading" border :data="comStaffList" @selection-change="handleSelectionChange">
  43. <el-table-column type="selection" width="55" align="center" />
  44. <el-table-column label="人员编码" align="center" prop="staffCode" />
  45. <el-table-column label="姓名" align="center" prop="staffName" />
  46. <el-table-column label="性别" align="center" prop="sex">
  47. <template #default="scope">
  48. <dict-tag :options="sys_user_sex" :value="scope.row.sex" />
  49. </template>
  50. </el-table-column>
  51. <!-- <el-table-column label="部门编码" align="center" prop="deptCode" /> -->
  52. <el-table-column label="部门名称" align="center" prop="deptName" />
  53. <el-table-column label="手机号" align="center" prop="phone" />
  54. <el-table-column label="岗位" align="center" prop="postName" />
  55. <el-table-column label="是否显示" align="center" prop="status">
  56. <template #default="scope">
  57. <el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
  58. </template>
  59. </el-table-column>
  60. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  61. <template #default="scope">
  62. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:comStaff:edit']">编辑</el-button>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
  67. </el-card>
  68. <!-- 添加或修改人员信息对话框 -->
  69. <el-dialog :title="dialog.title" v-model="dialog.visible" width="700px" append-to-body>
  70. <el-form ref="comStaffFormRef" :model="form" :rules="rules" label-width="100px">
  71. <el-row :gutter="20">
  72. <el-col :span="12">
  73. <el-form-item label="人员编码" prop="staffCode">
  74. <el-input v-model="form.staffCode" placeholder="请输入人员编码" :disabled="!!form.staffId" />
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="12">
  78. <el-form-item label="姓名" prop="staffName">
  79. <el-input v-model="form.staffName" placeholder="请输入姓名" />
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <el-row :gutter="20">
  84. <el-col :span="12">
  85. <el-form-item label="所属部门" prop="deptId">
  86. <el-tree-select
  87. v-model="form.deptId"
  88. :data="deptList"
  89. node-key="deptId"
  90. :props="{ value: 'deptId', label: 'deptName', children: 'children' }"
  91. placeholder="请选择部门"
  92. />
  93. </el-form-item>
  94. </el-col>
  95. <el-col :span="12">
  96. <el-form-item label="岗位" prop="postId">
  97. <el-select v-model="form.postId" placeholder="请选择岗位">
  98. <el-option v-for="post in postList" :key="post.postId" :label="post.postName" :value="post.postId" />
  99. </el-select>
  100. </el-form-item>
  101. </el-col>
  102. </el-row>
  103. <el-row :gutter="20">
  104. <el-col :span="12">
  105. <el-form-item label="手机号" prop="phone">
  106. <el-input v-model="form.phone" placeholder="请输入联系电话" />
  107. </el-form-item>
  108. </el-col>
  109. <el-col :span="12">
  110. <el-form-item label="性别" prop="sex">
  111. <el-radio-group v-model="form.sex">
  112. <el-radio v-for="dict in sys_user_sex" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
  113. </el-radio-group>
  114. </el-form-item>
  115. </el-col>
  116. </el-row>
  117. <el-row :gutter="20">
  118. <el-col :span="12">
  119. <el-form-item label="是否启用" prop="status">
  120. <el-radio-group v-model="form.status">
  121. <el-radio v-for="dict in sys_platform_yes_no" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
  122. </el-radio-group>
  123. </el-form-item>
  124. </el-col>
  125. </el-row>
  126. </el-form>
  127. <template #footer>
  128. <div class="dialog-footer">
  129. <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
  130. <el-button @click="cancel">取 消</el-button>
  131. </div>
  132. </template>
  133. </el-dialog>
  134. </div>
  135. </template>
  136. <script setup name="ComStaff" lang="ts">
  137. import { listComStaff, getComStaff, delComStaff, addComStaff, updateComStaff, changeStatus } from '@/api/company/comStaff';
  138. import { ComStaffVO, ComStaffQuery, ComStaffForm } from '@/api/company/comStaff/types';
  139. import { listDept, getDept, listDeptExcludeChild } from '@/api/system/dept';
  140. import { DeptVO } from '@/api/system/dept/types';
  141. import { listPost, getPost, deptTreeSelect } from '@/api/system/post';
  142. import { PostVO } from '@/api/system/post/types';
  143. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  144. const { sys_platform_yes_no, sys_user_sex } = toRefs<any>(proxy?.useDict('sys_platform_yes_no', 'sys_user_sex'));
  145. const comStaffList = ref<ComStaffVO[]>([]);
  146. const buttonLoading = ref(false);
  147. const loading = ref(true);
  148. const showSearch = ref(true);
  149. const ids = ref<Array<string | number>>([]);
  150. const single = ref(true);
  151. const multiple = ref(true);
  152. const total = ref(0);
  153. const deptList = ref<DeptVO[]>([]);
  154. const postList = ref<PostVO[]>([]);
  155. const queryFormRef = ref<ElFormInstance>();
  156. const comStaffFormRef = ref<ElFormInstance>();
  157. const dialog = reactive<DialogOption>({
  158. visible: false,
  159. title: ''
  160. });
  161. const initFormData: ComStaffForm = {
  162. staffId: undefined,
  163. staffCode: undefined,
  164. staffName: undefined,
  165. deptId: undefined,
  166. phone: undefined,
  167. postId: undefined,
  168. sex: '1',
  169. roleId: undefined,
  170. dataSource: undefined,
  171. password: undefined,
  172. validFrom: undefined,
  173. validTo: undefined,
  174. status: '0',
  175. remark: undefined
  176. };
  177. const data = reactive<PageData<ComStaffForm, ComStaffQuery>>({
  178. form: { ...initFormData },
  179. queryParams: {
  180. pageNum: 1,
  181. pageSize: 10,
  182. staffCode: undefined,
  183. staffName: undefined,
  184. deptId: undefined,
  185. phone: undefined,
  186. postId: undefined,
  187. sex: undefined,
  188. roleId: undefined,
  189. dataSource: undefined,
  190. password: undefined,
  191. validFrom: undefined,
  192. validTo: undefined,
  193. status: undefined,
  194. platformCode: undefined,
  195. params: {}
  196. },
  197. rules: {
  198. staffName: [{ required: true, message: '姓名不能为空', trigger: 'blur' }]
  199. }
  200. });
  201. const { queryParams, form, rules } = toRefs(data);
  202. /** 获取部门列表(树结构) */
  203. const getDeptList = async () => {
  204. const res = await listDept();
  205. const data = proxy?.handleTree<DeptVO>(res.data, 'deptId');
  206. if (data) {
  207. deptList.value = data;
  208. }
  209. loading.value = false;
  210. };
  211. /** 获取岗位列表 */
  212. const getPostList = async (deptId?: number | string) => {
  213. try {
  214. const res = await listPost({ belongDeptId: deptId });
  215. postList.value = res.rows || [];
  216. } catch (error) {
  217. console.error('获取岗位列表失败', error);
  218. }
  219. };
  220. /** 监听部门选择变化,更新岗位列表 */
  221. watch(
  222. () => queryParams.value.deptId,
  223. (newDeptId) => {
  224. // 清空岗位选择
  225. queryParams.value.postId = undefined;
  226. // 根据部门获取岗位列表
  227. if (newDeptId) {
  228. getPostList(newDeptId);
  229. } else {
  230. getPostList();
  231. }
  232. }
  233. );
  234. /** 监听对话框中部门选择变化,更新岗位列表 */
  235. watch(
  236. () => form.value.deptId,
  237. (newDeptId) => {
  238. // 清空岗位选择
  239. form.value.postId = undefined;
  240. // 根据部门获取岗位列表
  241. if (newDeptId) {
  242. getPostList(newDeptId);
  243. } else {
  244. getPostList();
  245. }
  246. }
  247. );
  248. /** 查询人员信息列表 */
  249. const getList = async () => {
  250. loading.value = true;
  251. const res = await listComStaff(queryParams.value);
  252. comStaffList.value = res.rows;
  253. total.value = res.total;
  254. loading.value = false;
  255. };
  256. /** 取消按钮 */
  257. const cancel = () => {
  258. reset();
  259. dialog.visible = false;
  260. };
  261. /** 表单重置 */
  262. const reset = () => {
  263. form.value = { ...initFormData };
  264. comStaffFormRef.value?.resetFields();
  265. };
  266. /** 搜索按钮操作 */
  267. const handleQuery = () => {
  268. queryParams.value.pageNum = 1;
  269. getList();
  270. };
  271. /** 重置按钮操作 */
  272. const resetQuery = () => {
  273. queryFormRef.value?.resetFields();
  274. handleQuery();
  275. };
  276. const handleStatusChange = async (row: ComStaffVO) => {
  277. const oldValue = row.status; // 保存旧值(0 或 1)
  278. try {
  279. await changeStatus(row.postId, row.status); // 传新值
  280. proxy?.$modal.msgSuccess('操作成功');
  281. } catch {
  282. row.status = oldValue; // 失败回滚
  283. proxy?.$modal.msgError('操作失败,请重试');
  284. }
  285. };
  286. /** 多选框选中数据 */
  287. const handleSelectionChange = (selection: ComStaffVO[]) => {
  288. ids.value = selection.map((item) => item.staffId);
  289. single.value = selection.length != 1;
  290. multiple.value = !selection.length;
  291. };
  292. /** 新增按钮操作 */
  293. const handleAdd = () => {
  294. reset();
  295. dialog.visible = true;
  296. dialog.title = '添加人员信息';
  297. };
  298. /** 修改按钮操作 */
  299. const handleUpdate = async (row?: ComStaffVO) => {
  300. reset();
  301. const _staffId = row?.staffId || ids.value[0];
  302. const res = await getComStaff(_staffId);
  303. Object.assign(form.value, res.data);
  304. dialog.visible = true;
  305. dialog.title = '修改人员信息';
  306. };
  307. /** 提交按钮 */
  308. const submitForm = () => {
  309. comStaffFormRef.value?.validate(async (valid: boolean) => {
  310. if (valid) {
  311. buttonLoading.value = true;
  312. if (form.value.staffId) {
  313. await updateComStaff(form.value).finally(() => (buttonLoading.value = false));
  314. } else {
  315. await addComStaff(form.value).finally(() => (buttonLoading.value = false));
  316. }
  317. proxy?.$modal.msgSuccess('操作成功');
  318. dialog.visible = false;
  319. await getList();
  320. }
  321. });
  322. };
  323. /** 删除按钮操作 */
  324. const handleDelete = async (row?: ComStaffVO) => {
  325. const _staffIds = row?.staffId || ids.value;
  326. await proxy?.$modal.confirm('是否确认删除人员信息编号为"' + _staffIds + '"的数据项?').finally(() => (loading.value = false));
  327. await delComStaff(_staffIds);
  328. proxy?.$modal.msgSuccess('删除成功');
  329. await getList();
  330. };
  331. /** 导出按钮操作 */
  332. const handleExport = () => {
  333. proxy?.download(
  334. 'system/comStaff/export',
  335. {
  336. ...queryParams.value
  337. },
  338. `comStaff_${new Date().getTime()}.xlsx`
  339. );
  340. };
  341. onMounted(() => {
  342. getDeptList();
  343. getPostList();
  344. getList();
  345. });
  346. </script>