<template>
  <div class="container-fluid">
    <div class="form form-inline">
      <div class="form-group">
        <label class="control-label">开始时间</label>
        <div class="form-group" style="margin-left: 10px;">
          <DateTime v-model="startDate" name="datetime" />
        </div>
      </div>
      <div class="form-group" style="margin-left: 10px;">
        <label class="control-label">结束时间</label>
        <div class="form-group" style="margin-left: 10px;">
          <DateTime v-model="endDate" name="datetime" />
        </div>
      </div>
      <button type="button" class="btn btn-primary" style="margin-left: 10px;" @click="excelReport()">
        生成报表
      </button>
    </div>
  </div>
</template>
<script>

export default {
  data: function () {
    return {
      processReportNo: null,
      previewExcelUrl: null,
      downloadExcelUrl: null,
      isExcelReport: false,
      startDate: null,
      endDate: null,
    };
  },

  watch: {
    '$route': function (to, from) {
      let processReportNo = to.params.processReportNo;
      if ((processReportNo != null && processReportNo != undefined)) {
        this.processReportNo = processReportNo;
        this.isExcelReport = false;
        this.startDate = null;
        this.endDate = null;
        this.previewExcelUrl = null;
        this.downloadExcelUrl = null;
      }
    },
  },

  mounted: function () {
    let processReportNo = this.$route.params.processReportNo;
    if (processReportNo != null) {
      this.processReportNo = processReportNo;
      this.isExcelReport = false;
      this.startDate = null;
      this.endDate = null;
      this.previewExcelUrl = null;
      this.downloadExcelUrl = null;
    }
  },
  methods: {

    /**
       * 加载excel报表
       */
    excelReport: function () {
      let _self = this;
      if (_self.startDate != null && _self.endDate != null) {
        let previewExcelUrl = '/static/x-spreadsheet/index.html?processReportNo=' + _self.processReportNo + '&startDate=' + _self.startDate + '&endDate=' + _self.endDate;
        _self.previewExcelUrl = previewExcelUrl;
        window.open(_self.previewExcelUrl);
      }
    },
  },
};
</script>

<style>
  .input-date {
    display: inherit;
  }
</style>