<template>
  <div class="container-accountability scoringWeightListPage">
    <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" 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 class="addBtnBg">
        <el-button type="primary" size="small" class="iconfont iconxinzeng" @click="add">新增</el-button>
    </el-row>
    <el-row>
      <el-col :span="24">
         <!-- @row-click="tableRowClick" -->
        <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="考核年度" 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="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)"
                ></el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="编辑" placement="top" v-if="buttonNameList.indexOf('编辑') > -1">
                <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="buttonNameList.indexOf('发布') > -1 && scope.row.status != '1'">
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont iconfabu operate_issued_btn"
                  :disabled='scope.row.isDisabled'
                  @click="handleModify(scope.row,scope.$index)">
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="删除" placement="top" v-if="buttonNameList.indexOf('删除') > -1 && scope.row.status != '1'">
                <el-button
                  type="primary"
                  size="small"
                  class="iconfont iconshanchu operate_delete_btn"
                  @click.stop="handleDetail(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 { authorityControl } from "@/api/login/login"; 
import * as management from "@/api/headResponsibility/scoringWeight";
export default {
  data() {
    return {
      formInline: {
        year:"",
        source: "20"
      },
      dateyear: [],
      tableList: [],
      loading: true,
      listLoading: false,
      paginationShow: true,
      page: {
        page: 1,
        size: 10,
        total: 0
      },
      buttonNameList: []
    };
  },
  methods: {
    getButtonList(menuCode,userCode) {
      let codeData = {
          resourceCode:menuCode,
          userId:userCode,
      }
      authorityControl(codeData).then(res => {
         let buttonNameList = []
         res.data.forEach(item => {
             this.buttonNameList.push(item.resourceName)
         })
      })
    },
    /**
     * 查询按钮
     */
    search(type) {
      this.loading=true
      this.paginationShow = false;
      // this.handleCurrentChange(1);
      this.getTabList(type)
      this.$nextTick(function() {
        this.paginationShow = true;
      });
    },
    reset() {
      this.formInline = {
        year:"",
        source: "20"
      }
      this.search()
    },
    /**
     * 新增按钮
     */
    add(){
        this.$router.push({ path: "/accountability/scoringWeightAdd" });
    },

    /**
     * 修改按钮
     */
    handleUpdate(row){
      this.$router.push({
        path:"/accountability/scoringWeightEdit",
        query:{
          id:row.id,
        }
      })
    },

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

    /**
     * 表格删除按钮
     */
    handleDetail(row){
            this.$confirm("您确定要删除吗?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            }).then(() => {
              management.scoringWeightDelete(row.id).then(res => {
              if (res.infoCode == 200) {
              this.$message({
                message: "删除成功",
                type: "success",
                duration: 2000
              });
              this.getTabList();
            } else {
              this.$message({
                message: res.msg,
                type: "error",
                duration: 2000
              });
            }
          });
        })
    },

    /**
     * 表格发布按钮
     */
    handleModify(row,ind){
      this.tableList[ind].isDisabled = true 
       management.publish(row.id).then(res=>{
          if (res.infoCode==200) {
            this.$message({
                message: '发布成功',
                type: 'success',
                duration: 2000
            })
            this.search()
          } else {
            this.$message({
                message: res.msg,
                type: 'error',
                duration: 2000
            })
            this.tableList[ind].isDisabled = false 
          }
       })
    },

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

    /**
     * 分页第几页
     */
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTabList()
    },
    /**
     * 粮食安全行政首长责任制-----考核评分权重---核评分权重分页模糊查询信息
     */
    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))
          }
      }
      management.responScoringWeightFindByPage(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',
                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>
