Forráskód Böngészése

迭代八数据填报:解决部门树传参

zhangyihao 9 hónapja
szülő
commit
1919f9b123

+ 18 - 6
src/views/inspectionWork/completed.vue

@@ -42,7 +42,7 @@
 <script setup lang="ts">
 import { onMounted, reactive, ref, watch } from 'vue';
 import { useRouter } from 'vue-router';
-import { deptList, patrolNum } from '@/api/inspectionWork/inspector';
+import { inspectorDivision, patrolNum } from '@/api/inspectionWork/inspector';
 
 const router = useRouter();
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@@ -75,7 +75,7 @@ const data = reactive({
 });
 
 const { queryParams, form } = toRefs(data);
-
+data.queryParams.area_code = '';
 const formatStatus = (status) => {
   return Number(status) === 1 ? '已完成' : '未完成';
 };
@@ -86,15 +86,26 @@ const filterNode = (value: string, data: any) => {
 };
 
 const getTreeSelect = async () => {
-  const res = await deptList();
-  deptOptions.value = res.data; // 直接赋值给 deptOptions
-  queryParams.value.area_code = res.data.code;
+  const res = await inspectorDivision();
+  if (res.code === 200) {
+    deptOptions.value = res.data; // 将部门树数据赋值给deptOptions
+  } else {
+    console.error(res.msg);
+  }
   loading.value = false; // 加载完成后关闭加载提示
 };
 
 const fetchUserData = async () => {
   loading.value = true; // 开始加载
-  return patrolNum(props.eventId, queryParams.value)
+
+  // 构造请求参数
+  const params = {
+    ...queryParams.value,
+    // 只在area_code有值时添加到请求参数中
+    ...(queryParams.value.area_code ? { area_code: queryParams.value.area_code } : {})
+  };
+
+  return patrolNum(props.eventId, params)
     .then((res) => {
       if (res.code === 200) {
         tableData.value = res.data; // 确保tableData是一个数组
@@ -116,6 +127,7 @@ watch(queryParams, () => {
 
 const handleNodeClick = (data: any) => {
   queryParams.value.deptId = data.id;
+  queryParams.value.area_code = data.code; // 设置area_code为点击节点的code值
   fetchUserData();
 };
 

+ 18 - 6
src/views/inspectionWork/incompleted.vue

@@ -42,7 +42,7 @@
 <script setup lang="ts">
 import { onMounted, reactive, ref, watch } from 'vue';
 import { useRouter } from 'vue-router';
-import { deptList, patrolNum_1 } from '@/api/inspectionWork/inspector';
+import { inspectorDivision, patrolNum_1 } from '@/api/inspectionWork/inspector';
 
 const router = useRouter();
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@@ -84,17 +84,29 @@ const filterNode = (value: string, data: any) => {
   if (!value) return true;
   return data.label.indexOf(value) !== -1;
 };
+data.queryParams.area_code = '';
 
 const getTreeSelect = async () => {
-  const res = await deptList();
-  deptOptions.value = res.data; // 直接赋值给 deptOptions
-  queryParams.value.area_code = res.data.code;
+  const res = await inspectorDivision();
+  if (res.code === 200) {
+    deptOptions.value = res.data; // 将部门树数据赋值给deptOptions
+  } else {
+    console.error(res.msg);
+  }
   loading.value = false; // 加载完成后关闭加载提示
 };
 
 const fetchUserData = async () => {
   loading.value = true; // 开始加载
-  return patrolNum_1(props.eventId, queryParams.value)
+
+  // 构造请求参数
+  const params = {
+    ...queryParams.value,
+    // 只在area_code有值时添加到请求参数中
+    ...(queryParams.value.area_code ? { area_code: queryParams.value.area_code } : {})
+  };
+
+  return patrolNum_1(props.eventId, params)
     .then((res) => {
       if (res.code === 200) {
         tableData.value = res.data; // 确保tableData是一个数组
@@ -109,13 +121,13 @@ const fetchUserData = async () => {
       loading.value = false; // 结束加载
     });
 };
-
 watch(queryParams, () => {
   fetchUserData();
 });
 
 const handleNodeClick = (data: any) => {
   queryParams.value.deptId = data.id;
+  queryParams.value.area_code = data.code; // 设置area_code为点击节点的code值
   fetchUserData();
 };