<template>
    <div class="edit-popup">
        <popup ref="popupRef" title="选择用户" :async="true" width="1000px" @confirm="handleSubmit" @close="handleClose">
            <el-form ref="formRef" :model="queryParams" label-width="80px" inline>
                <el-form-item prop="type" label="搜索用户">
                    <el-input v-model="queryParams.keyword" placeholder="请输入用户名称">
                        <template #append>
                            <el-button :icon="Search" @click="resetPage" />
                        </template>
                    </el-input>
                </el-form-item>
            </el-form>
            <el-table ref="tableRef" size="large" class="mt-[14px]" :data="pager.lists" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" />
                <el-table-column label="用户编号" prop="sn" />

                <el-table-column label="用户昵称">
                    <template #default="{ row }">
                        <div class="flex items-center">
                            <el-avatar :src="row.avatar" style="height: 60px; min-width: 60px" />

                            <el-tooltip :content="row.nickname" placement="top-start">
                                <div class="ml-[10px] text_hidden">{{ row.nickname }}</div>
                            </el-tooltip>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="用户余额" prop="sell_price">
                    <template #default="{ row }">￥{{ row.user_money }}</template>
                </el-table-column>
                <el-table-column label="手机号码" prop="sell_price">
                    <template #default="{ row }">{{ row.mobile }}</template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </popup>
    </div>
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus'
// import { orderRemark, orderdetail } from '@/api/order'
import Popup from '@/components/popup/index.vue'
import { Search } from '@element-plus/icons-vue'
import { getUserList } from '@/api/consumer'
import { usePaging } from '@/hooks/usePaging'
import { useDictOptions } from '@/hooks/useDictOptions'
const props = defineProps({
    selected: {
        type: Array
    }
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const tableRef = shallowRef()
const popupRef = shallowRef<InstanceType<typeof Popup>>()

const queryParams = reactive({
    keyword: ''
})

const open = () => {
    popupRef.value?.open()
    getLists()
}
//勾选框处理
const ids = ref<any[]>([])

const handleSelectionChange = (val: any) => {
    ids.value = val.map((item: any) => {
        return item
    })
}

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: getUserList,
    params: queryParams
})

const getDetail = async (row: Record<string, any>) => {
    // getLists()
}

const handleClose = () => {
    emit('close')
}
// const { optionsData } = useDictOptions<{
//     lists: any[]
// }>({
//     lists: {
//         api: getGoodsCategory
//     }
// })

defineExpose({
    open,
    // setFormData,
    getDetail
})
//提交
const handleSubmit = async () => {
    // await orderRemark(formData)
    popupRef.value?.close()
    emit('success', ids.value)
}
</script>
