<template>
    <app-view class="bank-hisstatement">
        <template #header>
            <app-navbar title="历史资金流水" />
        </template>
        <app-pull-refresh v-model:error="error" v-model:pageIndex="pageIndex" :page-count="pageCount"
            @refresh="onRefresh">
            <app-list class="bank-hisstatement__table" :columns="columns" :data-list="dataList">
                <template #createtime="{ value }">
                    <span>{{ formatDate(value, 'YYYY-MM-DD') }}</span>
                    <span>{{ formatDate(value, 'HH:mm:ss') }}</span>
                </template>
                <template #businesscode="{ value }">
                    {{ getAccountBusinessCodeName(value) }}
                </template>
            </app-list>
        </app-pull-refresh>
    </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { formatDate } from '@/filters'
import { getAccountBusinessCodeName } from '@/constants/bank'
import { useHisAmountStatementList } from '@/business/bank'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
import AppList from '@mobile/components/base/list/index.vue'

const { pageIndex, pageCount, getHisAmountStatementList } = useHisAmountStatementList()
const dataList = shallowRef<Model.HisAmountLogRsp[]>([])
const error = shallowRef(false)

const columns: Model.TableColumn[] = [
    { prop: 'createtime', label: '时间' },
    { prop: 'businesscode', label: '操作类型' },
    { prop: 'amount', label: '积分' },
]

const onRefresh = (finish: () => void) => {
    getHisAmountStatementList().then((res) => {
        if (pageIndex.value === 1) {
            dataList.value = []
        }
        dataList.value.push(...res)
    }).catch(() => {
        error.value = true
    }).finally(() => {
        finish()
    })
}
</script>

<style lang="less">
.bank-hisstatement {
    &__table {
        td.app-list__column {
            &:first-child {
                span:last-child {
                    color: #999;
                    font-size: .24rem;
                }
            }

            &:not(:first-child) {
                font-size: .32rem;
            }
        }
    }
}
</style>