//入库
<template>
  <div class="steel_inbound02">
    <div class="sache">
      <el-form :inline="true">
        <el-form-item>
          <span class="text">入库时间：</span>
          <el-date-picker
            disabled
            v-model="startTime"
            type="datetime"
            placeholder="选择日期"
            style="width: 200px;"
          >
          </el-date-picker>
          <span class="text">至</span>
          <el-date-picker
            disabled
            v-model="endTime"
            type="datetime"
            placeholder="选择日期"
            style="width: 200px;"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <span class="text">物资类型</span>
          <el-autocomplete
            v-model="inputText"
            :fetch-suggestions="querySearch"
            placeholder="请输入内容"
            @select="handleSelect"
            style="width: 200px;"
          ></el-autocomplete>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="btn" @click="onclick">
            <i class="el-icon-search"></i>查询
          </el-button>
          <el-button type="primary" class="btn" @click="onreserved">
            入库
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="table">
      <dilTable v-bind.sync="options"> </dilTable>
    </div>
  </div>
</template>

<script>
import { sjTime } from "@/utils/sharedJsFile";
import { getCookie } from "@/utils/util.js";
export default {
  data() {
    return {
      inputText: "",
      startTime: null,
      endTime: null,
      options: {
        // first请求数据的地址
        requestUrl: ""
        // selectionType: "select",
        // mapList: [],
      }
    };
  },
  created() {
    var date = new Date();
    let dateStr = this.formatDate(date, "yyyy-MM-dd hh:mm:ss");

    this.startTime = Date.parse(new Date(dateStr));
    this.endTime = new Date(this.startTime + 86400000);

    this.options.requestUrl =
      "/api/v1/wms/getWmsInboundResult?apiId=371&warehouseId=" +
      2 +
      "&startTime=" +
      sjTime(this.startTime) +
      "&endTime=" +
      sjTime(this.endTime);
    this.tableShow = true;
  },

  methods: {
    formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(
          RegExp.$1,
          (date.getFullYear() + "").substr(4 - RegExp.$1.length)
        );
      }
      let o = {
        "M+": date.getMonth() + 1,
        "d+": date.getDate(),
        "h+": 0,
        "m+": 0,
        "s+": 0
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
          let str = o[k] + "";
          fmt = fmt.replace(
            RegExp.$1,
            RegExp.$1.length === 1 ? str : this.padLeftZero(str)
          );
        }
      }
      return fmt;
    },
    padLeftZero(str) {
      return ("00" + str).substr(str.length);
    },
    querySearch(queryString, cb) {
      var restaurants = [
        { value: "螺纹钢" },
        { value: "盘螺" },
        { value: "乱尺" }
      ];
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return restaurant => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1
        );
      };
    },
    // inboundDetails(scope){
    //   	this.$router.push("/inboundDetails/" + scope.row.inboundId)
    // },
    onclick() {
      let startTime = null;
      let endTime = null;
      if (this.startTime) {
        startTime = sjTime(this.startTime);
      }
      if (this.endTime) {
        endTime = sjTime(this.endTime);
      }
      if (startTime && endTime) {
        if (startTime < endTime) {
          // if(getCookie("orgCode") == "dagangadmin" || getCookie("orgCode") == "zidonghuabu"){
          this.options.requestUrl =
            "/api/v1/wms/getWmsInboundResult?apiId=371&warehouseId=" +
            2 +
            "&startTime=" +
            startTime +
            "&endTime=" +
            endTime +
            "&i=" +
            new Date();
          this.options.requestQuery = {
            materialNames: this.inputText
          };
          // }else if(getCookie("orgCode") == "wuliuchuyunzhongxin"){
          // this.options.requestUrl = "/api/v1/wms/getWmsInboundResult?apiId=371&orderType=13&startTime=" + startTime + "&endTime=" + endTime + "&i=" +new Date();
          // }else{
          // this.options.requestUrl = '/api/v1/wms/getWmsInboundResult?apiId=371&userId=' + getCookie("orgCode") +"&startTime=" + startTime + "&endTime=" + endTime + "&i=" +new Date();
          // }
        } else {
          this.startTime = null;
          this.endTime = null;
          this.$message.warning("开始时间要比结束时间早");
        }
      } else {
        this.getRequestUrl();
      }
    },
    selectionChange(selection) {
      this.options.mapList = selection;
    },
    onreserved() {
      this.$router.push({
        path: "/bar2_addSteelInbound"
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.steel_inbound02 {
  .sache {
    margin-left: 20px;
    margin-top: 20px;
  }
  .table {
    margin-left: 20px;
    margin-top: 20px;
  }
}
</style>
