<template>
  <div id="bFangSearch" ref="bFangSearchRef">
    <ProjectSelect ref="projectSelectRef" clearable :_style="{width:'115px'}"/>
    <VxeInput v-model="queryParam.dcPl" clearable style="width: 110px" placeholder="请输入批量"/>
    <VxeButton status="primary" content="查询" @click="search" />
    <VxeSelect v-model="plParam.qy" ref="qyRef" clearable :options="qyList" @change="qyChange" style="margin-left: 10px;width: 125px" placeholder="选择区域"/>
    <VxeSelect v-model="plParam.dw" ref="dwRef" clearable :options="dwList" style="width: 115px" placeholder="选择垛位"/>
    <VxeButton status="primary" content="批量" @click="pl" />
    <VxeButton status="primary" content="提交" @click="tj" />
  </div>
</template>

<script>
import ProjectSelect from "@/components/ProjectSelect/index.vue";
import {getBFangDwxx} from "@/views/zyjhzx/bfang/comps/api";
import {EventBus} from "@/event-bus";

export default {
  name: 'BFangSearch',
  components: {ProjectSelect},
  data(){
    return {
      qyList:[],
      dwList:[],
      qyData:{},
      plParam:{
        qy:'',
        dw:''
      },
      queryParam:{
        dcPl:'',
      }
    }
  },
  created(){
    this.getDw()
  },
  methods:{
    search(){
      this.queryParam.dcCh=this.$refs.projectSelectRef.getDcch()
      EventBus.$emit('bfSearch', this.queryParam)
    },
    tj(){
      EventBus.$emit('bfSave', {})
    },
    pl(){
      EventBus.$emit('pl', this.plParam)
    },
    qyChange({value}){
      this.dwList=[]
      this.qyData[value]?.forEach(item=>{
        const dw={label:item.dwh,value:item.dwh};
        this.dwList.push(dw)
      })
    },
    getDw(){
      getBFangDwxx().then((res)=>{
        this.qyData=res.data
        this.qyList=[]
        Object.keys(this.qyData).forEach(key=>{
          const qy={label:key,value:key};
          this.qyList.push(qy)
        })
      })
    },
    getData(){

    }
  }
}
</script>
