usertab.vue 3.29 KB
<template>
  <div class="user-tab flex">
    <template v-for="(tab, index) in userData">
      <div :class="['tab-item', { active: selectIndex == index }]" :key="index" @click="getTrend(tab.view, tab.text)">
        <div class="tab-title">{{ tab.text }}</div>
        <div class="tab-count text-linear">{{ numAddSymbol(dataList[tab.value]) }}</div>
        <div class="tab-increase flex-between">
          <div class="increase-text">当年新增</div>
          <div class="increase-count">{{ numAddSymbol(dataList[tab.key]) }}</div>
        </div>
      </div>
    </template>
  </div>
</template>

<script>
const TEXT_VIEW = [
  {
    text: '用户数',
    value: 'totalnum',
    key: 'increnum',
    view: 'total'
  },
  {
    text: '企微客户数',
    value: 'totalwechatnum',
    key: 'increwechatnum',
    view: 'wechat'
  },
  {
    text: '企微群数',
    value: 'totalwechatgroupnum',
    key: 'increwechatgroupnum',
    view: 'wechatgroup'
  },
  {
    text: '小程序',
    value: 'totalappletnum',
    key: 'increappletnum',
    view: 'applet'
  },
  {
    text: '个微客户数',
    value: 'totalsinglewechantnum',
    key: 'incresinglewechantnum',
    view: 'individual'
  }
]
export default {
  name: 'UserTab',
  data() {
    return {
      dataList: {},
      userData: TEXT_VIEW,
      selectIndex: 0
    }
  },
  async created() {
    await this.getoverview()
    this.getTrend('total', '用户数')
  },
  methods: {
    getoverview() {
      this.api.user.getoverview().then(res => {
        if (res.code == 0) {
          this.dataList = res.data.dataList[0]
        }
      })
    },

    getTrend(queryItem, name) {
      const selectIndex = TEXT_VIEW.findIndex(item => item.text == name)
      if (selectIndex > 2) return
      this.selectIndex = selectIndex
      const params = { req: { queryItem } }
      this.api.user.getTrend(params).then(res => {
        if (res.code == 0) {
          const dataList = res.data.dataList
          const obj = {
            dataList,
            name
          }
          this.$bus.$emit('drawPrivateChart', obj)
        }
      })
    }
  }
}
</script>
<style scoped lang="scss">
.user-tab {
  height: 9.02vh;
  margin: 1.46vh 0 0.98vh 0;
  .tab-item {
    cursor: pointer;
    width: 9.65vw;
    height: 9.02vh;
    background: #0b0e31;
    margin-right: 0.28vw;
    padding: 0.28vh 0;
    box-sizing: border-box;
    &.active {
      border: 1px solid #6578ff;
      position: relative;
      &::after {
        content: '';
        position: absolute;
        bottom: -4px;
        left: 50%;
        height: 6px;
        width: 6px;
        margin-left: -3px;
        background: #0b0e31;
        border-bottom: 1px solid #6578ff;
        border-right: 1px solid #6578ff;
        transform: rotate(45deg);
      }
    }
    .tab-title {
      font-weight: 400;
      font-size: 12px;
      color: #e8e8e8;
      margin: 0 0.69vw;
      height: 2.07vh;
    }
    .tab-count {
      font-weight: 700;
      font-size: 22px;
      margin: 0 0.69vw;
      height: 3.8vh;
      line-height: 3.8vh;
    }
    .tab-increase {
      height: 2.44vh;
      border-top: 1px solid #171f60;
      padding: 0 0.69vw;
    }
    .increase-text {
      font-size: 9px;
      color: #dddddd;
    }
    .increase-count {
      font-weight: 700;
      font-size: 12px;
      color: #ffffff;
    }
  }
}
</style>