<template>
  <div>
    <template v-if="fieldTree.length > 0">
      <template>
        <div style="margin-bottom: 10px;">
          <span style="font-size: 14px;">开启关联模式</span>
          <el-switch style="display: block" v-model="ifHaveChild" active-color="#13ce66" inactive-color="#ff4949"
            active-text="描述：主分类包含子分类" inactive-text="" @change="switchChange">
          </el-switch>
        </div>
      </template>
      <div>
        <el-collapse v-model="activeNames" @change="handleChange($event, 2)" style="margin: 0px 5px 0px 5px;">
          <el-collapse-item v-for="item in fieldTree" :title="item.name" :name="item.value + 'a' + item.filedKind"
            :key="item.value">
            <div v-if="ifShow">
              <el-tree @check-change="onChangeTree($event, item)" :ref="item.value" :data="item.options" node-key="id"
                check-strictly default-expand-all :props="{ children: 'child', label: 'name' }">
                <span class="custom-tree-node" slot-scope="{ node, data }">
                  <el-checkbox-group v-model="item.check">
                    <el-checkbox :label="data.id">{{ data.name }}({{ getCount(item, data.id) }})</el-checkbox>
                  </el-checkbox-group>
                </span>
              </el-tree>
            </div>

          </el-collapse-item>
        </el-collapse>
      </div>

    </template>
    <template v-else>
      <div>暂无数据</div>
    </template>
  </div>
</template>

<script>
import mixins from './mixins'
export default {
  mixins: [mixins],
  props: {
    fieldTree: {
      type: Array,
      default: () => {
        return []
      }
    },
  },
  data() {
    return {
      ifShow: true,
      // 是否关联子分类false不关联，true关联
      ifHaveChild: false,
    }
  },
  watch: {
    // fieldTree: {
    //   handler() {
    //     this.ifShow = false
    //     this.$nextTick(() => {
    //       this.ifShow = true
    //     })
    //   },
    //   deep: true
    // }
  },
  mounted() {

  },
  methods: {
    switchChange(val) {
      this.$emit('switchChange', val)
    },

    // 选中的值
    onChangeTree(data, field) {//当前节点的数据，当前栏位的数据 
      // console.log(data, field);
      // var obj = {
      //   fieldId: field.value,
      //   fieldType: field.fieldType,
      //   value: [],
      //   isStatistic:true,
      // }
      // let arr = []
      // arr.push(obj)
      // this.$emit('customTab',arr)
      // console.log(obj);
    },
  },
}
</script>

<style lang="scss" scoped></style>