<template>
  <!-- 新增盘库作业页面 -->
  <div class="addCheckWarehouse">
    <page-title>盘库作业</page-title>
    <div class="material from">
      <span class="text">仓库：</span>
      <el-input class="input" v-model="warehouseName" disabled> </el-input>
      <el-button type="primary" @click="ondrawer(2)">浏览</el-button>
    </div>
    <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="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 {
      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/getSteelMaterialList?apiId=443"
      }else{
          this.second.requestUrl = "/api/v1/uc/getUnloadingMesByLike?apiId=374&index=库" + "&i=" + new Date();
      }
    },
    // 返回
    onClickCancel() {
      this.$router.push("/bar1_steel_checkWarehouse");
    },
    currentRadioChange1(selection) {
      console.log(selection);
      this.materialName = selection.materialName + selection.materialSpecification + '(' + selection.materialModel + ')' ;
      this.materialId = selection.materialId;
      this.materialCode = selection.materialCode
    },
    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/insertStockTaking?warehouseId=" + this.warehouseId + "&materialCode=" + this.materialCode + "&quantity=" + this.materialNumber ).then((res) => {
          if (res.data.code == "200") {
            this.$message({
              message: "添加成功!",
              type: "success",
            });
            this.disabled = false
            this.onClickCancel()
          }
        });
    },
  },
};
</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>