<template>
    <el-card class="!border-none" shadow="never">
        <el-form :model="formData" inline>
            <el-form-item label="用户信息">
                <el-input class="ls-input" v-model="formData.keyword" placeholder="用户昵称/手机号码/账号" />
            </el-form-item>
            <el-form-item label="注册时间">
                <data-picker
                    class="ls-input"
                    style="width: 280px"
                    v-model:startTime="formData.startTime"
                    v-model:endTime="formData.endTime"
                ></data-picker>
            </el-form-item>
            <el-form-item label="用户来源">
                <el-select v-model="formData.channel" class="w-56 ls-input" placeholder="请选择">
                    <el-option label="全部" value></el-option>
                    <el-option label="微信小程序" :value="1"></el-option>
                    <el-option label="微信公众号" :value="2"></el-option>
                    <el-option label="手机H5" :value="3"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <div class="flex">
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </div>
            </el-form-item>
        </el-form>
    </el-card>

    <el-card shadow="never" class="mt-4 !border-none">
        <div class="mt-4">
            <el-table ref="tableDataRef" :data="pager.lists" style="width: 100%" v-loading="pager.loading">
                <el-table-column label="头像" min-width="100">
                    <template #default="scope">
                        <el-image
                            style="width: 48px; height: 48px"
                            :src="scope.row.avatar"
                            :preview-src-list="[scope.row.avatar]"
                            :hide-on-click-modal="true"
                            :preview-teleported="true"
                            :fit="'cover'"
                        />
                    </template>
                </el-table-column>
                <el-table-column property="nickname" label="用户昵称" min-width="200" />
                <el-table-column property="username" label="账号" min-width="200" />
                <el-table-column property="mobile" label="手机号码" min-width="200">
                    <template #default="scope">
                        {{ scope.row.mobile || '-' }}
                    </template>
                </el-table-column>
                <el-table-column property="channel" label="用户来源" min-width="200" />
                <el-table-column property="createTime" label="注册时间" min-width="200" />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="scope">
                        <router-link :to="`/user/userList/detail?id=${scope.row.id}`">
                            <el-link type="primary" :underline="false">详情</el-link>
                        </router-link>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <div class="flex justify-end mt-4">
            <pagination v-model="pager" @change="getLists" />
        </div>
    </el-card>
</template>

<script lang="ts" setup>
import { apiUserLists } from '@/api/user'
import { ref } from 'vue'
import Pagination from '@/components/pagination/index.vue'
import DataPicker from '@/components/daterange-picker/index.vue'
import { usePaging } from '@/hooks/usePaging'

interface formDataObj {
    keyword?: string
    channel?: number | string // 1-微信小程序 2-微信公众号 3-手机H5
    startTime: string
    endTime: string
    type: number
}
const formData = ref<formDataObj>({
    keyword: '',
    channel: '',
    startTime: '',
    endTime: '',
    type: 1 //师傅端
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: apiUserLists,
    params: formData.value
})
getLists()
</script>

<style lang="scss" scoped>
.ls-input {
    width: 280px;
}
</style>
