
<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="demo-tabs-1">
                        <el-descriptions :column="2" border>


                            <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_name }}</el-descriptions-item>
                            <el-descriptions-item label="合同编号" label-align="left" align="left"
                                label-class-name="my-label">{{ formData.contract_no }}</el-descriptions-item>
                            <el-descriptions-item label="供应商编码" label-align="left" align="left"
                                label-class-name="my-label">{{ formData.supplier_code }}</el-descriptions-item>
                            <el-descriptions-item label="供应商名称" label-align="left" align="left"
                                label-class-name="my-label">{{ formData.supplier_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.signing_date }}
                            </el-descriptions-item>

                            <el-descriptions-item label="付款方式" label-align="left" align="left" label-class-name="my-label">
                                {{ formData.pay_type_text }}
                            </el-descriptions-item>


                            <el-descriptions-item label="账期" label-align="left" align="left" label-class-name="my-label">
                                {{ formData.account_period_text }}
                            </el-descriptions-item>
                            <el-descriptions-item label="合同金额" label-align="left" align="left" label-class-name="my-label">
                                {{ formData.contract_amount }}
                            </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.amount_excluding_tax }}
                            </el-descriptions-item>
                            <el-descriptions-item label="质保金比例(％)" label-align="left" align="left"
                                label-class-name="my-label">
                                {{ formData.retention_money_rate }}
                            </el-descriptions-item>
                            <el-descriptions-item label="质保金" label-align="left" align="left" label-class-name="my-label">
                                {{ formData.retention_money }}
                            </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="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="demo-tabs-2">
                        <div>
                            <el-table :data="tableData" stripe style="width: 100%">
                                <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="contract_no" show-overflow-tooltip />
                                <el-table-column label="合同类型" prop="contract_type" show-overflow-tooltip />
                                <!-- <el-table-column label="签订日期" prop="signing_date" show-overflow-tooltip /> -->
                                <el-table-column label="供应商名称" prop="supplier_name" show-overflow-tooltip />
                                <el-table-column label="工作类型" prop="work_type" show-overflow-tooltip />
                                <el-table-column label="工作内容" prop="work_content" show-overflow-tooltip />
                                <el-table-column label="项目特征" prop="project_features" show-overflow-tooltip />
                                <el-table-column label="单位" prop="unit" show-overflow-tooltip />
                                <el-table-column label="税率(%)" prop="tax_rate">
                                    <template #default="{ row }">
                                        <dict-value :options="dictData.tax_rate" :value="row.tax_rate" />
                                    </template>
                                </el-table-column>
                                <el-table-column label="工作量" prop="num" show-overflow-tooltip />
                                <el-table-column label="不含税金额" prop="amount_excluding_tax" show-overflow-tooltip />
                                <el-table-column label="含税金额" prop="amount_including_tax" show-overflow-tooltip />

                                <el-table-column label="备注" prop="remark" 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-tab-pane>
                    <el-tab-pane label="收票记录" name="demo-tabs-3">
                        <div>
                            <el-table :data="tableData1" stripe style="width: 100%">
                                <el-table-column label="开票日期" prop='invoicing_date' width="180" />
                                <el-table-column label="提交人" prop='commitor' width="180" />
                                <el-table-column label="发票类型" prop='invoice_type' />
                                <el-table-column label="发票编号" prop='invoice_no' width="180" />
                                <el-table-column label="发票税率(%)" prop='invoice_tax_rate' width="180" />
                                <el-table-column label="发票金额" prop='invoice_amount' />
                                <el-table-column label="不含税金额" prop='amount_excluding_tax' />
                                <el-table-column label="税额" prop='tax' />

                            </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="demo-tabs-4">
                        <div>
                            <el-table :data="tableData2" stripe style="width: 100%">
                                <el-table-column label="计划付款日期" prop='pay_date' width="180" />
                                <el-table-column label="期次" prop='period' width="180" />
                                <el-table-column label="状态" prop='status' />
                                <el-table-column label="金额" prop='amount' />
                                <el-table-column label="已付款" prop='competitor_advantages' />
                                <el-table-column label="未付款" prop='competitor_disadvantages' />
                                <el-table-column label="备注" prop='remark' />

                            </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-tab-pane label="付款记录" name="demo-tabs-5">
                        <div>
                            <el-table :data="tableData3" 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='competitor_disadvantages' />
                                <el-table-column label="付款性质" prop='competitor_disadvantages' />
                                <el-table-column label="付款金额" prop='competitor_disadvantages' />
                                <el-table-column label="备注" prop='remark' />

                            </el-table>
                        </div>
                        <div style="margin: 10px 0;">
                            <el-pagination v-model:current-page="pager4.page_no" v-model:page-size="pager4.page_size"
                                :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper"
                                :total="total3" @size-change="handleSizeChange4" @current-change="handleCurrentChange4" />
                        </div>
                    </el-tab-pane>
                    <el-tab-pane label="退款记录" name="demo-tabs-6">
                        <div>
                            <el-table :data="tableData4" 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='remark' />
                            </el-table>
                        </div>
                        <div style="margin: 10px 0;">
                            <el-pagination v-model:current-page="pager5.page_no" v-model:page-size="pager5.page_size"
                                :page-sizes="[10, 20, 30, 40]" layout="total, sizes, prev, pager, next, jumper"
                                :total="total4" @size-change="handleSizeChange5" @current-change="handleCurrentChange5" />
                        </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 { apiProcurementContractDetailLists } from '@/api/procurement_contract_detail'
import { apifinancereceiptLists } from '@/api/receiptrecord'
import { paymentplanLists } from '@/api/paymentplan'
import { paymentapplyLists } from '@/api/paymentrequest'
import { apiFinancerefundLists } from '@/api/refundrecord'
import { timeFormat } from '@/utils/util'
import type { TabsPaneContext } from 'element-plus'
import { apiSubcontractingContractDetailLists } from "@/api/subcontracting_contract_detail.ts"
const activeName = ref('demo-tabs-1')

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

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

})
const pager4 = reactive({
    page_size: 10,
    page_no: 1,
    contract_id: "",
    contract_type: 2

})
const pager5 = reactive({
    page_size: 10,
    page_no: 1,
    contract_id: "",
    contract_type: 2

})

const total = ref(0)
const total1 = ref(0)
const total2 = ref(0)
const total3 = ref(0)
const total4 = 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 tableData3 = ref([])
const tableData4 = ref([])

const handleClick = (tab: TabsPaneContext, event: Event) => {
    console.log(tab, event)
}
// 表单数据
const formData = reactive({

})


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

    pager1.page_size = val
    procurementContractDetailLists()
}
const handleSizeChange2 = (val: number) => {

    pager2.page_size = val
    financereceiptLists()
}
const handleSizeChange3 = (val: number) => {

    pager3.page_size = val
    planLists()
}
const handleSizeChange4 = (val: number) => {

    pager4.page_size = val
    payapplyLists()

}
const handleSizeChange5 = (val: number) => {

    pager5.page_size = val

    financerefundLists()
}

//分页
const handleCurrentChange1 = (val: number) => {
    console.log(`current page: ${val}`)
    pager1.page_no = val
    procurementContractDetailLists()
}
const handleCurrentChange2 = (val: number) => {
    console.log(`current page: ${val}`)
    pager2.page_no = val
    financereceiptLists()
}
const handleCurrentChange3 = (val: number) => {
    pager3.page_no = val
    console.log(`current page: ${val}`)
    planLists()
}
const handleCurrentChange4 = (val: number) => {
    pager4.page_no = val
    console.log(`current page: ${val}`)
    payapplyLists()

}
const handleCurrentChange5 = (val: number) => {
    pager5.page_no = val
    console.log(`current page: ${val}`)

    financerefundLists()
}
// 采购明细列表

const procurementContractDetailLists = () => {
    apiSubcontractingContractDetailLists(pager1).then((res) => {
        tableData.value = res.lists
        total.value = res.count

    })
}

// 获取收票记录列表
const financereceiptLists = () => {
    apifinancereceiptLists(pager2).then((res) => {
        tableData1.value = res.lists
        total1.value = res.count
    })
}

// 获取付款计划列表
const planLists = () => {
    paymentplanLists(pager3).then((res) => {
        tableData2.value = res.lists
        total2.value = res.count
    })
}

//获取付款记录
const payapplyLists = () => {
    paymentapplyLists(pager4).then((res) => {
        tableData3.value = res.lists
        total3.value = res.count
    })
}


//获取退款记录
const financerefundLists = () => {
    apiFinancerefundLists(pager4).then((res) => {
        tableData4.value = res.lists
        total4.value = res.count
    })
}


// 获取详情
const setFormData = async (data: Record<any, any>) => {
    Object.assign(formData, data)
    pager1.contract_id = data.id
    pager2.contract_id = data.id
    pager3.contract_id = data.id
    pager4.contract_id = data.id
    pager5.contract_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)
    }
    planLists()
    procurementContractDetailLists()
    financereceiptLists()
    payapplyLists()
    financerefundLists()
}

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>
