<template>
    <app-view>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 比例 -->
            <template #depositrate="{ value }">
                {{ parsePercent(value) }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :options="{ selectedRow: row }" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { parsePercent } from '@/filters'
import { useDataTable } from '@/hooks/datatable'
import { queryMyDeposit } from '@/services/api/common'
import { loginStore } from '@/stores'
import AppTable from '@pc/components/base/table/index.vue'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'

const { userId } = loginStore.$mapGetters()
const { dataList } = useDataTable<Model.MyDepositRsp>()
const loading = shallowRef(false)

const tableColumns = shallowRef<Model.TableColumn[]>([
    { prop: 'depositrate', label: '比例' },
    { prop: 'depositqty', label: '剩余量' },
    { prop: 'operate', label: '操作', width: 160, fixed: 'right' }
])

const getMyDeposit = () => {
    loading.value = true
    return queryMyDeposit({
        data: {
            userid: userId.value,
        },
        success: (res) => {
            dataList.value = res.data
        },
        complete: () => {
            loading.value = false
        }
    })
}

getMyDeposit().catch((err) => ElMessage.error(err))
</script>