<template>
  <!-- 修改运输计划页面 -->
  <div id="contractDetails">
    <page-title>运输计划</page-title>
    <div class="main">
      <span class="text">修改运输计划</span>
      <span class="a"></span>
    </div>
    <div class="contractTitle">
      <div class="form-box">
        <div class="form-one">
          <dil-form :formId="166" v-model="form1"></dil-form>
        </div>
      </div>
    </div>  
 
    <div class="button-box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";

export default {
  components: { PageTitle },
    data(){
          return {
          form1: {},
        }
    },
  mounted() {
    this.information();
  },
  methods: {
    information() {
      //编辑运输计划
      this.axios
        .post("/api/v1/ams/getPurPlanById/" + this.$route.params.planId)
        .then((res) => {
          res.data.data.forEach((e) => {
            this.form1 = e;
          });
        });
    },
     // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
     // 确认
    onClickConfirm() {
      let editTransportReserve = {
        planId: this.$route.params.planId,
        batchId: this.form1.batchId,
        planTruckTime: sjTime(this.form1.planTruckTime),
        carrierId: this.form1.carrierId,
        materialTotalWeight: this.form1.materialTotalWeight,
        planIncomingTime: sjTime(this.form1.planIncomingTime)
      };
      function isNumber() {
        var value = editTransportReserve.materialTotalWeight;
        //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
          return false;
        } else {
          return true;
        }
      }
      var val = this.value;
      if (
        editTransportReserve.batchId==null||
        editTransportReserve.planTruckTime==null||
        editTransportReserve.carrierId==null||
        editTransportReserve.materialTotalWeight==null||
        editTransportReserve.planIncomingTime==null||
        editTransportReserve.planId==null
      ) this.$message.error("存在空值！");
      else
      if (!isNumber(val)) this.$message.error("重量必须是数字！");
      else
      this.axios
        .post("/api/v1/ams/updatePurPlan", editTransportReserve)
        .then(() => {
          this.$message({
            type: "success",  
            message: "修改成功!",
          });
          this.$router.go(-1);
        });
    },
  },
};
</script>
<style lang="scss" scoped>
//@import "@/styles/appoint/contract/ContractInsert.scss";
</style>