<!--
 * @Author: Do not edit
 * @Date: 2024-04-22 15:49:56
 * @LastEditTime: 2024-04-23 17:16:11
 * @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="year" size="small" @change="changeTime"
            :picker-options="{firstDayOfWeek: 1}" :format="'yyyy 年' + '\u3000' + startTimeStamp + '-' + endTimeStamp"
            style="width: 350px" 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>
    <glassYear v-if="glassYearShow" ref="glassYear" :product="false" :params="listQuery" />
    <proYear v-if="proYearShow" ref="proYear" :product="false" :params="listQuery" />
  </div>
</template>

<script>
import glassYear from '../glass/year.vue'
import proYear from '../productionYearReport/index.vue'
import { parseTime } from '../../core/mixins/code-filter';

export default {
  components: { glassYear, proYear },
  data() {
    return {
      listQuery: {
				// pageSize: 10,
				// pageNo: 1,
				// total: 0,
				reportType: 5,
				reportTime: []
      },
      startTimeStamp: '',
      endTimeStamp: '',
      reportTime: '',
      glassYearShow: false,
      proYearShow: false
    }
  },
  created() {
    this.getCurrentYearFirst()
    this.glassYearShow = true
    this.proYearShow = true
  },
  methods: {
    handleExport() {
      this.$nextTick(() => {
        this.$refs['glassYear'].handleExport()
        this.$refs['proYear'].handleExport()
      })
    },
    search() {
      this.$nextTick(() => {
        this.$refs['glassYear'].getDataList()
        this.$refs['proYear'].getDataList()
      })
    },
    changeTime(val) {
			if(val) {
					// let timeStamp = val.getTime(); //标准时间转为时间戳，毫秒级别
        this.endTimeStamp = this.timeFun(new Date(val.getFullYear(),11, 31, 7, 0, 0).getTime()); //开始时间
        this.startTimeStamp = this.timeFun(new Date(val.getFullYear(), 0, 1, 7, 0, 1).getTime()); //结束时间
        this.listQuery.reportTime[0] = parseTime(new Date(val.getFullYear(), 0, 1, 7, 0, 1).getTime()) //+ ' 00:00:00' //new Date(this.startTimeStamp + ' 00:00:00').getTime() / 1000
        this.listQuery.reportTime[1] = parseTime(new Date(val.getFullYear(), 11, 31, 7, 0, 0).getTime()) //+ ' 23:59:59' //new Date(this.endTimeStamp + ' 23:59:59').getTime() / 1000
			} else {
					this.listQuery.reportTime = []
			}
		},
    getCurrentYearFirst() {
      let date = new Date();
      date.setDate(1);
      date.setMonth(0);
      this.reportTime = date;
      this.startTimeStamp = this.timeFun(new Date(new Date().getFullYear(), 0, 1,7,0,1).getTime()); //开始时间
      this.endTimeStamp = this.timeFun(new Date(new Date().getFullYear(), 11, 31, 7, 0, 0).getTime()); //结束时间
      this.listQuery.reportTime[0] = parseTime(new Date(new Date().getFullYear(), 0, 1, 7, 0, 1).getTime()) //+ ' 00:00:00' //new Date(this.startTimeStamp + ' 00:00:00').getTime() / 1000
      this.listQuery.reportTime[1] = parseTime(new Date(new Date().getFullYear(), 11, 31, 7, 0, 0).getTime()) //+ ' 23:59:59' //new Date(this.endTimeStamp + ' 23:59:59').getTime() / 100
    },
    //时间戳转为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>
