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

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

    <div class="binary-left panel panel-info" style="width: 66%" v-if="isdetail">
      <div class="panel-heading auto">
          &nbsp;&nbsp;&nbsp;{{parentData}}工具卡制作
      </div>
      <div style="height: auto" >
        <card-type-list class="col-sm-12" v-ref:update :carddata="row"  :parent-data="parentData" :card-info="cardInfo" @select-changed="selected2"></card-type-list>
        <card-type-detail class="col-sm-12" :typedata="row" :toolcardname="toolcardname" :config="config" :parent-data="parentData"  v-if="gasPriceShow" @close="refresh" @card-readed="cardReaded" v-ref:gas></card-type-detail>
      </div>
      <div style="margin-top: 3%">
        <read-tool-card></read-tool-card>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  title: '工具卡',
  data () {
    return {
      row: null,
      parentData: '',
      toolcardname: '',
      isdetail: false,
      gasPriceShow: false,
      cardInfo: {
        rows: []
      }
    }
  },
  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) {
      console.log('this.row ===> ' + JSON.stringify(this.row))
      console.log('obj ===> ' + JSON.stringify(obj))
      this.row = Object.assign({}, this.row, obj)
      this.gasPriceShow = true
    },
    // refresh () {
    //   this.row = null
    //   this.gasPriceShow = false
    //   this.isdetail = false
    //   this.$refs.list.search()
    // }
    cardReaded (cardInfo) {
      this.$set('cardInfo', {rows: cardInfo})
    }
  },
  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>
