<template>
  <!-- 修改水运价格信息 -->
  <div class="addTrainPrice">
    <page-title>编辑</page-title>
      <div class="form-box">
          <dil-form :formId="192" v-model="form1"></dil-form>
      </div>
    <div class="button-box">
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
      <el-button @click="onClickCancel">返回</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: {},
  }
 },
  mounted() {
    this.information();
  },
  methods: {
    information() {
      //编辑驳船作业
      this.axios
        .post("/api/v1/ams/selectTrainPriceToUpdate/" + this.$route.params.priceId)
        .then((res) => {
          res.data.data.forEach((e) => {
            this.form1 = e;
          
          });
        });
    },
    handleCheckedCitiesChange(value) {
      console.log(value);
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    currentRadioChange(row) {
      this.aaaa = row;
    },
    // 确认
    onClickConfirm() {
      let amsContractTrainPrice = {
        priceId: this.$route.params.priceId,
        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/updateTrainPrice",
          amsContractTrainPrice
        )
        .then((res) => {
          if(res.data.code == 200){
            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>
