Default.vue 9.6 KB

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