PageTaskManagement.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <div class="safety-platform-container">
  3. <header class="safety-platform-container__header">
  4. <span class="breadcrumb-title">检查任务管理</span>
  5. </header>
  6. <main class="safety-platform-container__main">
  7. <div class="search-table-container">
  8. <header class="disaster-precaution__header">
  9. <el-button
  10. type="primary"
  11. class="search-table-container--button"
  12. :icon="Plus"
  13. @click="handleCreateTask"
  14. v-if="taskManagementPermissions"
  15. >
  16. 创建检查任务单
  17. </el-button>
  18. <BasicSearch
  19. :searchConfig="TASK_MANAGEMENT_SEARCH_CONFIG"
  20. :searchData="searchData"
  21. @update:searchData="handleSearch"
  22. />
  23. </header>
  24. <div class="batch-table">
  25. <div class="batch-operation--div" v-show="taskManagementPermissions && selectionItems.length > 0">
  26. <span>已选{{ selectionItems.length }}项</span>
  27. <div class="batch-operation--div--close">
  28. <div class="batch-operation--div--button">
  29. <el-button class="custom-el-button" v-show="isBatchPublish" @click="handleBatchPublish"
  30. >批量发布</el-button
  31. >
  32. <el-button class="custom-el-button" v-show="isBatchWithdraw" @click="handleBatchWithdraw"
  33. >批量撤回</el-button
  34. >
  35. <el-button class="custom-el-button" v-show="isBatchDelete" @click="handleBatchDelete"
  36. >批量删除</el-button
  37. >
  38. </div>
  39. <el-icon class="close-icon" @click="handleCloseBatchOperation"><Close /></el-icon>
  40. </div>
  41. </div>
  42. <BasicTable
  43. ref="basicTableRef"
  44. :table-config="tableConfig"
  45. :table-data="tableData"
  46. @update:pageSize="handleSizeChange"
  47. @update:pageNumber="handleCurrentChange"
  48. @update:selection="handleSelectionChange"
  49. >
  50. <template #taskName="scope">
  51. <div class="task-name--div">
  52. <el-tooltip
  53. :content="scope.row.name"
  54. placement="top"
  55. effect="light"
  56. v-if="isToolTip(scope.row.overdue, scope.row.name)"
  57. >
  58. <span>{{ scope.row.name }}</span>
  59. </el-tooltip>
  60. <span v-else>{{ scope.row.name }}</span>
  61. <div class="overdue-icon">
  62. <img :src="OverdueIcon" alt="overdue" v-if="scope.row.overdue" />
  63. </div>
  64. </div>
  65. </template>
  66. <template #inspectType="scope">
  67. <span>{{ INSPECT_TYPE_MAP[scope.row.inspectType] }}</span>
  68. </template>
  69. <template #effectStatus="scope">
  70. <div class="active-status--div">
  71. <div
  72. class="dot"
  73. :style="{ backgroundColor: ACTIVE_STATUS_COLOR[scope.row.effectStatus as ACTIVE_STATUS] }"
  74. ></div>
  75. <span>{{ ACTIVE_STATUS_MAP[scope.row.effectStatus] }}</span>
  76. </div>
  77. </template>
  78. <template #taskStage="scope">
  79. <span>{{ TASK_STAGE_MAP[scope.row.taskState] }}</span>
  80. </template>
  81. <template #executive="scope">
  82. <div class="executive-container">
  83. <p v-for="person in scope.row.executive" :key="person.id">
  84. {{ person.realname }}({{person.staffNo}})
  85. </p>
  86. </div>
  87. </template>
  88. <template #action="scope">
  89. <div class="action-container--div">
  90. <ActionButton
  91. text="编辑"
  92. v-if="taskManagementPermissions && scope.row.effectStatus === ACTIVE_STATUS.NOT_EFFECTIVE"
  93. @click="handleEditTask(scope.row.id)"
  94. />
  95. <ActionButton
  96. text="查看"
  97. @click="
  98. handleViewTask(
  99. scope.row.id,
  100. scope.row.name,
  101. scope.row.deptName,
  102. scope.row.taskState,
  103. scope.row.inspectType,
  104. )
  105. "
  106. />
  107. <ActionButton
  108. text="发布"
  109. :popconfirm="{
  110. title: '确定要发布?',
  111. }"
  112. v-if="taskManagementPermissions && scope.row.effectStatus === ACTIVE_STATUS.NOT_EFFECTIVE"
  113. @confirm="handlePublishTask(scope.row.id)"
  114. />
  115. <ActionButton
  116. text="撤回"
  117. :popconfirm="{
  118. title: '确定要撤回?',
  119. }"
  120. v-else-if="
  121. taskManagementPermissions &&
  122. scope.row.taskState !== TASK_STAGE.COMPLETED &&
  123. scope.row.effectStatus === ACTIVE_STATUS.ACTIVE
  124. "
  125. @confirm="handleWithdrawTask(scope.row.id)"
  126. />
  127. <ActionButton
  128. text="删除"
  129. :popconfirm="{
  130. title: '确定要删除?',
  131. }"
  132. v-if="taskManagementPermissions && scope.row.effectStatus === ACTIVE_STATUS.NOT_EFFECTIVE"
  133. @confirm="handleDeleteTask(scope.row.id)"
  134. />
  135. </div>
  136. </template>
  137. </BasicTable>
  138. </div>
  139. </div>
  140. </main>
  141. </div>
  142. </template>
  143. <script setup lang="ts">
  144. import { useRouter } from 'vue-router';
  145. import { ref, onMounted, reactive } from 'vue';
  146. import { Plus, Close } from '@element-plus/icons-vue';
  147. import { ElMessage } from 'element-plus';
  148. import BasicTable from '@/components/BasicTable.vue';
  149. import ActionButton from '@/components/ActionButton.vue';
  150. import BasicSearch from '@/components/BasicSearch.vue';
  151. import useTableConfig from '@/hooks/useTableConfigHook';
  152. import { useUserInfoHook } from '@/views/disaster/hooks';
  153. import { openMessageBox } from '@/utils/element-plus/messageBox';
  154. import { isToolTip } from './src/utils';
  155. import type { TaskManagementListQuery, TaskManagementListResponse } from '@/types/disaster-precaution';
  156. import type { QueryPageRequest } from '@/types/basic-query';
  157. import {
  158. getTaskManagementList,
  159. deleteTaskManagementItem,
  160. withdrawTaskManagementItem,
  161. publishTaskManagementItem,
  162. } from '@/api/disaster-precaution';
  163. import OverdueIcon from '@/assets/svg/overdue.svg';
  164. import { INSPECT_TYPE_MAP, TASK_STAGE_MAP, TASK_STAGE } from './src/constants/task-execution';
  165. import {
  166. ACTIVE_STATUS,
  167. ACTIVE_STATUS_COLOR,
  168. ACTIVE_STATUS_MAP,
  169. DISASTER_PERMISSIONS,
  170. } from '@/views/disaster/constant';
  171. import {
  172. TABLE_OPTIONS_MANAGEMENT,
  173. TASK_MANAGEMENT_TABLE_COLUMNS,
  174. TASK_MANAGEMENT_SEARCH_CONFIG,
  175. TABLE_MANAGEMENT_HEIGHT_DEFAULT,
  176. TABLE_MANAGEMENT_HEIGHT_NOT_PERMISSION,
  177. } from './src/config';
  178. const { permissions } = useUserInfoHook();
  179. const router = useRouter();
  180. const searchData = reactive({
  181. inspectType: null,
  182. effectStatus: null,
  183. taskState: null,
  184. });
  185. const { tableConfig, pagination } = useTableConfig(TASK_MANAGEMENT_TABLE_COLUMNS, TABLE_OPTIONS_MANAGEMENT);
  186. let taskManagementListQuery: QueryPageRequest<TaskManagementListQuery> = {
  187. pageNumber: pagination.pageNumber,
  188. pageSize: pagination.pageSize,
  189. queryParam: {},
  190. };
  191. const handleSearch = () => {
  192. taskManagementListQuery.queryParam = {};
  193. if (searchData.inspectType) {
  194. taskManagementListQuery.queryParam.inspectType = searchData.inspectType;
  195. }
  196. if (searchData.effectStatus) {
  197. taskManagementListQuery.queryParam.effectStatus = searchData.effectStatus;
  198. }
  199. if (searchData.taskState) {
  200. taskManagementListQuery.queryParam.taskState = searchData.taskState;
  201. }
  202. getTableData();
  203. };
  204. const selectionItems = ref<any[]>([]);
  205. const isBatchPublish = ref(false);
  206. const isBatchWithdraw = ref(false);
  207. const isBatchDelete = ref(false);
  208. const getSelectionIds = (option: ACTIVE_STATUS) => {
  209. return selectionItems.value.filter((item) => item.effectStatus === option).map((item) => item.id);
  210. };
  211. const handleSelectionChange = (selection: any[]) => {
  212. selectionItems.value = selection;
  213. const publishIds = getSelectionIds(ACTIVE_STATUS.NOT_EFFECTIVE);
  214. isBatchPublish.value = Boolean(publishIds.length);
  215. const withdrawIds = getSelectionIds(ACTIVE_STATUS.ACTIVE);
  216. isBatchWithdraw.value = Boolean(withdrawIds.length);
  217. isBatchDelete.value = Boolean(selectionItems.value.length === publishIds.length);
  218. };
  219. const handleBatchPublish = async () => {
  220. const confirmed = await openMessageBox('', '确认发布任务吗?', 'warning');
  221. if (!confirmed) return;
  222. const publishIds = getSelectionIds(ACTIVE_STATUS.NOT_EFFECTIVE);
  223. try {
  224. await publishTaskManagementItem(publishIds);
  225. ElMessage.success('批量发布成功');
  226. } finally {
  227. getTableData();
  228. }
  229. };
  230. const handleBatchWithdraw = async () => {
  231. const confirmed = await openMessageBox('', '确认撤回已发布任务吗?', 'warning');
  232. if (!confirmed) return;
  233. const withdrawIds = getSelectionIds(ACTIVE_STATUS.ACTIVE);
  234. try {
  235. await withdrawTaskManagementItem(withdrawIds);
  236. ElMessage.success('批量撤回成功');
  237. } finally {
  238. getTableData();
  239. }
  240. };
  241. const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  242. const handleCloseBatchOperation = () => {
  243. if (!basicTableRef.value) return;
  244. basicTableRef.value.clearSelection();
  245. };
  246. const handleBatchDelete = async () => {
  247. const confirmed = await openMessageBox('', '删除后任务不可恢复,确认删除吗?', 'warning');
  248. if (!confirmed) return;
  249. const deleteIds = getSelectionIds(ACTIVE_STATUS.NOT_EFFECTIVE);
  250. await deleteTaskManagementItem(deleteIds);
  251. ElMessage.success('批量删除成功');
  252. getTableData();
  253. };
  254. const handlePublishTask = async (id: number) => {
  255. await publishTaskManagementItem(id);
  256. getTableData();
  257. ElMessage.success('发布成功');
  258. };
  259. const handleWithdrawTask = async (id: number) => {
  260. await withdrawTaskManagementItem(id);
  261. getTableData();
  262. ElMessage.success('已取消发布');
  263. };
  264. const handleDeleteTask = async (id: number) => {
  265. await deleteTaskManagementItem(id);
  266. getTableData();
  267. ElMessage.success('删除成功');
  268. };
  269. const defaultName = 'disaster-precaution-task-item';
  270. const handleCreateTask = () => {
  271. router.push({
  272. name: defaultName,
  273. query: {
  274. operate: 'create',
  275. },
  276. });
  277. };
  278. const handleEditTask = (id: number) => {
  279. router.push({
  280. name: defaultName,
  281. query: { operate: 'edit', id },
  282. });
  283. };
  284. const handleViewTask = (id: number, name: string, deptName: string, taskState: string, inspectType: string) => {
  285. router.push({
  286. name: defaultName,
  287. query: { id, name, deptName, taskState, inspectType },
  288. });
  289. };
  290. const tableData = ref<TaskManagementListResponse[]>([]);
  291. const handleSizeChange = (value: number) => {
  292. pagination.pageSize = value;
  293. taskManagementListQuery.pageSize = value;
  294. getTableData();
  295. };
  296. const handleCurrentChange = (value: number) => {
  297. pagination.pageNumber = value;
  298. taskManagementListQuery.pageNumber = value;
  299. getTableData();
  300. };
  301. const getTableData = async () => {
  302. tableConfig.loading = true;
  303. const res = await getTaskManagementList(taskManagementListQuery);
  304. tableData.value = res.records;
  305. pagination.total = res.totalRow;
  306. tableConfig.loading = false;
  307. };
  308. const taskManagementPermissions = ref<Boolean>(false);
  309. onMounted(() => {
  310. getTableData();
  311. taskManagementPermissions.value = Boolean(
  312. permissions.find((item: { code: string }) => item.code === DISASTER_PERMISSIONS.TASK_MANAGEMENT),
  313. );
  314. tableConfig.maxHeight = taskManagementPermissions.value
  315. ? TABLE_MANAGEMENT_HEIGHT_DEFAULT
  316. : TABLE_MANAGEMENT_HEIGHT_NOT_PERMISSION;
  317. });
  318. </script>
  319. <style scoped lang="scss">
  320. @use '@/styles/page-details-layout.scss' as *;
  321. @use '@/styles/page-main-layout.scss' as *;
  322. @use '@/styles/basic-table-action.scss' as *;
  323. @use './src/style/task-execution.scss' as *;
  324. @use '@/views/disaster/style/disaster.scss' as *;
  325. .batch-table {
  326. position: relative;
  327. width: 100%;
  328. height: 100%;
  329. }
  330. .batch-operation--div {
  331. @include flex-center;
  332. justify-content: flex-start;
  333. position: absolute;
  334. top: 0;
  335. left: 0;
  336. gap: 60px;
  337. width: 100%;
  338. height: 48px;
  339. border: 4px;
  340. padding: 16px 25px;
  341. background-color: #ddefff;
  342. z-index: 100;
  343. &--close {
  344. @include flex-center;
  345. justify-content: space-between;
  346. flex: 1;
  347. }
  348. .close-icon {
  349. font-size: 20px;
  350. color: #ff4d4f;
  351. cursor: pointer;
  352. }
  353. }
  354. </style>