<template>
  <div class="app-container">
    <div class="overview-toolbar">
      <el-tooltip content="刷新" placement="top">
        <el-button type="default" size="mini" circle icon="el-icon-refresh" @click="load" />
      </el-tooltip>
    </div>
    <el-row :gutter="16" v-loading="loading">
      <el-col :span="8">
        <el-card shadow="hover"><div class="metric-title">团队 ID</div><div class="metric-val">{{ info.deptId }}</div></el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover"><div class="metric-title">团队名称</div><div class="metric-val">{{ info.deptName }}</div></el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover"><div class="metric-title">团队剩余积分</div><div class="metric-val">{{ info.balance }}</div></el-card>
      </el-col>
    </el-row>
    <el-row :gutter="16" style="margin-top:16px">
      <el-col :span="8">
        <el-card shadow="hover"><div class="metric-title">AI用户数（实时）</div><div class="metric-val">{{ aiUserCountText }}</div></el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover"><div class="metric-title">近 7 日消耗积分 <span class="hint">（5 分钟缓存）</span></div><div class="metric-val">{{ info.last7DaysConsumeScore }}</div></el-card>
      </el-col>
      <el-col :span="8">
        <el-card shadow="hover"><div class="metric-title">近 7 日成功订单数 <span class="hint">（5 分钟缓存）</span></div><div class="metric-val">{{ info.last7DaysOrderCount }}</div></el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getSubteamOverview } from '@/api/subteam'

export default {
  name: 'SubteamOverview',
  data() {
    return {
      loading: true,
      info: {}
    }
  },
  created() {
    this.load()
  },
  computed: {
    aiUserCountText() {
      const cur = this.info.aiUserCount
      const max = this.info.aiUserMaxCount
      const left = cur != null && cur !== '' ? cur : 0
      if (max == null || max <= 0) {
        return left + '/无限制'
      }
      return left + '/' + max
    }
  },
  methods: {
    load() {
      this.loading = true
      getSubteamOverview()
        .then(res => {
          this.info = res.data || {}
        })
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>

<style scoped>
.overview-toolbar {
  margin-bottom: 12px;
}
.metric-title { color: #909399; font-size: 13px; }
.metric-val { font-size: 22px; margin-top: 8px; font-weight: 600; }
.hint { font-size: 12px; color: #909399; }
</style>
