<template>
  <!-- 添加车皮卸车实绩 -->
  <div class="addWagonLoad">
    <page-title>返回</page-title>
    <div>
      <div class="search" style="display:flex">
        <div style="margin-top: 18px;margin-left:10px">
          <el-label>车皮号：</el-label>
        </div>
        <el-input
        placeholder="请输入"
        v-model="wagon"
        style="margin: 10px; width:10%"
        clearable
        ></el-input>
        <div style="margin-top: 18px;margin-left:10px">
          <el-label>订单号：</el-label>
        </div>
        <el-input
        placeholder="请输入"
        v-model="purchaseOrderNum"
        style="margin: 10px; width:10%"
        clearable
        ></el-input>
        <div style="margin-top: 18px;margin-left:10px">
          <el-label>物资名：</el-label>
        </div>
        <el-input
          placeholder="请输入"
          v-model="materialName"
          style="margin: 10px;width:10%"
          clearable
        ></el-input>
      <el-button
        type="primary"
        class="btn"
        @click="searchOrder()"
        style="margin: 10px;">
        <i class="el-icon-search"></i>查询
      </el-button>
      </div>
      <dilTable
        v-bind.sync="option"
        ref="table"
        @selection-change="selectionChange"
      >
      </dilTable>
    </div>

    <div class="forwardingUnit item">
      <span class="text">卸货点：</span>
      <el-input v-model="unloadPointName" disabled> </el-input>
      <el-button type="primary" @click="ondrawer(3)">浏览</el-button>
    </div>

    <!-- 模态窗口 -->
    <el-drawer :visible.sync="drawer" :direction="direction" size="30%">
      <el-input
        placeholder="请输入内容"
        v-model="inputText"
        style="margin-top: 0rem; margin-right: 0.1rem; width: 230px"
        clearable
      ></el-input>
      <el-button
        type="primary"
        class="btn"
        @click="searchUnLoadPoint()"
        style="margin-bottom: 0.9375rem">
        <i class="el-icon-search"></i>查询
      </el-button>
       <div>
        <dilTable
          v-bind.sync="unloadPoint"
          @radio-change="currentRadioChange"
        ></dilTable>
      </div>
    </el-drawer>

  <div class="form">
      <div class="form_box">
         <dil-form :formId="255" v-model="form1" ></dil-form>
      </div>
    </div>
    <div class="button_box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</el-button>
    </div>
  </div>
</template>

<script>
import PageTitle from "@/components/Page/Title";
import { sjTime,isNumber } from "@/utils/sharedJsFile";
import { getCookie } from "@/utils/util.js";
export default {
  components: { PageTitle },
  data() {
    return {
      form1: {},
      inputText:null,
      drawer:false,
      unloadPoint:null,
      wagon:null,
      purchaseOrderNum:null,
      materialName:null,
      direction: "rtl",
      unloadPointId:null,
      unloadPointName:null,
      unloadPoint: {
        requestUrl: "/api/v1/uc/getUnloadingMesByLike?apiId=374",
        selectionType: "radio",
      },
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/tms/getWagonNo/2?apiId=213",
        // 控制显示当选列
        selectionType: "select",
      },
      value: undefined,
      list: [],
    };
  },
  mounted() {
    this.form1.resultArrivalDate=new Date();
    this.form1.resultUnloadTime=new Date();
  },
  methods: {
    searchOrder(){
      let requestUrl="/api/v1/tms/getWagonNo/2?apiId=213";
      if(typeof this.wagon !='undefined' && this.wagon!=null){
          requestUrl+=("&wagon="+this.wagon);
      }
      if(typeof this.purchaseOrderNum !='undefined' && this.purchaseOrderNum!=null){
          requestUrl+=("&purchaseOrderNum="+this.purchaseOrderNum);
      }
      if(typeof this.materialName !='undefined' && this.materialName!=null){
          requestUrl+=("&materialName="+this.materialName);
      }
      this.option.requestUrl=requestUrl;
    },
    ondrawer() {
      this.drawer = true;
    },
    searchUnLoadPoint(){
      this.unloadPoint.requestUrl =
          "/api/v1/uc/getUnloadingMesByLike?apiId=374&index=" + this.inputText;
    },
    currentRadioChange(selection){
      this.unloadPointId = selection.warehouseId;
      this.unloadPointName = selection.warehouseName;
      console.log(this.unloadPointId);
    },
    selectionChange(selection) {
      this.list = [];
      selection.forEach((e) => {
        this.list.push({
          resultWagonNo: e.resultWagonNo,
          resultId: e.resultId,
          purchaseOrderId: e.purchaseOrderId,
          unloadingPointId: e.unloadingPointId,
        });
      });
    },
    // 确定
    makeSure() {
      console.log("wagonNoList" +this.list)
      let tmstrainWagonUnloadResult = {
        wagonNoList: this.list,
        resultArrivalDate: sjTime(this.form1.resultArrivalDate),
        resultUnloadTime: sjTime(this.form1.resultUnloadTime),
        resultRemark: this.form1.resultRemark,
        unloadingPointId:this.unloadPointId,
        insertUsername:getCookie("userId"),
        resultType: 2,
      };
      console.log(tmstrainWagonUnloadResult);
      if (
        tmstrainWagonUnloadResult.wagonNoList == null ||
        tmstrainWagonUnloadResult.resultArrivalDate == null ||
        tmstrainWagonUnloadResult.resultUnloadTime == null ||
        tmstrainWagonUnloadResult.wagonNoList.length <=0 ||
         tmstrainWagonUnloadResult.unloadingPointId ==null
      )
        this.$message.error("请填写完整信息！");
      else
        this.axios
          .post(
            "/api/v1/tms/insertTmstrainWagonUnLoadResult",
            tmstrainWagonUnloadResult
          )
          .then((res) => {
            if (res.data.code == "200") {
              this.$message({
                type: "success",
                message: "新增成功!",
              });
            }
            this.$router.go(-1);
          });
    },
    // 取消
    cancel(){
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss'>
.addWagonLoad {
  .form {
    display: flex;
    .form_box {
      width: 340px;
      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;
              }
               .el-textarea {
                .el-textarea__inner {
                  width: 230px;
                  margin-top: 0.03rem;
                }
              }
            }
           
          }
        }
      }
    }
  }
  .button_box {
    margin-left: 42%;
    margin-top: 55px;
  }
}
.fromOther {
  margin-left: 34.5%;
  width: 50%;
  .inline-input {
    width: 300px;
  }
}
.forwardingUnit {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 320px;
    margin-left: 33%;
    margin-top: 30px;
    margin-right: 22px;
    .text {
      text-align: right;
      width: 8.125rem;
    }
  }
</style>