<template>
  <div id="unit" class="flex-row">
    <div class="flex" style="flex: 1; width:70%">
      <distribution-gather v-ref:list :row="row" @select-changed="selected"></distribution-gather>
      <distribution-detail v-show='disdetail' :data="row" @select-changed="detailselected" v-ref:detail></distribution-detail>
    </div>
    <div style="width:30%" v-if="modify || isShow">
      <modify-distribution v-if="modify" :data="modifyrow" v-ref:modifydis></modify-distribution>
      <change-bill-state  v-if="isShow" :data="billInfo"></change-bill-state>
    </div>
  </div>
</template>
<script>
  /**
   *发票分配汇总组件
   */
  export default {
    title: '发票管理',
    data () {
      return {
        isShow: false,
        row: null,
        modify: false,
        billInfo: null,
        disdetail: false,
        modifyrow: null
      }
    },
    watch: {
      'row' (val) {
        if (val && val.id) {
          this.disdetail = true
        }
      }
    },
    methods: {
      selected (obj) {
        this.row = obj.val
        this.modify = true
        this.isShow = false
        this.modifyrow = obj.val
      },
      detailselected (obj) {
        this.modify = false
        this.isShow = true
        this.billInfo = obj.val
      }
    },
    events: {
      'success' (name, row, res) {
        // this.billInfo = null
        this.isShow = false
        this.modify = true
        this.modifyrow = null
        this.$refs.list.search()
        this.$refs.detail.getBillDetail()
      },
      'clean' (row) {
        // this.billInfo = null
        this.isShow = false
        this.modify = true
        this.modifyrow = null
        this.$refs.list.search()
        this.$refs.detail.getBillDetail()
      },
      'error' (name, row, res) {
        this.billInfo = null
        this.$refs.list.search()
      },
      'add' (type) {
        this.modify = true
        this.isShow = false
        if (type === 'add') {
          this.$refs.modifydis.zzfph = false
          this.modifyrow = this.$refs.modifydis.initModel()
        } else if (type === 'update') {
          this.row = this.row
        }
      }
    }
  }
</script>
