number.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <template>
  2. <div class="sys-workforce-number-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:number: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:number: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="primary" @click="onEdit(row)" title="编辑班次" v-auth="'system:workforce:number:edit'"> 编辑 </el-button>
  43. <el-button link type="danger" @click="onDelete(row)" title="查看日志明细" v-auth="'system:workforce:number:delete'"> 删除 </el-button>
  44. </template>
  45. </ProTable>
  46. </el-card>
  47. <!-- 新增修改班次 -->
  48. <number-edit ref="numberEditRef" @updateList="queryList" />
  49. </div>
  50. </template>
  51. <script lang="tsx" setup name="systemWorkforceNumber">
  52. import { defineAsyncComponent, onMounted, reactive, ref } from 'vue';
  53. import type { FormInstance } from 'element-plus';
  54. import { ElMessage, ElMessageBox } from 'element-plus';
  55. import { formatDate } from '@/utils/formatTime';
  56. import { getWorkforceClassList, deleteWorkforceClass } from '@/api/system/workforce';
  57. // 引入组件
  58. const NumberEdit = defineAsyncComponent(() => import('@/views/system/workforce/components/Number-edit.vue')); // 新增修改班次
  59. const proTableRef = ref<RefType>(); // 表格ref
  60. // 表格配置项
  61. const columns = ref<any[]>([
  62. { type: 'selection', fixed: 'left', width: 55 },
  63. { prop: 'name', label: '班次名称' },
  64. {
  65. prop: 'workingTime',
  66. label: '上班时间',
  67. width: 200,
  68. },
  69. {
  70. prop: 'offDutyTime',
  71. label: '下班时间',
  72. width: 200,
  73. },
  74. {
  75. prop: 'creationTime',
  76. label: '创建时间',
  77. width: 170,
  78. render: (scope: any) => {
  79. return <span>{formatDate(scope.row.creationTime, 'YYYY-mm-dd HH:MM:SS')}</span>;
  80. },
  81. },
  82. { prop: 'operation', label: '操作', fixed: 'right', width: 160, align: 'center' },
  83. ]);
  84. // 定义变量内容
  85. const state = reactive({
  86. queryParams: {
  87. PageIndex: 1, // 当前页
  88. PageSize: 10, // 每页条数
  89. Keyword: null, // 关键字
  90. },
  91. tableData: [], // 列表数据
  92. loading: false, // 加载
  93. total: 0, // 总条数
  94. });
  95. const ruleFormRef = ref<FormInstance>(); // 表单ref
  96. /** 搜索按钮操作 */
  97. const handleQuery = () => {
  98. state.queryParams.PageIndex = 1;
  99. queryList();
  100. };
  101. /** 班次列表 */
  102. const queryList = async () => {
  103. state.loading = true;
  104. try {
  105. const response = await getWorkforceClassList(state.queryParams);
  106. state.tableData = response.result?.items ?? [];
  107. state.total = response.result?.total ?? 0;
  108. state.loading = false;
  109. } catch (e) {
  110. state.loading = false;
  111. console.log(e);
  112. }
  113. };
  114. /** 重置按钮操作 */
  115. const resetQuery = (formEl: FormInstance | undefined) => {
  116. if (!formEl) return;
  117. formEl.resetFields();
  118. queryList();
  119. };
  120. // 新增班次
  121. const numberEditRef = ref<RefType>();
  122. const onAdd = () => {
  123. numberEditRef.value.openDialog();
  124. };
  125. // 编辑班次
  126. const onEdit = (row: any) => {
  127. numberEditRef.value.openDialog(row.id);
  128. };
  129. // 删除班次
  130. const onDelete = (row: any) => {
  131. ElMessageBox.confirm(`确定删除【${row.name}】该班次?若当前班次已排班,删除后该班次将替换为休息日!是否确定删除?`, '提示', {
  132. confirmButtonText: '确定',
  133. cancelButtonText: '取消',
  134. type: 'warning',
  135. draggable: true,
  136. })
  137. .then(() => {
  138. deleteWorkforceClass({ ids: [row.id] }).then(() => {
  139. queryList();
  140. ElMessage.success('删除成功');
  141. });
  142. })
  143. .catch(() => {
  144. console.log('取消删除');
  145. });
  146. };
  147. // 批量删除班次
  148. const onDeleteMultiple = () => {
  149. const ids = proTableRef.value.selectedList.map((item: any) => item.id);
  150. ElMessageBox.confirm(
  151. `确定删除选中的${proTableRef.value.selectedList.length}个班次?若当前班次已排班,删除后该班次将替换为休息日!是否确定删除?`,
  152. '提示',
  153. {
  154. confirmButtonText: '确定',
  155. cancelButtonText: '取消',
  156. type: 'warning',
  157. draggable: true,
  158. }
  159. )
  160. .then(() => {
  161. deleteWorkforceClass({ ids }).then(() => {
  162. queryList();
  163. ElMessage.success('删除成功');
  164. });
  165. })
  166. .catch(() => {
  167. console.log('取消删除');
  168. });
  169. };
  170. onMounted(() => {
  171. queryList();
  172. });
  173. </script>