Show.vue 7.7 KB

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