<template>
  <div id="">
    <a-layout>
      <a-layout-sider theme="light" width="318px" style="border-right:2px solid #d5d5ff;float:left;overflow: auto;" :style="{ 'max-height': testHeight + 'px', 'height': testHeight + 'px' }">
        <a-tree
          :tree-data="treeData"
          @select="handleCheckChange"
          :fieldNames="{ children: 'children', title: 'pnm', key: 'pnm' }"
          :auto-expand-parent="true"
          :expandedKeys.sync="expandedKeys"
          ref="PTTab_OrgTree"
          style="height:100%;">
          <template #custom="item">
            <span style="float:left;">{{ item.pnm }}</span>
            <div style="float:right;display: flex;justify-content: flex-end;align-items: center;width:50%;">
              <span style="color:blue;width:80px;"></span>
            </div>
          </template>
        </a-tree>
      </a-layout-sider>
      <a-layout-content>
        <a-row style="padding: 5px 20px; display: flex; align-items: center;">
          <span style="white-space: nowrap;">督查事项：</span>
          <a-select v-model:value="prjType" show-search :filter-option="filterOption" placeholder="请选择" allow-clear style="width: 200px; min-width: 200px;">
            <a-select-option v-for="item in pTypeList" :key="item.dictTypeNum" :value="item.dictTypeNum">{{ item.nm }}</a-select-option>
          </a-select>
        </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="groupName" v-model="batchGroupName">
            <input type="hidden" name="ptype" v-model="prjType">
            <input type="hidden" name="orgid" v-model="orgid">
            <input type="hidden" name="excelName" v-model="excelName">
          </form>
          <a-card :body-style="{ 'height': dxdcMainHeight + 'px', 'padding': '0' }">
            <div style="width: 100%;height: 100%;">
              <iframe
                ref="frameMain"
                id="frameMain"
                name="frameMain"
                src=""
                frameborder="0"
                width="100%"
                height="100%"
                style="overflow: auto"></iframe>
            </div>
          </a-card>
        </a-row>
      </a-layout-content>
    </a-layout>
  </div>
</template>

<script>
import request from '../../utils/gw_ajax_request';
export default {
  data() {
    return {
      userid: localStorage.getItem('persId'),
      orgid: localStorage.getItem('currentOrgId'),
      treeData: [],
      expandedKeys: [],
      treeNodeArray: [],
      batchGroupName: '',
      batchName: '',
      prjType: undefined,
      pTypeList: [],
      testHeight: window.innerHeight - 130,
      reportSrc:
        '/modular-source/6ace62b8e2bb467d98286d260aebcef2/demo/reportJsp/reportJsp/showReport.jsp?rpx=zhdcgzcg_001.rpx',
      loading: true,
      dxdcMainHeight: window.innerHeight - 174,
      windowHeight: window.innerHeight - 220,
      windowWidth: window.innerWidth - 350,
      excelName: '综合督查工作成果',
    };
  },
  created() {
    this.getLeftTreeData();
    this.getPType();
  },
  methods: {
    getLeftTreeData() {
      this.expandedKeys = [];
      request
        .get('/dc/organization/base/getNewAllNode', {
          params: {
            userId: this.userId,
            orgType: '111',
          },
        })
        .then((res) => {
          this.treeData = [res.data];
          this.expandedKeys.push(res.data.pnm);
        });
    },
    handleCheckChange(data, checked) {
      this.prjType = undefined;
      this.treeNodeArray = data;
      if (checked.node.dataRef.levels == '0') {
        this.batchGroupName = '';
        this.batchName = '';
      } else if (checked.node.dataRef.levels == '1') {
        this.batchGroupName = '';
        this.batchName = checked.node.dataRef.pnm;
      } else {
        this.batchGroupName = checked.node.dataRef.pnm;
        this.batchName = checked.node.dataRef.batchName;
      }
      this.getPType();
    },
    getPType() {
      const params = {
        orgType: '111',
        batchName: this.batchName,
        pnm: this.batchGroupName,
      };
      request
        .post(
          '/bis/insp/BisInspProblemRelation/getProblemHandlingDropDownBox',
          params,
        )
        .then((res) => {
          if (res.success) {
            this.pTypeList = res.data;
            this.searchExecl();
          } else {
            this.$message.error(res.message);
          }
        });
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    // 获取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;
        };
      });
    },
  },
  watch: {
    prjType(n, o) {
      this.searchExecl();
    },
  },
};
</script>

<style lang='less' scoped>
/deep/ .ant-layout-sider,
/deep/ .ant-layout-content {
  background: #fff;
}

/deep/ .ant-select {
  width: 200px;
}
</style>
