<template>
    <el-main>
        <el-card shadow="never">
            <template #header>
                <span>剪辑师列表</span>
            </template>

            <el-table v-loading="loading" :data="list">
                <el-table-column prop="id" label="ID" width="80" />
                <el-table-column prop="real_name" label="姓名" min-width="100" show-overflow-tooltip />
                <el-table-column prop="nickname" label="昵称" min-width="100" show-overflow-tooltip />
                <el-table-column prop="phone" label="手机号" width="130" />
                <el-table-column prop="wechat" label="微信号" min-width="120" show-overflow-tooltip />
                <el-table-column label="状态" width="100">
                    <template #default="{ row }">
                        <el-tag v-if="row.status !== undefined && row.status !== null" size="small">
                            {{ formatStatus(row.status) }}
                        </el-tag>
                        <span v-else>-</span>
                    </template>
                </el-table-column>
                <el-table-column prop="add_time" label="时间" min-width="160" show-overflow-tooltip>
                    <template #default="{ row }">
                        {{ formatCellTime(row.add_time || row.create_time) }}
                    </template>
                </el-table-column>
            </el-table>

            <div class="pager">
                <el-pagination
                    background
                    layout="total, prev, pager, next, sizes"
                    :total="total"
                    :current-page="query.page"
                    :page-size="query.limit"
                    :page-sizes="[5, 10, 20, 50]"
                    @current-change="handlePageChange"
                    @size-change="handleSizeChange"
                />
            </div>
        </el-card>
    </el-main>
</template>

<script>
export default {
    name: "CutterList",
    data() {
        return {
            loading: false,
            list: [],
            total: 0,
            query: { page: 1, limit: 10 }
        };
    },
    created() {
        this.getList();
    },
    methods: {
        formatStatus(v) {
            const n = Number(v);
            const map = { 0: "禁用", 1: "正常" };
            return map[n] !== undefined ? map[n] : String(v);
        },
        formatCellTime(val) {
            if (val === undefined || val === null || val === "") return "-";
            const num = Number(val);
            if (!num) return String(val);
            const sec = num > 1e12 ? Math.floor(num / 1000) : num;
            return this.$TOOL.getTime(sec, "YYYY-MM-DD HH:mm:ss");
        },
        async getList() {
            this.loading = true;
            try {
                const res = await this.$API.cutter.list.get(this.query);
                if (res.code !== 1) {
                    this.$message.error(res.msg || "获取剪辑师列表失败");
                    return;
                }
                const data = res.data || {};
                this.list = data.data || data.list || [];
                this.total = Number(data.count || data.total || this.list.length || 0);
            } finally {
                this.loading = false;
            }
        },
        handlePageChange(page) {
            this.query.page = page;
            this.getList();
        },
        handleSizeChange(limit) {
            this.query.limit = limit;
            this.query.page = 1;
            this.getList();
        }
    }
};
</script>

<style scoped>
.pager {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
}
</style>
