<template>
  <div class="col-sm-12" >
    <div class="col-sm-6">
      <ware-house-list @select-changed="selected" v-ref:houselist></ware-house-list>
    </div>
    <div class="col-sm-6">
      <ware-house-operation :f_distribution_state="f_distribution_state" :row="row" :rowsdata="rowsdata"></ware-house-operation>
    </div>
  </div>
</template>

<script>
  export default {
    title: '仓库管理',
    name: 'WareHouseManage',
    data () {
      return {
        // 分配状态
        f_distribution_state: '',
        // 单选数据
        row: {},
        // 多选数据
        rowsdata: []
      }
    },
    created () {
    },
    ready () {
      this.arrAddFun()
    },
    methods: {
      arrAddFun() {
        //拓展数组去空值的方法
        Array.prototype.removeEmpty=function () {
          for(var i=0;i<this.length;i++){
            if(this[i]=="" || typeof(this[i])=="undefined"){
              this.splice(i,1);
              i--;
            }
          }
          return this;
        }
      },
      //合并二维数组并去空
      mergeRowData(rowsdata){
        let data = []
        //合并
        for(let array of rowsdata){
          data.push.apply(data,array);
        }
        //去空
        data = data.removeEmpty()
        this.rowsdata = data
      },
      selected (row) {
        this.row = row.val
      }
    },
    events: {
      'change-state' (state) {
        console.log('收到',state)
        this.f_distribution_state = state
      },
      'select' (rowsdata) {
        this.mergeRowData(rowsdata)
      },
      // 重新查询
      'refresh' () {
        this.$refs.houselist.search()
      },
      // 调拨组件选择调出仓库,根据选择仓库进行查询
      'idsearch' (f_warehouse_id) {
        this.$refs.houselist.$refs.paged.$refs.criteria.model.f_warehouse_id = f_warehouse_id
        this.$refs.houselist.search()
      }

    }
  }
</script>

<style lang="less">

</style>
