<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 type="selection" width="55" />

                    <el-table-column label="序号" type="index" width="55" />
                    <el-table-column label="客户名称" prop="name" show-overflow-tooltip />
                    <el-table-column label="客户属性" prop="custom_type">
                        <template #default="{ row }">
                            <dict-value :options="dictData.custom_type" :value="row.custom_type" />
                        </template>
                    </el-table-column>
                    <el-table-column label="省" property="province_name" />
                    <el-table-column label="市" property="city_name" />
                    <el-table-column label="区" property="area_name" />
                    <el-table-column label="职务" prop="master_position" show-overflow-tooltip />
                    <el-table-column label="电话" prop="master_phone" show-overflow-tooltip />
                    <el-table-column label="手机" prop="master_telephone" show-overflow-tooltip />
                    <el-table-column label="备注" prop="master_notes" show-overflow-tooltip />
                    <el-table-column label="负责人" prop="master_name" show-overflow-tooltip />
                    <el-table-column label="创建时间" prop="create_time" show-overflow-tooltip />
                    <el-table-column label="最后跟进" prop="last_follow_date" show-overflow-tooltip />
                    <el-table-column label="下次回访日期" prop="next_follow_date" show-overflow-tooltip />
                </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 { apiCustomLists } from '@/api/custom'
import { defineEmits } from "vue"

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

// 获取字典数据
const { dictData } = useDictData('custom_type')
// 选中数据
const emits = defineEmits(["customEvent"]);

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

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

getLists();
</script>