<template>
  <!-- 新增入库转预留作业页面 -->
  <div class="addCheckWarehouse">
    <page-title>入库转预留作业</page-title>
    <div class="material from">
      <span class="text">物资规格型号：</span>
      <el-input class="input" v-model="materialName" disabled> </el-input>
      <el-button type="primary" @click="ondrawer(1)">浏览</el-button>
    </div>
    <div class="materialNumber from">
      <span class="text">最大预留件数：</span>
      <el-input class="input" v-model="max" disabled> </el-input>
    </div>
    <div class="materialNumber from">
      <span class="text">件数：</span>
      <el-input class="input" v-model="materialNumber"> </el-input>
    </div>
    <!-- 模态窗口 -->
    <el-drawer :visible.sync="drawer" :direction="direction" size="40%">
      <div style="margin-bottom: 10px">
        <el-input
          placeholder="请输入内容"
          v-model="input"
          style="margin-top: 10px; margin-right: 10px; width: 250px"
          clearable
        ></el-input>
        <el-button type="primary" class="btn" @click="onclick(a)">
          <i class="el-icon-search"></i>查询
        </el-button>
      </div>
      <div v-show="a == 1">
        <dilTable
          v-bind.sync="first"
          @radio-change="currentRadioChange1"
        ></dilTable>
      </div>
      <div v-show="a == 2">
        <dilTable
          v-bind.sync="second"
          @radio-change="currentRadioChange2"
        ></dilTable>
      </div>          
    </el-drawer>
    <div class="button_box">
      <el-button @click="onClickCancel">返回</el-button>
      <el-button type="primary" @click="onClickConfirm" :disabled = "disabled">确认</el-button>
    </div>
  </div>
</template>
<script>
import PageTitle from "@/components/Page/Title";
import { sjTime, isNumber, isIntegerNumber } from "@/utils/sharedJsFile";
import { getCookie } from "@/utils/util.js";
export default {
  components: { PageTitle },
  data() {
    return {
      max:null,
      disabled:false,
      //仓库名称
      warehouseName:null,
      //物资名称
      materialName: null,
      //物资编码
      materialCode:null,
      //盘点数量
      materialNumber:null,
      //物资id
      materialId: null,
      //是否需要打开模态窗口
      drawer: false,
      a: 1,
      direction: "rtl",
      input: "",
      first: {
        requestUrl: "",
        selectionType: "radio",
        mapList1: [],
      },
      second: {
          requestUrl: "",
          selectionType:"radio"
      }
    };
  },
  watch: {
    drawer(val) {
      if (!val) {
        this.input = null;
      }
    },
  },
  created() {
      
  },
  methods: {
    onclick(a) {
      if (a == 1) {
        this.first.requestUrl =
          "/api/v1/uc/queryAPOMaterialByLike?apiId=244&startNum=050&index=" +
          this.input;
      }
    },
    ondrawer(num) {
      this.drawer = true;
      this.a = num;
      if(num==1){
          this.first.requestUrl = "/api/v1/wms/getSteelMaterialModelList?apiId=443&warehouseId="+3+"&status="+1
      }
    },
    // 返回
    onClickCancel() {
      this.$router.push("/steel_checkWarehouse");
    },
    currentRadioChange1(selection) {
      console.log(selection);
      this.materialName = selection.materialName + selection.materialSpecification + '(' + selection.materialModel + ')' ;
      this.materialId = selection.materialId;
      this.materialCode = selection.materialCode;
      this.materialSpecification = selection.materialSpecification;
      this.materialModel = selection.materialModel;
      this.max = selection.max;
    },
    currentRadioChange2(selection) {
      this.warehouseId = selection.warehouseId
      this.warehouseName = selection.warehouseName
    },
    // 确认
    onClickConfirm() {
      // console.log(this.warehouseId,this.materialCode,this.materialNumber);
      this.disabled = true
      this.axios.post("/api/v1/wms/insertReserved?warehouseId=" + 3 + "&materialCode=" + this.materialCode+"&materialSpecification="+this.materialSpecification+"&materialModel="+this.materialModel+ "&quantity=" + this.materialNumber ).then((res) => {
        console.log(res.data)
          if (res.data.code == "200") {
            this.$message({
              message: "预留成功!",
              type: "success",
            });
            this.disabled = false
            this.onClickCancel()
            this.$router.go(-1)
          }else if(res.data.code=="201"){
            this.$message({
              message:"预留的数量不正确",
              type:"faile",
            })
          }
          this.$router.go(-1)
        });
    },
  },
};
</script>
<style lang="scss" scope>
.addCheckWarehouse{
.contractDetails {
  width: 100%;
}
.from {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 5px;
  margin-bottom: 20px;
}
.warehouse {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  margin-right: 70px;
  .text {
    display: inline-block;
    width: 170px;
    text-align: right;
  }
  .input {
    width: 250px;
    margin-right: 20px;
  }
}
.material {
  display: flex;
  justify-content: center;
  margin-top: 20px;
  .text {
    display: inline-block;
    width: 170px;
    text-align: right;
  }
  .input {
    width: 250px;
    margin-right: 20px;
  }
}
.materialNumber {
    display: flex;
    justify-content: center;
    margin-top: 20px;
    margin-right: 70px;
    .text {
        display:inline-block;
        width: 170px;
        text-align: right;
    }
    .input {
        width: 250px;
        margin-right: 20px;
    }
}
.button_box {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100px;
}
}
</style>