<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="户主姓名" prop="name">
                    <el-input class="w-[280px]" v-model="queryParams.name" clearable
                        placeholder="请输入户主姓名" />
                </el-form-item>
                <el-form-item label="联系方式" prop="contact">
                    <el-input class="w-[280px]" v-model="queryParams.contact" type="number" clearable
                        placeholder="请输入联系方式" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column label="序号" type="index" width="55" />
                    <el-table-column label="户主姓名" prop="name" show-overflow-tooltip />
                    <el-table-column label="联系方式" prop="contact" show-overflow-tooltip />
                    <el-table-column label="家庭人数" prop="family_count" show-overflow-tooltip />
                    <el-table-column label="家庭地址" prop="address" show-overflow-tooltip />
                    <el-table-column label="操作" width="160" fixed="right">
                        <template #default="{ row }">
                            <el-button  link
                                @click="handledetail(row)" type="primary">
                                详情
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="flex justify-end mt-4">
                <!-- <pagination v-model="pager" @change="getLists" /> -->
                <pagination v-model="pager" @change="getLists" />

            </div>
        </el-card>
        <detail-popup v-if="showDtail" ref="detailRef"  @close="showDtail = false" />
    </div>
</template>

<script lang="ts" setup name="projectLists">
import { ref, reactive } from 'vue'
import { apivillageInfoLists } from "@/api/villageInfo"
import { usePaging } from "@/hooks/usePaging";
import DetailPopup from './detail.vue'

const detailRef = shallowRef<InstanceType<typeof DetailPopup>>()
// 是否显示编辑框

const showDtail = ref(false)


// 查询条件
const queryParams = reactive({
    name:"",
    contact:""
})

// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map(({ id }) => id)
}

// 获取字典数据

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apivillageInfoLists,
    params: queryParams
})


//详情
const handledetail = async (data: any) => {
    // let res = await apiinvoiceapplyDetail({ id: data.id })
    showDtail.value = true
    await nextTick()
    detailRef.value?.open()
    detailRef.value?.setFormData(data)
}

getLists()


</script>

