Default.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <div class="box">
  3. <div class="search-form">
  4. <QueryForm :is-show-tab="false" :ai-options="aiOptions" :manual-options="manualOptions"
  5. :location-options="locationOptions" @on-search="handleSearch" @on-reset="handleReset" />
  6. </div>
  7. <div class="table-list">
  8. <div v-if="showActionBar" class="action-bar">
  9. <span class="num-text">已选{{ chooseNum }}项</span>
  10. <el-button :class="isActiveHide ? 'btn-active' : 'btn-normal'" @click="handleHideAll">全部隐藏</el-button>
  11. <el-button :class="isActiveDelete ? 'btn-active' : 'btn-normal'" @click="handleDeleteAll">删除</el-button>
  12. <el-button :class="isActiveUrgent ? 'btn-active' : 'btn-normal'" @click="handleUrgentAll">标记加急</el-button>
  13. <el-button :class="isActiveCopy ? 'btn-active' : 'btn-normal'" @click="handleCopyToShow">复制到展示数据</el-button>
  14. <span class="close-btn" @click="handleSelectNone"></span>
  15. </div>
  16. <AlertTable ref="alertTableRef" class="table-bar" :is-show-tab="false" :table-data="tableData"
  17. :on-detail="handleDetail" :on-urgent="handleUrgent" :on-show="handleShow" :on-delete="handleDelete"
  18. @update:selection="handlePop" />
  19. </div>
  20. <div class="pagination-box">
  21. <Pagination v-model:page="query.pageNumber" v-model:size="query.pageSize" :total="total"
  22. @update:page="handlePageChange" @update:size="handleSizeChange" />
  23. </div>
  24. <DetailDialog :show-drawer="isDetailDialogShow" :description="detailDescription" :image-paths="detailPictures"
  25. @toggle-status="switchDetailDialog" />
  26. </div>
  27. </template>
  28. <script setup lang="ts">
  29. import { ref, onMounted, onBeforeMount } from 'vue';
  30. import { ElMessage, ElMessageBox } from 'element-plus';
  31. import QueryForm from '../common/QueryForm.vue';
  32. import AlertTable from '../common/AlertTable.vue';
  33. import DetailDialog from '../common/DetailDialog.vue';
  34. import Pagination from '../common/Pagination.vue';
  35. import { useIssueType } from '../../hooks/useIssueType';
  36. import { useWorkLocation } from '../../hooks/useWorkLocation';
  37. import {
  38. getDefaultTableData,
  39. updateDefaultTableData,
  40. deleteDefaultTableData,
  41. copyToShowTableData
  42. } from '@/api/datamanagement/alert-default';
  43. const { aiOptions, manualOptions, getAIOptions, getManualOptions } = useIssueType();
  44. const { locationOptions, getLocationOptions } = useWorkLocation();
  45. const alertTableRef = ref<typeof AlertTable>();
  46. const tableData = ref([]);
  47. const showActionBar = ref(false);
  48. const chooseNum = ref(0);
  49. const chooseId = ref<number[]>([]);
  50. const isActiveHide = ref(false);
  51. const isActiveDelete = ref(false);
  52. const isActiveUrgent = ref(false);
  53. const isActiveCopy = ref(false);
  54. // 详情
  55. const isDetailDialogShow = ref(false);
  56. const detailDescription = ref('');
  57. const detailPictures = ref<string[]>([]);
  58. // 分页
  59. const total = ref(0);
  60. const query = ref({
  61. pageNumber: 1,
  62. pageSize: 10
  63. });
  64. // 查询
  65. const handleSearch = (queryForm) => {
  66. query.value = queryForm;
  67. getTableData();
  68. };
  69. // 重置
  70. const handleReset = (queryForm) => {
  71. query.value = queryForm;
  72. getTableData();
  73. };
  74. // 多选
  75. const handlePop = (selection) => {
  76. selection.forEach((item) => {
  77. if (chooseId.value.indexOf(item.id) === -1)
  78. chooseId.value.push(item.id);
  79. });
  80. chooseNum.value = selection.length;
  81. showActionBar.value = chooseNum.value > 0 ? true : false;
  82. };
  83. // 取消多选
  84. const handleSelectNone = () => {
  85. chooseNum.value = 0;
  86. alertTableRef.value?.clearAll();
  87. showActionBar.value = false;
  88. };
  89. // 全部隐藏
  90. const handleHideAll = () => {
  91. if (showActionBar.value) isActiveHide.value = !isActiveHide.value;
  92. const updateList = {
  93. id: chooseId.value,
  94. hide: true,
  95. };
  96. updateDefaultTableData(updateList).then(() => {
  97. getTableData();
  98. ElMessage({
  99. message: '隐藏成功',
  100. type: 'success',
  101. });
  102. setTimeout(function () {
  103. isActiveHide.value = !isActiveHide.value;
  104. }, 1000);
  105. });
  106. };
  107. // 批量删除
  108. const handleDeleteAll = () => {
  109. if (showActionBar.value) isActiveDelete.value = !isActiveDelete.value;
  110. ElMessageBox.confirm(
  111. '删除之后,数据无法恢复',
  112. '请确认是否删除数据',
  113. {
  114. confirmButtonText: '确定',
  115. cancelButtonText: '取消',
  116. type: 'warning',
  117. customClass: 'deleteMessage',
  118. center: true
  119. }
  120. )
  121. .then(() => {
  122. deleteDefaultTableData(chooseId.value).then(() => {
  123. ElMessage({
  124. type: 'success',
  125. message: '删除成功',
  126. });
  127. getTableData();
  128. isActiveDelete.value = !isActiveDelete.value;
  129. })
  130. })
  131. .catch(() => {
  132. ElMessage({
  133. type: 'info',
  134. message: '取消删除',
  135. });
  136. isActiveDelete.value = !isActiveDelete.value;
  137. })
  138. };
  139. // 标记加急,设置priority = 1
  140. const handleUrgentAll = () => {
  141. if (showActionBar.value) isActiveUrgent.value = !isActiveUrgent.value;
  142. const updateList = {
  143. id: chooseId.value,
  144. priority: 1,
  145. };
  146. updateDefaultTableData(updateList).then(() => {
  147. getTableData();
  148. ElMessage({
  149. message: '已加急',
  150. type: 'success',
  151. });
  152. setTimeout(function () {
  153. isActiveUrgent.value = !isActiveUrgent.value;
  154. }, 1000);
  155. });
  156. };
  157. // 复制到展示数据
  158. const handleCopyToShow = () => {
  159. if (showActionBar.value) isActiveCopy.value = !isActiveCopy.value;
  160. copyToShowTableData(chooseId.value).then(() => {
  161. ElMessage({
  162. message: '复制成功',
  163. type: 'success',
  164. });
  165. setTimeout(function () {
  166. isActiveCopy.value = !isActiveCopy.value;
  167. }, 1000);
  168. })
  169. };
  170. // 详情
  171. const switchDetailDialog = (show: boolean) => {
  172. isDetailDialogShow.value = show;
  173. };
  174. const handleDetail = (row) => {
  175. isDetailDialogShow.value = true;
  176. detailDescription.value = row.description;
  177. detailPictures.value = row.pictures;
  178. };
  179. // 单个加急priority=1/取消加急priority=0
  180. const handleUrgent = (row) => {
  181. const tempPriority = row.priority === 0 ? 1 : 0;
  182. const updateList = {
  183. id: [row.id],
  184. priority: tempPriority,
  185. };
  186. updateDefaultTableData(updateList).then(() => {
  187. getTableData();
  188. });
  189. };
  190. // 单个显示hide=false/隐藏hide=true
  191. const handleShow = (row) => {
  192. const tempHide = row.isHide === false ? true : false;
  193. const updateList = {
  194. id: [row.id],
  195. hide: tempHide,
  196. };
  197. updateDefaultTableData(updateList).then(() => {
  198. getTableData();
  199. });
  200. };
  201. // 删除
  202. const handleDelete = (row) => {
  203. ElMessageBox.confirm(
  204. '删除之后,数据无法恢复',
  205. '请确认是否删除数据',
  206. {
  207. confirmButtonText: '确定',
  208. cancelButtonText: '取消',
  209. type: 'warning',
  210. customClass: 'deleteMessage',
  211. center: true
  212. }
  213. )
  214. .then(() => {
  215. deleteDefaultTableData([row.id]).then(() => {
  216. ElMessage({
  217. type: 'success',
  218. message: '删除成功',
  219. });
  220. getTableData();
  221. })
  222. })
  223. .catch(() => {
  224. ElMessage({
  225. type: 'info',
  226. message: '取消删除',
  227. })
  228. })
  229. };
  230. // 换页,重新获取表格
  231. const handlePageChange = (val) => {
  232. query.value.pageNumber = val;
  233. getTableData();
  234. };
  235. const handleSizeChange = (val) => {
  236. query.value.pageSize = val;
  237. getTableData();
  238. };
  239. const getTableData = () => {
  240. getDefaultTableData(query.value).then((res) => {
  241. console.log(res);
  242. tableData.value = res.records;
  243. total.value = res.totalRow;
  244. })
  245. };
  246. onMounted(() => {
  247. getTableData();
  248. });
  249. onBeforeMount(() => {
  250. getAIOptions();
  251. getManualOptions();
  252. getLocationOptions();
  253. });
  254. </script>
  255. <style scoped lang="scss">
  256. .box {
  257. display: flex;
  258. flex-direction: column;
  259. }
  260. .table-list {
  261. height: calc(100vh - 350px);
  262. overflow-y: scroll;
  263. .action-bar {
  264. display: flex;
  265. align-items: center;
  266. position: absolute;
  267. min-width: calc(100vw - 266px);
  268. height: 50px;
  269. border-radius: 4px 4px 0px 0px;
  270. background-color: #DDEFFF;
  271. z-index: 10;
  272. .num-text {
  273. margin: 0 34px 0 25px;
  274. color: rgba(0, 0, 0, 0.85);
  275. font-weight: 500;
  276. }
  277. .btn-normal {
  278. color: #1890FF;
  279. background: transparent;
  280. border: 1px solid #1890FF;
  281. border-radius: 2px;
  282. }
  283. .btn-active {
  284. color: #FFFFFF;
  285. background-color: #1890FF;
  286. }
  287. .close-btn {
  288. margin-left: auto;
  289. margin-right: 20px;
  290. }
  291. .close-btn:before {
  292. content: '\2716';
  293. color: #000;
  294. cursor: pointer;
  295. }
  296. }
  297. .table-bar {
  298. position: relative;
  299. }
  300. }
  301. .pagination-box {
  302. height: 50px;
  303. margin-top: 10px;
  304. }
  305. </style>
  306. <style lang="scss">
  307. .deleteMessage {
  308. padding: 20px 24px;
  309. box-shadow: 0px 12px 48px 16px rgba(0, 0, 0, 0.03), 0px 9px 28px 0px rgba(0, 0, 0, 0.05), 0px 6px 16px -8px rgba(0, 0, 0, 0.08);
  310. border-radius: 8px;
  311. .el-message-box__headerbtn {
  312. margin-top: 12px;
  313. margin-right: 12px;
  314. }
  315. .el-message-box__title {
  316. justify-content: start;
  317. color: rgba(0, 0, 0, 0.88);
  318. font-size: 16px;
  319. font-weight: 500;
  320. }
  321. .el-message-box__container {
  322. justify-content: start;
  323. margin-left: 23px;
  324. }
  325. .el-message-box__btns {
  326. display: block;
  327. float: right;
  328. }
  329. }
  330. </style>