<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";
import EditExpertInfoModal from "./components/EditExpertInfoModal.vue";
import AESCrypto from "../../../../utils/AESCrypto.js";

const columns = [
    {
        title: '商家ID',
        dataIndex: 'uid',
    },
    {
        title: '昵称',
        dataIndex: 'nickname',
    },
    {
        title: '头像',
        dataIndex: 'avatar',
        slotName: 'avatar',
    },
    {
        title: '手机号',
        dataIndex: 'mobile',
    },
    {
        title: '微信号',
        dataIndex: 'wechat',
    },
    {
        title: '状态',
        dataIndex: 'status',
        slotName: 'status',
    },
    {
        title: '邀请人',
        dataIndex: 'puid',
    },
    {
        title: '上上',
        dataIndex: 'second_person',
    },
    {
        title: '上上上',
        dataIndex: 'three_person',
    },
    {
        title: '等级',
        dataIndex: 'level',
    },
    {
        title: '入驻日期',
        dataIndex: 'createtime',
    },
    {
        title: '分佣比例',
        dataIndex: 'ratio'
    },
    {
        title: '任务收益',
        dataIndex: 'total_money',
    },
    {
        title: '操作',
        dataIndex: 'action',
        slotName: 'action',
        width: 140,
    },
];
const FilterConfig = [
    {
        key: 'uid',
        type: 'input',
        label: '达人ID',
        placeholder: '请输入达人ID',
    },
    {
        key: 'puid',
        type: 'input',
        label: '邀请人',
        placeholder: '请输入邀请人',
    },
    {
        key: 'mobile',
        type: 'input',
        label: '手机号',
        placeholder: '请输入手机号',
    },
    {
        key: 'status',
        type: 'select',
        label: '状态',
        placeholder: '请选择状态',
        api: async () => ({
            data: [
                {
                    name: '禁用',
                    id: 0,
                },
                {
                    name: '可用',
                    id: 1,
                },
            ]
        }),
    },
    {
        key: 'rangTime',
        start: 'start_time',
        end: 'end_time',
        type: 'datetime',
        label: '入驻时间',
    },
    {
        key: 'wd',
        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.getUserList,
    callback: (data) => {
        Object.assign(vo, data);
    }
});

const fastInput = (item) => {
    const po = new URLSearchParams(AESCrypto.encrypt(`${item.id}`)).toString();
    window.open(`${import.meta.env.VITE_WEB_MEMBER_HOST}/pages/fastInput/index?${po}`);
}
</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:avatar="{record}">
                <a-image :src="record.avatar" width="24px" height="24px"
                         class="rounded-[50%] overflow-hidden"></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 danger">{{ record.status_text }}</div>
            </template>
            <template v-slot:action="{record}">
                <div class="flex gap-[20px]">
                    <EditExpertInfoModal :id="record.id" @success="fetchData"></EditExpertInfoModal>
                    <a-link :hoverable="false" @click="fastInput(record)">快速进入</a-link>
                </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>
