<template>
  <div class="main">
    <a-row>
      <a-card :body-style="{ 'padding-top': '10px' }">
        <div class="block">
          <span>批次名称</span>
          <a-select v-model:value="batchName" show-search :filter-option="filterOption" placeholder="请选择" allow-clear>
            <a-select-option v-for="item in batchList" :key="item" :value="item">{{ item }}</a-select-option>
          </a-select>
          <a-button type="primary" icon="download" style="float: right;margin:0 5px" @click="exportExecl">导出</a-button>
          <a-button type="primary"  style="float: right;margin:0 5px" @click="searchExecl">查询</a-button>
        </div>
      </a-card>
    </a-row>
    <a-row>
      <form ref="formMain" id="formMain" target="frameMain" :action="reportSrc" method="post">
        <input type="hidden" name="width" v-model="windowWidth">
        <input type="hidden" name="height" v-model="windowHeight">
        <input type="hidden" name="batchName" v-model="batchName">
        <input type="hidden" name="excelName" v-model="excelName">
      </form>
      <a-card :body-style="{ 'height': dxdcMainHeight + 'px', 'padding': '0' }">
        <div style="width: 100%;height: 100%;" v-loading="loading">
          <iframe
            ref="frameMain"
            id="frameMain"
            name="frameMain"
            src=""
            frameborder="0"
            width="100%"
            height="100%"
            style="overflow: auto"></iframe>
        </div>
      </a-card>
    </a-row>
  </div>
</template>

<script>
import { getPersPlanType } from '../../api/duChaPlan';
import request from '../../utils/gw_ajax_request.js';
export default {
  data() {
    return {
      batchName: '',
      batchList: [],
      dxdcMainHeight: window.innerHeight - 154,
      windowHeight: window.innerHeight - 200,
      windowWidth: window.innerWidth - 350,
      reportSrc:
        '/modular-source/6ace62b8e2bb467d98286d260aebcef2/demo/reportJsp/reportJsp/showReport.jsp?rpx=batch_group.rpx',
      loading: true,
      excelName: '督查组发现问题统计',
    };
  },
  computed: {
    persId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  created() {
    this.getBatchList();
  },
  methods: {
    getBatchList() {
      this.batchList = [];
      this.batchName = '';
      request.get('/bis/insp/BisInspStatisAnal/getBatchList').then((res) => {
        if (res.data && res.data.length > 0) {
          this.batchList = res.data;
          this.batchName = res.data[0];
          this.searchExecl();
        }
      });
    },
    // 获取Excel数据
    searchExecl() {
      // console.log("搜索条件 - " + this.ids.length);
      this.$nextTick(() => {
        this.loading = true;
        // 使用form表单post提交，彻底解决参数值过长的问题
        this.$refs.formMain.submit();
        // 使用_this
        const _this = this;
        this.$refs.frameMain.onload = () => {
          _this.loading = false;
        };
      });
    },
    // 导出Excel数据
    exportExecl() {
      v = window.frames['frameMain'];
      v.report1_saveAsExcel();
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
  },
  watch: {
    ptype(n, o) {
      this.getLeftTreeData();
      this.searchExecl();
    },
    ids(n, o) {
      this.searchExecl();
    },
  },
};
</script>

<style lang='less' scoped>
.main {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
}
:deep(.ant-select) {
  width: 200px;
}
</style>
