<!-- 推广收益-明细 -->
<template>
    <app-drawer title="收益明细" :width="960" v-model:show="show">
        <app-table :data="dataList" :columns="tableColumns" :loading="loading" border>
            <!-- 时间 -->
            <template #tradetime="{ value }">
                {{ formatDate(value) }}
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex" @change="run" />
            </template>
        </app-table>
    </app-drawer>
</template>

<script lang="ts" setup>
import { shallowRef, PropType } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useRequest } from '@/hooks/request'
import { queryTHJPromotionIncomeDetail } from '@/services/api/order'
import AppDrawer from '@pc/components/base/drawer/index.vue'
import AppTable from '@pc/components/base/table/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'

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

const show = shallowRef(true)
const { loading, dataList, total, pageIndex, pageSize, run } = useRequest(queryTHJPromotionIncomeDetail, {
    params: {
        pagesize: 10,
        mouth: props.selectedRow.profitmonth,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { prop: 'tradetime', label: '时间', width: 180 },
    { prop: 'wrstandardname', label: '商品' },
    { prop: 'market', label: '市场' },
    { prop: 'buyorsell', label: '方向' },
    { prop: 'profitroletype', label: '级别' },
    { prop: 'profitamount', label: '金额' },
])
</script>