<script setup>
import {reactive} from "vue";
import useTableQuery from "../../../../hooks/useTableQuery.js";
import Api from "../../../../api/index.js";
import Filter from "../../../../components/Filter/index.vue";
import RefuseModal from "./components/RefuseModal.vue";
import {Message} from "@arco-design/web-vue";
import EditTGInfoModal from "./components/EditTGInfoModal.vue";

const columns = [
    {
        title: '账号ID',
        dataIndex: 'uid',
    },
    {
        title: '达人ID',
        dataIndex: 'uuid',
    },
    {
        title: '渠道',
        dataIndex: 'name',
    },
    {
        title: '主页截图',
        dataIndex: 'homepage',
        slotName: 'homepage',
    },
    {
        title: '主页二维码',
        dataIndex: 'qrcode',
        slotName: 'qrcode',
    },
    {
        title: '账号',
        dataIndex: 'account',
    },
    {
        title: '昵称',
        dataIndex: 'nickname',
    },
    {
        title: '推广账号状态',
        dataIndex: 'status',
        slotName: 'status',
    },
    {
        title: '添加日期',
        dataIndex: 'createtime',
    },
    {
        title: '操作',
        dataIndex: 'action',
        slotName: 'action',
        width: 160,
    },
];
const FilterConfig = [
    {
        key: 'uuid',
        type: 'input',
        label: '达人ID',
        placeholder: '请输入达人ID',
    },
    {
        key: 'account',
        type: 'input',
        label: '账号',
        placeholder: '请输入账号',
    },
    {
        key: 'rangeTime',
        start: 'start_time',
        end: 'end_time',
        type: 'datetime',
        label: '推广日期',
    },
];

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

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

const accept = async (id) => {
    const {msg} = await Api.admin.accept(id);
    Message.success(msg);
    await fetchData();
}
</script>

<template>
    <!-- 推广账号 -->
    <a-card>
        <Filter
            @search="initFetchData"
            v-model:from="po"
            :config="FilterConfig"
            :button-col="false">
        </Filter>

        <a-table
            :data="vo.rows"
            @page-change="(e) => pagination.current = e"
            :pagination="pagination"
            :loading="loading"
            :columns="columns"
            class="flex-grow">
            <template v-slot:homepage="{record}">
                <a-image width="24px" height="24px" :src="record.homepage"></a-image>
            </template>
            <template v-slot:qrcode="{record}">
                <a-image width="24px" height="24px" :src="record.qrcode"></a-image>
            </template>
            <template v-slot:status="{record}">
                <div v-if="record.status===1" class="status success">{{ record.status_text }}</div>
                <div v-if="record.status===0" class="status warning">{{ record.status_text }}</div>
                <div v-if="record.status===2 || record.status === -2 || record.status === -1" class="status danger">
                    {{ record.status_text }}
                </div>
                <div v-if="record.status===3 || record.status === -3" class="status primary">{{
                        record.status_text
                    }}
                </div>
            </template>
            <template v-slot:action="{record}">
                <div class="flex gap-[20px]">
                    <EditTGInfoModal :id="record.id" @success="fetchData"></EditTGInfoModal>
                    <a-link :hoverable="false" status="success" @click="accept(record.id)">通过</a-link>
                    <RefuseModal @success="fetchData" :id="record.id"></RefuseModal>
                </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))];
    }
}

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

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