<template>
  <div id="protectedItems" class="content-main">
    <el-form :inline="true" ref="formInline" :model="formInline" class="demo-form-inline recordsDetailsTable">
    <div style="text-align: center;font-size: 20px;font-weight: 600;margin-bottom: 20px;">大米按生产月份划分库存表</div>
	<div class="flexBox">
	  <div style="flex: 1">上报期数：{{ formInline.reportMonth }}</div>
      <div style="flex: 1;text-align: right;" >
        <span>单位：吨</span>
      </div>
    </div>
	<div style="width: 300px;">
		<div id="riceMonthReport"></div>
	</div>
	    <table>
	      <tbody>
	        <tr>
	          <th width="90px">生产年月</th>
	          <th v-for="(item, index) in formInline.riceReportDetailDOList" :key="index">
	            <span>{{item.produceMonth}}</span>
	          </th>
	        </tr>
	        <tr>
	          <td width="90px">
	            库存数量
	          </td>
	          <td v-for="(item, index) in formInline.riceReportDetailDOList" :key="index">
	            <span v-if="type != 'xg'">{{String(item.stockNum).indexOf(".") > -1
                      ? Number(item.stockNum).toFixed(3)
                      : item.stockNum}}</span>
	            <el-form-item
	            v-else
	              :key="item.key"
	              :prop="'riceReportDetailDOList.' + index + '.stockNum'"
	              :rules="[
	                {
	                  pattern: /^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
	                  message: '请输入数字,最多保留三位小数',
	                  trigger: 'blur',
	                },
	              ]"
	            >
	              <el-input
	                clearable
	                v-model="item.stockNum"
	                placeholder="请输入"
	              >
	              </el-input>
	            </el-form-item>
	          </td>
	        </tr>
	      </tbody>
	    </table>
	  <div style="margin-top: 20px;"></div>
		<!-- <el-row>
		 		  <el-form-item label="是否接收" label-width="80px">
		 		    <el-radio-group :disabled="type != 'js'" v-model="formInline.receiveStatus">
		 		      <el-radio :label="1">是</el-radio>
		 		      <el-radio :label="0">否</el-radio>
		 		    </el-radio-group>
		 		  </el-form-item>
		 </el-row> -->
<!-- 		 <div class="areawidth">
		    <el-form-item label="接收意见" label-width="80px">
		    <el-input :readonly="type != 'js'" type="textarea" :rows="2" clearable v-model="formInline.receiveOpinion" placeholder="请输入"></el-input>
		    </el-form-item>
		  </div> -->
		  <el-row>
		 		   <el-form-item label="接收人" label-width="80px">
		 		     <el-input clearable readonly v-model="formInline.receiver" placeholder="请输入"></el-input>
		 		   </el-form-item>
		 		   <el-form-item label="接收时间" label-width="80px">
		 			   <el-date-picker
		 			   :readonly="type != 'js'"
		 				 v-model="formInline.receiveTime"
		 				 type="date"
		 				 placeholder="选择时间"
		 				 format="yyyy-MM-dd"
		 				 value-format="yyyy-MM-dd">
		 				</el-date-picker>
		 		   </el-form-item>
		  </el-row> 
	  <!-- </div> -->

      <div style="text-align: center; margin-top: 20px">
       <el-button type="primary" :loading="stateLoading" @click="saveZc('','formInline','1')" size="small" class="iconfont icongaizhang"
       	v-if="type != 'ck' && (formInline.status == '90100000' || formInline.status == '91000200')">接收</el-button>
		<el-button type="primary" :loading="stateLoading" @click="saveZc('','formInline','2')" size="small" class="iconfont iconbohui"
			v-if="type != 'ck' && (formInline.status == '90100000' || formInline.status == '91000200')">驳回</el-button>
       <el-button type="primary" @click="saveZc('','formInline','4')" size="small" class="iconfont iconbohui"
       	v-if="type != 'ck' && formInline.status == '90200000' ">撤销</el-button>
        <el-button @click="cancelClick" type="primary"
          icon="iconfont iconfanhui">返回</el-button>
      </div>

    </el-form>
  </div>
</template>

<script>
  import {
    GetReportId,ReceiveReportSave,Receiverebut,riceReportRepeal
  } from "@/api/riceMonthReport/index";
  import {dateFormat} from '@/utils/index'
  export default{
    data() {
      return {
        stateLoading:false,
        type:this.$route.query.type,
        formInline:{
          orgCode:sessionStorage.getItem("orgCode"),
          orgName: sessionStorage.getItem("orgName"),
          riceReportDetailDOList:[
          ],
        }
      }

    },
    created(){
      if(this.$route.query.id){
        this.getJxcInfo()
      }else{
        // this.GetPeriod()
      }

    },
    methods:{
      cancelClick(){
        this.$router.push({
          name: "riceReceiveIndex",
        });
      },

      saveZc(type,formName,shtype,sussInfo,errInfo){
        console.log('66555-==============')
        this.shtype=shtype
		if(this.shtype == 4){
			var data={
				...this.formInline,
				receiveTime:'',
			}
		}else{
			var data={
				...this.formInline,
			}
		}
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(shtype == 1){
              // console.log(this.formInline,'ooiyy7778-----')
              ReceiveReportSave(data).then(res =>{
                if(res.infoCode == 200){
                  this.$message({
                    message: "接收成功",
                    type: "success",
                  });
                  this.$router.push({
                    name: "riceReceiveIndex",
                  });
                }else{
                  this.$message.error(res.msg);
                }
              })
            }else if(shtype == 2){
              // console.log(this.formInline,'ooiyy7778----+++++++++++++-')
              Receiverebut(data).then(res =>{
                if(res.infoCode == 200){
                  this.$message({
                    message: "驳回成功",
                    type: "success",
                  });
                  this.$router.push({
                    name: "riceReceiveIndex"
                  });
                }else{
                  this.$message.error(res.msg);
                }
              })
            }else if(shtype == 4){
				riceReportRepeal(data).then(res =>{
                if(res.infoCode == 200){
                  this.$message({
                    message: "撤销成功",
                    type: "success",
                  });
                  this.$router.push({
                    name: "riceReceiveIndex"
                  });
                }else{
                  this.$message.error(res.msg);
                }
              })
			}
          }
        })

      },
	    getJxcInfo() {
	      var data = {
	        riceReportId:this.$route.query.id,
	      };
	      GetReportId(data).then((res) => {
	        if (res.infoCode == 200) {
	          // this.formInline.id=this.$route.query.id
	          this.formInline = res.data;
			  if(this.type == 'js'){
			  	this.formInline.receiveTime=dateFormat(new Date())
			  	this.formInline.receiver=sessionStorage.getItem("userName")
			  }
			  this.formInline.riceReportId=this.$route.query.id
			  this.formInline.status=this.$route.query.status
			  this.formInline.reportMonth=this.$route.query.reportMonth
	          if (this.formInline.signature) {
	            if (this.formInline.signature.indexOf("newSeal") == -1) {
	              this.$nextTick(() => {
	                this.$ShowSeal("riceMonthReport", 1);
	                this.$SetSealData(this.formInline.signature, 0, "lingdao", 1);
	              });
	            } else {
	              this.$signatureOnload(
	                "riceMonthReport",
	                this.formInline.signature.substring(7)
	              );
	            }
	          }
	        }
	      });
	    },
    }
  }
</script>

<style scoped lang="scss">
.recordsDetailsTable{
    background-color: #fff;
    font-size: 14px;
    padding-bottom: 20px;
    table {
      width: 100%;
      margin-top: 10px;
      font-size: 14px;
    }
    .tdsize{
      font-size: 18px;
      font-weight: 700;
    }
    td,
    th {
      text-align: center;
      border: 1px solid #eaeaea;
      word-wrap: break-word;
      height: 40px;
    }
    span,
    .el-input,
    .el-textarea {
      font-size: 12px;
    }
}
.title-name{
    text-align: center;
    font-size: 22px;
    font-weight: 600;
  }
  .line-box{
    display: flex;
  }
  .flexBox{
    display: flex;
    line-height: 40px;
    height: 40px;
    // text-align: center;
  }
  .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>
  #riceMonthReport {
    position: relative !important;
  }

  #riceMonthReport > div {
    left: 0px !important;
    top: -40px !important;
  }
</style>
