<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="302" 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";
import { sjTime } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      // 表单
      form1: {},
    };
  },
  mounted() {
    // this.unit();
  },
  created(){
      this.form1 = {resultPleaseDate:new Date()}
      
  },
  methods: {
    handleCheckedCitiesChange(value) {
      console.log(value);
    },

    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    // 确认
    onClickConfirm() {
      let tmstrainPleaseApproveResult = {
        resultPleaseDate: sjTime(this.form1.resultPleaseDate),
        resultPleaseNumber: this.form1.resultPleaseNumber,
        railPlanId: this.form1.railPlanId,
      };
      console.log(tmstrainPleaseApproveResult);
      function isNumber() {
        var value = tmstrainPleaseApproveResult.resultPleaseNumber;
        //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
          return false;
        } else {
          return true;
        }
      }
      var val = this.value;
      if (
        tmstrainPleaseApproveResult.resultPleaseDate == null ||
        tmstrainPleaseApproveResult.resultPleaseNumber == null ||
        tmstrainPleaseApproveResult.railPlanId == null
      )
        this.$message.error("存在空值！");
      else if (!isNumber(val)) this.$message.error("请车数量必须是数字！");
      else
        this.$axios
          .post("/api/v1/tms/addWagonPleaseForNZ", tmstrainPleaseApproveResult)
          .then((res) => {
            if (res.data.code == "200") {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
              this.$router.go(-1);
            }
          });
    },
  },
};
</script>
<style lang="scss">
</style>