<!-- 推广收益 -->
<template>
    <app-view>
        <template #header>
            <app-filter :options="filterOptons" :loading="loading" />
        </template>
        <!-- 表格数据 -->
        <app-table :data="dataList" v-model:columns="tableColumns" :loading="loading">
            <!-- 日期 -->
            <template #reckondate="{ value }">
                {{ formatDate(value, 'YYYYMM') }}
            </template>
            <!-- 操作 -->
            <template #operate="{ row }">
                <app-auth-operation :menus="handleOperateButtons(row)" :options="{ selectedRow: row }"
                    @closed="onRefresh" />
            </template>
            <template #footer>
                <app-pagination :total="total" v-model:page-size="pageSize" v-model:page-index="pageIndex"
                    @change="onRefresh" />
            </template>
        </app-table>
    </app-view>
</template>

<script lang="ts" setup>
import { shallowRef } from 'vue'
import { ElMessage } from 'element-plus'
import { formatDate } from '@/filters'
import { useDataFilter } from '@/hooks/datatable'
import { useRequest } from '@/hooks/request'
import { queryTHJPromotionIncome } from '@/services/api/order'
import AppTable from '@pc/components/base/table/index.vue'
import AppFilter from '@pc/components/base/table-filter/index.vue'
import AppPagination from '@pc/components/base/pagination/index.vue'
import AppAuthOperation from '@pc/components/modules/auth-operation/index.vue'

const { filterOptons, getQueryParams } = useDataFilter<Model.THJPromotionIncomeReq>()
const { loading, dataList, total, pageIndex, pageSize, run } = useRequest(queryTHJPromotionIncome, {
    params: {
        pagesize: 20,
        profitstatus: 1,
    },
    onError: (err) => {
        ElMessage.error(err)
    }
})

const tableColumns = shallowRef<Model.TableColumn[]>([
    { prop: 'profitmonth', label: '时间' },
    { prop: 'sumamount', label: '金额' },
    { prop: 'operate', label: '操作' },
])

filterOptons.selectList = [
    {
        label: '支付状态',
        key: 'profitstatus',
        locked: true,
        selectedValue: 1,
        options: [
            { label: '未支付', value: 1 },
            { label: '支取中', value: 3 },
            { label: '已支付', value: 2 }
        ],
    },
]

filterOptons.buttonList = [
    { lable: '查询', className: 'el-button--primary', onClick: () => onSearch() }
]

// 3:委托成功 7:部成 -  状态有撤销
const handleOperateButtons = (row: Model.THJPromotionIncomeRsp) => {
    if (row.profitstatus === 1) {
        return ['PromotionDetails', 'PromotionPayment']
    }
    return ['PromotionDetails']
}

const onSearch = (clear = false) => {
    getQueryParams((qs) => {
        pageIndex.value = 1
        run(qs)
    }, clear)
}

const onRefresh = () => {
    getQueryParams((qs) => run(qs))
}
</script>