
<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="160px">
                <el-tabs v-model="activeName" class="demo-tabs" @tab-click="handleClick">
                    <el-tab-pane label="概况" name="demo-1">
                        <el-card class="mb-2">
                            <el-row>
                                <el-col :span="12">
                                    <el-form-item label="项目名称">
                                        {{ formData.name }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="客户名称">
                                        {{ formData.custom_name }}

                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="项目类型">
                                        <dict-value :options="dictData.project_type" :value="formData.project_type" />

                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="联系人">
                                        {{ formData.contacts }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="联系人职位">
                                        {{ formData.position }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="联系电话">
                                        {{ formData.telephone }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="项目所在地">
                                        {{ formData.project_address }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="信息来源">

                                        <dict-value :options="dictData.information_sources" :value="formData.information_sources" />

                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="负责人">
                                        {{ formData.person }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="战略意义">
                                        <dict-value :options="dictData.strategic_significance" :value="formData.strategic_significance" />
                                    </el-form-item>

                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="招标方式" prop="notes">
                                        <dict-value :options="dictData.bidding_method" :value="formData.bidding_method" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="所属行业" prop="notes">
                                        <dict-value :options="dictData.industry" :value="formData.industry" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="单位性质" prop="notes">
                                        <dict-value :options="dictData.unit_nature" :value="formData.unit_nature" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="竞争对手" prop="notes">
                                        {{ formData.competitor }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="项目建设资金来源" prop="notes">
                                        <dict-value :options="dictData.construction_funds_sources" :value="formData.construction_funds_sources" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="建设方付款方式" prop="notes">
                                        {{ formData.construction_payment_method }}
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="建设方财务状况" prop="notes">
                                        <dict-value :options="dictData.construction_financial_status" :value="formData.construction_financial_status" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="建设方对我方认可度" prop="notes">
                                        <dict-value :options="dictData.construction_recognition" :value="formData.construction_recognition" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="我方对建设方认可度" prop="notes">
                                        <dict-value :options="dictData.my_construction_recognition" :value="formData.my_construction_recognition" />
                                    </el-form-item>
                                </el-col>
                                <el-col :span="12">
                                    <el-form-item label="关系度" prop="notes">
                                        <dict-value :options="dictData.relationship" :value="formData.relationship" />

                                    </el-form-item>
                                </el-col>
                                <el-col :span="8">
                                    <el-form-item label="附件" prop="field127">

                                        <div v-if="formDataannex.length > 0">
                                            <div v-for="(item, index) in formDataannex" style="margin-left: 5px;display: block;">
                                                <a style="margin-left: 10px; color: #4a5dff; align-self: flex-start" :href="item.uri" target="_blank">{{ item.name }}</a>
                                                <!-- <span style="cursor: pointer;margin-left: 5px;" @click="delFileFn(index)">x</span> -->
                                            </div>
                                        </div>
                                        <div v-else>暂无附件</div>



                                    </el-form-item></el-col>

                            </el-row>
                        </el-card>
                    </el-tab-pane>
                    <el-tab-pane label="商机" name="demo-2">Config</el-tab-pane>
                    <el-tab-pane label="投标" name="demo-3">Role</el-tab-pane>
                    <el-tab-pane label="合同" name="demo-4">Task</el-tab-pane>
                    <el-tab-pane label="预算" name="demo-5">User</el-tab-pane>
                    <el-tab-pane label="计划" name="demo-6">Config</el-tab-pane>
                    <el-tab-pane label="材料" name="demo-7">Role</el-tab-pane>
                    <el-tab-pane label="采购" name="demo-8">Task</el-tab-pane>
                    <el-tab-pane label="分包" name="demo-9">Config</el-tab-pane>
                    <el-tab-pane label="进度" name="demo-10">Role</el-tab-pane>
                    <el-tab-pane label="任务" name="demo-11">Task</el-tab-pane>
                    <el-tab-pane label="人力" name="demo-12">Task</el-tab-pane>
                    <el-tab-pane label="机具" name="demo-13">Task</el-tab-pane>
                    <el-tab-pane label="收款" name="demo-14">Task</el-tab-pane>
                    <el-tab-pane label="付款" name="demo-15">Task</el-tab-pane>
                    <el-tab-pane label="费用" name="demo-16">Task</el-tab-pane>
                    <el-tab-pane label="文档" name="demo-17">Task</el-tab-pane>
                    <el-tab-pane label="统计" name="demo-18">Task</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 { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
import type { TabsPaneContext } from 'element-plus'

const activeName = ref('demo-1')

const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
defineProps({
    dictData: {
        type: Object as PropType<Record<string, any[]>>,
        default: () => ({})
    }
})
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 formData = reactive({
    id: '',
    name: '',
    custom_id: '',
    custom_name: '',
    project_type: '',
    project_code: '',
    project_content: [],
    project_estimation: '',
    project_address: '',
    estimated_construction: '',
    bidding_time: '',
    bidding_method: '',
    contacts: '',
    position: '',
    telephone: '',
    department: '',
    person: '',
    relationship: '',
    discovery_time: '',
    information_sources: '',
    competitor: '',
    construction_funds_sources: '',
    construction_payment_method: '',
    construction_financial_status: '',
    construction_recognition: '',
    my_construction_recognition: '',
    strategic_significance: '',
    industry: '',
    unit_nature: '',
    annex: [],
    status: '',
})




// 获取详情
const setFormData = async (data: Record<any, any>) => {
    for (const key in formData) {
        if (data[key] != null && data[key] != undefined) {
            //@ts-ignore
            formData[key] = data[key]

        }

    }


    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)
    }


}

const getDetail = async (row: Record<string, any>) => {
    const data = await apiCustomDetail({
        id: formData.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">
.tit {
    font-size: 1.2em;
    margin-bottom: 10px;
}
</style>
