<template>
  <!-- 修改合同单价信息 -->
  <div class="addWagonLoad">
    <PageTitle>返回</PageTitle>
    <div class="form-box">
      <!-- <dil-form :formId="271" v-model="form1" ref="from1"></dil-form> -->
      <el-form v-model="form">
          <div class="preview-group">
            <el-form-item label="合同号">
                <el-input v-model="form.contractNo"></el-input>
            </el-form-item>
             <el-form-item label="单价">
                <el-input v-model="form.unitPrice" type="number"></el-input>
            </el-form-item>
             <el-form-item label="起始日期">
                 <el-date-picker
                    v-model="form.startTime"
                    type="datetime"
                    placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
             <el-form-item label="截止日期">
                 <el-date-picker
                    v-model="form.endTime"
                    type="datetime"
                    placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <!-- <el-form-item label="港口:">
                <el-select filterable  v-model="portId">
                    <el-option v-for="item in ports" :value="item.portId" :key="item.portId" :label="item.portName"></el-option>
                </el-select>
            </el-form-item> -->
          </div>
     </el-form>
    </div>
    <div class="button-box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure" :loading="isLoading">确定</el-button>
    </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: {
        contractNo:null,
        unitPrice:null,
        startTime:null,
        endTime:null,
        userId:getCookie("userId")
      },
      portId:null,
      ports:[],
      isLoading:false
    };
  },
  mounted() {
    //this.getPorts();
    this.information();
  },
  methods: {
    //渲染界面
    information() {
      console.log("resultId",this.$route.params.resultId);
      this.axios
        .post(
          "/api/v1/rms/selectBmsshipPriceList/" +
            this.$route.params.resultId
        )
        .then((res) => {
            console.log(res)
          res.data.data.forEach((e) => {
            this.form = e;
            console.log(e);
          });
        });
    },
    makeSure() {
      this.isLoading=true;
      console.log(this.form);
      let map=this.form;
      map={
        resultId:this.form.resultId,
        contractNo:this.form.contractNo,
        unitPrice:this.form.unitPrice,
        startTime: sjTime(this.form.startTime),
        endTime:sjTime(this.form.endTime),
        userId:getCookie("userId")
      }
      if (map.contractNo == null || 
      map.contractNo =='' ||
      map.unitPrice =='' ||
      map.unitPrice == null ||
      map.startTime == null || 
      map.endTime == null){
        this.$message.error("存在空值！");
        this.isLoading=false;
      }else if(map.startTime>=map.endTime){
        this.$message.error("起始日期必须小于截止日期！");
        this.isLoading=false;
      }else{
         this.axios.post("/api/v1/rms/updateBmsshipContractPrice",map).then(res => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "修改成功!"
            });
            this.cancel();
            this.isLoading=false;
          } else {
            this.$message.error(res.data.data);
            this.isLoading=false;
          }
        });
      }
       
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
    //查询港口id
    getPorts(){
        this.axios.post("/api/v1/rms/getPortName?index=").then(res => {
          if (res.data.code == 200) {
            this.ports=res.data.data;
            console.log(this.ports);
          } else {
            this.$message.error(res.data.data);
          }
        });
    }
  }
};
</script>
<style lang="scss">
.button-box {
  display: flex;
  justify-content: center;
  margin: 20px;
  .el-button {
    width: 80px;
    margin: 10px;
  }
}
.form-box {
  display: flex;
  justify-content: center;
  .el-form-item {
    display: flex;
    justify-content: center;
    .el-form-item__label {
      display: flex;
      align-items: center;
    }
    .el-form-item__content {
      .el-input {
        .el-input__inner {
          width: 250px;
        }
      }
    }
  }
}
</style>
