<template>
  <div class="container-accountability managementList">
    <el-form :model="formInline" :inline="true" class="search-bm-boder">
      <el-form-item label="考核年度:">
        <!--        <el-select v-model="formInline.year" placeholder="请选择考核年度" clearable class="inputCompatible">-->
<!--          <el-option :key="item.index" :label="item" :value="item" v-for="item in dateyear"></el-option>-->
<!--        </el-select>-->
        <el-date-picker
                type="year"
                v-model="formInline.year"
                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" class="outButton" icon="el-icon-search" @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 style="height: 60px;">
      <el-col :span="3">
        <el-button type="primary" class="outButton" @click="add">新增</el-button>
      </el-col>
    </el-row> -->
    <el-row>
      <el-col :span="24">
        <!-- @row-click="tableRowClick" -->
        <el-table
          :data="tableList"
          v-loading="loading"
          border
          stripe
          highlight-current-row
          style="margin-top:0;"
        >
          <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="考核年度" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.YEAR}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="修改时间" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.UPDATE_TIME}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="发布时间" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.FB_TIME}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="状态" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.STATUS_VALUE}}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="115" 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)"
                ></el-button>
              </el-tooltip>
               <el-tooltip class="item" effect="light" content="编辑" placement="top" v-if="scope.row.STATUS != '2'">
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont iconxiugai1 operate_edit_btn"
                  @click.stop="handleUpdate(scope.row)">
                </el-button>
              </el-tooltip>
               <el-tooltip class="item" effect="light" content="发布" placement="top" v-if="scope.row.STATUS_VALUE != '已发布'">
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont iconfabu operate_issued_btn"
                  @click.stop="handleModify(scope.row)">
                </el-button>
              </el-tooltip>
            </template>
          </el-table-column>
        </el-table>
        <div v-show="!listLoading" class="pag-right clearFix">
          <el-pagination
            class="right"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="page.page"
            :page-sizes="[10,20,30,50]"
            :page-size="page.size"
            layout="total, sizes, prev, pager, next, jumper"
            v-if="paginationShow"
            :total="page.total"
          ></el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import * as management from "@/api/headResponsibility/taskReporting";
export default {
  data() {
    return {
      formInline: {
        year:"",
        areaCode: sessionStorage.getItem("areaCode")
      },
      dateyear: [],
      tableList: [{}],
      loading: false,
      listLoading: false,
      paginationShow: true,
      page: {
        page: 1,
        size: 10,
        total: 0
      }
    };
  },
  methods: {
    /**
     * 查询按钮
     */
    search() {
      this.loading=true
      this.paginationShow = false;
      this.handleCurrentChange(1);
      this.$nextTick(function() {
        this.paginationShow = true;
      });
    },
    reset() {
      this.formInline.year = ''
      this.search()
    },
    /**
     * 修改按钮
     */
    handleUpdate(row){
      this.$router.push({
        path:"/accountability/taskReportingAdd",
        query:{
          id:row.ID,
          type:"edit"
        }
      })
    },

    /**
     * 表格行内点击事件
     */
    tableRowClick(row, column, event) {
      if (event.label != "操作") {
        this.handleSee(row);
      }
    },
    /**
     * 表格查看按钮
     */
    handleSee(row) {
        this.$router.push({
            path:"/accountability/taskReportingAdd",
            query:{
                id:row.ID,
                type:"see"
            }
        })
    },

    /**
     * 表格发布按钮
     */
    handleModify(row){
       management.release(row.ID).then(res=>{
          if (res.infoCode==200) {
            this.$message({
              type: 'success',
              message: '发布成功',
              duration: 2000
            });
            this.search()
          } else {
            this.$message.error(res.msg)
          }
       })
    },

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

    /**
     * 分页第几页
     */
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTabList()
    },
    /**
     * 粮食安全行政首长责任制-----考核评分权重---核评分权重分页模糊查询信息
     */
    getTabList() {
      management.taskReportingList(this.formInline, this.page)
        .then(res => {
            this.loading = false;
            if (res.infoCode==200) {
                this.tableList=res.data.list
                this.page.total=res.data.total
            } else {
              this.$message({
                type: 'error',
                message: res.msg,
                duration: 2000
              })
            }
        });
    }
  },
  created() {
    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();

  }
};
</script>
<style lang="scss">
.managementList {
  .el-select {
    width: 100%;
  }
}

</style>
