<template>
    <div>
        <el-card class="!border-none" 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>
                    <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" @cell-click="handleCurrentChange">
                    <el-table-column label="序号" type="index" />
                    <el-table-column label="建档人" property="create_user" />
                    <el-table-column label="供应商名称" property="supplier_name" />
                    <el-table-column label="供应商编码" property="supplier_code" />
                    <el-table-column label="供应商分组" prop="group_id">
                        <template #default="{ row }">
                            <dict-value :options="dictData.supplier_group" :value="row.group_id" />
                        </template>
                    </el-table-column>
                    <el-table-column label="供应商分类" prop="category_id">
                        <template #default="{ row }">
                            <dict-value :options="dictData.supplier_category" :value="row.category_id" />
                        </template>
                    </el-table-column>

                    <el-table-column label="供应商等级" prop="grade">
                        <template #default="{ row }">
                            <dict-value :options="dictData.supplier_grade" :value="row.grade" />
                        </template>
                    </el-table-column>
                    <el-table-column label="联系人" property="contacts" />
                    <el-table-column label="性别" property="contacts_sex" />
                    <el-table-column label="电话号码" property="phone" />
                    <el-table-column label="性别" property="contacts_sex">
                        <template #default="{ row }">
                            <dict-value :options="dictData.sex" :value="row.contacts_sex" />
                        </template>
                    </el-table-column>
                    <el-table-column label="邮箱地址" property="email" />


                </el-table>

            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>
  
<script lang="ts" setup>
import { usePaging } from "@/hooks/usePaging"
import { useDictData } from "@/hooks/useDictOptions"
import { apisupplierLists } from '@/api/suppler_list'
import { defineEmits } from "vue"

// 查询条件
const queryParams = reactive({
    name: ''
});

const { dictData } = useDictData('supplier_grade,supplier_group,supplier_category,sex')

// 选中数据
const emits = defineEmits(["customEvent"]);

// 选中数据子父传递
const handleCurrentChange = (value: any) => {
    emits("customEvent", value);
};

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

getLists();
</script>