<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form class="mb-[-16px]" :model="queryParams" inline>
                <el-form-item label="查询" prop="theme">
                    <el-input class="w-[280px]" v-model="queryParams.theme" 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="客户名称" prop="custom_name" show-overflow-tooltip />
                    <el-table-column label="项目名称" prop="project_name" show-overflow-tooltip />
                    <!-- <el-table-column label="项目编码" prop="project_code" show-overflow-tooltip /> -->
                    <el-table-column label="需求主题" prop="theme" show-overflow-tooltip />
                    <el-table-column label="客户需求提供人" prop="supplier" show-overflow-tooltip />
                    <el-table-column label="提供人联系方式" prop="supplier_contacts" show-overflow-tooltip />
                    <el-table-column label="重要程度" prop="importance_text" show-overflow-tooltip />
                    <el-table-column label="记录时间" prop="recording_time" show-overflow-tooltip />
                    <el-table-column label="需求内容" prop="demand_content" show-overflow-tooltip />
                    <el-table-column label="附件" prop="annex" show-overflow-tooltip>
                        <template #default="{ row }">
                            <div v-if="row.annex && row.annex.length > 0">
                                <div v-for="(item, i) in row.annex " :key='i'>
                                    <el-link :href="item" target="_blank">文件{{ i + 1 }}查看</el-link>
                                </div>
                            </div>
                            <div v-else>
                                暂无文件
                            </div>
                        </template>
                    </el-table-column>
                </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 { apiCustomerDemandLists } from '@/api/customer_demand'
import { defineEmits } from "vue"
import { timeFormat } from '@/utils/util'
const props = defineProps({
    productid: {
        type: String
    }
})

// 查询条件
const queryParams = reactive({
    project_id: props.productid,
    theme: ''
});
const { dictData } = useDictData('project_type,project_content,bidding_method,relationship,information_sources,construction_funds_sources,construction_financial_status,construction_recognition,my_construction_recognition,strategic_significance,industry,unit_nature')

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

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

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

getLists();
</script>