// 新增采购内转需求
<template>
  <div id="endMaintenance">
    <page-title>新增需求</page-title>
    <div class="main">
      <span class="text">新增</span>
      <span class="a"></span>
    </div>
    <div>
      <div class="form-box f2">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="采购订单号">
            <el-input v-model="purchaseOrder" disabled> </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="ondrawer(1)">浏览</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-box f3">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="外轮船名">
            <el-input v-model="foreignShipName" disabled> </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-box f4">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="物资名称">
            <el-input v-model="materialName" disabled> </el-input>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-box f5">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="用车地点">
            <el-input v-model="truckPoint" disabled> </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="ondrawer(2)">浏览</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-box f5">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="卸货地点">
            <el-input v-model="truckPoint1" disabled> </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="ondrawer(3)">浏览</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-box f5">
        <el-form :inline="true" class="demo-form-inline">
          <el-form-item label="装货月台">
            <el-input v-model="requirementPlatformName" disabled> </el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="ondrawer(4)">浏览</el-button>
          </el-form-item>
        </el-form>
      </div>
      <div class="form-box">
        <dil-form :formId="300" v-model="form"></dil-form>
      </div>
      <el-drawer
        :visible.sync="drawer"
        :direction="direction"
        :before-close="handleClose"
        size="30%"
      >
        <el-input
          placeholder="请输入内容"
          v-model="input"
          style="margin-top: 10px; margin-left: 20px"
          clearable
        >
        </el-input>
        <el-button
          type="primary"
          class="btn"
          @click="onclick(a)"
          style="margin-bottom: 15px"
        >
          <i class="el-icon-search"></i>查询
        </el-button>
        <div v-show="a == 1">
          <dilTable
            v-bind.sync="second"
            @radio-change="currentRadioChange1"
          ></dilTable>
        </div>
        <div v-show="a == 2">
          <dilTable
            v-bind.sync="second1"
            @radio-change="currentRadioChange2"
          ></dilTable>
        </div>
        <div v-show="a == 3">
          <dilTable
            v-bind.sync="second2"
            @radio-change="currentRadioChange3"
          ></dilTable>
        </div>
         <div v-show="a == 4">
          <dilTable
            v-bind.sync="second3"
            @radio-change="currentRadioChange4"
          ></dilTable>
        </div>
      </el-drawer>
    </div>
    <div class="button-box">
      <el-button type="primary" @click="makeSure">确认新增</el-button>
      <el-button type="primary" @click="cancel">返回</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { sjTime } from "@/utils/sharedJsFile";
export default {
  components: { PageTitle },
  data() {
    return {
      purchaseOrder: "",
      foreignShipName: "",
      materialName: "",
      a: 1,
      direction: "rtl",
      input: "",
      truckPoint: "",
      truckPoint1:'',
      requirementPlatformName: "",
      drawer: false,
      form: {},
      second: {
        requestUrl: "/api/v1/ams/getPurchaseIdByBatch?apiId=252",
        selectionType: "radio",
        mapList1: [],
      },
      second1: {
        requestUrl: "/api/v1/ams/getWareHouse?apiId=251",
        selectionType: "radio",
        mapList2: [],
      },
      second2 :{
        requestUrl: "/api/v1/ams/getWareHouse?apiId=251",
        selectionType: "radio",
        mapList3: [],
      },
      second3 :{
        requestUrl: "/api/v1/ams/getWareHouse?apiId=251",
        selectionType: "radio",
        mapList4: [],
      },
    };
  },
  methods: {
    ondrawer(num) {
      this.drawer = true;
      this.a = num;
    },
    handleClose(done) {
      done();
    },
    onclick(a) {
      if (a == 1) {
        this.second.requestUrl =
          "/api/v1/ams/getPurchaseIdByBatch?apiId=252&con=" + this.input;
      } else {
        this.second1.requestUrl =
          "/api/v1/ams/getWareHouse?apiId=251&con=" + this.input;
      }
    },
    currentRadioChange1(selection) {
      this.mapList1 = selection
      this.purchaseOrder = this.mapList1.purchaseOrderNo
      this.foreignShipName = this.mapList1.resultForeignShipName
      this.materialName = this.mapList1.materialName;
    },
    currentRadioChange2(selection) {
      this.mapList2 = selection
      this.truckPoint = this.mapList2.wareHouseName;
    },
    currentRadioChange3(selection) {
      this.mapList3 = selection
      this.truckPoint1 = this.mapList3.wareHouseName;
    },
    currentRadioChange4(selection) {
      this.mapList4 = selection
      this.requirementPlatformName = this.mapList4.wareHouseName;
    },
    // 新增
    makeSure() {
      let requiremnet = {
        purchaseOrderId: this.mapList1.purchaseOrderId,
        requiremntUnitId: this.mapList2.wareHouseId,
        capacityTypeId: this.form.capacityTypeId,
        materialWeight: this.form.materialWeight,
        materialNumber: this.form.materialNumber,
        requirementEstimatedDuration: this.form.requirementEstimatedDuration,
        requirementOverlimit: this.form.requirementOverlimit,
        requirementShipperId: this.form.requirementShipperId,
        requirementTruckTime: sjTime(this.form.requirementTruckTime),
        requirementType: this.form.requirementType,
        requirementWorkContent: this.form.requirementWorkContent,
        requirementWorkEnvironment: this.form.requirementWorkEnvironment,
        requirementWorkType: this.form.requirementWorkType,
        requirementUnloadUnitId:this.mapList3.wareHouseId,
        requirementPlatformId: this.mapList4.wareHouseId
      };
      console.log(requiremnet);
      this.axios
        .post("/api/v1/ams/addTruckRequirement", requiremnet)
        .then((res) => {
          if (res.data.code == 200) {
            this.$message({
              type: "success",
              message: "新增成功!",
            });
            this.$router.go(-1);
          } else {
            this.$message.error("新增失败！");
          }
        });
    },
    // 返回
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="scss">
.el-form-item{
  display: flex;
}
.form-box,
.button-box
{
  display: flex;
  text-align: center;
  align-items: center;
  justify-content: center;
  margin-top: 0.3125rem;
  margin-bottom: 1.25rem;
}
</style>
