<template>
  <div id="evaluate-handle-situation" >

    <el-form size="small" :model="formData" inline>
      <el-form-item label="事项名称">
        <el-input

          v-model="formData.name"
          placeholder="事项名称">
        </el-input>
      </el-form-item>
      <el-form-item label="部门名称">
<!--        <el-select v-model="formData.myTotalEvaluate" placeholder="请选择">-->
<!--          <el-option-->
<!--            v-for="item in totalEvaluate"-->
<!--            :key="item.value"-->
<!--            :label="item.label"-->
<!--            :value="item.value">-->
<!--          </el-option>-->
<!--        </el-select>-->
        <el-input
            v-model="formData.unit"
            placeholder="部门名称">
        </el-input>
      </el-form-item>
      <el-form-item class="btn-i">

        <el-button class="role_button" role_button_code="dd87f7c3-1717-43fb-8247-33711a21726b" @click="onCommit">查询</el-button>
        <el-button class="role_button" role_button_code="1640beee-6e7f-4936-b423-f5f8afb93af9"  @click="downloadFile()">导出</el-button>
      </el-form-item>
    </el-form>
    <div class="tab-number">
      <div class="search_right">
        <span>共有</span>
        <span>{{totalCount}}</span>
        <span>条记录</span>
      </div>
    </div>
<!--    <div class="tab-area">-->
<!--      <tab-control :tab-id.sync="currentRepeatId" style-type="colorful" :data-arr="isRepeatTabArr" />-->
<!--    </div>-->
    <div class="table-area">
<!--      <my-table  :headers="evaluateHandleSituationTableHeader" :table-data="tableData" :has-commit="true" :has-fill="true">-->
<!--        <template #selectionBefore>-->
<!--          <el-table-column-->
<!--            type="selection"-->
<!--            width="55"-->
<!--          >-->
<!--          </el-table-column>-->

<!--        </template>-->
<!--        <template #commit="{data}">-->
<!--          <el-link class="mr-link" type="primary" @click="openFileModel(data,'commitSituation')">评价情况</el-link>-->
<!--        </template>-->
<!--        <template #fill="{data}">-->
<!--          <el-link class="mr-link" type="primary" @click="openFileModel(data,'changePlan')">填报</el-link>-->
<!--        </template>-->
<!--      </my-table>-->


      <el-table ref="Table"  :fit='true'
                :data="tableData" :height="tableHeight"     row-key="RN" :key="Math.random()"
                lazy
                :load="load"
                :tree-props="{children: 'children', hasChildren: 'hasChildren'}">
        <el-table-column
            type="selection"
            :selectable ='checkboxInit'
            width="55">
        </el-table-column>
        <el-table-column prop="MATTER_NAME" label="事项名称">
          <template slot-scope="scope">
            <span>{{scope.row.MATTER_NAME}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="UNIT_NAME" label="责任部门" width="350">
        </el-table-column>
        <el-table-column prop="CP_DATA_COUNT" label="差评次数" width="180">
        </el-table-column>
        <el-table-column prop="RECTIFICATION_NUM" label="整改次数" width="180">
        </el-table-column>
        <el-table-column prop="COOPERATION_DEPARTMENT" label="评价情况"  width="150">
          <template slot-scope="scope">
            <span v-if="scope.row.hasChildren"></span>
<!--            <span class="guide_button" v-if="!scope.row.hasChildren" :class="[scope.row.COOPERATION_DEPARTMENT == '0'?'show_disable':'']"-->
<!--                  type="primary"-->
<!--                  size="mini"-->
<!--                  @click="showDialog(scope.row.COOPERATION_DEPARTMENT,scope.row.NAME)">指南-->
<!--              </span>-->
            <el-link class="mr-link" v-if="!scope.row.hasChildren" type="primary" @click="openFileModel(scope.row,'commitSituation')">评价情况</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="COOPERATION_DEPARTMENT" label="整改填报"  width="150">
          <template slot-scope="scope">
            <span v-if="scope.row.hasChildren"></span>
<!--            <span class="guide_button" v-if="!scope.row.hasChildren" :class="[scope.row.COOPERATION_DEPARTMENT == '0'?'show_disable':'']"-->
<!--                  type="primary"-->
<!--                  size="mini"-->
<!--                  @click="showDialog(scope.row.COOPERATION_DEPARTMENT,scope.row.NAME)">指南-->
<!--              </span>-->
            <el-link class="mr-link" v-if="!scope.row.hasChildren" type="primary" @click="openFileModel(scope.row,'changePlan')">填报</el-link>
          </template>
        </el-table-column>
      </el-table>


    </div>
    <div class="page">
      <ele-pagination  @sizeOrPageChange="sizeOrPageChange"  :total-count="totalCount" :current-page="currentPage" :page-size="pageSize"/>
    </div>
    <event-handle-file-model :dialog-visible.sync="isEditModelShow" title="整改计划" :situationCode="detailSituationCode" :matterCode="detailMatterCode" :showType="showType"></event-handle-file-model>
<!--    整改计划的查看，审核-->
    <evant-handle-oper-model :operation-type="'find'" :dialog-visible.sync="isOperationModelShow" title="整改计划"></evant-handle-oper-model>
<!--  整改计划的model-->
    <plan-time-line-model  :dialog-visible.sync="isPlanModelShow" title="整改计划"></plan-time-line-model>

  </div>
</template>

<script>
import {allDepartment, evaluateHandleSituationTableHeader} from "@/views/units/local-data";
import ElePagination from "@/components/ele-paga/ElePagination";
import EventHandleFileModel from "@/views/evaluate/c-cpns/EventHandleFileModel";
import EvantHandleOperModel from "@/views/evaluate/c-cpns/EvantHandleOperModel";
import PlanTimeLineModel from "@/views/evaluate/c-cpns/PlanTimeLineModel";
import selectConfigModuleByRole from "@/role_button";

export default {
  name: "EventHandleSituation",
  components: {PlanTimeLineModel, EvantHandleOperModel, EventHandleFileModel, ElePagination,},
  data() {
    return {
      showType:'commitSituation',
      totalCount:0,
      tableHeight: 0,
      tableData:[],
      currentRepeatId:'',
      formData:{
        name:'',
        unit:'',
        myTotalEvaluate:''
      },
      currentPage:1,
      pageSize:10,
      isEditModelShow:false,
      isOperationModelShow:false,
      isPlanModelShow:false,

      detailSituationCode:'',
      detailMatterCode:''
    }
  },
  computed:{
    evaluateHandleSituationTableHeader(){
      return evaluateHandleSituationTableHeader
    },
    totalEvaluate() {
      return allDepartment
    },

  },
  mounted(){
    this.commit();
    selectConfigModuleByRole(this);
    this.$nextTick(function () {
      this.tableHeight = window.innerHeight - this.$refs.Table.$el.offsetTop - 100;
      // 监听窗口大小变化
      let ZJWself = this;
      window.onresize = function() {
        ZJWself.tableHeight = window.innerHeight - self.$refs.Table.$el.offsetTop - 100;
      }
    });
  },
  methods:{
    downloadFile(){
      let  MATTER_NAME = this.formData.name;
      let UNIT_NAME =  this.formData.unit;


      let url='http://10.81.66.9:9250/ywtb/export_YwtbEvaluateZgqkMatterPageList?1=1';

      if(MATTER_NAME!=''){
        url +='&MATTER_NAME='+MATTER_NAME
      }
      if(UNIT_NAME!=''){
        url +='&UNIT_NAME='+UNIT_NAME
      }


      console.log(url)
      const a = document.createElement('a')
      a.href = url;
      a.style.display="none";
      //测试链接
      console.log(a.href)
      a.download = '差评回复--'+MATTER_NAME + '--' + UNIT_NAME;// 下载文件的名字
      document.body.appendChild(a)
      a.click();
      document.body.removeChild(a);
    },
    onCommit(){
      this.currentPage = 1;
      this.commit();
    },
    commit(){
      this.$request({
        url:'/ywtb/selectYwtbEvaluateZgqkMatterPageList',
        method:'post',
        data:{
          'MATTER_NAME':this.formData.name,
          'UNIT_NAME':this.formData.unit,
          'pageSize':this.pageSize,
          'pageIndex':this.currentPage
        }
      }).then(response => {
        let dataArr = response.data.msg[0].Rows
        this.totalCount =response.data.msg[0].TotalRowCount;
        if(dataArr.length > 0){
          this.tableData = [];
          for(let i=0;i<dataArr.length;i++){
            dataArr[i].hasChildren =true;
            this.tableData.push(dataArr[i]);
          }
        }else{
          this.tableData = [];
        }
      })
    },
    checkboxInit(row){
      if(row.hasChildren){
        return 1;
      }else{
        return 0;
      }
    },
    load(tree, treeNode, resolve) {
      this.dialog_item_title = tree.NAME;
      this.$request({
        url:'/ywtb/selectYwtbEvaluateZgqkAttributeByMatterCode',
        method:'post',
        data:{
          "MATTER_CODE":tree.MATTER_CODE
        }
      }).then(response => {
        for(let i=0;i<response.data.msg[0].Rows.length;i++){
          response.data.msg[0].Rows[i].RN =response.data.msg[0].Rows[i].MATTER_CODE;
        }
        resolve(response.data.msg[0].Rows);
      })

    },
    sizeOrPageChange(page,size){
      this.currentPage = page;
      this.pageSize = size;
      this.commit();
    },
    openFileModel(data,index) {
      console.log(data)
      this.detailSituationCode = data.MATTER_CODE;
      this.detailMatterCode = '1';
      this.showType =index;
      this.isEditModelShow = true;
    }
  },
}
</script>

<style scoped lang="scss">
#evaluate-handle-situation{
  width:100%;
  height:100%;
  .tab-number{
    width: 100%;
    display: flex;
    justify-content: flex-end;
    .search_right{
      width: 30%;
      height: 100%;
      color: #fff;
      font-size: 17px;
      display: flex;
      flex-direction: row;
      justify-content: flex-end;
    }
  }
  .table-area{
    width: 100%;
    height:85%;
  }
  .page{
    margin-top: 10px;
    text-align: right;
  }
}
</style>
