
<template>
    <div class="detail-popup">
        <popup ref="popupRef" title="客户需求详情" :async="true" width="80%" @confirm="handleSubmit" @close="handleClose">
            <el-form ref="formRef" :model="formData" label-width="120px">
                <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
                    <el-tab-pane label="需求详情" name="first">
                        <el-descriptions :column="2" border>
                            <el-descriptions-item label="组织名称" label-align="left" align="left" label-class-name="my-label">{{ formData.org_name }}</el-descriptions-item>
                            <el-descriptions-item label="部门名称" label-align="left" align="left" label-class-name="my-label">{{ formData.dept_name }}</el-descriptions-item>
                            <el-descriptions-item label="客户名称" label-align="left" align="left" label-class-name="my-label">{{ formData.custom_name }}</el-descriptions-item>
                            <el-descriptions-item label="项目名称" label-align="left" align="left" label-class-name="my-label"> {{ formData.project_name }}</el-descriptions-item>
                            <el-descriptions-item label="项目编码" label-align="left" align="left" label-class-name="my-label"> {{ formData.project_code }}</el-descriptions-item>
                            <el-descriptions-item label="需求主题" label-align="left" align="left" label-class-name="my-label">
                                {{ formData.theme }}
                            </el-descriptions-item>
                            <el-descriptions-item label="客户需求提供人" label-align="left" align="left" label-class-name="my-label"> {{ formData.supplier
                            }}</el-descriptions-item>
                            <el-descriptions-item label="提供人联系方式" label-align="left" align="left" label-class-name="my-label"> {{ formData.supplier_contacts

                            }}</el-descriptions-item>

                            <el-descriptions-item label="重要程度" label-align="left" align="left" label-class-name="my-label"> {{ formData.importance_text }}</el-descriptions-item>

                            <el-descriptions-item label="记录时间" label-align="left" align="left" label-class-name="my-label"> {{ formData.recording_time

                            }}</el-descriptions-item>
                            <el-descriptions-item label="需求内容" label-align="left" align="left" label-class-name="my-label"> {{ formData.demand_content

                            }}</el-descriptions-item>

                            <el-descriptions-item label="添加人" label-align="left" align="left" label-class-name="my-label"> {{ formData.add_user_name

                            }}</el-descriptions-item>
                            <el-descriptions-item label="创建日期" label-align="left" align="left" label-class-name="my-label"> {{ formData.create_time
                            }}</el-descriptions-item>
                            <el-descriptions-item label="更新人" label-align="left" align="left" label-class-name="my-label"> {{ formData.update_user_name


                            }}</el-descriptions-item>
                            <el-descriptions-item label="更新日期" label-align="left" align="left" label-class-name="my-label"> {{ formData.update_time



                            }}</el-descriptions-item>


                            <el-descriptions-item label="附件" label-align="left" align="left" label-class-name="my-label">
                                <div v-if="formDataannex.length > 0">
                                    <div v-for="(item, index) in formDataannex" style="margin-left: 5px;display: block;">
                                        <el-link style="margin-left: 10px; color: #4a5dff; align-self: flex-start" :href="item.uri" target="_blank">文件{{ index + 1 }}查看</el-link>

                                    </div>
                                </div>
                                <div v-else>
                                    暂无附件
                                </div>
                            </el-descriptions-item>
                        </el-descriptions>
                    </el-tab-pane>
                    <el-tab-pane label="解决方案" name="second">
                        <div>
                            <el-table :data="tableData" stripe style="width: 100%">
                                <el-table-column label="解决方案主题" prop='customer_demand_name' width="180" />
                                <el-table-column label="提交时间" prop='submission_time' width="180" />
                                <el-table-column label="方案内容" prop='solution_content' />
                                <el-table-column label="客户反馈" prop='customer_feedback' />
                                <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 style="margin: 10px 0;">
                            <el-pagination v-model:current-page="pager1.page_no" v-model:page-size="pager1.page_size" :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="total" @size-change="handleSizeChange1" @current-change="handleCurrentChange1" />
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="项目概算" name="third">
                        <div>
                            <el-table :data="tableData1" stripe style="width: 100%">
                                <el-table-column label="概算来源" prop='estimate_source_text' width="180" />
                                <el-table-column label="制单人" prop='create_user' width="180" />
                                <el-table-column label="报价日期" prop='quotation_date' />
                                <el-table-column label="技术人员" prop='technician_name' width="180" />
                                <el-table-column label="概算金额(万元)" prop='estimate_amount' width="180" />
                                <el-table-column label="要求" prop='ask' />
                                <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 style="margin: 10px 0;">
                            <el-pagination v-model:current-page="pager2.page_no" v-model:page-size="pager2.page_size" :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="total1" @size-change="handleSizeChange2" @current-change="handleCurrentChange2" />
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="竞争对手" name="fourth">
                        <div>
                            <el-table :data="tableData2" stripe style="width: 100%">
                                <el-table-column label="竞争对手名称" prop='competitor_name' width="180" />
                                <el-table-column label="竞争对手联系人" prop='competitor_contacts' width="180" />
                                <el-table-column label="联系人电话" prop='competitor_contacts_phone' />
                                <el-table-column label="竞争能力" prop='competitive_power' />
                                <el-table-column label="竞争对手优势" prop='competitor_advantages' />
                                <el-table-column label="竞争对手劣势" prop='competitor_disadvantages' />
                                <el-table-column label="备注" prop='remark' />
                                <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 style="margin: 10px 0;">
                            <el-pagination v-model:current-page="pager3.page_no" v-model:page-size="pager3.page_size" :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper" :total="total2" @size-change="handleSizeChange3" @current-change="handleCurrentChange3" />
                        </div>
                    </el-tab-pane>
                </el-tabs>
            </el-form>
        </popup>
    </div>
</template>

<script lang="ts" setup name="customdetail">

import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiCustomDetail } from '@/api/custom'
import { apiCustomerDemandSolutionLists } from '@/api/customer_demand_solution'
import { apiProjectEstimateLists } from '@/api/project_estimate'
import { apiCompetitorLists } from '@/api/competitor'
import { timeFormat } from '@/utils/util'
import type { TabsPaneContext } from 'element-plus'

const activeName = ref('first')

import type { PropType } from 'vue'
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})

const pager1 = reactive({
    page_size: 10,
    page_no: 1,
    customer_demand_id: ""
})
const pager2 = reactive({
    page_size: 10,
    page_no: 1,
    customer_demand_id: ""
})
const pager3 = reactive({
    page_size: 10,
    page_no: 1,
    customer_demand_id: ""
})

const total = ref(0)
const total1 = ref(0)
const total2 = ref(0)
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const formDataannex = reactive([])
const datas = reactive({
    provinceOptions: [],
    cityOptions: [],
    areaOptions: [],
});
const tableData = ref([])
const tableData1 = ref([])
const tableData2 = ref([])
const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
// 表单数据
const formData = reactive({

})


//条数
const handleSizeChange1 = (val: number) => {
    pager1.page_size = val
}
const handleSizeChange2 = (val: number) => {
    pager2.page_size = val
    estimateLists()
}
const handleSizeChange3 = (val: number) => {

    pager3.page_size = val
    competitorLists()
}
//分页
const handleCurrentChange1 = (val: number) => {
    console.log(`current page: ${val}`)
    pager1.page_no = val
    solutionLists()
}
const handleCurrentChange2 = (val: number) => {
    console.log(`current page: ${val}`)
    pager2.page_no = val
    estimateLists()
}
const handleCurrentChange3 = (val: number) => {
    pager3.page_no = val
    console.log(`current page: ${val}`)
    competitorLists()
}
// 解决方案列表
const solutionLists = () => {
    apiCustomerDemandSolutionLists(pager1).then((res) => {
        tableData.value = res.lists

        total.value = res.count

    })
}

// 获取项目概算列表
const estimateLists = () => {
    apiProjectEstimateLists(pager2).then((res) => {
        tableData1.value = res.lists
        total1.value = res.count
    })
}

// 获取竞争对手列表
const competitorLists = () => {
    apiCompetitorLists(pager3).then((res) => {
        tableData2.value = res.lists
        total2.value = res.count
    })
}




// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    pager1.customer_demand_id = data.id
    pager2.customer_demand_id = data.id
    pager3.customer_demand_id = data.id
    if (data.annex && data.annex.length > 0) {
        const arry1 = data.annex.map((item: any, index: any) => {
            return {
                name: `文件${index + 1}`,
                uri: item
            };
        });
        Object.assign(formDataannex, arry1)
    }
    competitorLists()
    solutionLists()
    estimateLists()
}

const getDetail = async (row: Record<string, any>) => {
    const data = await apiCustomDetail({
        id: row.id
    })
    setFormData(data)
}


// 提交按钮
const handleSubmit = async () => {
    popupRef.value?.close()

}

//打开弹窗
const open = () => {
    console.log('1111111')
    popupRef.value?.open()
}

// 关闭回调
const handleClose = () => {
    emit('close')
}








defineExpose({
    open,
    setFormData,
    getDetail
})
</script>
<style lang="scss" scoped>
.tit {
    font-size: 1.2em;
    margin-bottom: 10px;
}

:deep(.my-label) {
    width: 150px;
}
</style>
