<template>
  <div id="unit" class="row" :class="{'binary':showItem}">
    <div :class="{'basic-main':!showItem,'binary-left':showItem}" style="height:98%">
      <garbage-list @select-changed="idsearch" :showMessage.sync="showAddMssage" v-if="stepControl"
                  v-ref:stocklist></garbage-list>
    </div>
    <div class="binary-right"  v-show="showItem">
      <garbage-main :recordlist="recordlist" :model="model" :oldmodel="oldmodel" v-show="showItem"
                            :f_distribution_state="f_distribution_state" :row="row" :rowsdata="rowsdata1"
                            :warehousename="warehousename"></garbage-main>
    </div>
  </div>

</template>

<script>
  import {HttpResetClass} from 'vue-client'
  export default {
    title: '垃圾费费记录维护',
    name: 'GarbageManage',
    data () {
      return {
        showupload: false,
        recordlist: [],
        model: {},
        oldmodel: {},
        showAddMssage: false,
        // 分配状态z
        f_distribution_state: '',
        // 单选数据
        row: {},
        // 多选数据
        rowsdata: [],
        rowsdata1: {},
        stepControl: true,
        warehousename: '',
        showItem: false
      }
    },
    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
      },
      join (rowsdata) {
      },
      idsearch (row) {
        this.$refs.stocklist.editList = true
        this.showAddMssage = true
        this.showItem = true
        this.model = JSON.parse(JSON.stringify(row.val))
        this.oldmodel = JSON.parse(JSON.stringify(row.val))
        this.getGroupData()
      },
      getGroupData () {
        let data = {}
        let condition = ' garbage_id= ' + this.model.id
        condition += " and tablename='t_flotsamprice'"
        data.condition = condition
        let http = new HttpResetClass()
        http.load('POST', 'rs/logic/OperationRecord',
          {data: data},
          {resolveMsg: null, rejectMsg: null}).then((res) => {
            this.recordlist = res.data
          })
      }
    },
    events: {
      'change-state' (state) {
        this.f_distribution_state = state
        this.rowsdata1 = {}
      },
      'getwarehouse' (a) {
        this.warehousename = a
      },
      'change-receive' (state) {
        this.f_distribution_state = state
      },
      'change-state1' (state) {
        console.log('选择分配状态', state)
        this.rowsdata1 = {}
      },
      'select' (rowsdata) {
        this.mergeRowData(rowsdata)
      },
      'join' (rowsdata) {
        this.rowsdata1 = Object.assign({}, rowsdata)
        console.log('111:', this.rowsdata1)
      },
      // 重新查询
      'refresh' () {
      },
      'close' () {
        this.$refs.stocklist.editList = false
        this.showItem = false
        this.$refs.stocklist.$refs.paged.$refs.criteria.search()
        console.log('this.$refs', this.$refs)
        console.log('showitem', this.showItem)
      },
      // 调拨组件选择调出仓库,根据选择仓库进行查询
      'idsearch' (f_warehouse_id) {
      }
    }
  }
</script>

<style lang="less">

</style>
