
<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-descriptions title="基本信息" :column="2" border>

                    <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.bid_document_no }}</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.contract_code }}</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.contract_type_text }}
                    </el-descriptions-item>
                    <el-descriptions-item label="合同计价方式" label-align="left" align="left" label-class-name="my-label"> {{ formData.contract_pricing_method_text
                    }}</el-descriptions-item>
                    <el-descriptions-item label="甲方" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_a

                    }}</el-descriptions-item>

                    <el-descriptions-item label="乙方" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_b }}</el-descriptions-item>

                    <el-descriptions-item label="通讯地址" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_a_contact_address

                    }}</el-descriptions-item>
                    <el-descriptions-item label="通讯地址" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_b_contact_address

                    }}</el-descriptions-item>

                    <el-descriptions-item label="主要负责人" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_a_diretor

                    }}</el-descriptions-item>

                    <el-descriptions-item label="主要负责人" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_b_diretor

                    }}</el-descriptions-item>




                    <el-descriptions-item label="电话" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_a_phone

                    }}</el-descriptions-item>
                    <el-descriptions-item label="电话" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_b_phone

                    }}</el-descriptions-item>
                    <el-descriptions-item label="手机" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_a_mobile

                    }}</el-descriptions-item>
                    <el-descriptions-item label="手机" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_b_mobile

                    }}</el-descriptions-item>
                    <el-descriptions-item label="邮箱" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_a_email

                    }}</el-descriptions-item>
                    <el-descriptions-item label="邮箱" label-align="left" align="left" label-class-name="my-label"> {{ formData.party_b_email

                    }}</el-descriptions-item>
                    <el-descriptions-item label="金额" label-align="left" align="left" label-class-name="my-label"> {{ formData.amount

                    }}</el-descriptions-item>
                    <!-- <el-descriptions-item label="金额大写" label-align="left" align="left" label-class-name="my-label"> {{ formData.amount

                            }}</el-descriptions-item> -->
                    <el-descriptions-item label="业务负责人" label-align="left" align="left" label-class-name="my-label"> {{ formData.business_director_name

                    }}</el-descriptions-item>
                    <el-descriptions-item label="状态" label-align="left" align="left" label-class-name="my-label"> {{ formData.contract_status_text

                    }}</el-descriptions-item>

                    <el-descriptions-item label="合同有效期" label-align="left" align="left" label-class-name="my-label"> {{ formData.expire

                    }}</el-descriptions-item>
                    <el-descriptions-item label="签约日期" label-align="left" align="left" label-class-name="my-label"> {{ formData.contract_date

                    }}</el-descriptions-item>
                    <el-descriptions-item label="主要条款" label-align="left" align="left" label-class-name="my-label"> {{ formData.main_content

                    }}</el-descriptions-item>
                    <el-descriptions-item label="备注" label-align="left" align="left" label-class-name="my-label"> {{ formData.remark

                    }}</el-descriptions-item>


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

                            </div>
                        </div>
                        <div v-else>
                            暂无附件
                        </div>
                    </el-descriptions-item>
                </el-descriptions>

                <div name="demo-tabs-2" style="margin:20px 0">
                    回款计划
                </div>
                <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="annex" show-overflow-tooltip />

                    </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-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'


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 total = 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 handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
// 表单数据
const formData = reactive({

})


//条数
const handleSizeChange1 = (val: number) => {

    pager1.page_size = val
    solutionLists()
}

//分页
const handleCurrentChange1 = (val: number) => {
    console.log(`current page: ${val}`)
    pager1.page_no = val
    solutionLists()
}

// 解决方案列表
const solutionLists = () => {
    apiCustomerDemandSolutionLists(pager1).then((res) => {
        tableData.value = res.lists

        total.value = res.count

    })
}



// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    pager1.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()

}

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>
