<script setup>
import Filter from "../../../../components/Filter/index.vue";
import {reactive} from "vue";
import useTableQuery from "../../../../hooks/useTableQuery.js";
import Api from "../../../../api/index.js";

const columns = [
    {
        title: '动账日期',
        dataIndex: 'createtime1',
    },
    {
        title: '动账时间',
        dataIndex: 'createtime2',
    },
    {
        title: '交易流水号',
        dataIndex: 'sn',
    },
    {
        title: '动账渠道',
        dataIndex: 'platform_name',
    },
    {
        title: '状态',
        dataIndex: 'status',
        slotName: 'status',
    },
    {
        title: '动账用途',
        dataIndex: 'purpose_name',
    },
    {
        title: '动账金额(元)',
        dataIndex: 'money',
    },
    {
        title: '付款人账户',
        dataIndex: 'account',
    },
    {
        title: '收款人账户',
        dataIndex: 'receive',
    },
    {
        title: '商家ID',
        dataIndex: 'b_uid',
    },
    {
        title: '关联任务ID',
        dataIndex: 'm_code',
    },
    {
        title: '子任务ID',
        dataIndex: 't_code',
    },
    {
        title: '达人ID',
        dataIndex: 'u_uid',
    },
    {
        title: '推广账号ID',
        dataIndex: 'account_id',
    },
    {
        title: '推广账号',
        dataIndex: 'account_name',
    },
];
const FilterConfig = [
    {
        key: 'uid',
        type: 'input',
        label: '商家ID',
        placeholder: '请输入商家ID',
    },
    {
        key: 'task_id',
        type: 'input',
        label: '关联任务ID',
        placeholder: '请输入关联任务ID',
    },
    {
        key: 'u_uid',
        type: 'input',
        label: '达人ID',
        placeholder: '请输入达人ID',
    },
    {
        key: 'platform',
        type: 'select',
        label: '动账渠道',
        placeholder: '请选择动账渠道',
        api: async () => Api.admin.getBusinessmoneylogPlatform(),
    },
    {
        key: 'purpose',
        type: 'select',
        label: '动账用途',
        placeholder: '请选择动账用途',
        api: async () => Api.admin.getBusinessmoneylogPurpose(),
    },
    {
        key: 'rangeTime',
        start: 'start_time',
        end: 'end_time',
        type: 'datetime',
        label: '动账日期',
    }
];

const po = reactive({});
const vo = reactive({
    page: '',
    rows: [],
    total: 0,
});

const {loading, pagination, initFetchData} = useTableQuery({
    parameter: po,
    api: Api.admin.getBusinessmoneylogList,
    callback: (data) => {
        Object.assign(vo, data);
    }
});
</script>

<template>
    <!-- 资金管理(商) -->
    <a-card>
        <Filter
            @search="initFetchData"
            v-model:from="po"
            :config="FilterConfig">
        </Filter>

        <a-table
            :data="vo.rows"
            @page-change="(e) => pagination.current = e"
            :pagination="pagination"
            :loading="loading"
            :columns="columns"
            class="flex-grow">
            <template v-slot:status="{record}">
                <div v-if="record.status===1" class="status success">成功</div>
                <div v-if="record.status===0" class="status danger">失败</div>
            </template>
        </a-table>
    </a-card>
</template>

<style lang="scss" scoped>
.status {
    @apply flex whitespace-nowrap items-center gap-[6px];
    &::before {
        content: '';
        @apply block size-[6px] rounded-[50%];
    }
}

.success {
    &::before {
        @apply bg-[rgb(var(--green-6))];
    }
}

.danger {
    &::before {
        @apply bg-[rgb(var(--red-6))];
    }
}
</style>
