<template>
  <el-container>
    <el-main>
      <el-form :inline="true" size="small" class="demo-form-inline">
        <el-form-item label="选择阶段">
          <el-select style="width:180px;" v-model="addForm.bgType">
            <el-option :label="item.nowStep" :value="item.nowId" :key="index"
                       v-for="(item,index) in bgTypeList"/>
          </el-select>
        </el-form-item>
        <el-form-item label="选择年度">
          <el-select style="width:180px;" v-model="addForm.year" @change="changeYear">
            <el-option :lable="item.year" :value="item.year" :key="item.id" v-for="item in yearList"/>
          </el-select>
        </el-form-item>
        <el-form-item label="选择批次">
          <el-select style="width:180px;" v-model="addForm.batch" clearable @change="changeBatch">
              <el-option :label="item.label" :value="item.value"  v-for="item in pcList"/>
          </el-select>
        </el-form-item>
        <el-form-item label="选择项目">
          <el-select style="width:180px;" v-model="addForm.objId" clearable filterable>
            <el-option :label="item.label" :value="item.value"  v-for="item in proList"/>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-button type="primary" @click="search">确定</el-button>
        </el-form-item>
      </el-form>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane v-for="(item,index) in tabList" :key="index" :label="item.label" :lazy="true" :name="item.value">
          <div v-if="showReport" style="width:100%;padding:0 0;" :style="{'height' : tableHeight + 'px'}">
            <iframe :id="'iframe' + item.value"
                    :src="item.tableSrc + '&year=' + addForm.year + '&pcid=' + addForm.batch +'&objId=' + addForm.objId +'&bgType=' + addForm.bgType + '&currentRlcode='+currentRlcode+ '&isStage='+(addForm.bgType=='0'?'0':'1')+ '&width=1920&height=592'"
                    frameborder="0" width="100%" height="100%" style="overflow: auto"></iframe>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-main>
  </el-container>
</template>
<script>
  import summary from './summary'
  import request from "@/utils/gw_ajax_request"

  export default {
    props:['query'],
    computed: {
      currentOrgId(){
        return localStorage.getItem("currentOrgId") ? localStorage.getItem("currentOrgId") : ''
      }
    },
    components: {
      summary,
    },
    data() {
      return {
        tableHeight: window.innerHeight - 220,
        activeName: 'membership',
        showReport: false,
        tabList: [
          {label: '人员组成情况', value: 'membership', tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_ryzc_02.rpx'},
          {label: '稽察问题统计', value: 'problemSummary', tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_wttj_03_new.rpx'},
          {label: '专业稽察问题汇总', value: 'problemReport', tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_wttj_09.rpx'},
          {
            label: '严重问题汇总',
            value: 'seriousProblemReport',
            tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_yzwt_04_new.rpx'
          },
          {
            label: '较重问题汇总',
            value: 'heavierProblemReport',
            tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_jzwt_05_new.rpx'
          },
          {
            label: '一般问题汇总',
            value: 'commonProblemReport',
            tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_ybtj_06_new.rpx'
          },
          {
            label: '地区问题统计',
            value: 'allProblemCountReport',
            tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_wttj_08.rpx'
          },
          {
            label: '追责情况统计',
            value: 'AccountabilityReport',
            tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_zrdwwtsjzrqktj_07_new.rpx'
          },
          {label: '投资计划情况', value: 'summary', tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_qkhz_01.rpx'},
          {
              label: '复查项目整改情况一览表',
              value: 'jc_fc1',
              tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_fc/1-1'
          },
          {
              label: '复查专业整改情况一览表',
              value: 'jc_fc2',
              tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_fc/1-2'
          },
          {
              label: '复查等级整改情况一览表',
              value: 'jc_fc3',
              tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_fc/1-3'
          },
          {
              label: '复查市级整改情况一览表',
              value: 'jc_fc4',
              tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_fc/1-4'
          },
          // {label: '度汛问题汇总',value: 'floodReport', tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_qkhz_01.rpx'},
          // {label: '农民工工资问题汇总',value: 'salaryReport', tableSrc: '/demo/reportJsp/showReport.jsp?rpx=jc_qkhz_01.rpx'}
        ],
        addForm: {
          year: '',
          batch: '',
          objId:'',
          persId: localStorage.getItem("userid")
        },
        yearList: [],
        pcList: [],
        proList:[],
        bgType: '0',
        currentRlcode: localStorage.getItem('currentRlcode'),
        bgTypeList: [],
        addjcqkflag:false
      }
    },
    mounted() {
      this.$nextTick(() => {
        if(this.query.date){
            this.addForm.year = this.query.date;
            this.addForm.batch = this.query.batch;
            this.changeYear();
        }
        this.getYearPc();
        this.search();
      })
    },
    methods: {
      async getYearPc() {
        await request.post(`/tac/insp/year/list`, {}).then(res => {
          if (res.success) {
            this.$nextTick(() => {
              this.yearList = res.data;
              // this.addForm.year = this.yearList[0].year
              this.showReport = true
            })
          }
        })

        //省份对应稽查流程
        request.post(`/tac/province/plan/process/list`, {}).then(res => {

          if (res.success) {
            this.bgTypeList = res.data;
            let expertOpinion = {
              nowStep: '专家现场意见稿',
              nowId: '0'
            }
            this.bgTypeList.unshift(expertOpinion);//方法将把它的参数插入 arrayObject 的头部
          }
        })
      },
      search() {
        let activeItem;
        let addjcqk={
          label: '2020年稽察追责情况',
          value: 'jcqk',
          tableSrc: '/demo/reportJsp/showReport.jsp?rpx=zj2020jcqk.rpx'
        };

        if(this.currentOrgId == '036'&&this.addForm.year=='2020'&&!this.addjcqkflag){
          this.addjcqkflag=true;
          this.tabList.push(addjcqk);
        }
        this.tabList.forEach(item => {
          if (this.activeName === item.value) {
            activeItem = item;
          }
        });

        let iframe = document.getElementById('iframe' + activeItem.value);
        iframe.src = activeItem.tableSrc
          + '&year=' + this.addForm.year
          + '&pcid=' + this.addForm.batch
          + '&objId =' + this.addForm.objId
          + '&bgType=' + this.addForm.bgType
          + '&currentRlcode=' + this.currentRlcode
          + '&isStage=' + (this.addForm.bgType === '0' ? '0' : '1')
          + '&width=1920&height=592'
      },
      changeYear() {
        ;
        var _self = this;
        _self.pcList = [];
        _self.addForm.batch = "";
        _self.proList = [];
        _self.addForm.objId = "";
        var params = {
          year:this.addForm.year
        }
        request.post(`/tac/insp/year/batch/area/areasListByBatch`,params).then(res=>{
          if (res.success) {
            if (res != null && res.data.length > 0) {
              res.data.forEach(ele => {
                _self.pcList.push({value:ele.batch,label:ele.batch+ele.adName})
              })

            }
          } else {
          }
        })
      },
      changeBatch() {
          var _self = this;
          _self.proList = [];
          _self.addForm.objId = "";
          var params = {
              year:this.addForm.year,
              batch:this.addForm.batch
          }
          request.post(`/tac/insp/year/batch/obj/objsListByBatch`,params).then(res=>{
              if (res.success) {
                  if (res != null && res.data.length > 0) {
                      res.data.forEach(ele => {
                          _self.proList.push({value:ele.objId,label:ele.ojbNm})
                      })

                  }
              } else {
              }
          })
      },
      handleClick() {

      }
    },
    watch: {
      activeName(val) {
      }
    }
  }
</script>

<style  scope>

</style>
