<template>
  <!-- 添加水运价格 -->
  <div class="addTrainPrice">
    <page-title>新增</page-title>
     <div class="form-box" >
        <dil-form :formId="192" v-model="form1" ref="from1"></dil-form>
      </div>
    <div class="button-box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { sjTime, isNumber } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      form1: {},
      value: undefined,
    };
  },
  mounted() {},
  methods: {
    // 确定
    makeSure() {
      let amsContractTrainPrice = {
        trainPrice: this.form1.trainPrice,
        trainPriceDate: sjTime(this.form1.trainPriceDate),
        trainType: this.form1.trainType
      };
      try{
        let temp=parseFloat(amsContractTrainPrice.trainPrice);
        if(temp==temp){
          amsContractTrainPrice.trainPrice=temp;
        }
      }catch(error){
        
      }
      console.log(amsContractTrainPrice);
      if (
      (!amsContractTrainPrice.trainPrice && amsContractTrainPrice.trainPrice!=0) ||
      !amsContractTrainPrice.trainPriceDate ||
      !amsContractTrainPrice.trainType
      ) this.$message.error("必填项存在空值!");
      else if(typeof amsContractTrainPrice.trainPrice != 'number' || amsContractTrainPrice.trainPrice <= 0){
        this.$message.error("单价必须是大于零的数字!"); 
      }
      else
      this.axios
        .post(
          "/api/v1/ams/addTrainPrice",
          amsContractTrainPrice
        )
        .then((res) => {
          this.$router.go(-1);
        });
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>
.addTrainPrice {
  .form-box {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    .el-form-item {
      display: flex !important;
      .el-form-item__label {
        width: 170px !important;
      }
      .el-input {
        width: 210px !important;
      }
    }
  }
  .button-box {
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
</style>