<template>
  <!-- 添加车皮卸车实绩 -->
  <div class="addWagonLoad">
    <page-title>返回</page-title>
    <div class="main">
      <el-divider content-position="left"></el-divider>
    </div>
    <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>
    <div class="form">
      <div class="form_box" style="margin-right: 10rem">
        <dil-form :formId="255" v-model="form1" ref="from1"></dil-form>
      </div>
    </div>
    <div class="button-box">
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="makeSure">确定</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>
</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: {},
      inputText:null,
      drawer:false,
      unloadPoint:null,
      wagon:null,
      purchaseOrderNum:null,
      materialName:null,
      direction: "rtl",
      unloadPointId:null,
      unloadPointName:null,
      option: {
        // 表格请求数据的地址
        requestUrl: "/api/v1/tms/getWagonNo/3?apiId=213",
        // 控制显示当选列
        selectionType: "select",
      },
      unloadPoint: {
        requestUrl: "/api/v1/uc/getUnloadingMesByLike?apiId=374",
        selectionType: "radio",
      },
      value: undefined,
      list: [],
    };
  },
  mounted() {
    this.form1.resultArrivalDate=new Date();
    this.form1.resultUnloadTime=new Date();
  },
  // created() {
  //   this.form1 = {
  //     arrivalStationId: 1,
  //   };
  // },
  methods: {
    searchOrder(){
      let requestUrl="/api/v1/tms/getWagonNo/3?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() {
      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: 3,
      };
      console.log(tmstrainWagonUnloadResult);
      if (
        tmstrainWagonUnloadResult.wagonNoList == null ||
        tmstrainWagonUnloadResult.wagonNoList.length <=0 ||
        tmstrainWagonUnloadResult.resultArrivalDate == null ||
        tmstrainWagonUnloadResult.resultUnloadTime == null ||
        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);
            } else {
              ({ type: "failed", message: "新增失败!" });
            }
          });
    },
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss' scoped>
.addWagonLoad {
  .form {
    display: flex;
    .form_box {
      width: 320px;
      margin-left: 35%;
      margin-top: 30px;
      margin-right: 22px;
      .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: 220px;
              }
              .el-textarea {
                .el-textarea__inner {
                  width: 230px;
                  // margin-left: 45px;
                  margin-top: 0.03rem;
                }
              }
            }
          }
        }
      }
    }
  }
  .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;
    }
  }
  .button-box {
    margin-left: 42%;
    margin-top: 25px;
    width: 300px;
  }
}
</style>