<template>
  <div class="col-sm-12" >
    <div class="col-sm-6">
      <repository-list @select-changed="idsearch" style="height: 30%" v-ref:repositorylist></repository-list>
      <ware-house-list1 @select-changed="selected" style="height: 69%;margin-top: 1%" v-ref:houselist></ware-house-list1>
    </div>
    <div class="col-sm-6">
      <meter-operation :f_distribution_state="f_distribution_state" :f_warehouse_id="f_warehouse_id" :row="row" :rowsdata="rowsdata"></meter-operation>
    </div>
  </div>
</template>

<script>
  export default {
    title: '表具管理',
    name: 'MeterReceiveManage',
    data () {
      return {
        // 分配状态
        f_distribution_state: '',
        // 选择仓库id
        f_warehouse_id: '',
        // 单选数据
        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
      },
      // 根据选择仓库进行查询
      idsearch (row) {
        this.$refs.houselist.$refs.paged.$refs.criteria.model.f_warehouse_id = row.val.id
        this.$refs.houselist.search()
      }
    },
    events: {
      'change-state' (state) {
        console.log('收到',state)
        this.f_distribution_state = state
      },
      'change-warehouseid' (f_warehouse_id) {
        console.log('收到仓库id',f_warehouse_id)
        this.f_warehouse_id = f_warehouse_id
      },
      'select' (rowsdata) {
        this.mergeRowData(rowsdata)
      },
      // 重新查询
      'refresh' () {
        this.$refs.houselist.search()
        this.$refs.repositorylist.search()
      }
    }
  }
</script>

<style lang="less">

</style>
