<template>
  <div id="unit" class="row" :class="{'binary':showItem}">
    <div :class="{'basic-main':!showItem,'binary-left':showItem}" style="height:98%">
      <hand-list-maintain @select-changed="idsearch" :showMessage.sync="showAddMssage" v-if="stepControl"
                            v-ref:stocklist></hand-list-maintain>
    </div>
    <div class="binary-right" v-if="showItem">
      <hand-operator-maintain :recordlist="recordlist" :model="model" :oldmodel="oldmodel" v-show="showItem"
                                :f_distribution_state="f_distribution_state" :row="row" :rowsdata="rowsdata1"
                                :warehousename="warehousename"></hand-operator-maintain>
    </div>
  </div>
  <modal :show.sync="showupload" width="80%" style="width:auto;"  v-ref:modal middle backdrop="false">
    <article slot="modal-body">
      <upload :blodid="row.f_userinfo_id" v-ref:upload isupload="false" takeimg="false" :businessid="row.id" fusetype="抄表" isremark="false" style="width:auto" ></upload>
    </article>
    <footer slot="modal-footer" class="modal-footer">
    </footer>
  </modal>
</template>

<script>
  import {HttpResetClass} from 'vue-client'
  export default {
    title: '抄表记录维护',
    name: 'WareHouseManage',
    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
      },
      // changeDisplay () {
      //   this.stepControl = !this.stepControl
      //   this.$dispatch('change-state', '')
      // },
      join (rowsdata) {

      },
      idsearch (row) {
        this.showAddMssage = true
        this.showItem = true
        this.model = JSON.parse(JSON.stringify(row.val))
        this.oldmodel = JSON.parse(JSON.stringify(row.val))

        this.getGroupData()
      },
      async getGroupData () {
        console.log('获取记录')
        let condition = ' hand_id= ' + this.model.id + " and tablename='t_handplan'"
        let res = await this.$resetpost('rs/sql/singleTable_OrderBy', {
          data: {
            items: '*',
            tablename: 't_inforecord',
            orderitem: 'modifitime DESC',
            condition: condition
          }
        }, {resolveMsg: null, rejectMsg: '获取记录出错'})
        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.showItem = false
        this.$refs.stocklist.search()
        console.log('this.$refs', this.$refs)
        console.log('showitem', this.showItem)
      },
      // 调拨组件选择调出仓库,根据选择仓库进行查询
      'idsearch' (f_warehouse_id) {

      }
    }
  }
</script>

<style lang="less">

</style>
