<template>
  <div class="container-accountability scoringWeightListPage">
	  <div style="height: 40px;font-size: 18px;font-weight: 600;">
	  	<span>评分表名称：{{$route.query.pfbmc}}</span>
	  	<span style="float: right;margin-right: 10px;">考核年度：{{$route.query.khnd}}</span>
	  </div>
    <el-row>
      <el-col :span="24">
        <el-table
          :data="tableList"
		  :height="tableHeight"
		  ref="table"
          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">
				<el-button type="text" @click="CkqyzpbClick(scope.row)">{{scope.row.qymc}}</el-button>
              <!-- <span>{{scope.row.year}}</span> -->
            </template>
          </el-table-column>
          <el-table-column align="center" label="评价时间" :show-overflow-tooltip="true">
            <template slot-scope="scope">
              <span>{{scope.row.qjpjrq}}</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 align="center" label="区级评分" :show-overflow-tooltip="true">
		    <template slot-scope="scope">
			  <el-input v-if="$route.query.type == 'XG'" v-model="scope.row.qjpf" type="text"></el-input>
		      <span v-else>{{scope.row.qjpf}}</span>
		    </template>
		  </el-table-column>
        </el-table>
      </el-col>
	 <el-col style="text-align: center;margin-top: 20px;">
		  <span >
		  	<el-button
		  		v-if="$route.query.type == 'XG'"
		  		type="primary"
		  		size="small"
		  		class="iconfont icontijiao"
		  		@click="saveClick()"
		  		>保存</el-button>
		  	<el-button
		  		type="primary"
		  		size="small"
		  		class="iconfont iconfanhui"
		  		@click="returnList"
		  		>返回</el-button>
		  </span> 
	  </el-col>
    </el-row>
  </div>
</template>
<script>
import {getKhqybList,updateKhqybDetailBatch} from "@/api/evaluationMan/index";
export default {
  data() {
    return {
		tableHeight: 'calc(100vh - 360px)',
		pfbmc:'',
		khnd:'',
      formInline: {
        year:"",
        source: "20"
      },
      dateyear: [],
      tableList: [],
      loading: true,
      listLoading: false,
    };
  },
  methods: {
	  //查看企业自评表
	  CkqyzpbClick(row){
		this.$router.push({
		    path:"/accountability/component/qyzpb",
		    query:{
		        id:row.qyzplxid,
				orgCode:row.orgCode,
				khnd:this.$route.query.khnd,
				pfbmc:this.$route.query.pfbmc,
		    }
		})
	  },
	  //保存
	  saveClick(){
		  var obj={}
		  var arr=[]
		  this.tableList.forEach(item =>{
			  obj={
				  id:item.id,
				  qjpjrq:this.dateFormat(new Date()),
				  qjpjr:sessionStorage.getItem('userName'),
				  qjpf:item.qjpf,
			  }
			arr.push(obj) 
		  })
		  updateKhqybDetailBatch(arr).then(res =>{
			  if(res.infoCode == 200){
				this.$router.push({
				   path:"/accountability/districtEvaluation/index",
				})  
			  }else{
				this.$message({
				  type: 'error',
				  duration: 2000,
				  message: res.msg
				}) 
			  }
		  })
	  },
	  //返回
	  returnList(){
		 this.$router.push({
		    path:"/accountability/districtEvaluation/index",
		 }) 
	  },
   //获取详情
    getTabList(type) {
	  this.loading = false;
	  var data={
		  id:this.$route.query.id,
		  pageType:'2',
		  orgCode:sessionStorage.getItem('orgCode')
	  }
      getKhqybList(data)
        .then(res => {
            this.loading = false;
            if (res.infoCode==200) {
                this.tableList=res.data
                // this.page.total=res.data.total
            } else {
              this.$message({
                type: 'error',
                duration: 2000,
                message: res.msg
              })
            }
        });
    },
	dateFormat(date) {
	  // let date = new Date();
	  let year = date.getFullYear();
	  /* 在日期格式中，月份是从0开始的，因此要加0
	   * 使用三元表达式在小于10的前面加0，以达到格式统一  如 09:11:05
	   * */
	  let month =
	    date.getMonth() + 1 < 10
	      ? "0" + (date.getMonth() + 1)
	      : date.getMonth() + 1;
	  let day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
	  let hours =
	    date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
	  let minutes =
	    date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
	  let seconds =
	    date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
	  // 拼接
	  return year + "-" + month + "-" + day + ' ' + hours + ':' + minutes + ':' +seconds;
	},
	
  },
  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.getTabList('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>
