<template>
    <app-view class="bank-statement">
        <template #header>
            <app-navbar title="资金流水">
                <template #right>
                    <div class="button-more" @click="routerTo('bank-hisstatement')" style="padding:.2rem;">
                        <span>更多</span>
                    </div>
                </template>
            </app-navbar>
        </template>
        <app-pull-refresh v-model:loading="loading" v-model:error="error" v-model:pageIndex="pageIndex"
            :page-count="pageCount" @refresh="run">
            <app-list class="bank-statement__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 { useRequest } from '@/hooks/request'
import { useNavigation } from '@/hooks/navigation'
import { getAccountBusinessCodeName } from '@/constants/bank'
import { queryAmountLog } from '@/services/api/bank'
import AppPullRefresh from '@mobile/components/base/pull-refresh/index.vue'
import AppList from '@mobile/components/base/list/index.vue'

const { routerTo } = useNavigation()
const dataList = shallowRef<Model.AmountLogRsp[]>([])
const error = shallowRef(false)

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

const { loading, pageIndex, pageCount, run } = useRequest(queryAmountLog, {
    manual: true,
    params: {
        pagesize: 20,
        pageflag: 1,
    },
    onSuccess: (res) => {
        if (pageIndex.value === 1) {
            dataList.value = []
        }
        dataList.value.push(...res.data)
    },
    onError: () => {
        error.value = true
    }
})
</script>

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

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