Default.vue 9.5 KB

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