<template>
  <ChartsContainer title="学习成长">
    <div ref="content" style="height: 100%;">
      <div class="content-row" v-if=" type ">
        <div class="content-row-title">{{ rowTableItem.name }}</div>
        <div class="content-row-list">
          <div class="content-row-item">
            <div>平均分</div>
            <div>{{ rowTableItem.averageScore }}</div>
          </div>
          <div class="content-row-item">
            <div>最高分</div>
            <div>{{ rowTableItem.highestScore }}</div>
          </div>
          <div class="content-row-item">
            <div>最低分</div>
            <div>{{ rowTableItem.lowestScore }}</div>
          </div>
        </div>
      </div>
      <el-table v-auto-scroll v-else :data="tableData" border style="width: 100%" height="100%">
        <el-table-column prop="name" label="部门" />
        <el-table-column prop="averageScore" label="平均分" min-width="80" />
        <el-table-column prop="highestScore" label="最高分" min-width="80" />
        <el-table-column prop="lowestScore" label="最低分" min-width="80" />
      </el-table>
    </div>
  </ChartsContainer>
</template>

<script setup>
import ChartsContainer from '../ChartsContainer.vue';
import { ref } from 'vue';
import { getGrowthPortrait } from '@/api/item/items'
import { useTimeOut } from '../pageItems/useTimeOut'
const props = defineProps({
  type: {
    type: String,
    default: '' // team, department, station
  }
})
const tableData = ref([])
const rowTableItem = ref({})
const params = inject('provideParams')
useTimeOut(() => {
  let apiParams = {}
  if (props.type === 'team') {
    apiParams = { teamId: params.value.deptId }
  } else if (props.type === 'department') {
    apiParams = { departmentId: params.value.deptId }
  } else if (props.type === 'personal') {
    apiParams = { userId: params.value.deptId }
  } else {
    apiParams = { deptId: params.value.deptId }
  }
  params.value.deptId && getGrowthPortrait(apiParams).then(res => {
    tableData.value = res.data
    rowTableItem.value = (res.data || []).find(item => item.id == params.value.deptId) || {}
  })
}, [ params ])


</script>

<style lang="scss" scoped>
.content-row {
  display: flex;
  flex-direction: column;
  height: 100%;

  .content-row-title {
    font-size: 14px;
    color: #77DBF4;
    height: 30px;
  }

  .content-row-list {
    display: flex;
    flex: 1;
    flex-direction: column;
    justify-content: space-evenly;
    row-gap: 15px;
  }

  .content-row-item {
    flex: 1;
    background: url('../../../../../assets/images/rowBg.png') no-repeat;
    background-position: -10px;
    background-size: calc(100% + 20px) 100%;
    overflow: hidden;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 16px;
    border-radius: 5px;
    padding: 0 15px;
    font-weight: bold;
  }
}
</style>