<template>
    <HcCard>
        <template #extra>
            <HcNewSwitch :datas="tabData" :keys="tabKey" @change="tabChange"/>
        </template>
        <HcTable ref="tableRef" :column="tableColumn" :datas="tableData" :loading="tableLoading"/>
        <template #action>
            <HcPages :pages="searchForm" @change="pageChange"/>
        </template>
    </HcCard>
</template>

<script setup>
import {ref, nextTick, watch} from "vue";

//参数
const props = defineProps({
    projectId: {
        type: [String,Number],
        default: ''
    },
    contractId: {
        type: [String,Number],
        default: ''
    },
    treeData: {
        type: Object,
        default: () => ({})
    }
})

//变量
const projectId = ref(props.projectId);
const contractId = ref(props.contractId);
const nodeData = ref(props.treeData);

//监听
watch(() => [
    props.treeData
], ([treeData]) => {
    nodeData.value = treeData;
    setQueryData(treeData)
})

//渲染完成
nextTick(() => {
    setQueryData(props.treeData)
})

//获取相关数据
const setQueryData = (data) => {
    /*const cid = data?.contractIdRelation || ''
    const wbsId = data['contractIdRelation'] ? data['id'] : data['primaryKeyId']
    if (wbsId) {
        searchInternalForm.value.contractId = cid ? cid : contractId.value;
        searchInternalForm.value.contractIdRelation = data['contractIdRelation']
        searchInternalForm.value.wbsIds = [wbsId]
        searchInternalClick()
    }*/
}

//搜索表单
const searchForm = ref({
    current: 1, size: 20, total: 0
})

//tab数据和相关处理
const tabKey = ref('tab1')
const tabData = ref([
    {key:'tab1',  name: '需要整改的文件'},
    {key:'tab2', name: '已整改记录'}
]);
const tabChange = (item) => {
    tabKey.value = item?.key;
}


//分页被点击
const pageChange = ({current, size}) => {
    searchForm.value.current = current
    searchForm.value.size = size
    getTableData()
}

//内业台账表头
const tableRef = ref(null)
const tableColumn = ref([
    {key:'key1', name: '所属案卷'},
    {key:'key2', name: '具体文件'},
    {key:'key3', name: '问题描述'}
])
const tableData = ref([])

//获取数据
const tableLoading = ref(false)
const getTableData = async () => {
    /*tableInternalLoading.value = true
    const {error, code, data} = await internalApi.queryInternalPage({
        ...searchInternalForm.value,
        projectId: projectId.value,
    })
    //判断状态
    tableInternalLoading.value = false
    if (!error && code === 200) {
        tableInternalData.value = getArrValue(data['records'])
        searchInternalForm.value.total = data['total'] || 0
    } else {
        tableInternalData.value = []
        searchInternalForm.value.total = 0
    }*/
}
</script>
