<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.sskdmc}}</div>
        <div style="flex: 1;text-align: center;">填报期数：{{formInline.period}}</div>
        <div style="flex: 1;text-align: right;">
          <span>单位：吨/元</span>
        </div>
      </div>
	  <div style="width: 300px">
	    <div id="tjbtgrainsubsidy"></div>
	  </div>
      <table>
        <thead>
          <tr>
            <th rowspan="2">
              项目
            </th>
            <th>年初</th>
            <th>上月</th>
            <th>补贴标准</th>
            <th>本月</th>
            <th>本年累计</th>
            <th>本年累计</th>
            <th>期末</th>
          </tr>
          <tr>
            <td>未补金额</td>
            <td>期末库存</td>
            <td>(元/吨·年)</td>
            <td colspan='1'>应补金额</td>
            <td colspan='1'>应补</td>
            <td colspan='1'>已补</td>
            <td colspan='1'>未补金额</td>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(item,index) in formInline.detailList">
            <td>
              {{item.pzmc}}
            </td>
            <td>
              <span v-if="type != 'xg' || index ==0 || index ==7 || index ==10">
                {{String(item.ncwb).indexOf(".") > -1
                ? Number(item.ncwb).toFixed(2)
                : item.ncwb}}</span>
              <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.ncwb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/,
                     message: '请输入数字,最多保留两位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.ncwb" @change="gcinputnum(index,'ncwb')" placeholder="请输入">
                </el-input>
              </el-form-item>
            </td>
            <td>
              <span>
                {{String(item.syyqmkc).indexOf(".") > -1
                ? Number(item.syyqmkc).toFixed(3)
                : item.syyqmkc}}</span>
              <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.syyqmkc'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
                     message: '请输入数字,最多保留三位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.syyqmkc" @change="gcinputnum(index,'syyqmkc')" placeholder="请输入">
                </el-input>
              </el-form-item> -->
            </td>
            <td>
              <span>
                {{item.btbz}}</span>
             <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.btbz'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
                     message: '请输入数字,最多保留三位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.btbz" @change="gcinputnum(index,'btbz')" placeholder="请输入">
                </el-input>
              </el-form-item> -->
            </td>
            <td>
              <span v-if="type != 'xg' || index ==0 || index ==7 || index ==10">
                {{String(item.byyb).indexOf(".") > -1
                ? Number(item.byyb).toFixed(2)
                : item.byyb}}</span>
              <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.byyb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/,
                     message: '请输入数字,最多保留两位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.byyb" @change="gcinputnum(index,'byyb')" placeholder="请输入">
                </el-input>
              </el-form-item>
            </td>
            <td>
              <span v-if="type != 'xg' || index ==0 || index ==7 || index ==10">
                {{String(item.bnljygb).indexOf(".") > -1
                ? Number(item.bnljygb).toFixed(2)
                : item.bnljygb}}</span>
              <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.bnljygb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/,
                     message: '请输入数字,最多保留两位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.bnljygb" @change="gcinputnum(index,'bnljygb')" placeholder="请输入">
                </el-input>
              </el-form-item>
            </td>
            <td>
              <span v-if="type != 'xg' || index ==0 || index ==7 || index ==10">
                {{String(item.bnljyb).indexOf(".") > -1
                ? Number(item.bnljyb).toFixed(2)
                : item.bnljyb}}</span>
              <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.bnljyb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/,
                     message: '请输入数字,最多保留两位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.bnljyb" @change="gcinputnum(index,'bnljyb')" placeholder="请输入">
                </el-input>
              </el-form-item>
            </td>
            <td>
              <span v-if="type != 'xg' || index ==0 || index ==7 || index ==10">
                {{String(item.qmwb).indexOf(".") > -1
                ? Number(item.qmwb).toFixed(2)
                : item.qmwb}}</span>
              <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.qmwb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/,
                     message: '请输入数字,最多保留两位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.qmwb" @change="gcinputnum(index,'qmwb')" placeholder="请输入">
                </el-input>
              </el-form-item>
            </td>
          </tr>
        </tbody>
      </table>
	  <div style="margin-top: 20px;"></div>
	  <div class="areawidth" v-if="formInline.remark">
	     <el-form-item label="备注" label-width="80px">
	     <el-input :readonly="type != 'xg'" type="textarea" :rows="2" clearable v-model="formInline.remark" placeholder="请输入"></el-input>
	     </el-form-item>
	   </div>
      <el-row style="margin-top: 10px;">
		<el-col :span="6">
			<el-form-item label="单位负责人">
				<span>{{formInline.leader}}</span>
			</el-form-item>
		</el-col>
		<el-col :span="6">
        <el-form-item label="审核">
			<span>{{formInline.auditor}}</span>
        </el-form-item>
		</el-col>
		<el-col :span="6">
        <el-form-item label="制表">
			<span>{{formInline.reporter}}</span>	
        </el-form-item>
		</el-col>
		<el-col :span="6">
        <el-form-item label="填报日期">
			<span>{{formInline.reportDate}}</span>
        </el-form-item>
		</el-col>
      </el-row>
	  <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="type != 'js'" 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.receiveDate"
		 				 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','3')" size="small" class="iconfont icongaizhang"
       	v-if="type != 'ck' && (formInline.status == '91000202' || formInline.status == '91000200')">提交</el-button>
      		<!-- <el-button type="primary" :loading="stateLoading" @click="saveZc('','formInline','3')" size="small" class="iconfont iconbohui"
      			v-if="type != 'ck' && (formInline.status == '91000202' || formInline.status == '91000200')">驳回</el-button> -->
        <el-button type="primary" @click="saveZc('','formInline','4')" size="small" class="iconfont iconbohui"
        	v-if="type != 'ck' && formInline.status == '91000201' ">撤销</el-button>
		<el-button @click="cancelClick" type="primary"
          icon="iconfont iconfanhui">返回</el-button>
      </div>
    </el-form>
    <!-- <sealDialog ref="sealDialog" sealId="btgrainsubsidy" @sealTodo="sealTodo" @sealError="sealError"></sealDialog> -->
  </div>
</template>

<script>
  import {
    storageSubsidyInfo,
    storageSubsidyUpdate,
  } from "@/api/cwbb/index";
  import {dateFormat} from '@/utils/index'
  // import sealDialog from "@/components/sealDialog/index.vue";
  export default {
    // components:{
    //   sealDialog
    // },
    data() {
      return {
        stateLoading:false,
        type: this.$route.query.type,
        formInline: {
			receiveDate:'',
			receiveOpinion:'',
			receiver:'',
			receiveStatus:1,
          dataType: '1',
          leader: '',
          auditor: '',
          reporter: '',
          reportDate: '',
          orgCode: sessionStorage.getItem("orgCode"),
          period: '',
          sskdbm: sessionStorage.getItem("tyshxydm") + '001',
          sskdmc: sessionStorage.getItem("orgName"),
          operationType: '',
		  summaryStatus:0,
		  isDelete:0,
          detailList: [
          ],
        }
      }
    },
    created() {
		console.log(this.$route.query.id,'uyu========')
      if (this.$route.query.id) {
        this.getJxcInfo()
      } else {
        // this.GetPeriod()
      }

    },
    methods: {
      cancelClick() {
        this.$router.push({
          name: "receive",
          query: { active: 'bt',searchShowMoreBool:this.$route.query.searchShowMoreBool }
        });
      },
      saveZc(type, formName, shtype, sussInfo, errInfo) {
        console.log('66555-==============')
        this.shtype = shtype
        if (sussInfo == '盖章成功！' || shtype == 2) {
          this.formInline.signatureStatus = type
        } else {
          this.formInline.operationType = type
        }

        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.$route.query.id) {
              // console.log(this.formInline,'ooiyy7778-----')
              storageSubsidyUpdate(this.formInline, this.shtype).then(res => {
                if (res.infoCode == 200) {
                  this.$message({
                    message: "提交成功",
                    type: "success",
                  });
                  this.$router.push({
                    name: "receive",
                    query: { active: 'bt',searchShowMoreBool:this.$route.query.searchShowMoreBool }
                  });
                } else {
                  this.$message.error(res.msg);
                }
              })
            }
          }
        })

      },
      getJxcInfo() {
        var data = {
          ssId: this.$route.query.id
        }
        storageSubsidyInfo(data).then(res => {
          if (res.infoCode == 200) {
            this.formInline = res.data
			if(this.type == 'js'){
				// this.formInline.receiveOpinion=''
				this.formInline.receiveDate=dateFormat(new Date())
				this.formInline.receiver=sessionStorage.getItem("userName")
				this.formInline.receiveStatus=1
			}
            if (this.formInline.signature) {
              if (this.formInline.signature.indexOf("newSeal") == -1) {
                this.$nextTick(() => {
                  this.$ShowSeal("tjbtgrainsubsidy", 1);
                  this.$SetSealData(this.formInline.signature, 0, "lingdao", 1);
                });
              } else {
                this.$signatureOnload(
                  "tjbtgrainsubsidy",
                  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;
    }
  }

  .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>
  #tjbtgrainsubsidy {
    position: relative !important;
  }

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