浏览代码

筛选日期限制

duy 2 年之前
父节点
当前提交
212673102c
共有 2 个文件被更改,包括 34 次插入4 次删除
  1. 14 0
      src/utils/tools.js
  2. 20 4
      src/views/static/plan.vue

+ 14 - 0
src/utils/tools.js

@@ -49,9 +49,23 @@ export const getDiffDay=(date_1, date_2)=> {
     diffDate = Math.abs(myDate_1 - myDate_2) // 取相差毫秒数的绝对值
 
     totalDays = Math.floor(diffDate / (1000 * 3600 * 24)) // 向下取整
+    let year= Math.floor(diffDate / (1000 * 3600 * 24))/365 // 向下取整
     console.log(totalDays,'天数')
+    console.log(year,'年数')
 
     return totalDays    // 相差的天数
   }
 
+  export const getDiffYear=(date_1, date_2)=> {
+    // 计算两个日期之间的差值
+    let totalDays,diffDate
+    let myDate_1 = Date.parse(date_1)
+    let myDate_2 = Date.parse(date_2)
+    // 将两个日期都转换为毫秒格式,然后做差
+    diffDate = Math.abs(myDate_1 - myDate_2) // 取相差毫秒数的绝对值
 
+    let year= Math.floor(diffDate / (1000 * 3600 * 24))/365 // 向下取整
+    console.log(year,'年数')
+
+    return year    // 相差的天数
+  }

+ 20 - 4
src/views/static/plan.vue

@@ -68,6 +68,7 @@
  import mainApi from '~api/static/plan.js'
  import {getObjValue,getArrValue} from "js-fast-way"
  import { getdepartmentList,getuserList} from "~api/other";
+ import {getDiffYear} from "~uti/tools";
 
  onMounted(()=>{
     getDepartmentDict()
@@ -89,12 +90,21 @@
  ])
  //搜索
 const searchClick = () => {
-    searchForm.value.current = 1;
+  
     console.log(searchForm.value)
 
     let start=searchForm.value.start
     let end=searchForm.value.end
-    console.log(end-start);
+    let year=getDiffYear(start,end)
+    if(year>=1){
+        window.$message.warning('选择间隔日期不能超过一年')
+    }else{
+        getImageData()
+        planFinishedRatio()
+    }
+
+ 
+
 }
 
 //重置
@@ -102,6 +112,8 @@ const resetClick = () => {
     searchForm.value = {
         deptId:null,userId:null
     }
+    getImageData()
+    planFinishedRatio()
 }
 //计划统计图
 const planDatas = ref([])
@@ -124,7 +136,9 @@ const slegend=ref( ['风险暂停计划', '正常计划',])
 
 //项目图表数据
 const getImageData = async () => {
-    const {error, code, data} = await mainApi.MonthOfYearPlanOverview2()
+    const {error, code, data} = await mainApi.MonthOfYearPlanOverview2(
+        {        ...searchForm.value}
+    )
     //判断状态
     if (!error && code === 200) {
        planDatas.value=data['dataList']
@@ -138,7 +152,9 @@ const getImageData = async () => {
 }
 //任务完成率
 const planFinishedRatio = async () => {
-    const {error, code, data} = await mainApi.planFinishedRatio()
+    const {error, code, data} = await mainApi.planFinishedRatio(
+      {  ...searchForm.value}
+    )
     //判断状态
     if (!error && code === 200) {
        let image=getObjValue(data)