<template>
  <div id="unit" class="binary">
    <div :class="{'basic-main': !isdetail,'binary-left': isdetail}">
      <hand-account-querylist  v-ref:list
                               :row="row"
                               @select-changed="selected"
                               style="width:50%">
      </hand-account-querylist>
    </div>
    <div class="binary-right" :style="{width:'70%'}" v-if="isdetail">
      <hand-account-queryprint v-ref:update
                               :data="row"
                               :parent-data="parentData"
                               @select-changed="selected2">
      </hand-account-queryprint>
    </div>
  </div>
</template>
<script>
/**
 *阶梯气价管理组件
 */

export default {
  title: '抄表结算查询',
  data () {
    return {
      endDate: '',
      row: null,
      parentData: '',
      isdetail: false,
      gasPriceShow: false
    }
  },

  methods: {
    async selected (obj) {
      this.row = obj.val
      this.parentData = this.row.f_userinfo_id
      console.log(this.parentData)
      this.isdetail = false
      await this.$nextTick()
      this.isdetail = true
      if (this.row.pricecount <= 1) {
        this.row.pricecount = null
      }
      this.gasPriceShow = !this.row.pricecount
    },
    selected2 (obj) {
      this.gasPriceShow = true
      this.row = Object.assign({}, this.row, obj.val)
    },
    refresh () {
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
      this.$refs.list.search()
    }
  },
  events: {
    'success' (name, row, res) {
      this.row = row
      this.gasPriceShow = false
      this.isdetail = false
      this.$refs.list.search()
      if (row.pricecount) {
        this.$refs.update.getUpdate()
      }
    },
    'error' (name, row, res) {
      this.row = row
      this.gasPriceShow = false
      this.isdetail = false
      this.$refs.list.search()
      if (row.pricecount) {
        row.pricecount === 1
        this.$refs.update.getUpdate()
      }
    },
    'close' (res) {
      this.$refs.list.$refs.paged.$refs.grid.selectStore.selected = null
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
    },
    'search' () {
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
      // this.$refs.list.search()
    },
    'add' () {
      this.isdetail = true
      if (this.gasPriceShow) {
        this.$refs.gas.initModel()
      }
      this.gasPriceShow = true
      this.$refs.list.$refs.paged.$refs.grid.selectStore.selected = null
      this.row = null
    }
  }
}
</script>
