From 4cf0b6d70e50ee02611e2c6d844b6133f1383241 Mon Sep 17 00:00:00 2001
From: xiaoxiao <2014227881@qq.com>
Date: Tue, 10 Jun 2025 22:39:16 +0800
Subject: [PATCH] 查询

---
 src/views/dataCenter/components/searchData.vue |   45 +++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/src/views/dataCenter/components/searchData.vue b/src/views/dataCenter/components/searchData.vue
index fe67363..a8a9ac0 100644
--- a/src/views/dataCenter/components/searchData.vue
+++ b/src/views/dataCenter/components/searchData.vue
@@ -111,10 +111,10 @@
 import dayjs from 'dayjs';
 import { useStore } from 'vuex';
 import { getRegionTreeAll, getDeviceRegion, deptsByAreaCode } from '@/api/job/task';
-
 const store = useStore();
 const userAreaCode = computed(() => store.getters.userInfo.detail.areaCode);
 const selectedAreaCode = computed(() => store.state.user.selectedAreaCode);
+const emit = defineEmits(['search']);
 const treeProps = {
   label: 'name',
   value: 'id',
@@ -172,7 +172,21 @@
 let deptData = ref([]);
 // 从单机巢任务传参值
 const signDevice_sn = ref('');
-const handleDateChange = () => {};
+// 日期限制
+const handleDateChange = val => {
+  if (val && val.length === 2) {
+    const start = dayjs(val[0]);
+    const end = dayjs(val[1]);
+    const diff = end.diff(start, 'day');
+
+    if (diff > 31) {
+      ElMessage.warning('日期范围不能超过31天');
+      dateRange.value = [];
+      return;
+    }
+  }
+  handleSearch();
+};
 // 部门下得机巢
 const requestDockInfo = () => {
   getRegionTreeAll({ parentCode: userAreaCode.value }).then(res => {
@@ -207,9 +221,32 @@
   });
 };
 // 搜索
-const handleSearch = () => {};
+const handleSearch = () => {
+  if (!dateRange.value) {
+    dateRange.value = [];
+  }
+  let params = {
+    ...searchForm,
+    start_date: dateRange.value.length
+      ? dayjs(dateRange?.value[0]).startOf('day').format(timeFormat)
+      : null,
+    end_date: dateRange.value.length
+      ? dayjs(dateRange?.value[1]).endOf('day').format(timeFormat)
+      : null,
+  };
+  console.log('searchForm', params);
+  // 调用父组件方法
+  emit('search', params);
+};
 // 重置
-const handleReset = () => {};
+const handleReset = () => {
+  dateRange.value = [];
+  Object.keys(searchForm).forEach(key => {
+    searchForm[key] = '';
+  });
+  handleNodeClick({ id: userAreaCode.value });
+  handleSearch();
+};
 onMounted(() => {
   requestDockInfo();
 });

--
Gitblit v1.9.3