<template>
  <!-- 修改装船指令 -->
  <div class="shipTransport">
    <page-title>返回</page-title>
    <div class="form">
      <div class="form_box">
        <dil-form :formId="114" v-model="form1" ref="from1"></dil-form>
        <span> 二程:海港-江港</span>
        <el-switch
          v-model="status"
          active-color="#13ce66"
          inactive-color="#909399"
          @change="changeStatus"
        >
        </el-switch>
      </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: {},
      status: false,
    };
  },
  mounted() {
    this.information();
  },
  methods: {
    information() {
      //编辑装船指令
      this.axios
        .post(
          "/api/v1/tms/getShipmentInstructions/" +
            this.$route.params.instructionsId
        )
        .then((res) => {
          res.data.data.forEach((e) => {
            this.form1 = e;
          });
        });
    },
    handleCheckedCitiesChange(value) {
      console.log(value);
    },
    
    //改变二程状态
    changeStatus() {
      console.log(this.status);
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    currentRadioChange(row) {
      this.aaaa = row;
    },
    // 确认
    onClickConfirm() {
      let omsshipShipmentInstructions = {
        shipmentInstructionsId: this.$route.params.instructionsId,
        instructionsTotalTonnage: this.form1.instructionsTotalTonnage,
        instructionTime: sjTime(this.form1.instructionTime),
        statu: this.status,
      };

      //判断合计吨位是否为数字
      function isNumber() {
        var value = omsshipShipmentInstructions.instructionsTotalTonnage;
        //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
          return false;
        } else {
          return true;
        }
      }
      var val = this.value;

      if (
        omsshipShipmentInstructions.instructionsTotalTonnage == null ||
        omsshipShipmentInstructions.instructionTime == null
      )
        this.$message.error("存在空值！");
      else if (!isNumber(val)) this.$message.warning("合计吨位请填写数字");
      else
        this.axios
          .post(
            "/api/v1/tms/updateShipmentInstructions",
            omsshipShipmentInstructions
          )
          .then((res) => {
            if (res.data.code == 200) {
              this.$message({
                type: "success",
                message: "修改成功!",
              });
              // this.$refs.table.refreshData();
              this.$router.go(-1);
            } else {
              this.$message.error("修改失败！");
            }
            this.$refs["table"].resetField();
          });
    },
  },
};
</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>
