<template>
  <!-- 修改卸船作业 -->
  <div class="shipTransport">
    <page-title>返回</page-title>
    <div class="form">
      <div class="form_box">
        <dil-form :formId="134" v-model="form1" ref="from1"></dil-form>
      </div>
    </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 } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      form1: {}
    };
  },
  computed: {
    a1() {
      return this.form1.resultEndTime;
    }
  },
  watch: {
    a1() {
      this.unloadShipMes();
    }
  },
  mounted() {
    this.information();
  },
  methods: {
    unloadShipMes() {
      if (
        typeof this.form1.resultStartTime == "undefined" ||
        this.form1.resultStartTime == null ||
        this.form1.resultStartTime == "null" ||
        this.form1.resultStartTime == "undefined"
      ) {
        this.$message.warning("请先填写卸船开始时间！");
        this.form1.resultEndTime = null;
      }
      return;
    },
    information() {
      //编辑卸船作业
      this.axios
        .post("/api/v1/tms/getUnloadShip/" + this.$route.params.resultId)
        .then(res => {
          if (res.data.data[0] != null) {
            res.data.data.forEach(e => {
              this.form1 = e;
              // console.log(e);
              // console.log(this.form1);
              // console.log(this.$route.params.loadingId);
            });
          }
        });
    },
    handleCheckedCitiesChange(value) {
      console.log(value);
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    currentRadioChange(row) {
      this.aaaa = row;
    },
    // 确认
    onClickConfirm() {
      if (
        this.form1.resultEndTime != null &&
        this.form1.resultEndTime != "undefined" &&
        typeof this.form1.resultEndTime != "undefined" &&
        this.form1.resultEndTime != "null"
      ) {
        this.unloadShipMes();
      }
      let resultArrivalDate = null;
      let resultStartTime = null;
      let resultEndTime = null;
      if (
        typeof this.form1.resultArrivalDate != "undefined" &&
        this.form1.resultArrivalDate != null
      ) {
        resultArrivalDate = sjTime(this.form1.resultArrivalDate);
      }
      if (
        typeof this.form1.resultStartTime != "undefined" &&
        this.form1.resultStartTime != null
      ) {
        resultStartTime = sjTime(this.form1.resultStartTime);
      }
      if (
        typeof this.form1.resultEndTime != "undefined" &&
        this.form1.resultEndTime != null
      ) {
        resultEndTime = sjTime(this.form1.resultEndTime);
      }
      let unloadMap = {
        resultId: this.$route.params.resultId,
        resultArrivalDate: resultArrivalDate,
        resultStartTime: resultStartTime,
        resultEndTime: resultEndTime,
        resultStatus: this.form1.resultStatus
      };
      this.axios.post("/api/v1/tms/updateUnLoadShip", unloadMap).then(res => {
        if (res.data.code == 200) {
          this.$message({
            type: "success",
            message: "修改成功!"
          });
          // this.$refs.table.refreshData();
          this.$router.go(-1);
        } else {
          this.$message.error("修改失败！");
        }
      });
    }
  }
};
</script>
<style lang="scss">
.shipTransport {
  .form {
    display: flex;
    .form_box {
      width: 320px;
      margin-left: 35%;
      margin-top: 30px;
      margin-right: 20px;
      .el-form {
        .preview-group {
          .el-form-item {
            .el-form-item__label {
              display: inline-block;
              width: 70px !important;
            }
            .el-form-item__content {
              .el-select {
                width: 250px;
              }
              .el-input {
                width: 250px;
              }
            }
          }
        }
      }
    }
  }
  .button_box {
    margin-left: 45%;
  }
}
</style>
