<!--
 * @Author: Do not edit
 * @Date: 2024-04-22 15:49:56
 * @LastEditTime: 2024-04-23 17:06:16
 * @LastEditors: DY
 * @Description: 
-->
<template>
  <div class="weekly">
    <el-form :inline="true" :model="listQuery" class="blueTip">
      <el-form-item label="月" prop="reportTime">
        <el-date-picker v-model="reportTime" type="month" size="small" @change="changeTime" placeholder="选择月">
        </el-date-picker>
      </el-form-item>
      <el-button v-if="this.$auth.hasPermi('base:report-auto-production:query')" type="primary" size="small" @click="search()">
        查询
      </el-button>
      <el-button v-if="this.$auth.hasPermiAnd(['base:report-auto-original-glass:export', 'base:report-auto-production:export'])" type="primary" size="small" plain
        @click="handleExport">导出</el-button>
    </el-form>
    <monthWeek v-if="glassWeekShow" ref="monthWeek" :product="false" :params="listQuery" />
    <proMonth v-if="proWeekShow" ref="proMonth" :product="false" :params="listQuery" />
  </div>
</template>

<script>
import monthWeek from '../glass/month.vue'
import proMonth from '../productionMonthReport/index.vue'
import { parseTime } from '../../core/mixins/code-filter';

export default {
  components: { monthWeek, proMonth },
  data() {
    return {
      listQuery: {
				// pageSize: 10,
				// pageNo: 1,
				// total: 0,
				reportType: 4,
				reportTime: []
      },
      startTimeStamp: '',
      endTimeStamp: '',
      reportTime: '',
      glassWeekShow: false,
      proWeekShow: false
    }
  },
  created() {
    this.getCurrentMonthFirst()
    this.glassWeekShow = true
    this.proWeekShow = true
  },
  methods: {
    getCurrentMonthFirst() {
      const date = new Date();
      date.setDate(1);
      this.reportTime = date
      // console.log(date)
      this.changeTime(date)
      // console.log(date.valueOf());
    },
    handleExport() {
      this.$nextTick(() => {
        this.$refs['monthWeek'].handleExport()
        this.$refs['proMonth'].handleExport()
      })
    },
    search() {
      this.$nextTick(() => {
        this.$refs['monthWeek'].getDataList()
        this.$refs['proMonth'].getDataList()
      })
    },
    changeTime(val) {
      console.log(val)
			if(val) {
					const timeStamp = val.getMonth(); //标准时间转为时间戳，毫秒级别
					const fullyear = val.getFullYear()
					let days = 0
					switch (timeStamp) {
            case 0:
            case 2:
            case 4:
            case 6:
            case 7:
            case 9:
            case 11:
							days = 31
							break
            case 3:
            case 4:
            case 8:
            case 10:
							days = 30
							break
						case 1:
							if ((fullyear % 400 === 0) || (fullyear % 4 === 0 && fullyear % 100 !== 0)) {
								days = 29
							} else {
								days = 28
              }
              break
					}
        this.startTimeStamp = this.timeFun(new Date(fullyear, timeStamp, 1, 7, 0, 1).getTime()); //开始时间
        this.endTimeStamp = this.timeFun(new Date(fullyear, timeStamp, days, 7, 0, 0).getTime()); //结束时间
					console.log(this.startTimeStamp, this.endTimeStamp)
        this.listQuery.reportTime[0] = parseTime(new Date(fullyear, timeStamp, 1, 7, 0, 1).getTime()) //+ ' 00:00:00' //new Date(this.startTimeStamp + ' 00:00:00').getTime() / 1000
					this.listQuery.reportTime[1] = parseTime(new Date(fullyear, timeStamp, days, 7, 0, 0).getTime()) //+ ' 23:59:59' //new Date(this.endTimeStamp + ' 23:59:59').getTime() / 1000
			} else {
					this.listQuery.reportTime = []
			}
		},
    //时间戳转为yy-mm-dd hh:mm:ss
		timeFun(unixtimestamp) {
				var unixtimestamp = new Date(unixtimestamp);
				var year = 1900 + unixtimestamp.getYear();
				var month = "0" + (unixtimestamp.getMonth() + 1);
				var date = "0" + unixtimestamp.getDate();
				return year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length)
		}
  }
}
</script>

<style scoped>
.weekly {
  padding-top: 16px;
}
.blueTip::before{
  display: inline-block;
  content: '';
  width: 4px;
  height: 18px;
  background: #0B58FF;
  border-radius: 1px;
  margin-right: 8PX;
  margin-top: 8px;
  margin-left: 16px;
}
</style>
