<template>
  <div id="unit" class="flex-row">
    <sale-material-display @select-changed='selected' @modify-res="modifyRes"
                      @add-res="addRes"
                      class="basic-main" style="width:auto;" v-ref:funlist>
    </sale-material-display>
    <div class="binary-right" style="width: 40%;overflow-x: hidden; overflow-y: scroll;" v-if="row">
      <sale-materials-base  :look='look' :data="row" :title="title"
                       :parent="row.parent_name" @cancel="cancel">
      </sale-materials-base>
    </div>
  </div>
</template>

<script>

export default {
  title: '功能展示',
  data () {
    return {
      row: null,
      look: true,
      title: '功能信息'
    }
  },
  methods: {
    // 选中数据
    selected (obj) {
      this.title = '功能信息'
      this.look = true
      this.row = obj.val.data
    },
    // 修改数据
    modifyRes (obj) {
      this.title = '修改信息'
      this.row = obj.data
      this.look = false
    },
    // 添加数据
    addRes (obj) {
      this.title = '添加功能'
      let type = ''
      if (obj.type === '品名') {
        type = '规格'
      } else if (obj.type === '规格') {
        type = '型号'
      }
      this.row = Object.assign({}, {parent_id: obj.id, type: type})
      this.look = false
    },
    // 返回
    cancel () {
      // 把选择的节点清空  不然点击同样的节点点不出来
      this.$refs.funlist.$refs.list.selectStore.selected = null
      this.row = null
    }

  }
}
</script>
