// 新增倒库单
<template>
    <div class="steel_restackAdd">
        <div class="search">
            <div class="warehouse">
                <span>仓库名称：</span>
                <el-select v-model="value1" placeholder="请选择" @change="onchange1()">
                    <el-option
                    v-for="(item,i) in options1"
                    :key="i"
                    :label="item.label"
                    :value="item.value"
                    >
                    </el-option>
                </el-select>
            </div>
            <div class="stack">
                <span>垛位：</span>
                <el-select v-model="value2" placeholder="请选择" @change ="onchange2()">
                    <el-option
                        v-for="(item,i) in options2"
                        :key="i"
                        :label="item.label"
                        :value="item.value"
                    >
                    </el-option>
                </el-select>
            </div>
            <div class="gradationnumber">
                <span>层次：</span>
                <el-select v-model="value3" placeholder="请选择" @change="onchange3()">
                    <el-option
                    v-for="(item,i) in options3"
                    :key="i"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
            </div>
            <div class="newWarehouse">
                <span>新仓库：</span>
                <el-select v-model="value4" placeholder="请选择" @change="onchange4()">
                    <el-option
                    v-for="(item,i) in options1"
                    :key="i"
                    :label="item.label"
                    :value="item.value">
                    </el-option>
                </el-select>
            </div>
        </div>
        <div class="table" >
            <dilTable v-bind.sync="options11"  @selection-change="selectionChange"></diltable>
        </div>
        <div class="button_box">
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="onClickConfirm()">确定</el-button>
        </div>
    </div>  
</template>

<script>
// import PageTitle from "@/components/Page/Title";
export default {
  data(){
    return{
      form1:{},
      inputText:"",
        options11:{
        // first请求数据的地址
      requestUrl: "/api/v1/wms/getWmspRestackMakeResultList?apiId=106",
      selectionType: "select",
      mapList:[]
      },

        //仓库
        options1:[],
        // 选中的仓库
        value1:'',
        // 垛位
        options2:[],
        // 选中垛位
        value2:'',
        // 层次
        options3:[],
        // 选中的层次
        value3:'',
        //新仓库
        value4:'',
        // 新增下拉框
        // 垛位
        options5:[],
        // 选中垛位
        value5:'',
        inf: {}
    }
  },
    mounted(){
        this.initialization();
        //新增下拉框方法
        this.initialization1();
    },
     methods: {
         //初始化选择仓库垛位
     initialization(){
         this.axios.get('/api/v1/wms/selectWarehouse').then((res)=>{
             this.options1 = res.data.data
             this.axios.post('/api/v1/wms/getWmspRestackMakeResultList?apiId=106',{
                 warehouseid:this.value1
             }) 
         })
     },
     onchange1(){
            console.log(1);
            //  查询选中的仓库垛位
             this.axios.get('/api/v1/wms/selectStackingId?warehouseid='+this.value1).then((res)=>{
             this.options2 = res.data.data;
             this.options5=res.data.data;
             this.options11.requestUrl="/api/v1/wms/getWmspRestackMakeResultList?apiId=106&warehouseid="+this.value1;
             this.options.requestUrl = "/api/v1/wms/getWmspRestackMakeResultList?apiId=106&warehouseid=" + this.value1;       
         })
     },
     onchange2(){
        if(this.value1 == ''){
            this.$message({
                message: '请选择仓库之后！再选择',
                type: 'warning'
            });
            this.value2 = ''
        }else{
            this.options11.requestUrl="/api/v1/wms/getWmspRestackMakeResultList?apiId=106&warehouseid="+this.value1+"&stackingId="+this.value2;        
            //选择仓库层次号
            this.axios.get('/api/v1/wms/selectGardationNumber?warehouseid='+this.value1+'&stackingId='+this.value2).then((res)=>{
            this.options3 = res.data.data;          
         })
    }},
    onchange3(){
        if(this.value2 == ''||this.value1==''){
            this.$message({
                message: '请选择仓库和垛位之后！再选择',
                type: 'warning'
            });
            this.value3 = ''
        }else{
            console.log(this.value1,this.value2)
            this.options11.requestUrl="/api/v1/wms/getWmspRestackMakeResultList?apiId=106&warehouseid="+this.value1 + 
            "&stackingId="+this.value2+"&gradtionNumber="  + this.value3 
        }
    },
     onclick(){
      console.log("点击事件");
     },
       // 确认
      onClickConfirm() {
        let ivBoundResult = {
            resultBeforeWarehouseId:this.value1,
            resultAfterWarehouseId:this.value4,
            mapList:this.mapList
        };
        console.log(ivBoundResult)
       this.axios
        .post("/api/v1/wms/addIvboundMakeResult", ivBoundResult)
         .then((res) => {
         if(res.data.code == 200){
            this.$router.go(-1); 
            this.$message({
            type: "success",  
            message: "新增成功!",
           });
         }
         
          
        });
    },
    selectionChange(selection) {
        this.mapList = selection
        console.log(this.mapList)
    },
    
    // 取消
    cancel() {
      this.$router.go(-1);
    },
  },
};
</script>
<style lang="scss" scode>
.steel_restackAdd{
    .search{
        height: 5rem;
        display: flex;
        align-items:center;
        padding-left:0.625rem;
        .warehouse,.stack,.gradationnumber,newWarehouse{
            margin-left: 1.25rem;
        }
    }
    .form{
        display: inline;
        justify-content: center;
        margin-left: 1.25rem;
        
    }
    .button_box{
        width: 90%;
        position: fixed;
        bottom: 1.25rem;
        display: flex;
        justify-content: center;
    }
}
</style>