<template>
  <div class="container-accountability managementList">
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-row>
        <el-col :span="8">
          <el-form-item label="考核年度">
            <el-select  class="wdh" v-model="formInline.year" placeholder="年度考核目标任务:" >
              <el-option :key="item.index" :label="item" :value="item" v-for="item in dateyear"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item>
            <el-button type="primary" class="outButton" icon="el-icon-search" @click="search">查询</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row style="height: 60px;">
      <el-col :span="2">
        <el-button type="primary" class="outButton" @click="handleSubmit" :disabled="submitButton" >提交</el-button>
      </el-col>
      <el-col :span="2">
        <el-button type="primary" class="outButton" @click="theImport">导入</el-button>
      </el-col>
      <el-col :span="2">
        <el-button type="primary" class="outButton" @click="excelDownload" >下载模板</el-button>
      </el-col>
    </el-row>
    &nbsp;&nbsp;<span style="color: red">{{weightMessage}}</span>
    <el-row>
      <el-col :span="24">
        <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="考核年度" width="120" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.YEAR}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="考核任务" width="140" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.TASK_NAME}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="分值" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.TOTAL_SCORE}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="自评部门" width="120" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.ZPBM}}</span>
            </template>
          </el-table-column>

          <el-table-column align="center" label="自评评分" width="120" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.ZPBM_SCORE}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="牵头部门" width="120" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.QTBM}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="牵头部门评分" width="140" sortable :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.QTBM_SCORE}}</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="180">
            <template slot-scope="scope">
              <el-tooltip class="item" effect="light" content="查看" placement="top">
                <el-button
                  type="primary"
                  size="small"
                  icon="el-icon-zoom-in"
                  class="button"
                  @click.stop="handleSee(scope.row)">
                </el-button>
              </el-tooltip>
              <el-tooltip class="item" effect="light" content="编辑" placement="top">
                <el-button
                  v-if="scope.row.STATUS==2"
                  type="primary"
                  size="small"
                  class="difStateEditBtn"
                  icon="el-icon-news"
                  @click.stop="handleModify(scope.row)">
                </el-button>
              </el-tooltip>
               <el-tooltip class="item" effect="light" content="录入" placement="top">
                <el-button
                  v-if="scope.row.STATUS==1"
                  type="primary"
                  size="small"
                  class="difStateEditBtn"
                  icon="el-icon-news"
                  @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>

    <el-dialog
      title="上传excel"
      :visible.sync="showExcelUplod"
      width="50%"
      :close-on-click-modal="false"
      >
      <el-form label-width="120px">
        <el-form-item>
          <el-upload
            action
            accept=".xls"
            :on-change="uploadFile"
            :auto-upload="false"
            :show-file-list="true"
            :file-list="excelFileList"
            >
            <el-button slot="trigger" size="small" type="primary">请选择上传文件</el-button>
          </el-upload>
        </el-form-item>
      </el-form>
              <span slot="footer" class="dialog-footer">
                 <el-button type="primary" class="outButton" @click="excelUplodQx()">取 消</el-button>
              </span>
    </el-dialog>



  </div>
</template>
<script>
import * as cityEntry from "@/api/headResponsibility/cityEntry";
import * as management from "@/api/headResponsibility/management";
import * as scoringWeight from "@/api/headResponsibility/scoringWeight";
import {downloadExcel } from "@/api/index";
export default {
  data() {
    return {
      isSub:"",
      weightMessage:"",
      submitButton:true,
      showExcelUplod: false,
      excelFileList: [],
      weight:{},
      excelDownloadDataFile: `${downloadExcel}`,
      formInline: {
        year:"",
        source: "10"
      },
      dateyear: [],
      tableList: [],
      loading: true,
      listLoading: false,
      paginationShow: true,
      page: {
        page: 1,
        size: 10,
        total: 0
      }
    };
  },
  methods: {


    /**
     * 提交按钮----查询当前盟市是是否可以统一提交
     */
    isSubmit(year,score){
        cityEntry.respScoreInputFindByIsSubmit(year,score).then(res=>{
          if (res.infoCode==200) {
            if(res.data=='yes'){
              this.submitButton=false
            }else{
              this.submitButton=true
            }
        }
      })
    },


    /**
     * 查询按钮
     */
    search() {
      this.loading=true
      this.paginationShow = false;
      this.handleCurrentChange(1);
      this.$nextTick(function() {
        this.paginationShow = true;
      });
    },
    /**
     * 提交按钮  managementSave
     */
    handleSubmit(){
      cityEntry.respScoreInputUpdateCitySubmit(this.formInline.year).then(res=>{
        if (res.infoCode==200) {
          this.$message.success(res.msg)
        this.getTabList();
        } else {
          this.$message.error(res.msg)
        }
      })
    },


    /**
     * 下载模板
     */
    excelDownload(){
      const data = JSON.parse(window.localStorage.getItem("userInfo"));
      window.location.href=this.excelDownloadDataFile+"/exportCityExcel?year="+this.formInline.year+"&areaCode="+data.areaCode;
    },

    /**
     * 导入按钮
     */
    theImport(){
      this.showExcelUplod=true;
      this.excelFileList = [];
    },

    /**
     * 取消
     */
    excelUplodQx() {
      this.showExcelUplod = false;
      this.excelFileList = [];
    },

    /**
     *粮食安全行政首长责任制--盟市评分结果录入---导入评分表
     */
    uploadFile(item){
        const formData = new FormData()
        formData.append('file', item.raw)
        cityEntry.respScoreInputDownloadCityExcel(formData).then(res=>{
          if (res.infoCode==200) {
          this.$message.success("上传成功")
          this.getTabList();
        } else {
          this.$message.error(res.msg)
        }
      })
    },


    /**
     * 表格查看按钮
     */
    handleSee(row) {
      //  isDisabled: 1 查询  2 编辑
        this.$router.push({
            path:"/supervisionCheck/headResponsibility/cityEntrySee",
            query:{
                id:row.ID,
                year:row.YEAR,
                isDisabled:"1"
            }
        })
    },
    /**
     * 表格录入按钮
     */
    handleModify(row){
      if(row.result=='yes'){
        //  isDisabled: 1 查询  2 编辑
        this.$router.push({
          path:"/supervisionCheck/headResponsibility/cityEntryAdd",
          query:{
            id:row.ID,
          }
        })
      }else{
        this.$message({
          message: "当前考核任务时间,不在盟市考核起止时间之内!",
          type: 'info'
        });
      }


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

    /**
     * 分页第几页
     */
    handleCurrentChange(val) {
      this.page.page = val;
      this.getTabList()
    },
    /**
     * 表格数据查询接口
     */
    getTabList() {
      cityEntry.respScoreInputFindByPage(this.formInline, this.page)
        .then(res => {
            this.loading = false;
            if (res.infoCode==200) {
                this.tableList=res.data.list
                this.page.total=res.data.total
               this.isSubmit(this.formInline.year,"10");
            } else {

            }
            // console.log(res)
        });
        this.findByYearAndStatus(this.formInline.year,1);
    },





      /**
       * 查询可选年分
       */
      findByYear(type){
        management.responsibilityFindByYear(type).then(res => {
          if (res.infoCode == 200) {
          this.dateyear = res.data;
          if(this.dateyear !=null){
            this.formInline.year= this.dateyear[0]
            this.search();

          }
        }
      });
      },


      /**
       * 据年分和状态---考核评分权重--对象
       */
      findByYearAndStatus(year,status){
        scoringWeight.findByYearAndStatus(year,status).then(res => {
          if (res.infoCode == 200) {
          this.weight = res.data;
          // console.log("this.weight",this.weight);
            var arrStart =  this.weight.zsStartTime.split("T");
            var arrEnd =  this.weight.zsEndTime.split("T");
            var start=arrStart[0];
            var end=arrEnd[0];
            this.weightMessage="盟市考核起止时间:"+start+"---"+end;
        }
      });
      }







  },
  created() {
  this.findByYear('page');

  }
};
</script>
<style lang="scss">
.managementList {
}
</style>
