<template>
  <!-- 修改运输预约页面 -->
  <div id="contractDetails">
    <page-title>运输预约</page-title>
    <div class="contractTitle">
      <div class="form-one">
        <dil-form :formId="220" v-model="form1"> </dil-form>
      </div>
      <div class="btn">
        <div class="btn1">
          <el-button type="primary" @click="selectTruck">浏览</el-button>
        </div>
        <div class="btn1">
          <el-button type="primary" @click="selectUnloadingPoint"
            >浏览</el-button
          >
        </div>
      </div>
    </div>

    <div class="button_box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm">确认</el-button>
    </div>

    <el-drawer
      :visible.sync="drawer"
      :direction="direction"
      size="40%"
      :wrapperClosable="true"
      :close-on-press-escape="false"
      :destroy-on-close="false"
      :show-close="false"
      :withHeader="true"
      modal
    >
      <el-input
        placeholder="请输入内容"
        v-model="input"
        style="margin-top: 0.625rem; margin-left: 1.25rem; width: 200px"
        clearable
      ></el-input>
      <el-button
        type="primary"
        class="btn"
        @click="onclick(a)"
        style="margin-bottom: 0.9375rem"
      >
        <i class="el-icon-search"></i>查询
      </el-button>
      <div v-show="a == 1">
        <dilTable
          v-bind.sync="third"
          @radio-change="currentRadioChange"
        ></dilTable>
      </div>
      <div v-show="a == 2">
        <dilTable
          v-bind.sync="unloadPoint"
          @radio-change="currentRadioChange2"
        ></dilTable>
      </div>
    </el-drawer>
  </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 {
      form1: {},
      drawer: false,
      direction: "rtl",
      a: null,
      third: {
        requestUrl: "",
        selectionType: "radio",
      },
      unloadPoint: {
        requestUrl: "/api/v1/uc/getUnloadingMesByLike?apiId=374",
        selectionType: "radio",
      },
      capacityId: null,
      warehouseId: null,
      input: null,
      orderType: null,
    };
  },
  created() {
    //判断是否是承运商
    if (getCookie("orgCode") == "chengyunshang") {
      this.third.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=248&carrierSsoId=" +
        getCookie("userId");
    } else {
      this.third.requestUrl =
        "/api/v1/uc/getAllCapacityByCarrierLike?apiId=248&carrierSsoId=" + null;
    }
  },
  mounted() {
    this.information();
  },
  methods: {
    onclick(a) {
      if (a == 1) {
        //判断是否是承运商
        if (getCookie("orgCode") == "chengyunshang") {
          this.third.requestUrl =
            "/api/v1/uc/getAllCapacityByCarrierLike?apiId=248&carrierSsoId=" +
            getCookie("userId") +
            "&con=" +
            this.input;
        } else {
          this.third.requestUrl =
            "/api/v1/uc/getAllCapacityByCarrierLike?apiId=248&carrierSsoId=" +
            null +
            "&con=" +
            this.input;
        }
      } else if (a == 2) {
        this.unloadPoint.requestUrl =
          "/api/v1/uc/getUnloadingMesByLike?apiId=374&con=" + this.input;
      }
    },
    selectTruck() {
      this.a = 1;
      this.drawer = true;
    },
    selectUnloadingPoint() {
      this.a = 2;
      this.drawer = true;
    },
    currentRadioChange(row) {
      this.form1.capacityNumber = row.capacityNumber;
      this.capacityId = row.capacityId;
    },
    currentRadioChange2(row) {
      this.form1.warehouseName = row.warehouseName;
      this.warehouseId = row.warehouseId;
    },
    information() {
      this.axios
        .post("/api/v1/oms/selectOrderByOrderId/" + this.$route.params.orderId)
        .then((res) => {
          res.data.data.forEach((e) => {
            this.form1 = e;
          });
        });
    },
    // 返回
    onClickCancel() {
      this.$router.go(-1);
    },
    // 确认
    onClickConfirm() {
      let obj = {
        orderId: this.$route.params.orderId,
        capacityId: parseInt(this.capacityId),
        unloadPointId: this.warehouseId,
        orderEntryTime: sjTime(this.form1.orderEntryTime),
        orderType: parseInt(this.form1.orderType),
      };
      this.axios.post("/api/v1/oms/updateOrder", obj).then((res) => {
        if (res.data.code == "200") {
          this.$message({
            type: "success",
            message: "修改成功!",
          });
          this.$router.push("/transportReserveRan");
        }
      });
    },
  },
};
</script>
<style lang="scss">
.contractTitle {
  display: flex;
  justify-content: center;
  margin: 20px;
  .el-form-item {
    display: flex;
    justify-content: center;
    .el-form-item__label {
      display: flex;
      align-items: center;
      font-size: 14px;
    }
    .el-input {
      width: 250px;
    }
  }
  .btn {
    margin-left: 20px;
    padding-top: 105px;
    .btn1 {
      margin-bottom: 15px;
    }
  }
}
.button_box {
  display: flex;
  justify-content: center;
  align-items: center;
  .el-button {
    width: 80px;
    margin: 10px;
  }
}
</style>