<template>
  <!-- 添加车皮卸车实绩 -->
  <!-- 新增请作业页面 -->
  <div class="contractDetails">
    <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="116" v-model="form1"></dil-form>
      </div>
    </div>
    <!-- 确定和取消 -->
    <div class="button_box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm">确认</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/1?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/1?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){
      console.log("warehouse:",selection);
      this.unloadPointId = selection.warehouseId;
      this.unloadPointName = selection.warehouseName;
    },
    selectionChange(selection) {
      this.list = selection;
      console.log("list:",selection);
    },
    // 确定
    onClickConfirm() {
      let tmstrainWagonUnloadResult = {
        list: this.list,
        resultArrivalDate: sjTime(this.form1.resultArrivalDate),
        resultUnloadTime: sjTime(this.form1.resultUnloadTime),
        resultRemark: this.form1.resultRemark,
        unloadingPointId:this.unloadPointId,
        insertUsername:getCookie("userId"),
        resultType: 1,
      };
      console.log(tmstrainWagonUnloadResult);
      if (
        tmstrainWagonUnloadResult.list == null ||
        tmstrainWagonUnloadResult.resultArrivalDate == null ||
        tmstrainWagonUnloadResult.resultUnloadTime == null ||
        tmstrainWagonUnloadResult.list.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: "新增成功!",
              });
            } else {
              ({ type: "failed", message: "新增失败!" });
            }

            this.$router.go(-1);
          });
    },
    // 取消
    onClickCancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang='scss'>
.contractDetails {
  .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-left: 45px;
                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>