<template>
  <div id="unit" class="row" :class="{'binary':showItem}">
    <div :class="{'basic-main':!showItem,'binary-left':showItem}" style="height:98%">
      <bill-list-maintain @select-changed="idsearch" :showMessage.sync="showAddMssage" v-if="stepControl"
                          v-ref:stocklist></bill-list-maintain>
    </div>
    <div class="binary-right" v-if="showItem">
      <bill-operator-maintain :recordlist="recordlist" :model="model" :oldmodel="oldmodel" v-show="showItem"
                              :row="row" :rowsdata="rowsdata1"
                              ></bill-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: 'billRecordManage',
    data () {
      return {
        showupload: false,
        recordlist: [],
        model: {},
        oldmodel: {},
        showAddMssage: false,

        // 单选数据
        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 = ' bill_id= ' + this.model.id + " and tablename='t_billdetail'"
        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: {
      'close' () {
        this.showItem = false
        this.$refs.stocklist.search()
        console.log('this.$refs', this.$refs)
        console.log('showitem', this.showItem)
      }
    }
  }
</script>

<style lang="less">

</style>
