Browse Source

月报汇总接口调用

duy 1 year ago
parent
commit
c58df7c622
3 changed files with 147 additions and 121 deletions
  1. 35 0
      src/api/modules/tentative/collect/month.js
  2. 30 0
      src/utils/tools.js
  3. 82 121
      src/views/tentative/collect/monthly.vue

+ 35 - 0
src/api/modules/tentative/collect/month.js

@@ -0,0 +1,35 @@
+import { httpApi } from '../../../request/httpApi'
+
+
+
+//月报汇总分页查询
+export const getMonthPage = (form, msg = true) => httpApi({
+    url: '/api/blade-business/trial/summary/monthly/page',
+    method: 'post',
+    data: form,
+}, msg)
+//月报汇总编辑备注
+export const editRemark = (form, msg = true) => httpApi({
+    url: '/api/blade-business/trial/summary/monthly/edit',
+    method: 'post',
+    data: form,
+}, msg)
+
+//月报汇总下载
+export const download = (form, msg = true) => httpApi({
+    url: '/api/blade-business/trial/summary/monthly/download',
+    method: 'post',
+    data: form,
+}, msg)
+
+//月报汇总打印
+export const print = (form, msg = true) => httpApi({
+    url: '/api/blade-business/trial/summary/monthly/print',
+    method: 'post',
+    data: form,
+}, msg)
+
+
+
+
+

+ 30 - 0
src/utils/tools.js

@@ -66,3 +66,33 @@ export const setAppName = (name) => {
 export const isPathUrl = (path) => {
     return /^(https?:|mailto:|tel:)/.test(path)
 }
+
+//判断起止时间是否为1个月
+export const isExactlyOneMonthApart = (dateStr1, dateStr2)=> {
+    // 将日期字符串转换为 Date 对象
+    const date1 = new Date(dateStr1)
+    const date2 = new Date(dateStr2)
+    
+    // 获取两个日期的年、月、日
+    const year1 = date1.getFullYear()
+    const month1 = date1.getMonth()
+    const day1 = date1.getDate()
+    
+    const year2 = date2.getFullYear()
+    const month2 = date2.getMonth()
+    const day2 = date2.getDate()
+    
+    // 计算日期差值(以毫秒为单位)
+    const diff = Math.abs(date2 - date1)
+    
+    // 计算日期相差的天数
+    const daysDiff = Math.ceil(diff / (1000 * 60 * 60 * 24))
+    
+    // 判断日期相差的天数是否等于一个月的天数
+    const daysInMonth1 = new Date(year1, month1 + 1, 0).getDate() // 当月的天数
+    const daysInMonth2 = new Date(year2, month2 + 1, 0).getDate() // 下个月的天数
+    
+    return daysDiff === daysInMonth1 || daysDiff === daysInMonth2
+}
+
+

+ 82 - 121
src/views/tentative/collect/monthly.vue

@@ -1,45 +1,9 @@
 <template>
     <div class="hc-page-layout-box">
-        <!-- <div :style="`width:${leftWidth}px;`" class="hc-layout-left-box bg-white">
-            <div class="hc-project-box">
-                <div class="hc-project-icon-box">
-                    <HcIcon name="stack" />
-                </div>
-                <div class="ml-2 project-name-box">
-                    <span class="project-alias">{{ projectInfo.projectName }}</span>
-                </div>
-            </div>
-            <div class="hc-tree-search-box">
-                <div class="hc-search-tree-val">
-                    <el-input v-model="searchTreeVal" block clearable placeholder="请输入名称关键词检索" @keyup="searchTreeKeyUp">
-                        <template #suffix>
-                            <HcIcon name="search-2" ui="text-xl" />
-                        </template>
-                    </el-input>
-                </div>
-                <div v-loading="treeLoading" class="hc-tree-scrollbar" element-loading-text="获取数据中...">
-                    <el-scrollbar>
-                        <KeepAlive>
-                            <template v-if="isSearchTree">
-                                <HcTreeData :datas="searchTreeData" @change="testTreeCheckChange" />
-                            </template>
-                            <template v-else>
-                                <TestTree
-                                    :contract-id="contractId" :project-id="projectId"
-                                    @change="testTreeCheckChange"
-                                />
-                            </template>
-                        </KeepAlive>
-                    </el-scrollbar>
-                </div>
-            </div>
-    
-            <div class="horizontal-drag-line" @mousedown="onmousedown" />
-        </div> -->
         <div class="hc-page-content-box">
             <HcNewCard>
                 <template #header>
-                    <div class="w-40">
+                    <div class="w-60">
                         <el-select v-model="searchForm.type" clearable placeholder="请选择检测类别">
                             <el-option
                                 v-for="item in typeData" :key="item.value" :label="item.label"
@@ -52,15 +16,18 @@
                     </div>
                     <div class="w-64 ml-2">
                         <el-tree-select
+                            ref="selectTree"
                             v-model="testId"
-                            :data="testData"
-                            :render-after-expand="false"
-                            show-checkbox
+                            lazy
+                            multiple
+                            :load="tesrtreeload"
+                            :props="testprops"
                             style="width: 240px"
+                            show-checkbox
                             placeholder="请选择试验检测项目名称"
                         />
                     </div>
-                    <div class="ml-2">
+                    <div class="ml-14">
                         <el-button type="primary" @click="searchClick">
                             <HcIcon name="search-2" />
                             <span>搜索</span>
@@ -132,22 +99,22 @@
 <script setup>
 import { onMounted, ref, watch } from 'vue'
 import { useAppStore } from '~src/store'
-import { useRoute, useRouter } from 'vue-router'
-import TestTree from './components/TestTree.vue'
-import HcTreeData from './components/HcTreeData.vue'
+
+
 import queryApi from '~api/data-fill/query'
-import { getArrValue } from 'js-fast-way'
+import { calcDate, getArrValue } from 'js-fast-way'
 import { getDictionary } from '~api/other'
+import samplingApi from '~api/tentative/material/sampling'
+import { getMonthPage } from '~api/tentative/collect/month'
+import { isExactlyOneMonthApart } from '~uti/tools'
 
-//初始变量
-const router = useRouter()
-const useRoutes = useRoute()
 const useAppState = useAppStore()
 
 //全局变量
 const projectId = ref(useAppState.getProjectId)
 const contractId = ref(useAppState.getContractId)
 const projectInfo = ref(useAppState.getProjectInfo)
+const userInfo = ref(useAppState.getUserInfo)
 const isCollapse = ref(useAppState.getCollapse)
 
 //监听
@@ -193,79 +160,38 @@ const searchTreeClick = async () => {
 }
 
 const testId = ref()
-const testData = ref([
-{
-    value: '1',
-    label: 'Level one 1',
-    children: [
-      {
-        value: '1-1',
-        label: 'Level two 1-1',
-        children: [
-          {
-            value: '1-1-1',
-            label: 'Level three 1-1-1',
-          },
-        ],
-      },
-    ],
-  },
-  {
-    value: '2',
-    label: 'Level one 2',
-    children: [
-      {
-        value: '2-1',
-        label: 'Level two 2-1',
-        children: [
-          {
-            value: '2-1-1',
-            label: 'Level three 2-1-1',
-          },
-        ],
-      },
-      {
-        value: '2-2',
-        label: 'Level two 2-2',
-        children: [
-          {
-            value: '2-2-1',
-            label: 'Level three 2-2-1',
-          },
-        ],
-      },
-    ],
-  },
-  {
-    value: '3',
-    label: 'Level one 3',
-    children: [
-      {
-        value: '3-1',
-        label: 'Level two 3-1',
-        children: [
-          {
-            value: '3-1-1',
-            label: 'Level three 3-1-1',
-          },
-        ],
-      },
-      {
-        value: '3-2',
-        label: 'Level two 3-2',
-        children: [
-          {
-            value: '3-2-1',
-            label: 'Level three 3-2-1',
-          },
-        ],
-      },
-    ],
-  },
-])
+const selectTree = ref(null)
+const tesrtreeload = async (node, resolve) => {
+    let parentId = '0'
+    if (node.level !== 0) {
+        parentId = node?.data?.id
+    }
+    //获取数据
+    const { error, code, data } = await samplingApi.queryLazyTree({
+        wbsId:projectInfo.value?.referenceWbsTemplateIdTrial,
+        tenantId:  userInfo.value?.tenant_id,
+        projectId: projectId.value,
+        parentId,
+        wbsType: 2,
+    })
+    //处理数据
+    if (!error && code === 200) {
+        resolve(getArrValue(data))
+    } else {
+        resolve([])
+    }
+}
+
+const testprops = ref({
+    label: 'title',
+    children: 'children',
+    isLeaf: function (data) {
+          return !data.hasChildren
+    },
+})
 //搜索表单
 const searchForm = ref({
-    type: null, approval: null, betweenTime: null,
+    type: '', contractId: '', endTime: '', startTime:'', ids:'',
     current: 1, size: 20, total: 0,
 })
 //检测类别
@@ -289,13 +215,27 @@ const gettypeData = async () => {
 //日期时间被选择
 const betweenTime = ref(null)
 const betweenTimeUpdate = ({ arr, query }) => {
+    const date1 = new Date(arr[0])
+    const date2 = new Date(arr[1])
+
+     // 计算两个日期的月份差
+     const monthDiff = isExactlyOneMonthApart(date1, date2)
+     console.log(monthDiff, 'monthDiff')
+     if (!monthDiff) {
+        window.$message.warning('起始时间必须为1个月')
+        return
+     }
+
     betweenTime.value = arr
-    searchForm.value.betweenTime = query
+    searchForm.value.startTime = arr[0]
+    searchForm.value.endTime = arr[1]
 }
 
 //搜索
 const searchClick = () => {
     searchForm.value.current = 1
+    searchForm.value.ids = testId.value.join(',')
+    console.log(testId.value, '11111111')
     getTableData()
 }
 
@@ -369,8 +309,29 @@ const tableData = ref([
         zip: 'CA 90036',
     },
 ])
-const getTableData = () => {
+const getTableData = async () => {
+    if (!searchForm.value.type) {
+        window.$message.warning('请选择检查类别')
+        return
+    } else if (!!searchForm.value.startTime || !searchForm.value.endTime) {
+        window.$message.warning('请选择开始时间和结束时间')
+        return
+    } else if (searchForm.value.ids) {
+        window.$message.warning('请选择试验检测项目名称')
+        return
+    }
+    const { error, code, data } = await getMonthPage({
+            ...searchForm.value,
+            contractId:contractId.value,
+        })
+        //判断状态
+        if (!error && code === 200) {
+            let resdata = getArrValue(data['records'])
+        tableData.value = resdata
 
+        } else {
+            tableData.value = []
+        }
 }