completed.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <el-dialog v-model="showSearch" title="已完成" width="80%" @close="$emit('close')">
  3. <el-row :gutter="20">
  4. <el-col :lg="4" :xs="24">
  5. <el-tree
  6. ref="deptTreeRef"
  7. class="mt-2"
  8. node-key="id"
  9. :data="deptOptions"
  10. :props="{ label: 'label', children: 'children' }"
  11. :expand-on-click-node="false"
  12. :filter-node-method="filterNode"
  13. highlight-current
  14. default-expand-all
  15. @node-click="handleNodeClick"
  16. />
  17. </el-col>
  18. <el-col :lg="20" :xs="24">
  19. <transition name="fade">
  20. <div v-show="showSearch">
  21. <el-form ref="queryFormRef" :model="queryParams">
  22. <el-button type="primary" @click="handleExport">导出</el-button>
  23. </el-form>
  24. </div>
  25. </transition>
  26. <el-table ref="multipleTable" v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
  27. <el-table-column label="排查范围" align="center" prop="area" />
  28. <el-table-column label="任务进度" align="center" prop="task_status">
  29. <!-- 使用自定义槽来渲染转换后的文本 -->
  30. <template #default="scope">
  31. {{ formatStatus(scope.row.task_status) }}
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="巡查人员" align="center" prop="nick_name" />
  35. <el-table-column label="上报时间" align="center" prop="create_time" />
  36. </el-table>
  37. </el-col>
  38. </el-row>
  39. </el-dialog>
  40. </template>
  41. <script setup lang="ts">
  42. import { onMounted, reactive, ref, watch } from 'vue';
  43. import { useRouter } from 'vue-router';
  44. import { inspectorDivision, patrolNum } from '@/api/inspectionWork/inspector';
  45. const router = useRouter();
  46. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  47. const loading = ref(true);
  48. const showSearch = ref(true);
  49. const ids = ref<Array<number | string>>([]);
  50. const single = ref(true);
  51. const multiple = ref(true);
  52. const total = ref(0);
  53. const deptOptions = ref([]);
  54. const deptTreeRef = ref(null);
  55. const tableData = ref([]);
  56. const props = defineProps<{ eventId: string }>();
  57. const initFormData = reactive({
  58. area: '',
  59. task_status: '',
  60. yzy_organization: '',
  61. nick_name: '',
  62. create_time: ''
  63. });
  64. const data = reactive({
  65. form: { ...initFormData },
  66. queryParams: {
  67. area_code: '',
  68. deptId: ''
  69. }
  70. });
  71. const { queryParams, form } = toRefs(data);
  72. const formatStatus = (status) => {
  73. return Number(status) === 1 ? '已完成' : '未完成';
  74. };
  75. const filterNode = (value: string, data: any) => {
  76. if (!value) return true;
  77. return data.label.indexOf(value) !== -1;
  78. };
  79. const getTreeSelect = async () => {
  80. const res = await inspectorDivision();
  81. if (res.code === 200) {
  82. deptOptions.value = res.data; // 将部门树数据赋值给deptOptions
  83. } else {
  84. console.error(res.msg);
  85. }
  86. loading.value = false; // 加载完成后关闭加载提示
  87. };
  88. const fetchUserData = async () => {
  89. loading.value = true; // 开始加载
  90. // 构造请求参数
  91. const params = {
  92. ...queryParams.value,
  93. // 只在area_code有值时添加到请求参数中
  94. ...(queryParams.value.area_code ? { area_code: queryParams.value.area_code } : {})
  95. };
  96. return patrolNum(props.eventId, params)
  97. .then((res) => {
  98. if (res.code === 200) {
  99. tableData.value = res.data; // 确保tableData是一个数组
  100. total.value = res.total;
  101. } else {
  102. console.error(res.msg);
  103. }
  104. loading.value = false; // 结束加载
  105. })
  106. .catch((error) => {
  107. console.error('Error fetching sub tasks:', error);
  108. loading.value = false; // 结束加载
  109. });
  110. };
  111. watch(queryParams, () => {
  112. fetchUserData();
  113. });
  114. const handleNodeClick = (data: any) => {
  115. queryParams.value.deptId = data.id;
  116. queryParams.value.area_code = data.code; // 设置area_code为点击节点的code值
  117. fetchUserData();
  118. };
  119. const handleSelectionChange = (selection) => {
  120. ids.value = selection.map((item) => item.id);
  121. };
  122. onMounted(async () => {
  123. await getTreeSelect();
  124. fetchUserData();
  125. });
  126. </script>
  127. <style scoped>
  128. .mt-2 {
  129. max-width: 300px; /* 设置最大宽度 */
  130. max-height: 800px; /* 设置最大高度 */
  131. overflow-y: auto; /* 如果内容超出高度则显示滚动条 */
  132. }
  133. </style>