staff.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <div class="sys-workforce-staff-container layout-pd">
  3. <el-card shadow="never">
  4. <el-form :model="state.queryParams" ref="ruleFormRef" inline @submit.native.prevent>
  5. <el-form-item label="关键词" prop="Keyword">
  6. <el-input v-model="state.queryParams.Keyword" placeholder="姓名" clearable @keyup.enter="handleQuery" class="keyword-input" />
  7. </el-form-item>
  8. <el-form-item>
  9. <el-button type="primary" @click="handleQuery" :loading="state.loading"> <SvgIcon name="ele-Search" class="mr5" />查询 </el-button>
  10. <el-button @click="resetQuery(ruleFormRef)" class="default-button" :loading="state.loading">
  11. <SvgIcon name="ele-Refresh" class="mr5" />重置
  12. </el-button>
  13. </el-form-item>
  14. </el-form>
  15. </el-card>
  16. <el-card shadow="never">
  17. <ProTable
  18. ref="proTableRef"
  19. :columns="columns"
  20. :data="state.tableData"
  21. @updateTable="queryList"
  22. :loading="state.loading"
  23. :total="state.total"
  24. v-model:page-index="state.queryParams.PageIndex"
  25. v-model:page-size="state.queryParams.PageSize"
  26. >
  27. <template #tableHeader="scope">
  28. <el-button type="primary" @click="onAdd" v-auth="'system:workforce:staff:add'" :loading="state.loading"
  29. ><SvgIcon name="ele-Plus" class="mr5" />选择人员
  30. </el-button>
  31. <el-button
  32. type="danger"
  33. @click="onDeleteMultiple"
  34. v-auth="'system:workforce:staff:deleteMultiple'"
  35. :disabled="!scope.isSelected"
  36. :loading="state.loading"
  37. ><SvgIcon name="ele-Delete" class="mr5" />删除
  38. </el-button>
  39. </template>
  40. <!-- 表格操作 -->
  41. <template #operation="{ row }">
  42. <el-button link type="danger" @click="onDelete(row)" title="删除人员" v-auth="'system:workforce:staff:delete'"> 删除 </el-button>
  43. </template>
  44. </ProTable>
  45. </el-card>
  46. <!-- 选择用户 -->
  47. <select-user ref="selectUserRef" @updateList="queryList" />
  48. </div>
  49. </template>
  50. <script lang="tsx" setup name="systemWorkforceStaff">
  51. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  52. import type { FormInstance } from 'element-plus';
  53. import { ElMessage, ElMessageBox } from 'element-plus';
  54. import { formatDate } from '@/utils/formatTime';
  55. import { deleteWorkforce, getWorkforceList } from '@/api/system/workforce';
  56. // 引入组件
  57. const SelectUser = defineAsyncComponent(() => import('@/views/system/workforce/components/Select-user.vue')); // 选择用户
  58. const proTableRef = ref<RefType>(); // 表格ref
  59. // 表格配置项
  60. const columns = ref<any[]>([
  61. { type: 'selection', fixed: 'left', width: 55 },
  62. { prop: 'userName', label: '姓名' },
  63. {
  64. prop: 'creationTime',
  65. label: '创建时间',
  66. width: 170,
  67. render: (scope: any) => {
  68. return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  69. },
  70. },
  71. { prop: 'operation', label: '操作', fixed: 'right', width: 100, align: 'center' },
  72. ]);
  73. // 定义变量内容
  74. const state = reactive({
  75. queryParams: {
  76. PageIndex: 1, // 当前页
  77. PageSize: 10, // 每页条数
  78. Keyword: null, // 关键字
  79. },
  80. tableData: [], // 列表数据
  81. loading: false, // 加载
  82. total: 0, // 总条数
  83. });
  84. const ruleFormRef = ref<FormInstance>(); // 表单ref
  85. /** 搜索按钮操作 */
  86. const handleQuery = () => {
  87. state.queryParams.PageIndex = 1;
  88. queryList();
  89. };
  90. /** 人员列表 */
  91. const queryList = async () => {
  92. state.loading = true;
  93. try {
  94. const response = await getWorkforceList(state.queryParams);
  95. state.tableData = response.result?.items ?? [];
  96. state.total = response.result?.total ?? 0;
  97. state.loading = false;
  98. } catch (e) {
  99. state.loading = false;
  100. console.log(e);
  101. }
  102. };
  103. /** 重置按钮操作 */
  104. const resetQuery = (formEl: FormInstance | undefined) => {
  105. if (!formEl) return;
  106. formEl.resetFields();
  107. queryList();
  108. };
  109. // 选择人员
  110. const selectUserRef = ref<RefType>();
  111. const onAdd = () => {
  112. selectUserRef.value.openDialog();
  113. };
  114. // 删除人员
  115. const onDelete = (row: any) => {
  116. ElMessageBox.confirm(`确定删除【${row.userName}】该人员?`, '提示', {
  117. confirmButtonText: '确定',
  118. cancelButtonText: '取消',
  119. type: 'warning',
  120. draggable: true,
  121. })
  122. .then(() => {
  123. deleteWorkforce({ ids: [row.id] }).then(() => {
  124. queryList();
  125. ElMessage.success('删除成功');
  126. });
  127. })
  128. .catch(() => {
  129. console.log('取消删除');
  130. });
  131. };
  132. const onDeleteMultiple = () => {
  133. const ids = proTableRef.value.selectedList.map((item: any) => item.id);
  134. ElMessageBox.confirm(`确定删除选中的${proTableRef.value.selectedList.length}个人员?`, '提示', {
  135. confirmButtonText: '确定',
  136. cancelButtonText: '取消',
  137. type: 'warning',
  138. draggable: true,
  139. })
  140. .then(() => {
  141. deleteWorkforce({ ids }).then(() => {
  142. queryList();
  143. ElMessage.success('删除成功');
  144. });
  145. })
  146. .catch(() => {
  147. console.log('取消删除');
  148. });
  149. };
  150. onMounted(() => {
  151. queryList();
  152. });
  153. </script>