<template>
  <div id="unit">
    <div v-if="isEnable" 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' v-ref:detail  :data="row" @select-changed="detailselected" style="height:200px"></distribution-detail>
      </div>
      <div style="width:35%" v-if = "modify">
        <modify-distribution :data="modifyrow" v-ref:modifydis></modify-distribution>
      </div>
      <div style="width:35%" v-if = "isShow">
        <change-bill-state :data="billInfo"></change-bill-state>
      </div>
    </div>
    <div v-if="!isEnable" class="flex">
      <distribution-detail :enable="isEnable"></distribution-detail>
    </div>
  </div>
</template>
<script>
  /**
   *发票分配汇总组件
   */

  export default {
    title: '发票管理',
    data () {
      return {
        isShow: false,
        row: null,
        modify: false,
        billInfo: null,
        disdetail: false,
        modifyrow: null,
        isEnable: false
      }
    },
    watch: {
      'row' (val) {
        if (val && val.id) {
          this.disdetail = true
        }
      }
    },
    ready () {
      // 获取是否启用发票管理
      this.isEnable = this.$appdata.getSingleValue('发票管理') === '启用'
    },
    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 = false
        this.disdetail = false
        this.modifyrow = null
        this.$refs.list.search()
        this.$refs.detail.search()
      },
      'clean' (row) {
        // this.billInfo = null
        this.isShow = false
        this.modify = false
        this.disdetail = false
        this.modifyrow = null
        this.$refs.list.search()
        this.$refs.detail.search()
      },
      '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>
