<template>
  <div id="unit" class="flex-row" >

    <tool-card-list :class="{'basic-main':!isdetail,'binary-left':isdetail}"  v-ref:list  :row="row" :ispartial="gasPriceShow"  @select-changed="selected" ></tool-card-list>

    <div class="binary-left"  v-if="isdetail">
      <ul class="nav nav-tabs" >
        <li class="active"><a href="#">工具卡种类</a></li>
      </ul>
      <div style="max-height: 200px;" >
        <card-type-list v-ref:update :carddata="row"  :parent-data="parentData" @select-changed="selected2"></card-type-list>
      </div>
      <card-type-detail :typedata="row" :toolcardname="toolcardname" :config="config"  v-if="gasPriceShow" @close="refresh" v-ref:gas></card-type-detail>
    </div>
  </div>
</template>
<script>
/**
*阶梯气价管理组件
*/


let readGen = async function (self) {
  // 获取气价里面的配置

}

export default {
  title: '工具卡管理',
  data () {
    return {
      row: null,
      parentData: '',
      toolcardname:'',
      isdetail: false,
      gasPriceShow: false
    }
  },
  ready () {
    readGen(this)
  },
  methods: {
    selected (obj) {
      this.row = obj.val
      this.parentData = this.row.name
      this.isdetail = true
      if (this.row.pricecount <= 1) {
        this.row.pricecount = null
      }
      this.gasPriceShow = !this.row.pricecount
    },
    selected2 (obj) {
      this.row = Object.assign({}, this.row, obj.val)
      this.gasPriceShow = true
    },
    // 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.row = null
      this.gasPriceShow = false
      this.isdetail = false
    },
    'search' () {
      this.row = null
      this.gasPriceShow = false
      this.isdetail = false
      // this.$refs.list.search()
    }
  }
}
</script>
<style>

</style>
