<template>
  <div class="dily-register-user" :data-language="language">
    <el-row :gutter="10">
      <el-col :span="24">
        <div v-for="(item, index) in list" :key="index">
          <el-card v-if="sysOriginPlatforms.includes(item.sysOrigin)" class="box-card">
            <div slot="header" class="clearfix">
              <span>{{ $t('pages.dashboard.dailyRegisterUser.title', { sysOriginName: item.sysOriginName }) }}</span>
            </div>
            <div v-loading="loading" style="padding: 10px 0">
              <el-row :gutter="20" class="register-logout-count">
                <el-col :span="24">
                  <div class="date">{{ item.registerLogout ? item.registerLogout.statisticsTime : '' | dateFormat('yyyy-MM-dd') }}</div>
                </el-col>
                <el-col :md="6" :xs="24">
                  <div class="block-card">
                    <div class="block-card-title">{{ $t('pages.dashboard.dailyRegisterUser.male') }}</div>
                    <div class="block-card-content cite">{{ item.registerLogout ? item.registerLogout.maleCount || 0 : 0 }}</div>
                  </div>
                </el-col>
                <el-col :md="6" :xs="24">
                  <div class="block-card">
                    <div class="block-card-title">{{ $t('pages.dashboard.dailyRegisterUser.maleLogout') }}</div>
                    <div class="block-card-content cite">{{ item.registerLogout ? item.registerLogout.maleLogout || 0 : 0 }}</div>
                  </div>
                </el-col>
                <el-col :md="6" :xs="24">
                  <div class="block-card">
                    <div class="block-card-title">{{ $t('pages.dashboard.dailyRegisterUser.female') }}</div>
                    <div class="block-card-content cite">{{ item.registerLogout ? item.registerLogout.femaleCount || 0 : 0 }}</div>
                  </div>
                </el-col>
                <el-col :md="6" :xs="24">
                  <div class="block-card">
                    <div class="block-card-title">{{ $t('pages.dashboard.dailyRegisterUser.femaleLogout') }}</div>
                    <div class="block-card-content cite">{{ item.registerLogout ? item.registerLogout.femaleLogout || 0 : 0 }}</div>
                  </div>
                </el-col>
                <el-col class="card-col" :md="24" :xs="24">
                  <line-graph-charts :key="item.sysOrigin + '-' + language" :charts-data="item.lastMonths" height="300px" />
                </el-col>
              </el-row>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { latestRegisterLogout } from '@/api/statistics'
import LineGraphCharts from './line-graph-charts'
import { mapGetters } from 'vuex'

export default {
  name: 'DilyRegisterUser',
  components: { LineGraphCharts },
  data() {
    return {
      loading: false,
      list: []
    }
  },
  computed: {
    ...mapGetters(['permissionsSysOriginPlatformAlls', 'language']),
    sysOriginPlatforms() {
      if (!this.permissionsSysOriginPlatformAlls || this.permissionsSysOriginPlatformAlls.length <= 0) {
        return []
      }
      return this.permissionsSysOriginPlatformAlls.map(item => item.value)
    }
  },
  created() {
    if (!this.permissionsSysOriginPlatformAlls || this.permissionsSysOriginPlatformAlls.length <= 0) {
      return
    }
    this.renderData()
  },
  methods: {
    renderData() {
      this.loading = true
      latestRegisterLogout().then(res => {
        this.loading = false
        const { body } = res
        const list = body || []
        this.list = list.filter(item => !item.sysOrigin || this.permissionsSysOriginPlatformAlls.some(sys => sys.value === item.sysOrigin))
      }).catch(() => {
        this.loading = false
      })
    }
  }
}
</script>

<style scoped lang="scss">
.box-card {
  margin-bottom: 10px;
  padding: 10px;

  .card-col {
    margin-bottom: 10px;
  }
}

.register-logout-count {
  .date {
    font-weight: bold;
    line-height: 30px;
  }
}
</style>
