checkTemplateManagement.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="safety-platform-container">
  3. <header class="safety-platform-container__header">
  4. <div class="breadcrumb-title">检查单模版管理</div>
  5. </header>
  6. <main class="safety-platform-container__main">
  7. <div class="search-table-container">
  8. <header>
  9. <div style="position: relative">
  10. <el-button type="primary" :icon="Plus" class="search-table-container--button" @click="handleCreate">
  11. 添加
  12. </el-button>
  13. </div>
  14. <div class="act-search">
  15. <section class="select-box">
  16. <div class="select-box--item">
  17. <span>模版名称:</span>
  18. <el-input
  19. v-model="tableQuery.queryParam.templateName"
  20. placeholder="搜索检查单模版名称"
  21. class="act-search-input"
  22. />
  23. </div>
  24. <div class="select-box--item">
  25. <span>状态:</span>
  26. <el-select
  27. v-model="tableQuery.queryParam.status"
  28. placeholder="请选择状态"
  29. clearable
  30. >
  31. <el-option label="启用" :value="true" />
  32. <el-option label="禁用" :value="false" />
  33. </el-select>
  34. </div>
  35. <div class="select-box--item">
  36. <span>日期范围:</span>
  37. <el-date-picker
  38. v-model="dateRange"
  39. type="daterange"
  40. range-separator="-"
  41. start-placeholder="开始日期"
  42. end-placeholder="结束日期"
  43. value-format="YYYY-MM-DD"
  44. format="YYYY-MM-DD"
  45. />
  46. </div>
  47. </section>
  48. <section class="search-btn">
  49. <el-button type="primary" @click="handleSearch">查询</el-button>
  50. <el-button @click="handleReset">重置</el-button>
  51. </section>
  52. </div>
  53. </header>
  54. <div class="batch-table">
  55. <BasicTable
  56. ref="basicTableRef"
  57. :tableData="tableData"
  58. :tableConfig="tableConfig"
  59. @update:pageSize="handleSizeChange"
  60. @update:pageNumber="handleCurrentChange"
  61. >
  62. <template #status="scope">
  63. <span>
  64. {{ scope.row.status === 1 ? '启用' : scope.row.status === 0 ? '禁用' : scope.row.status === 2 ? '草稿' : '-' }}
  65. </span>
  66. </template>
  67. <template #action="scope">
  68. <div class="action-container--div" style="justify-content: left">
  69. <ActionButton text="编辑" @click="handleEdit(scope.row.id)" />
  70. <ActionButton
  71. text="删除"
  72. :popconfirm="{
  73. title: '确定要删除?',
  74. }"
  75. @confirm="handleDelete(scope.row.id)"
  76. />
  77. <ActionButton text="查看" @click="handleView(scope.row.id)" />
  78. </div>
  79. </template>
  80. </BasicTable>
  81. </div>
  82. </div>
  83. </main>
  84. </div>
  85. </template>
  86. <script setup lang="ts">
  87. import { onMounted, reactive, ref } from 'vue';
  88. import { ElMessage } from 'element-plus';
  89. import { Plus } from '@element-plus/icons-vue';
  90. import BasicTable from '@/components/BasicTable.vue';
  91. import useTableConfig from '@/hooks/useTableConfigHook';
  92. import ActionButton from '@/components/ActionButton.vue';
  93. import { TABLE_OPTIONS, CHECK_TEMPLATE_TABLE_COLUMNS } from './configs/tables';
  94. import { useRouter } from 'vue-router';
  95. import {
  96. queryChecklistTemplateList,
  97. deleteChecklistTemplate,
  98. type ChecklistTemplateQuery,
  99. } from '@/api/production-safety-system';
  100. const router = useRouter();
  101. // 表格
  102. const basicTableRef = ref<InstanceType<typeof BasicTable>>();
  103. const { tableConfig, pagination } = useTableConfig(CHECK_TEMPLATE_TABLE_COLUMNS, TABLE_OPTIONS);
  104. const tableData = ref<any[]>([]);
  105. const tableQuery = reactive<{
  106. pageNumber: number;
  107. pageSize: number;
  108. queryParam: ChecklistTemplateQuery;
  109. }>({
  110. pageNumber: pagination.pageNumber,
  111. pageSize: pagination.pageSize,
  112. queryParam: {
  113. templateName: '',
  114. status: undefined,
  115. startDate: '',
  116. endDate: '',
  117. },
  118. });
  119. // 日期范围(用于日期选择器)
  120. const dateRange = ref<[string, string] | null>(null);
  121. const handleSizeChange = (value: number) => {
  122. pagination.pageSize = value;
  123. tableQuery.pageSize = value;
  124. getTableData();
  125. };
  126. const handleCurrentChange = (value: number) => {
  127. pagination.pageNumber = value;
  128. tableQuery.pageNumber = value;
  129. getTableData();
  130. };
  131. async function getTableData() {
  132. tableConfig.loading = true;
  133. try {
  134. const res = await queryChecklistTemplateList(tableQuery);
  135. if (res) {
  136. tableData.value = (res.records || []).map((item) => ({
  137. id: item.id,
  138. templateName: item.templateName,
  139. status: item.status,
  140. categoryName: item.categoryName,
  141. useCount: item.useCount ?? 0,
  142. remark: item.remark,
  143. updateUserName: item.updateUserName,
  144. updatedAt: (item as any).updatedAt,
  145. }));
  146. pagination.total = res.totalRow ?? 0;
  147. }
  148. } catch (e) {
  149. console.error('获取检查单模版列表失败:', e);
  150. tableData.value = [];
  151. pagination.total = 0;
  152. } finally {
  153. tableConfig.loading = false;
  154. }
  155. }
  156. const handleSearch = () => {
  157. // 处理日期范围
  158. if (dateRange.value && dateRange.value.length === 2) {
  159. tableQuery.queryParam.startDate = dateRange.value[0];
  160. tableQuery.queryParam.endDate = dateRange.value[1];
  161. } else {
  162. tableQuery.queryParam.startDate = '';
  163. tableQuery.queryParam.endDate = '';
  164. }
  165. pagination.pageNumber = 1;
  166. tableQuery.pageNumber = 1;
  167. getTableData();
  168. };
  169. const handleReset = () => {
  170. tableQuery.queryParam.templateName = '';
  171. tableQuery.queryParam.status = undefined;
  172. tableQuery.queryParam.startDate = '';
  173. tableQuery.queryParam.endDate = '';
  174. dateRange.value = null;
  175. handleSearch();
  176. };
  177. const handleCreate = () => {
  178. router.push({
  179. name: 'checkTemplateManagementItem',
  180. query: {
  181. operate: 'check-template-create',
  182. },
  183. });
  184. };
  185. const handleEdit = (id: number) => {
  186. router.push({
  187. name: 'checkTemplateManagementItem',
  188. query: {
  189. id,
  190. operate: 'check-template-edit',
  191. },
  192. });
  193. };
  194. const handleDelete = async (id: number) => {
  195. try {
  196. await deleteChecklistTemplate(id);
  197. ElMessage.success('删除成功');
  198. getTableData();
  199. } catch (e) {
  200. console.error('删除检查单模版失败:', e);
  201. ElMessage.error(e?.message || e?.data || '删除失败,请重试');
  202. }
  203. };
  204. const handleView = (id: number) => {
  205. router.push({
  206. name: 'checkTemplateManagementItem',
  207. query: {
  208. id,
  209. operate: 'check-template-view',
  210. },
  211. });
  212. };
  213. onMounted(() => {
  214. getTableData();
  215. });
  216. </script>
  217. <style scoped lang="scss">
  218. @use '@/styles/page-details-layout.scss' as *;
  219. @use '@/styles/page-main-layout.scss' as *;
  220. @use '@/styles/basic-table-action.scss' as *;
  221. @use '@/views/traffic/violation/style/act-search-table.scss' as *;
  222. </style>