
<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: center;">粮食性质：{{formInline.orgLevelName}}</div>
        <div style="flex: 1;text-align: right;">
          <!-- <span>单位：吨/元</span> -->
        </div>
      </div>
	  <div style="float: right;width: 300px;margin-top: -120px;">
	    <div id="tjbtgrainsubsidy"></div>
	  </div>
      <table>
        <thead>
          <tr>
            <th rowspan="3">
              序号
            </th>
			<th rowspan="3">
			  库点名称
			</th>
            <th colspan="9">储备粮</th>
			<th colspan="5">储备油</th>
            <th rowspan='2'>地址</th>
            <th rowspan='2'>联系人</th>
            <th rowspan='2'>电话</th>
          </tr>
		  <tr>
			<th rowspan="2">折合原粮合计</th>
			<th rowspan="2">小麦</th>
			<th rowspan="2">稻谷</th>
			<th colspan="3">面粉</th>
			<th colspan="3">大米</th>
			<th rowspan="2">合计</th>
			<th rowspan="2">大豆原油</th>
			<th colspan="3">成品油</th>
		  </tr>
		  <tr>
			<th>小计</th>
			<th>小包装</th>
			<th>罐存</th>
			<th>小计</th>
			<th>小包装</th>
			<th>罐存</th>
			<th>合计</th>
			<th>小包装</th>
			<th>罐存</th>
			<th></th>
			<th></th>
			<th></th>
		  </tr>
        </thead>
        <tbody>
          <tr v-for="(item,index) in formInline.reserveSizeReportVOList">
			<td><span style="width: 60px;">{{index+1}}</span></td>
           <!-- <td style="width: 120px;">
              <span style="width: 120px;">{{item.kdmc}}</span>
            </td> -->
			<td style="width: 120px;">
				<el-form-item style="width: 120px;" :key="item.key" :prop="'reserveSizeReportVOList.' + index + '.xm'">
				  {{item.kdmc}}
				</el-form-item>
			  
			</td>
            <td>
              <span>
                {{String(item.cblhj).indexOf(".") > -1
                ? Number(item.cblhj).toFixed(3)
                : item.cblhj}}</span>
             <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.ncwb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\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.xm).indexOf(".") > -1
                ? Number(item.xm).toFixed(3)
                : item.xm}}</span>
            </td>
            <td>
              <span>
                {{String(item.dg).indexOf(".") > -1
                ? Number(item.dg).toFixed(3)
                : item.dg}}</span>
            </td>
            <td>
              <span>
                {{String(item.mfhj).indexOf(".") > -1
                ? Number(item.mfhj).toFixed(3)
                : item.mfhj}}</span>
              <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.mfxj'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
                     message: '请输入数字,最多保留三位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.mfxj" @change="gcinputnum(index,'mfxj')" placeholder="请输入">
                </el-input>
              </el-form-item> -->
            </td>
            <td>
              <span>
                {{String(item.mfXbz).indexOf(".") > -1
                ? Number(item.mfXbz).toFixed(3)
                : item.mfXbz}}</span>
            </td>
            <td>
              <span>
                {{String(item.mfGc).indexOf(".") > -1
                ? Number(item.mfGc).toFixed(3)
                : item.mfGc}}</span>
            </td>
            <td>
              <span>
                {{String(item.dmhj).indexOf(".") > -1
                ? Number(item.dmhj).toFixed(3)
                : item.dmhj}}</span>
              <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.qmwb'" :rules="[
                   {
                     pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
                     message: '请输入数字,最多保留三位小数',
                     trigger: 'blur',
                   },
                 ]">
                <el-input clearable v-model="item.qmwb" @change="gcinputnum(index,'qmwb')" placeholder="请输入">
                </el-input>
              </el-form-item> -->
            </td>
			<td>
			  <span>
			    {{String(item.dmXbz).indexOf(".") > -1
			    ? Number(item.dmXbz).toFixed(3)
			    : item.dmXbz}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.dmGc).indexOf(".") > -1
			    ? Number(item.dmGc).toFixed(3)
			    : item.dmGc}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.cbyhj).indexOf(".") > -1
			    ? Number(item.cbyhj).toFixed(3)
			    : item.cbyhj}}</span>
			  <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.qmwb'" :rules="[
			       {
			         pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
			         message: '请输入数字,最多保留三位小数',
			         trigger: 'blur',
			       },
			     ]">
			    <el-input clearable v-model="item.qmwb" @change="gcinputnum(index,'qmwb')" placeholder="请输入">
			    </el-input>
			  </el-form-item> -->
			</td>
			<td>
			  <span>
			    {{String(item.ddyy).indexOf(".") > -1
			    ? Number(item.ddyy).toFixed(3)
			    : item.ddyy}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.cpyhj).indexOf(".") > -1
			    ? Number(item.cpyhj).toFixed(3)
			    : item.cpyhj}}</span>
			  <!-- <el-form-item v-else :key="item.key" :prop="'detailList.' + index + '.qmwb'" :rules="[
			       {
			         pattern:/^(-)?(0|[1-9]\d*)(\s|$|\.\d{1,3}\b)/,
			         message: '请输入数字,最多保留三位小数',
			         trigger: 'blur',
			       },
			     ]">
			    <el-input clearable v-model="item.qmwb" @change="gcinputnum(index,'qmwb')" placeholder="请输入">
			    </el-input>
			  </el-form-item> -->
			</td>
			<td>
			  <span>
			    {{String(item.cpyxbzhj).indexOf(".") > -1
			    ? Number(item.cpyxbzhj).toFixed(3)
			    : item.cpyxbzhj}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.cpyGc).indexOf(".") > -1
			    ? Number(item.cpyGc).toFixed(3)
			    : item.cpyGc}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.address).indexOf(".") > -1
			    ? Number(item.address).toFixed(3)
			    : item.address}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.linkman).indexOf(".") > -1
			    ? Number(item.linkman).toFixed(3)
			    : item.linkman}}</span>
			</td>
			<td>
			  <span>
			    {{String(item.phone).indexOf(".") > -1
			    ? Number(item.phone).toFixed(3)
			    : item.phone}}</span>
			</td>
          </tr>
        </tbody>
      </table>
	  <div class="flexBox">
	    <div style="flex: 1;">上报单位：{{formInline.orgName}}</div>
	    <div style="flex: 1;text-align: right;">
	      <span>上报时间：{{formInline.reportDay}}</span>
	    </div>
	  </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' && ($route.query.status == '90000001' || $route.query.status == '90100000')">接收</el-button>
      		<el-button type="primary" :loading="stateLoading" @click="saveZc('','formInline','3')" size="small" class="iconfont iconbohui"
      			v-if="type != 'ck' && ($route.query.status == '90000001' || $route.query.status == '90100000')">驳回</el-button>
		<el-button type="primary" @click="saveZc('','formInline','2')" size="small" class="iconfont iconbohui"
			v-if="type == 'cx' && $route.query.status == '90200000'">撤销</el-button>
		<el-button @click="cancelClick" type="primary"
          icon="iconfont iconfanhui">返回</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
  import {
	  reserveSizeGetId,
	  reserveSizeReport,
	  reserveSizeAcceptId
  } from "@/api/reserveScaleReport/index";
  import {dateFormat} from '@/utils/index'
  export default {
    data() {
      return {
        stateLoading:false,
        type: this.$route.query.type,
        formInline: {
          orgCode: sessionStorage.getItem("orgCode"),
          period: '',
          sskdbm: sessionStorage.getItem("tyshxydm") + '001',
          orgName: sessionStorage.getItem("orgName"),
          operationType: '',
		  summaryStatus:0,
		  isDelete:0,
          reserveSizeReportVOList: [
			  {
				  dg:0,
				  xm:0,
			  }
          ],
        }
      }
    },
    created() {
		const now = new Date();
		const year = now.getFullYear(); // 年
		// const month = now.getMonth()+1
		const month = now.getMonth() <9 ? '0'+(now.getMonth()+ 1) : now.getMonth()+ 1; // 月
		this.formInline.period=`${year}-${month}`
		this.formInline.year=dateFormat(new Date())
		console.log(this.$route.query.id,'uyu========')
		// this.getJxcInfo()
      if (this.$route.query.id) {
        this.getJxcInfo()
      } else {
        // this.GetPeriod()
      }

    },
    methods: {
      cancelClick() {
        this.$router.push({
          name: "receiveIndex"
        });
      },
      saveZc(type, formName, status, sussInfo, errInfo) {
        console.log('66555-==============')
        // this.shtype = shtype
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.$route.query.id) {
				this.formInline.status=status
				this.formInline.id=this.$route.query.id
              console.log(this.formInline,'ooiyy7778-----')
              reserveSizeAcceptId(this.formInline).then(res => {
                if (res.infoCode == 200) {
                  this.$message({
                    message: "提交成功",
                    type: "success",
                  });
                  this.$router.push({
                    name: "receiveIndex",
                  });
                } else {
                  this.$message.error(res.msg);
                }
              })
            }
          }
        })

      },
      getJxcInfo() {
        var data = {
          id: this.$route.query.id
        }
        reserveSizeGetId(data).then(res => {
          if (res.infoCode == 200) {
			  var Hjsl={
			  	address: "",
			  	cblhj: null,
			  	cbyhj: null,
			  	cpy5: null,
			  	cpy10: null,
			  	cpy20: null,
			  	cpyGc: null,
			  	cpyhj: null,
			  	cpyxbzhj: null,
			  	createTime: null,
			  	ddyy: null,
			  	dg: null,
			  	dmGc: null,
			  	dmXbz: null,
			  	dmhj: null,
			  	id: null,
			  	kdLevel: "",
			  	kdbm: "",
			  	kdmc: "合计",
			  	linkman: "",
			  	mfGc: null,
			  	mfXbz: null,
			  	mfhj:null,
			  	phone: null,
			  	reserveSizeId: this.$route.query.id,
			  	updateTime: null,
			  	xm: null,
			  }
			  res.data.reserveSizeReportVOList.forEach((item) =>{
			  	console.log(item)
			  	if(item !=null){
			  		Hjsl.cblhj+=Number(item.cblhj)
					Hjsl.xm+=Number(item.xm)
					Hjsl.dg+=Number(item.dg)
					Hjsl.mfhj+=Number(item.mfhj)
					Hjsl.mfXbz+=Number(item.mfXbz)
					Hjsl.mfGc+=Number(item.mfGc)
					Hjsl.dmhj+=Number(item.dmhj)
					Hjsl.dmXbz+=Number(item.dmXbz)
					Hjsl.dmGc+=Number(item.dmGc)
					Hjsl.cbyhj+=Number(item.cbyhj)
					Hjsl.ddyy+=Number(item.ddyy)
					Hjsl.cpyhj+=Number(item.cpyhj)
					Hjsl.cpyxbzhj+=Number(item.cpyxbzhj)
					Hjsl.cpyGc+=Number(item.cpyGc)
			  	    // arr.push(item)
			  	}
			  })
			this.formInline = res.data
			this.formInline.reserveSizeReportVOList.unshift(Hjsl)
			this.formInline.reserveSizeId=this.$route.query.id
			this.formInline.orgLevelName=this.$route.query.orgLevelName
			this.formInline.reportMonth=this.$route.query.reportMonth
			if(this.type == 'sb'){
				// this.formInline.receiveOpinion=''
				this.formInline.orgName=sessionStorage.getItem("orgName"),
				this.formInline.reportDay=dateFormat(new Date())
				// this.formInline.receiver=sessionStorage.getItem("userName")
				// this.formInline.receiveStatus=1
			}else{
				this.formInline.orgName=this.$route.query.orgName
				this.formInline.reportDay=this.$route.query.reportDay
			}
          }
        })
      },
    }
  }
</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>
