<template>
  <!-- 具体标签 -->
  <div class="tag-some-list">
    <el-table :data="tableData">
      <el-table-column label="标签名称" prop="tagName" min-width="120">
        <template slot-scope="scope">
          <span class="tag-name">{{ scope.row.tagName }}</span>
          <el-tooltip class="item" effect="dark" content="添加标签" placement="top">
            <i class="iconfont icon-tag-name icon-PlusOutlined" v-if="getCodeAuth" :limit-code="getCode" v-track:common.click="handleTrackParam('addTag', scope.row)" @click="addTag(scope.row)"></i>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column v-if="type != 'system'" label="覆盖人数" prop="memberCount" min-width="140" show-overflow-tooltip>
        <template slot="header">
          覆盖人数
          <el-popover width="260" trigger="hover" placement="top">
            <div style="color: #303133;">
              标签下不同标签值可能覆盖相同的会员，因此此处“标签”覆盖人数去重显示（如“喜欢的颜色-白、红、黑、蓝”，某会员身上可能同时具备“白、黑”二种标签值）
            </div>
            <i slot="reference" class="iconfont icon-QuestionCircleOutlined refresh"></i>
          </el-popover>
        </template>

        <template slot-scope="scope">
          {{ scope.row.memberCount ? (scope.row.memberCount | formatNum) + '人' : '--' }}
        </template>
      </el-table-column>
      <el-table-column v-else label="是否实时" prop="isActive" min-width="40">
        <template slot-scope="scope">
          <span> {{ scope.row.isActive == 1 ? '实时' : '非实时' }} </span>
        </template>
      </el-table-column>
      <el-table-column min-width="200" label="标签描述" prop="tagDescribe" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.tagDescribe || '--'}}
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import Emitter from '@/mixins/emitter';
import tagDetails from '@/components/tagDetail/mixin/index';
export default {
  name: 'tag-container',

  mixins: [tagDetails, Emitter],

  props: {
    data: {
      type: Array,
      default() {
        return [];
      }
    },
    type: String,
    refersh: Object
  },

  data() {
    return {
      tableData: [],
      tagData: {}
    };
  },
  methods: {
    addTag(list) {
      this.$emit('addTag', list);
    },
    handleTrackParam(type, data) {
      let fn = {
        addTag: () => {
          return {
            data: { id: data.tagId, name: data.tagName }
          };
        }
      }[type];
      return { fn: () => {}, data: fn ? fn() : {} };
    }
  },
  watch: {
    data: {
      immediate: true,
      handler(newval) {
        this.tableData = newval;
      }
    },
    refersh: {
      immediate: true,
      handler(newval) {
        // 刷新
        if (newval.changeRefersh) {
          let index = this.tableData.findIndex(el => newval.tagId === el.tagId);
          this.tableData[index].refersh = true;
        }
      }
    }
  },
  computed: {
    getCodeAuth() {
      let code = 'memberTagCreateGroup';
      return this.$getButtonLimit(this.$buttonCode[code]);
    },
    getCode() {
      let code = 'memberTagCreateGroup';
      return this.$buttonCode[code];
    }
  }
};
</script>

<style lang="scss" scoped>
.tag-some-list {
  height: 430px !important;
  margin-left: 20px;
  overflow-y: auto;
}
.icon-tag-name {
  display: inline-block;
  vertical-align: bottom;
  font-size: 16px;
  cursor: pointer;
  color: #303133;
  transition: all 0.3s;
  color: #2f54eb;
  &:hover {
    transform: scale(1.25);
  }
}
.refresh {
  color: #606266;
  position: relative;
  top: 1px;
}
</style>
