<template>
  <div class="container-accountability scoringWeightListPage" id="protectedItems">
	<el-form :model="formInline" :inline="true"  ref="formInline" :rules="rule"> 
	  <div style="height: 40px;font-size: 18px;font-weight: 600;">
	  	<span>评分表名称：{{formInline.pfbmc}}</span>
	  	<span style="float: right;margin-right: 10px;">考核年度：{{formInline.khnd}}</span>
	  </div>
	  <div style="margin: 0 80px;top: 30px;" id="summaryManage"></div>
    <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.qymc}}</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.qyzp}}</el-button>
		    </template>
		  </el-table-column>
		  <el-table-column align="center" label="区粮办评价" :show-overflow-tooltip="true">
		    <template slot-scope="scope">
		      <span>{{scope.row.qjpf}}</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.taskName" type="text"></el-input> -->
		      <span>{{scope.row.cbgspf}}</span>
		    </template>
		  </el-table-column>
		  <el-table-column align="center" label="考评结果" :show-overflow-tooltip="true">
		     <template slot-scope="scope">
			  <span>{{scope.row.kpjg}}</span>
		    </template>
		  </el-table-column>
        </el-table>
      </el-col>
    </el-row>
		<div style="height: 40px;line-height: 40px;"></div>
	<div class="areawidth" v-if="$route.query.type == 'YJ' || ($route.query.type == 'CK' && $route.query.zt == '评分完成')">
	  <!-- <el-col :span='22'> -->
		<el-form-item label-width="80px" label='审查意见' prop="scyj"
		 :rules="[
		      { required:true, message: '审查意见不能为空', trigger: 'blur' }
		    ]">
		  <el-input
		    :disabled="$route.query.type == 'CK'"
		    type="textarea"
		    :autosize="{ minRows: 2, maxRows: 20 }"
		    maxlength="300"
		    v-model="formInline.scyj"
		    show-word-limit
		  ></el-input>
		</el-form-item>  
	  <!-- </el-col> -->
	</div>
	 <el-row v-if="$route.query.type == 'YJ' || ($route.query.type == 'CK' && $route.query.zt == '评分完成')">
		 <el-form-item label="审查人" prop="scr" label-width="80px">
			 <el-input :disabled="true" v-model="formInline.scr" type="text"></el-input>
		   <!-- <span>{{formInline.}}</span>  -->
		 </el-form-item>
		 <el-form-item label="审查日期" prop="scrq">
			 <el-date-picker
			   :disabled="true"
			   clearable
			   v-model="formInline.scrq"
			   type="date"
			   value-format="yyyy-MM-dd"
			 ></el-date-picker>
		   <!-- <span>{{formInline.ywdwqrr}}</span>  -->
		 </el-form-item>
	 </el-row>
	 <div style="text-align: center;height: 60px;">
	  <span >
		<el-button
		v-if="$route.query.type == 'GZ'"
		type="primary"
		size="small"
		:loading="stateLoading"
		class="iconfont icongaizhang"
		@click="stamp()"
		>盖章</el-button>
		<el-button
		v-if="$route.query.type == 'GZ'"
		type="primary"
		size="small"
		class="iconfont iconbohui"
		@click="signNotDo()"
		>驳回</el-button>
		<el-button
		v-if="$route.query.type == 'YJ'"
		type="primary"
		size="small"
		class="iconfont icontijiao"
		@click="saveClick('提交成功','提交失败','tj')"
		>提交</el-button>
		<el-button
		v-if="$route.query.type == 'YJ'"
		type="primary"
		size="small"
		class="iconfont iconbohui"
		@click="saveClick('驳回成功','驳回失败','bh')"
		>驳回</el-button>
		<el-button
		type="primary"
		size="small"
		class="iconfont iconfanhui"
		@click="returnList"
		>返回</el-button>
	  </span> 
	  </div>
	</el-form>
	  <sealDialog
	    ref="sealDialog"
	    sealId="summaryManage"
	    @sealTodo="sealTodo"
	    @sealError="sealError"
	  ></sealDialog>
  </div>
</template>
<script>
import {getKhhzbDetail,updateKhhzb} from "@/api/evaluationMan/index";
import sealDialog from "@/components/sealDialog/index.vue";
export default {
	components: {
	  sealDialog,
	},
  data() {
    return {
		stateLoading:false,
		kpjgOptions:[
			{
				name:'优秀',
				value:'优秀'
			},
			{
				name:'良好',
				value:'良好'
			},
			{
				name:'合格',
				value:'合格'
			},
			{
				name:'不合格',
				value:'不合格'
			}
		],
      formInline: {
        scr:sessionStorage.getItem('userName'),
		scrq:this.dateFormat(new Date()),
      },
	  qz:'',
      dateyear: [],
      tableList: [],
      loading: true,
      listLoading: false,
	  rule:{},
    };
  },
  methods: {
	  //查看企业自评表
	  CkqyzpbClick(row){
	  	this.$router.push({
	  	    path:"/accountability/component/qyzpb",
	  	    query:{
	  	        id:row.id,
	  			orgCode:row.orgCode,
	  			khnd:this.formInline.khnd,
	  			pfbmc:this.formInline.pfbmc,
	  	    }
	  	})
	  },
	  //保存
	  saveClick(suss,errors,status){
		  console.log(this.tableList,'hhhfhf---------')
		  if(this.$route.query.type == 'GZ'){
			 var data={
			  id:this.$route.query.id,
			  qz:this.qz,
			  zt:this.formInline.zt,
			  khzbid:this.formInline.zt== '盖章驳回' ? this.formInline.khzbid : undefined
			 } 
		  }else if(this.$route.query.type == 'YJ'){
			  var data={
			   id:this.$route.query.id,
			   ...this.formInline,
			   zt:status == 'tj' ? '评分完成' : '市监督检查处驳回'
			  } 
		  }
		  updateKhhzb(data).then(res =>{
			if (res.infoCode == 200) {
			  this.$message({
			    message: suss,
			    type: "success",
			  });
			  this.$router.go(-1);
			} else {
			  this.$message.error(errors);
			}
		  })
	  },
	  //返回
	  returnList(){
		 this.$router.push({
		    path:"/accountability/summaryManage/index",
		 }) 
	  },
	  //盖章
	  stamp() {
	    this.$confirm("是否确认盖章？", "提示", {
	      confirmButtonText: "确定",
	      cancelButtonText: "取消",
	      type: "warning",
	    })
	      .then(() => {
	        this.stateLoading = true;
	        this.$refs.sealDialog.getData();
	      })
	      .catch(() => {
	        this.$message({
	          type: "info",
	          message: "已取消盖章",
	        });
	      });
	  },
	  sealTodo(sealData) {
	    // new签章
	    var sh = `newSeal${sealData}`;
	    this.qz = sh;
	    this.formInline.zt = "市监督检查处意见";
	    this.saveClick("盖章成功！", "盖章失败！");
	  },
	  sealError() {
	    this.stateLoading = false;
	  },
	  //驳回
	  signNotDo() {
	    this.$confirm("是否确认驳回？", "提示", {
	      confirmButtonText: "确定",
	      cancelButtonText: "取消",
	      type: "warning",
	    })
	      .then(() => {
	        this.formInline.zt = "盖章驳回";
	        this.saveClick("签章驳回成功！", "签章驳回失败！");
	      })
	      .catch(() => {
	        this.$message({
	          type: "info",
	          message: "已取消驳回",
	        });
	      });
	  },
   //获取详情
    getTabList(type) {
	  this.loading = false;
	  var data={
		  id:this.$route.query.id
	  }
      getKhhzbDetail(data)
        .then(res => {
            this.loading = false;
            if (res.infoCode==200) {
                this.tableList=res.data.khqybList
				this.formInline=res.data
				this.qz=res.data.qz
				if(this.$route.query.type == 'YJ'){
					this.formInline.scr=sessionStorage.getItem('userName')
					this.formInline.scrq=this.dateFormat(new Date())
				}
				this.formInline.pfbmc=this.$route.query.pfbmc
				this.formInline.khnd=this.$route.query.khnd
				if (this.qz) {
				  if (this.qz.indexOf("newSeal") == -1) {
				    this.$nextTick(() => {
				      this.$ShowSeal("summaryManage", 1);
				      this.$SetSealData(this.qz, 0, "lingdao", 1);
				    });
				  } else {
				    this.$nextTick(() => {
				      this.$signatureOnload(
				        "summaryManage",
				        this.qz.substring(7)
				      );
				    });
				  }
				}
            } 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 scoped 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;
  }
}
.areawidth {
		width: 100%;
	}

.areawidth /deep/ .el-textarea__inner {
	width: 100% !important;
}

// .el-form--inline .el-form-item
.areawidth /deep/.el-form-item {
	width: 100% !important;
}

.areawidth /deep/ .el-form-item__content {
	width: 93% !important;
}
</style>
<style>
#summaryManage{
  position: relative;
}

#summaryManage > div {
  top: -80px !important;
  align-items: center;
  /* left: -25px !important; */
}
</style>
