<!-- 账号管理-资金账户管理-资金流水 -->
<template>
    <teleport to="#appPageTeleport">
        <app-view>
            <template #header>
                <app-filter :option="filterOption" />
            </template>
            <app-table :data="dataList" :columns="tableColumns" :loading="loading">
                <template #headerLeft>
                    <span>{{ t('account.fundacct.bankstatement.accountId') }}：{{ record.accountId }}</span>
                </template>
                <template #headerRight>
                    <div>
                        <el-button type="primary">{{ t('operation.export') }}</el-button>
                        <el-button @click="emit('closed')">{{ t('operation.close') }}</el-button>
                    </div>
                </template>
                <template #footer>
                    <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                        @change="onSearch" />
                </template>
            </app-table>
        </app-view>
    </teleport>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { useRequest } from '@/hooks/request'
import { useDataFilter } from '@/hooks/datatable-v2'
import { queryAmountStream } from '@/services/api/account'
import AppTable from '@pc/components/base/table/index.vue'
import AppFilter from '@pc/components/base/table-filter-v2/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import { i18n } from '@/stores'

const props = defineProps({
    record: {
        type: Object as PropType<Model.TaAccountRsp>,
        required: true
    }
})

const { global: { t } } = i18n

const emit = defineEmits(['closed'])

const { dataList, total, pageSize, pageIndex, loading, run } = useRequest(queryAmountStream, {
    params: {
        logType: 1,
        accountId: props.record.accountId.toString(),
        pageNum: 1,
        pageSize: 20
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { field: 'operateType', label: 'account.fundacct.bankstatement.operateType' },
    { field: 'relationOrderId', label: 'account.fundacct.bankstatement.relationOrderId' },
    { field: 'marketName', label: 'account.fundacct.bankstatement.marketName' },
    { field: 'goodsName', label: 'account.fundacct.bankstatement.goodsName' },
    { field: 'amount', label: 'account.fundacct.bankstatement.amount' },
    { field: 'balance', label: 'account.fundacct.bankstatement.balance' },
    { field: 'currentBalance', label: 'account.fundacct.bankstatement.currentBalance' },
    { field: 'createTime', label: 'account.fundacct.bankstatement.createTime' },
    { field: 'amountAdjustTypeName', label: 'account.fundacct.bankstatement.amountAdjustTypeName' },
])

const { filterOption, getQueryParams } = useDataFilter<Model.AmountStreamReq>({
    filters: [
        {
            field: 'logType',
            label: t('account.fundacct.bankstatement.logType'),
            value: 1,
            options: () => [
                { label: t('common.current'), value: 1 },
                { label: t('common.history'), value: 2 },
            ],
        }
    ],
    buttons: [
        { label: t('operation.search'), className: 'el-button--primary', onClick: () => onSearch() },
        { label: t('operation.reset'), className: 'el-button--primary', onClick: () => onSearch(true) }
    ]
})

const onSearch = (clear = false) => {
    const qs = getQueryParams(clear)
    run(qs)
}
</script>