<template>
  <div class="container-accountability scoringWeightListPage">
    <el-form :model="formInline" :inline="true" class="search-bm-boder">
      <el-form-item label="考核年度:">
        <el-date-picker
                type="year"
                v-model="formInline.khnd"
                class="inputCompatible"
                value-format="yyyy"
                placeholder="请选择考核年度"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <div class="search-button">
          <span class="search-line"></span>
          <el-button type="primary" size="small" class="iconfont iconchaxun" @click="search">查询</el-button>
          <el-button type="primary" size="small" class="iconfont iconzhongzhi" @click="reset">重置</el-button>
        </div>
      </el-form-item>
    </el-form>
    <el-row>
      <el-col :span="24">
        <el-table
          :data="tableList"
          v-loading="loading"
          border
          stripe
          highlight-current-row
        >
          <el-table-column align="center" label="序号" width="60">
            <template slot-scope="scope">
              <span>{{scope.$index+1}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="考核年度" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.khnd}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="考核汇总表" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.khzmc}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="发布时间" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.fbsj}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="状态" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.zt}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="light" content="查看" placement="top">
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont iconchakan2 operate_show_btn"
                  @click.stop="handleSee(scope.row,'CK')"
                ></el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="盖章" placement="top" 
			  v-if="buttonNameList.indexOf('盖章') > -1 && (scope.row.zt == '待盖章' || scope.row.zt == '市监督检查处驳回')">
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont icongaizhang operate_edit_btn"
                  @click.stop="handleSee(scope.row,'GZ')">
                </el-button>
              </el-tooltip>
			  <el-tooltip class="item" effect="light" content="填写意见" placement="top" 
			  v-if="buttonNameList.indexOf('填写意见') > -1 && scope.row.zt == '市监督检查处意见'">
			    <el-button
			      type="primary"
			      size="small"
			      class="iconfont iconxiugai1 operate_edit_btn"
			      @click.stop="handleSee(scope.row,'YJ')">
			    </el-button>
			  </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <div class="pag-right clearFix">
          <el-pagination
            class="right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="page.pageNum"
            :page-sizes="[10,20,30,50]"
            :page-size="page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page.total"
          ></el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import { authorityControl } from "@/api/login/login"; 
import {getKhhzbPage} from "@/api/evaluationMan/index";
export default {
  data() {
    return {
      formInline: {
        khnd:'',
      },
      dateyear: [],
      tableList: [],
      loading: true,
      listLoading: false,
      page: {
        pageNum: 1,
        pageSize: 10,
        total: 0
      },
      buttonNameList: []
    };
  },
  methods: {
    getButtonList(menuCode,userCode) {
      let codeData = {
          resourceCode:menuCode,
          userId:userCode,
      }
      authorityControl(codeData).then(res => {
         res.data.forEach(item => {
             this.buttonNameList.push(item.resourceName)
console.log(this.buttonNameList,'jhfss=========')
         })
      })
    },
    /**
     * 查询按钮
     */
    search(type) {
      this.loading=true
      // this.handleCurrentChange(1);
      this.getTabList(type)
    },
    reset() {
      this.formInline = {
        khnd:"",
      }
      this.search()
    },
    /**
     * 表格查看按钮
     */
    handleSee(row,type) {
        this.$router.push({
            path:"/accountability/summaryManage/detail",
            query:{
                id:row.id,
				type:type,
				pfbmc:row.khzmc,
				khnd:row.khnd,
				zt:row.zt
            }
        })
    },

    /**
     * 分页大小
     */
    handleSizeChange(val) {
      this.page.pageSize = val;
      this.getTabList()
    },

    /**
     * 分页第几页
     */
    handleCurrentChange(val) {
      this.page.pageNum = val;
      this.getTabList()
    },
    /**
     * 区级评价List
     */
    getTabList(type) {
      if (type != "start") {//非初始化调用：查询、分页
          sessionStorage.setItem('searchData', JSON.stringify(this.formInline))
          sessionStorage.setItem('pageData', JSON.stringify(this.page))
      } else {//初始化分两种情况，详情页等返回后的初始化，以及第一次进入此菜单的初始化
          if(JSON.parse(sessionStorage.getItem('searchData'))){//详情页返回后，将对应查询条件和分页的字段赋值，页面回显参数
              this.formInline = JSON.parse(sessionStorage.getItem('searchData'))
              this.page = JSON.parse(sessionStorage.getItem('pageData'))
          }else {//第一次进去此菜单时，保存上方默认的data
              sessionStorage.setItem('searchData', JSON.stringify(this.formInline))
              sessionStorage.setItem('pageData', JSON.stringify(this.page))
          }
      }
	  var data={
		  ...this.formInline
	  }
      getKhhzbPage(this.formInline, this.page)
        .then(res => {
            this.loading = false;
            if (res.infoCode==200) {
                this.tableList=res.data.items
                this.page.total=res.data.total
            } else {
              this.$message({
                type: 'error',
                duration: 2000,
                message: res.msg
              })
            }
        });
    }
  },
  created() {
    this.getButtonList(sessionStorage.getItem("resourceCode"),sessionStorage.getItem("userCode")) 
    let date = new Date();
    this.year = date.getFullYear();
    for (var i = 0; i < 10; i++) {
      this.dateyear.push(this.year);
      this.year = this.year - 1;
    }
    // this.formInline.year= date.getFullYear()
    this.search('start')
    

  }
};
</script>
<style lang="scss">
.scoringWeightListPage {
  .el-select {
    width: 100%;
  }
  .titleUseStyle{
    // position: absolute;
    // top: 0;
    font-size: 14px;
    width: 100%;
    height: 30px;
    line-height: 30px;
    color: #fff;
    font-weight: 400;
    background: #3d62c1 !important;
    padding-left: 8px;
  }
}
</style>
