Procházet zdrojové kódy

fix: 周报默认选择

zhangyuhan před 4 roky
rodič
revize
3f9632de2c

+ 15 - 11
src/components/report-data/SelectMonth.vue

@@ -31,6 +31,9 @@ export default {
     [Icon.name]: name
   },
   props: {
+    queryDate: {
+      type: Object
+    },
     getTypeTime: {
       type: Object,
       default () {
@@ -59,9 +62,9 @@ export default {
     this.getFirst()
   },
   methods: {
+    changeActive (time) {},
     getFirst () {
       getReportStartTime().then((res) => {
-        console.log(res)
         if (res.data) {
           if (res.data.month_firsttime !== 0) {
             this.month_starttime = res.data.month_firsttime
@@ -84,12 +87,10 @@ export default {
       } else {
         week = date.slice(4, 6)
       }
-      console.log(week)
       for (let a = week; a <= 12; a++) {
         var weeks = a
         aloneWeek.push(weeks + '')
       }
-      console.log(aloneWeek)
       // 月报不需要展示当月,加class隐藏
       const _this = this
       // aloneWeek.forEach(function (time, i) {
@@ -121,29 +122,32 @@ export default {
       }
       this.listWeek.push(aloneWeek)
       this.listWeek[0].forEach(function (item, index) {
-        console.log(item)
         if (item === nowweek) {
           _this.lastIndex = index
           _this.listWeek[0] = _this.listWeek[0].splice(0, index + 1)
         }
       })
       // 高亮处理
-      if (this.getTypeTime.judgeTime === 'month') {
-        this.isActive = this.listWeek[0].length - 2
-        this.isIndexActive = 0
+      const tempData = {
+        year: 0,
+        month: 0
+      }
+      if (this.queryDate && Object.keys(this.queryDate).length) {
+        tempData.year = this.listYear.indexOf(this.queryDate.year) || 0
+        tempData.month = this.listWeek[tempData.year].indexOf(this.queryDate.month) || (this.listWeek[tempData.year].length - ((this.getTypeTime.judgeTime === 'month') ? 2 : 1))
       } else {
-        this.isActive = this.listWeek[0].length - 1
-        this.isIndexActive = 0
+        tempData.year = 0
+        tempData.month = (this.listWeek[tempData.year].length - ((this.getTypeTime.judgeTime === 'month') ? 2 : 1))
       }
+      this.isActive = tempData.month
+      this.isIndexActive = tempData.year
     },
     getWeek (index, i, month) {
-      console.log(index, i, month)
       this.isActive = i
       this.isIndexActive = index
       if (month < 10) {
         month = '0' + month
       }
-      console.log(month)
       this.$emit('selectYear', this.listYear[index])
       this.$emit('selectYm', this.listYear[index] + month)
     },

+ 43 - 6
src/views/reportData/pageWeek.vue

@@ -3,7 +3,7 @@
     <div class="page_week_main">
       <!-- 选择周报时间 -->
       <div class="week_time">
-        <SelectMonth @selectYm="getSelectTime"></SelectMonth>
+        <SelectMonth ref="selectMonth" :queryDate="getQueryTime" @selectYm="getSelectTime"></SelectMonth>
         <div class="select_report">
           <div class="week_report" v-for="(item, index) in weekList" :key="index" @click="selectWeek(index, item)" :class="{weekActive:index==isWeekIndex}">
             <div class="week_report_main">
@@ -111,6 +111,7 @@ export default {
   },
   data () {
     return {
+      canQuery: true,
       isWeekIndex: 0,
       start: 0,
       end: 0,
@@ -174,17 +175,37 @@ export default {
       }
     }
   },
-  created () {
+  mounted () {
     const nowtime = dateFormatter(new Date(), 'yyyyMM')
     this.getReportList(nowtime)
     if (this.$refs.weekitempoint && this.$refs.weekitempoint.length > 0) {
       this.$refs.weekitempoint[0].style.display = 'none'
     }
   },
+  computed: {
+    getQueryTime () {
+      const paramsDate = this.$route.query.start
+      if (paramsDate) {
+        const paramsData = {
+          year: dateFormatter(paramsDate * 1000, 'yyyy'),
+          month: Number(dateFormatter(paramsDate * 1000, 'MM')).toString(),
+          ym: dateFormatter(paramsDate * 1000, 'yyyyMM'),
+          start: this.$route.query.start,
+          end: this.$route.query.end
+        }
+        return paramsData
+      }
+      return false
+    }
+  },
   methods: {
     dateFormatter,
     // 周报列表
-    getReportList (time) {
+    getReportList (yearMonth) {
+      let time = yearMonth
+      if (this.getQueryTime) {
+        time = this.getQueryTime.ym
+      }
       getReportIndex({ ym: time }).then((res) => {
         console.log(res)
         if (res.data && res.data.list && res.data.list.length !== 0) {
@@ -201,9 +222,25 @@ export default {
             }
           })
           this.weekList = res.data.list
-          this.getDetail(res.data.list[0].startdate, res.data.list[0].enddate)
-          this.start = res.data.list[0].startdate
-          this.end = res.data.list[0].enddate
+          const queryData = {
+            start: res.data.list[0].startdate,
+            end: res.data.list[0].enddate
+          }
+          if (this.canQuery && this.getQueryTime) {
+            if (this.getQueryTime.ym === time) {
+              queryData.start = this.getQueryTime.start
+              queryData.end = this.getQueryTime.end
+              this.weekList.forEach((v, index) => {
+                if (String(v.startdate) === queryData.start) {
+                  this.isWeekIndex = index
+                }
+              })
+            }
+            this.canQuery = false
+          }
+          this.getDetail(queryData.start, queryData.end)
+          this.start = queryData.start
+          this.end = queryData.end
           this.nodata = true
         } else {
           this.weekList = []