<template>
    <view class="scroll-container theme-light">
        <view class="bt-page">
            <MemberInfoSubNav title="我的积分" @back="goBack" />
            <view class="bt-page__body">
                <view class="mi-mod-points-hero">
                    <text class="mi-mod-points-hero__label">当前积分</text>
                    <text class="mi-mod-points-hero__value">{{ balance }}</text>
                    <text class="mi-mod-points-hero__tip">{{ config.rate }} · {{ config.rule }}</text>
                </view>

                <view class="bt-card">
                    <text class="bt-card__title">快捷入口</text>
                    <view class="bt-grid">
                        <view class="bt-grid__item" hover-class="mi-tap--hover" @tap="goMall">
                            <image class="bt-grid__icon" src="https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/images/star.png" mode="aspectFit" />
                            <text class="bt-grid__label">积分商城</text>
                        </view>
                        <view class="bt-grid__item" hover-class="mi-tap--hover" @tap="goHistory">
                            <image class="bt-grid__icon" src="https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/images/clock.png" mode="aspectFit" />
                            <text class="bt-grid__label">积分明细</text>
                        </view>
                        <view class="bt-grid__item" hover-class="mi-tap--hover" @tap="checkIn">
                            <image class="bt-grid__icon" src="https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/images/usercheck.png" mode="aspectFit" />
                            <text class="bt-grid__label">签到赚积分</text>
                        </view>
                        <view class="bt-grid__item" hover-class="mi-tap--hover" @tap="goReferral">
                            <image class="bt-grid__icon" src="https://gymfuture.oss-cn-chengdu.aliyuncs.com/static/images/share2.png" mode="aspectFit" />
                            <text class="bt-grid__label">邀请赚积分</text>
                        </view>
                    </view>
                </view>

                <view class="bt-card">
                    <view class="bt-trend-link" style="border:none;margin:0;padding:0;" @tap="goHistory">
                        <text class="bt-card__title">最近明细</text>
                        <text class="bt-trend-link__text">查看全部</text>
                    </view>
                    <view v-for="item in historyPreview" :key="item.id" class="mi-mod-points-row">
                        <view class="mi-mod-points-row__info">
                            <text class="mi-mod-points-row__title">{{ item.title }}</text>
                            <text class="mi-mod-points-row__time">{{ item.time }}</text>
                        </view>
                        <text
                            class="mi-mod-points-row__amount"
                            :class="item.amount > 0 ? 'mi-mod-points-row__amount--earn' : 'mi-mod-points-row__amount--spend'"
                        >{{ item.amount > 0 ? '+' : '' }}{{ item.amount }}</text>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import MemberInfoSubNav from '@/components/memberInfo/MemberInfoSubNav.vue'
import { PAGE, navigateToPage } from '@/common/constants/routes.js'
import { getPointsPageData } from '@/common/memberInfo/moduleStore.js'
import { loadMemberStore } from '@/common/memberInfo/store.js'
import { subPageMixin } from '@/common/memberInfo/mixins.js'

export default {
    components: { MemberInfoSubNav },
    mixins: [subPageMixin],
    data() {
        return { balance: 0, config: {}, historyPreview: [] }
    },
    onShow() {
        const data = getPointsPageData(loadMemberStore())
        this.balance = data.balance
        this.config = data.config
        this.historyPreview = data.history.slice(0, 5)
    },
    methods: {
        goMall() { navigateToPage(PAGE.POINTS_MALL) },
        goHistory() { navigateToPage(PAGE.POINTS_HISTORY) },
        goReferral() { navigateToPage(PAGE.REFERRAL) },
        checkIn() { uni.showToast({ title: '签到成功 +10 积分', icon: 'success' }) }
    }
}
</script>

<style>
@import '@/common/style/base.css';
@import '@/common/style/memberInfo/pages/page-reset.css';
@import '@/common/style/memberInfo/pages/sub-page-base.css';
@import '@/common/style/memberInfo/member-info-component-reset.css';
@import '@/common/style/memberInfo/member-info-sub-nav.css';
@import '@/common/style/memberInfo/member-info-tap.css';
@import '@/common/style/memberInfo/pages/body-test-common.css';
@import '@/common/style/memberInfo/pages/module-pages-common.css';
</style>
