<template>
  <!-- 新增请作业页面 -->
  <div class="contractDetails">
    <page-title>返回</page-title>
    <div>
      <el-form   label-width="80px" style="margin-left:35%;">
        <el-form-item label="批复车数">
          <el-input v-model="form.resultApproveNumber" type="number" style="width:240px"></el-input>
        </el-form-item>
        <el-form-item label="落空车数">
          <el-input v-model="form.resultVoidNumber" type="number" style="width:240px"></el-input>
        </el-form-item>
        <el-form-item label="实装车数">
          <el-input v-model="form.resultRealNumber" type="number" style="width:240px"></el-input>
        </el-form-item>
        <el-form-item label="日期">
          <el-date-picker v-model="form.resultDate" type="datetime" placeholder="日期" @change="getRealNumber"></el-date-picker>
        </el-form-item>
      </el-form>
      <!-- 确定和取消 -->
      <div style="margin-left:40%">
        <el-button @click="cancel">返回</el-button>
        <el-button type="primary" @click="makeSure">确认</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { sjTime } from "@/utils/sharedJsFile";
import { getCookie } from "@/utils/util.js";
export default {
  components: { PageTitle },
  data() {
    return {
      form:{
        resultRealNumber:0,
        resultDate:new Date()
      }
    };
  },
  created() {
    
  },
  mounted(){
    this.getRealNumber();
  },
  methods: {
    cancel() {
      this.$router.go(-1);
    },
    makeSure() {
      console.log("form",this.form.resultVoidNumber-this.form.resultApproveNumber);
      if(!this.form.resultDate ||
      !this.form.resultApproveNumber||
      !this.form.resultVoidNumber||
      !this.form.resultRealNumber){
        this.$message.warning("存在空值!");
        return;
      }else if(this.form.resultVoidNumber-this.form.resultApproveNumber>0){
        this.$message.warning("落空车数不能超过批复车数!");
        return;
      }
      this.form.resultDate= sjTime(this.form.resultDate);
      this.form.resultSurplusNumber=this.form.resultApproveNumber-this.form.resultVoidNumber;
      this.form.userId= getCookie("userId");
      this.axios.post("/api/v1/tms/addPleaseResult", this.form).then(() => {
          this.$message({
            type: "success",
            message: "新增成功!",
          });
          this.$router.go(-1);
        });
    },
    //获取当天车皮数量
    getRealNumber(){
      if(this.form.resultDate){
        this.form.resultDate=sjTime(this.form.resultDate);
        this.axios.post("/api/v1/tms/getRealNumber",this.form).then((res)=>{
          console.log("res",res);
          this.form.resultRealNumber=res.data.data;
          console.log("form",this.form);
        });
      }
    }
  },
};
</script>
<style lang="scss">
</style>