<template>
    <div v-loading="isPageLoading" class="hc-page-box">
        <HcTabCard
            :tabs="authBtnTabdata" :tab-key="authBtnTabKey"
            :disabled="router.currentRoute.value.query?.id && router.currentRoute.value.query?.id.length > 0 || newId?.length > 0"
            @change="authBtnTabClick"
        >
            <template #extra>
                <el-button hc-btn type="info" @click="toBackClick">返回</el-button>
                <el-button
                    :disabled="NodeStatus === '3' || listItemData.length <= 0" :loading="tableFormSaveLoading" hc-btn
                    color="#12C060" style="color: white; font-weight: bold" @click="tableFormSaveClick"
                >
                    保存
                </el-button>
                <el-button
                    :disabled="NodeStatus === '3' || NodeStatus === '1'" :loading="reportLoading" hc-btn
                    color="#FF976A" style="color: white;" @click="reportModalClick"
                >
                    上报
                </el-button>
                <el-button
                    :disabled="NodeStatus === '1'" :loading="bussPdfsLoading" hc-btn color="#A16222"
                    @click="bussPdfsClick(router.currentRoute.value.query.id || nodeIdvalue)"
                >
                    预览
                </el-button>
                <el-button v-if="NodeStatus === '3'" hc-btn color="#FF976A" style="color: white;" @click="abolishOneClick">撤回上报流程</el-button>
                <el-dropdown @command="dropdownCommand">
                    <el-button type="primary" hc-btn>
                        <span>更多</span>
                        <HcIcon name="arrow-down-s" />
                    </el-button>
                    <template #dropdown>
                        <el-dropdown-menu>
                            <el-dropdown-item command="linksRelate" :disabled="listItemData.length <= 0">
                                关联工程用途及部位
                            </el-dropdown-item>
                            <el-dropdown-item command="linksRaw" :disabled="!isMixRatioTestIds">
                                关联原材检测报告
                            </el-dropdown-item>
                            <el-dropdown-item command="linksSample" :disabled="NodeStatus === '3'">
                                关联取样
                            </el-dropdown-item>
                            <el-dropdown-item command="linksAssociation" :disabled="NodeStatus === '3'">
                                关联委托单
                            </el-dropdown-item>
                        </el-dropdown-menu>
                    </template>
                </el-dropdown>
            </template>
            <template #search>
                <div class="mr-5 w-40">
                    <el-select v-model="contractId" placeholder="选择标段" filterable block>
                        <el-option v-for="item in contractData" :key="item.id" :label="item.contractName" :value="item.id" />
                    </el-select>
                </div>
                <div class="mr-5 w-32">
                    <el-select v-model="tabTypeKey" block @change="tabTypeChange">
                        <el-option v-for="item in tabTypeTab" :key="item.key" :label="item.name" :value="item.key" />
                    </el-select>
                </div>
                <div v-if="tabTypeKey === '2'" class="ml-2 w-36">
                    <el-date-picker
                        v-model="listItemBaseData.reportDate" :clearable="false" class="block"
                        placeholder="请选择报告日期" type="date" value-format="YYYY-MM-DD"
                    />
                </div>
                <div v-if="tabTypeKey === '2'" class="ml-2 w-28">
                    <el-select v-model="listItemBaseData.detectionResult" block placeholder="是否合格">
                        <el-option label="合格" value="1" />
                        <el-option label="不合格" value="0" />
                    </el-select>
                </div>
                <div class="ml-2 w-36">
                    <el-select v-model="listItemBaseData.detectionCategory" block placeholder="选择检测类型">
                        <el-option v-for="item in categoryData" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey" />
                    </el-select>
                </div>
                <div class="ml-2 w-40">
                    <el-input v-model="listItemBaseData.trialUserName" clearable placeholder="请输入试验人员" />
                </div>
            </template>
            <!-- 清表列表 -->
            <el-scrollbar v-if="listItemData.length > 0" ref="ListItemScrollRef" v-loading="isLoadList">
                <ListItem
                    ref="ListItemRef" :node-status="NodeStatus" :alllist-data="alllistData"
                    :auth-btn-tab-key="authBtnTabKey"
                    :base-data="listItemBaseData" :datas="listItemData"
                    :device-use-ids="listDeviceUseIds"
                    :node-idvalue="nodeIdvalue"
                    :status="1"
                    :tab-type-key="tabTypeKey"
                    :newlistdata="newlistdata"
                    @chageorin-data="chageorinData"
                    @change-iscanclick="changeIscanclick"
                    @changesdate="changeorinsdate"
                    @changesing-save-id="changesingSaveId"
                    @offset-top="ListItemOffsetTop"
                    @renew="getTableDataAll"
                    @upcheck-table-id="upcheckTableId"
                    @updevice-use-ids="updeviceUseIds"
                    @get-list="searchNodeAllTable1"
                    @new-id="listItemNewId"
                />
            </el-scrollbar>
            <hc-empty v-else v-loading="isLoadList" title="暂无表单" />
        </HcTabCard>

        <!-- 关联工程用途及部位 -->
        <hc-new-dialog
            :show="linksRelateModal" is-table save-text="确认关联" title="关联工程用途及部位" widths="50rem"
            @close="linksRelateModalClose" @save="linksRelateModalSave"
        >
            <div class="hc-links-relate-tree-box">
                <div class="hc-search-tree-val">
                    <el-input v-model="linksRelateSearchTreeVal" clearable block placeholder="请输入名称关键词检索" @keyup="searchTreeKeyUp">
                        <template #suffix>
                            <HcIcon name="search-2" ui="text-xl" @click="searchTreeClick" />
                        </template>
                    </el-input>
                </div>
                <div v-loading="linksRelateTreeLoading" class="hc-tree-scrollbar" element-loading-text="获取数据中...">
                    <el-scrollbar>
                        <hc-lazy-tree
                            ref="ElTreeRef"
                            :h-props="treeProps"
                            show-checkbox
                            :check-strictly="true"
                            :default-checked-keys="defaultCheckarrIds"
                            @load="treeLoadNode"
                            @node-tap="divisionTreeClick"
                            @check="divisionTreeCheck"
                        />
                    </el-scrollbar>
                </div>
            </div>
        </hc-new-dialog>

        <!-- 关联原材检测报告 -->
        <hc-new-dialog
            v-model="linksRawModal" is-table save-text="确认关联" title="关联原材检测报告" widths="75rem"
            @close="linksRawModalClose" @save="linksRawModalSave"
        >
            <div class="hc-links-sample-modal-box">
                <div class="hc-links-sample-tree-box">
                    <el-scrollbar>
                        <TestTreeMaterial
                            :mix-ratio-test-tree-data="MixRatioTestTreeData" :from-type="true"
                            :node-id="nodeId" :project-id="projectId" :tenant-id="userInfo?.tenant_id"
                            :wbs-temp-id="projectInfo?.referenceWbsTemplateIdTrial" :wbs-type="2"
                            :entrust="1" @node-tap="linksRawTreeClick"
                        />
                    </el-scrollbar>
                </div>
                <div class="hc-links-sample-table-box">
                    <hc-table
                        ref="tableRawRef" :column="linksRawTableColumn" :datas="linksRawTableData"
                        :is-index="false" :loading="linksRawTableLoading" is-new is-check :check-style="{ width: 29 }"
                        @selection-change="linksRawTableSelection"
                    />
                </div>
            </div>
        </hc-new-dialog>

        <!-- 关联取样 -->
        <hc-new-dialog
            v-model="linksSampleModal" is-table save-text="确认" title="关联取样信息" widths="75rem"
            @close="linksSampleModalClose" @save="linksSampleModalSave"
        >
            <div class="hc-links-sample-modal-box">
                <div class="hc-links-sample-tree-box">
                    <el-scrollbar>
                        <TestTree
                            :project-id="projectId" :tenant-id="userInfo?.tenant_id"
                            :wbs-temp-id="projectInfo?.referenceWbsTemplateIdTrial" :wbs-type="2"
                            :entrust="1" @node-tap="linksSampleTreeClick"
                        />
                    </el-scrollbar>
                </div>
                <div class="hc-links-sample-table-box">
                    <HcTable
                        ref="tableSampleRef" :column="linksSampleTableColumn" :datas="linksSampleTableData"
                        :is-index="false" :loading="linksSampleTableLoading" is-new is-check
                        :check-style="{ width: 29 }"
                        @selection-change="linksSampleTableSelection"
                    />
                </div>
            </div>
        </hc-new-dialog>

        <!-- 批量上报审批 -->
        <hc-report-modal
            :classify-type="authBtnTabKey"
            :addition="reportAddition" :contract-id="contractId" :ids="reportIds"
            :project-id="projectId" :show="showReportModal" :task-name="reportTaskName"
            :trial-self-inspection-record-id="dataId.length > 0 ? dataId : nodeIdvalue"
            :type-data="reportTypeData" title="批量上报审批" type="wbs"
            url="informationWriteQuery/taskOne" @finish="showReportFinish"
            @hide="showReportModal = false"
        />

        <!-- 关联委托单 -->
        <LinkAssociation v-model="isLinksAssociation" :ids="listItemBaseData.commissionId" :cid="contractId" @change="commissionChange" @close="isLinksAssociation = false" />
    </div>
</template>

<script setup>
import { nextTick, onMounted, ref, watch } from 'vue'
import { useAppStore } from '~src/store'
import { useRoute, useRouter } from 'vue-router'
import ListItem from './components/ListItem.vue'
import dataApi from '~api/tentative/detect/test'
import samplingApi from '~api/tentative/material/sampling'
import divisionApi from '~api/data-fill/division'
import { getStoreValue, setStoreValue } from '~src/utils/storage'
import TestTree from '../material/components/TestTree.vue'
import TestTreeMaterial from '../material/components/TestTreeMaterial.vue'
import LinkAssociation from './components/linkAssociation.vue'
import { arrToId, getArrValue, getObjValue, isNullES, isString, useClick } from 'js-fast-way'
import { eVisaTaskCheckApi, getDictionary, getErtractInfo } from '~api/other'
import wbsApi from '~api/data-fill/wbs'
import { toPdfPage } from '~uti/btn-auth'
import dayjs from 'dayjs'

//变量
const router = useRouter()
const useRoutes = useRoute()
const useAppState = useAppStore()
const userInfo = ref(useAppState.getUserInfo)
const projectId = ref(useAppState.getProjectId)
const contractIds = ref(useAppState.getContractId)
const projectInfo = ref(useAppState.getProjectInfo)
const contractInfo = ref(useAppState.getContractInfo)
const divisionTree = ref(null)

//获取模板标签数据
const isTableForm = ref(false)

//路由参数
const routerQuery = useRoutes?.query
//存储目录格式 1按部位存储，2按日期存储
const dataId = routerQuery?.id || ''
const nodeId = routerQuery?.nodeId || ''
const dataType = routerQuery?.dataType || '1'
let isaddType = routerQuery?.isaddType || false
let currentCid = routerQuery?.cid
let currentPage = routerQuery?.current
const afterAdd = ref(false)
const dayDate = dayjs().format('YYYY-MM-DD')
const testTreeItem = ref(getStoreValue('testTreeItem'))
const isMixRatioTestIds = ref(false)
const tabTypeKey = ref('')
const isopersampleIds = ref(false)

//渲染完成
onMounted(() => {
    tabTypeKey.value = routerQuery?.tabTypeKey || '1'
    const commissionId = routerQuery?.commissionId || ''
    const { title, mixRatioTestIds } = getObjValue(testTreeItem.value)
    const info = getStoreValue('test-form') || {}
    isMixRatioTestIds.value = !(!mixRatioTestIds || mixRatioTestIds <= 0)
    listItemBaseData.value.contractId = contractId.value
    listItemBaseData.value.trialProjectName = title
    listItemBaseData.value.reportDate = dayDate
    listItemBaseData.value.commissionId = commissionId
    listItemBaseData.value.entrustId = commissionId
    // listItemBaseData.value.detectionCategory = Number(dataType)
    listItemBaseData.value.detectionCategory = info.detectionCategory || 1
    listItemBaseData.value.trialUserName = info.trialUserName || (userInfo.value['nick_name'])

    listItemBaseData.value.projectPosition = info.projectPosition || ''
    listItemBaseData.value.rawMaterialIds = info.rawMaterialIds || ''
    listItemBaseData.value.sampleIds = info.sampleIds || ''

    if (info && info.detectionResult) {
        listItemBaseData.value.detectionResult = info.detectionResult.toString()
    }
    if (info && info.projectPosition) {
        defaultCheckarrIds.value = info.projectPosition.split(',')
        defaultprojectPositionName.value = info?.projectPositionName
    }
    getSearchNodeTables()
    getSearchNodeTablesall()
    //getSearchNodeTablesall(2)
    getCategoryData()
    getContractData()
})
//监听路由参数改变
watch(() => useRoutes?.query, (query) => {
    if (isNullES(query.key)) {
        setTimeout(() => {
            window?.location?.reload() //刷新页面
        }, 1000)
    }
}, { deep: true })

//监听项目，合同段
watch(() => [
    useAppState.getProjectId,
    useAppState.getContractId,
], ([pid, cid]) => {
    if (pid || cid) {
        toBackClick()
    }
})

//获取合同段信息
const contractData = ref([])
const contractId = ref(contractIds.value)
const getContractData = async () => {
    const { data } = await getErtractInfo({
        projectId: projectId.value,
        contractId: contractIds.value,
    })
    const res = getArrValue(data)
    contractData.value = res
    if (!isNullES(currentCid)) {
        contractId.value = currentCid
    }
    if (isNullES(currentCid) && res.length > 0) {
        contractId.value = res[0].id
    }
}

//身份按钮切换数据
const authBtnTabKey = ref(dataType)
const authBtnTabdata = ref([
    { key: '1', name: '施工质检' },
    { key: '2', name: '监理抽检' },
    { key: '3', name: '业主抽检' },
])
const authBtnTabClick = ({ key }) => {
    if (key !== authBtnTabKey.value) {
        authBtnTabKey.value = key
        listItemBaseData.value.type = key
        listItemBaseData.value.detectionCategory = Number(key)
        getSearchNodeTables()
    }
}

//更多菜单
const dropdownCommand = (val) => {
    if (val === 'linksRelate') {
        linksRelateModalClick()
    } else if (val === 'linksRaw') {
        linksRawModalClick()
    } else if (val === 'linksSample') {
        linksSampleModalClick()
    } else if (val === 'linksAssociation') {
        linksAssociationModalClick()
    }
}

//类型tab数据和相关处理
const tabTypeTab = ref([
    { key: '1', name: '记录表' },
    { key: '2', name: '报告单' },
])
const tabTypeChange = (key) => {
    tabTypeKey.value = key
    let curform = ListItemRef.value?.getFormData()
    setAllListData(curform)
    if (listItemBaseData.value.detectionResult === '' && tabTypeKey.value == 2) {
        window.$message?.warning('请选择报告单是否合格')
    }
    getSearchNodeTablesall()
    getSearchNodeTables()
}

//获取检测类别类型
const categoryData = ref([])
const getCategoryData = async () => {
    const { data } = await getDictionary({
        code: 'trial_detection_category',
    })
    const arrData = getArrValue(data)
    arrData.forEach(item => {
        item.dictKey = Number(item.dictKey)
    })
    categoryData.value = arrData
}

//顶部表单
const ListItemRef = ref(null)
const listItemBaseData = ref({
    sampleIds: '', contractId: null, nodeId: nodeId, trialProjectName: null, type: dataType, tableType: '1',
    detectionCategory: '', detectionResult: '', reportDate: '', trialUserName: '', id: dataId,
})


const listItemData = ref([])
const isLoadList = ref(false)
const listDeviceUseIds = ref('')
const reportData = ref([])
const testData = ref([])
const alllistData = ref([])
const orgAlllistData = ref([])
const getSearchNodeTables = async (newaddId) => {
    isLoadList.value = true
    const isid = dataId.length > 0 ? dataId : nodeIdvalue.value || newaddId || ''
    if (isaddType) {
        const { error, code, data } = await dataApi.searchNodeTables({
            id: dataId.length > 0 ? dataId : nodeIdvalue.value || newaddId,
            projectId: projectId.value,
            contractId: contractId.value,
            primaryKeyId: nodeId,
            type: authBtnTabKey.value,
            tableType: tabTypeKey.value,
            // isAdd: 1
            isAdd: isid.length > 0 ? '' : 1,
        })
        //处理数据
        if (!error && code === 200) {
            listItemData.value = getArrValue(data)
            listItemData.value.forEach((item) => {
                if (item.pKeyId === singSaveId.value) {
                    item.isCancopy = true
                }
            })
        } else {
            listItemData.value = []
        }
        isLoadList.value = false
        setEntrustId()
    } else {
        queryNodeStatus()//查询按钮状态
        const { error, code, data } = await dataApi.searchNodeTables({
            id: dataId.length > 0 ? dataId : nodeIdvalue.value,
            projectId: projectId.value,
            contractId: contractId.value,
            primaryKeyId: nodeId,
            type: authBtnTabKey.value,
            tableType: tabTypeKey.value,

        })
        //处理数据
        if (!error && code === 200) {
            listItemData.value = getArrValue(data)
            listItemData.value.forEach((item) => {
                    if (item.pKeyId === singSaveId.value) {
                        item.isCancopy = true
                    }
                },
            )
        } else {
            listItemData.value = []
        }
        isLoadList.value = false
        setEntrustId()
    }
}
const getSearchNodeTablesall = async (newaddId) => {
    const type = tabTypeKey.value
    orgAlllistData.value = []
    const isid = dataId.length > 0 ? dataId : nodeIdvalue.value || newaddId || ''
    const { error, code, data } = await dataApi.searchNodeTables({
        id: dataId.length > 0 ? dataId : nodeIdvalue.value || newaddId,
        projectId: projectId.value,
        contractId: contractId.value,
        primaryKeyId: nodeId,
        type: authBtnTabKey.value,
        tableType: type,
        // isAdd: 1
        // isAdd: isaddType ? 1 : ''
        isAdd: isid.length > 0 ? '' : 1,

    })
    //处理数据
    if (!error && code === 200) {
        // listItemData.value = getArrValue(data)
        if (type === 1) {
            testData.value = getArrValue(data)
            testData.value.forEach((item) => {
                let bussDataInfoTrialData = item.bussDataInfoTrial
                if (bussDataInfoTrialData && Object.keys(bussDataInfoTrialData).length !== 0) {
                    for (let key in bussDataInfoTrialData) {
                        item[key] = bussDataInfoTrialData[key]
                    }
                }
                orgAlllistData.value.push(item)
            })
        } else {
            reportData.value = getArrValue(data)
            reportData.value.forEach((item) => {
                let bussDataInfoTrialData = item.bussDataInfoTrial
                if (bussDataInfoTrialData && Object.keys(bussDataInfoTrialData).length !== 0) {
                    for (let key in bussDataInfoTrialData) {
                        item[key] = bussDataInfoTrialData[key]
                    }
                }
                orgAlllistData.value.push(item)
            })
        }
    } else {
        // listItemData.value = []
        // eslint-disable-next-line eqeqeq
        if (type == 1) {
            testData.value = []
            alllistData.value = []
        } else {
            reportData.value = []
            alllistData.value = []
        }
    }
}

//获取关联委托单
const setEntrustId = () => {
    const arr = getArrValue(listItemData.value)
    const { commissionId } = getObjValue(listItemBaseData.value)
    for (let i = 0; i < arr.length; i++) {
        const { entrustId } = getObjValue(arr[i])
        if (isNullES(commissionId) && !isNullES(entrustId)) {
            listItemBaseData.value.entrustId = entrustId
            listItemBaseData.value.commissionId = entrustId
            break
        }
    }
}

//改变原始数据复制隐藏本表的状态
const newId = ref('')
//获取数据
const getTableDataAll = async (newaddId, key) => {
    newId.value = newaddId
    await getSearchNodeTables(newaddId)
    await queryNodeStatus(newaddId)
    await getSearchNodeTablesall(newaddId)

    //保存后自动展开到当前表单
    if (!isNullES(key)) {
        console.log(key)
        await nextTick(() => {
            ListItemRef.value?.setCollapseKey(key)
        })
    }
}
//隐藏显示本表改变原始数据

const changeorinsdate = async (pKeyId, isBussShow, id) => {
    orgAlllistData.value.forEach((item) => {
        if (item.pKeyId === pKeyId) {
            const isBussShows = isBussShow === 2 ? 1 : 2 //状态(1显示 2隐藏)
            item.isBussShow = isBussShows
        }
    })

    listItemData.value.forEach((item) => {
        if (item.pKeyId === pKeyId) {
            const isBussShows = isBussShow === 2 ? 1 : 2 //状态(1显示 2隐藏)
            item.isBussShow = isBussShows
        }
    })


}
//复制本表改变原始数据
const chageorinData = async () => {
    getSearchNodeTablesall()
}
//设置滚动条位置
const ListItemScrollRef = ref(null)
const ListItemOffsetTop = (offsetTop) => {
    if (offsetTop > 0) {
        setTimeout(() => {
            ListItemScrollRef.value?.setScrollTop(offsetTop)
        }, 350)
    } else {
        ListItemScrollRef.value?.setScrollTop(offsetTop)
    }
}
const checkTabId = ref('')
const upcheckTableId = (val) => {
    checkTabId.value = val
}
const singSaveId = ref('')
const iscanclick = ref(true)
const changeIscanclick = () => {
    iscanclick.value = false
}
const changesingSaveId = (id) => {
    singSaveId.value = id
}
//关联工程用途及部位 树
const linksRelateModal = ref(false)
const linksRelateModalClick = () => {
    linksRelateModal.value = true
    linksRelateSearchTreeVal.value = ''
    getContractInfoTreeApi()
}

//获取导入树
const unmatchedTreeData = ref([])
const defaultCheckarrIds = ref([])
const defaultprojectPositionName = ref('')
const isdivisionLoading = ref(false)
const getContractInfoTreeApi = async () => {
    isdivisionLoading.value = true
    const { error, code, data } = await divisionApi.getengineerInfoTree1({
        projectId: projectId.value,
        contractId: contractId.value,
        wbsId: projectInfo?.value.referenceWbsTemplateId,
        selfId: dataId,
    })
    //判断状态
    if (!error && code === 200) {
        unmatchedTreeData.value = getArrValue(data['treeContractAll'])
        searchTreeData.value = getArrValue(data['treeContractAll'])
        setStoreValue('unmatchedTreeData', unmatchedTreeData.value)

        // defaultCheckarrIds.value=getArrValue(data['isSelectedStatus'])
        checkrelationId.value = getArrValue(data['isSelectedStatus'])
    } else {
        unmatchedTreeData.value = []
    }
    isdivisionLoading.value = false
}

//关联树
const divisionTreeItemInfo = ref({})
const divisionTreeClick = ({ data }) => {
    divisionTreeItemInfo.value = data
}
const checkrelationId = ref([])
const checkrelationString = ref([])
const ElTreeRef = ref(null)
const divisionTreeCheck = (data1, data2) => {
    checkrelationId.value = data2?.checkedNodes
}
const seaElTreeProps = ref({
    label: 'fullName',
    children: 'children',
})
const linksRelateSearchTreeVal = ref('')
// watch(tabTypeKey, (val) => {
//     if(val){
//          console.log(val);
//         if (val==='1') {

//              leftFormData.value=ListItemRef.value?.getFormData()
//         }else{
//              rightFormData.value= ListItemRef.value?.getFormData()
//         }
//     }

// },


// )
watch(linksRelateSearchTreeVal, (val) => {
        if (!val.length) {
            isSearchTree.value = !isSearchTree.value

        }

    },
)
const linksRelateTreeLoading = ref(false)
const searchTreeData = ref([])
const searchlinksRelateTreeLoading = ref(false)
const searchTreeKeyUp = (e) => {
    if (e.key === 'Enter') {
        searchTreeClick()
    }
}


//树搜索
const isSearchTree = ref(false)
const searchTreeClick = async () => {
    if (linksRelateSearchTreeVal.value) {
        nextTick(() => {
            isSearchTree.value = false


        })

        //   const {error, code, data} = await queryApi.searchContractTree({
        //         contractId: contractId.value,
        //         queryValue: linksRelateSearchTreeVal.value
        //     })
        //     //判断状态
        //     if (!error && code === 200) {

        //         searchlinksRelateTreeLoading.value = false
        //     } else {
        //         searchlinksRelateTreeLoading.value = false
        //         searchTreeData.value = []
        //     }
    }
}
const positiondata = ref([])
//确认关联
const linksRelateModalSave = async () => {
    let idarr = []
    checkrelationId.value.forEach((item) => {
        idarr.push(item.primaryKeyId)
    })
    checkrelationString.value = idarr.toString()

    listItemBaseData.value.projectPosition = checkrelationString.value


    let infodata = await getpositiondata()
    positiondata.value = infodata
    ListItemRef.value.changePositionInput(infodata)
    if (infodata.length > 0) {
        window.$message?.success('操作成功')
        linksRelateModal.value = false
    }
    linksRelateModal.value = false


}
const linksRelateModalClose = () => {
    linksRelateModal.value = false
}


//关联原材检测报告
const linksRawModal = ref(false)
const MixRatioTestTreeData = ref([])
const linksRawModalClick = () => {
    linksRawModal.value = true
    getTreeData()
}
const getTreeData = async (node, reslove) => {
    const { error, code, data } = await samplingApi.getMixRatioTestTree({
        pKeyId: nodeId,
    })
    MixRatioTestTreeData.value = getArrValue(data)
}

const linkNodeid = ref('')
//树被点击
const linksRawTreeClick = ({ data }) => {
    linkNodeid.value = data.pKeyId
    getrawMaterialList()
}


//原材检测报告数据
const tableRawRef = ref(null)
const linksRawTableColumn = ref([
    { key: 'reportNo', name: '报告编号' },
    { key: 'trialProjectName', name: '试验项目名称' },
    { key: 'projectPositionName', name: '工程部位及用途' },
    { key: 'reportDate', name: '报告日期' },
])
const linksRawTableData = ref([])
const linksRawTableLoading = ref(false)

//多选
const tableRawCheckedKeys = ref([])
const tableRawCheckedKeysid = ref('')
const linksRawTableSelection = (rows) => {
    tableRawCheckedKeys.value = rows
    let arr = []
    tableRawCheckedKeys.value.forEach((item) => {
        arr.push(item.id)
    })
    tableRawCheckedKeysid.value = arr.join()
}

const linksRawModalSave = async () => {
    linksRawModal.value = false
    listItemBaseData.value.rawMaterialIds = tableRawCheckedKeysid.value
    window.$message?.success('操作成功')
    //     const { error, code, data } = await dataApi.rawMaterialSubmit({
    //     id: dataId,
    //     ids:tableRawCheckedKeysid.value,
    //     projectId: projectId.value,
    //     contractId: contractId.value,
    //     primaryKeyId: nodeId,
    //     type: authBtnTabKey.value,
    //  })
    // if (!error && code === 200) {
    //         window.$message?.success('操作成功')
    //         tableRawCheckedKeys.value=[]
    //         linksRawModal.value = false
    //         tableRawRef.value?.clearSelection();
    //  }
    //  else {
    //     window.$message?.warning(error)
    //  }

}

//关闭原材检测报告
const linksRawModalClose = () => {
    linksRawModal.value = false
    linksRawTableData.value = []
    tableRawRef.value?.clearSelection()
}

const formpositon = ref('')
//关联取样
const linksSampleModal = ref(false)
const linksSampleModalClick = () => {
    linksSampleTableData.value = []
    linksSampleModal.value = true
    let FormData = ListItemRef.value?.getFormData()
    formpositon.value = FormData
    getKetarr()

}
const positonkey = ref([])
const positionName = ref('')
//取出工程部位名称的key值
const getKetarr = () => {
    let rekey = []
    if (positiondata.value.length > 0) {
        positiondata.value.forEach((ele) => {
            let arr = Object.keys(ele)
            arr.forEach((item) => {
                if (item.indexOf('key') !== -1) {
                    rekey.push(item)
                    positionName.value = ele[item]
                }
            })
        })
    }
    positonkey.value = rekey
}
const formname = ref('')
//取样工程部位值清空与替换
const clearinf = () => {
    //1.点了工程部位进行清空
    if (positonkey.value.length > 0) {
        positonkey.value.forEach((item) => {
            sampledata.value.forEach((ele) => {
                let arr = Object.keys(ele)
                arr.forEach((ele1) => {
                    if (ele1.indexOf(item) !== -1) {
                        ele[ele1] = positionName.value
                    }
                })
            })
        })
        ListItemRef.value.changeSimpleInput(sampledata.value, checkTabId.value)
    } else if (defaultCheckarrIds.value.length > 0) {
        //2.表单工程部位有值，替换为工程部位的值
        sampledata.value.forEach((ele) => {
            let arr = Object.keys(ele)
            arr.forEach((ele1) => {
                if (ele1.indexOf('取样对应工程部位Key') !== -1) {
                    ele[ele[ele1]] = defaultprojectPositionName.value
                }
            })
        })
        ListItemRef.value.changeSimpleInput(sampledata.value, checkTabId.value)
    } else {
        let rekey = []
        sampledata.value.forEach((ele) => {
            let arr = Object.keys(ele)
            arr.forEach((item) => {
                if (item.indexOf('取样对应') !== -1) {
                    rekey.push(ele['取样对应工程部位Key'])
                }
            })
        })
        formpositon.value.forEach((ele1) => {
            rekey.forEach((ele2) => {
                if (ele1[ele2]) {
                    formname.value = ele1[ele2]
                }

            })
        })
        rekey.forEach((item) => {
            sampledata.value.forEach((ele) => {
                let arr = Object.keys(ele)
                arr.forEach((ele1) => {
                    if (ele1.indexOf(item) !== -1) {
                        //    ele[item]= formname.value
                        if (formname.value.length > 0) {
                            ele[item] = formname.value
                        } else {
                            console.log(454545)
                        }
                    }
                })
            })
        })
        ListItemRef.value.changeSimpleInput(sampledata.value, checkTabId.value)
    }
}


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

//树被点击
const linksSampleTreeClick = ({ data }) => {
    linksSampleSearchForm.value.nodeId = data.primaryKeyId
    linksSampleSearchForm.value.current = 1
    getLinksSampleData()
}

//关联取样数据
const tableSampleRef = ref(null)
const linksSampleTableColumn = ref([
    { key: 'materialName', name: '样品名称' },
    { key: 'samplingDate', name: '取样日期' },
    { key: 'specificationModel', name: '规格型号' },
    { key: 'proposedPosition', name: '拟用部位' },
    { key: 'userName', name: '取样人' },
])
const linksSampleTableData = ref([])

//获取关联数据
const linksSampleTableLoading = ref(false)
const getLinksSampleData = async () => {
    linksSampleTableLoading.value = true
    const { error, code, data } = await dataApi.sampleListInfo({
        ...linksSampleSearchForm.value,
        projectId: projectId.value,
        contractId: contractId.value,
        id: dataId,
    })
    //处理数据
    linksSampleTableLoading.value = false
    if (!error && code === 200) {
        linksSampleTableData.value = getArrValue(data)
        linksSampleTableData.value.forEach((iten) => {
            if (iten.isRelation === 1) {
                nextTick(() => {
                    tableSampleRef.value?.toggleRowSelection(iten, true)
                })

            }
        })
        //searchForm.value.total = data.total || 0
    } else {
        linksSampleTableData.value = []
        //searchForm.value.total = 0
    }
}
//获取关联原材料检测报告
const getrawMaterialList = async () => {
    linksRawTableLoading.value = true
    const { error, code, data } = await dataApi.rawMaterialList({
        nodeId: linkNodeid.value,
        contractId: contractId.value,
        id: dataId,
    })
    //处理数据
    linksRawTableLoading.value = false
    if (!error && code === 200) {
        linksRawTableData.value = getArrValue(data)
        linksRawTableData.value.forEach((iten) => {
            if (iten.isRawMaterialRelation === 1) {
                nextTick(() => {
                    tableRawRef.value?.toggleRowSelection(iten, true)
                })
            }
        })
        //searchForm.value.total = data.total || 0
    } else {
        linksRawTableData.value = []
        //searchForm.value.total = 0
    }
}
//多选
const tableSampleCheckedKeys = ref([])
const linksSampleTableSelection = (rows) => {
    tableSampleCheckedKeys.value = rows
}
const sampledata = ref([])
//保存关联
const linksSampleModalSave = async () => {
    const rows = tableSampleCheckedKeys.value
    listItemBaseData.value.sampleIds = arrToId(rows) || ''
    window.$message?.success('操作成功')
    isopersampleIds.value = true
    let infodata = await getrecordsamplegetData()
    sampledata.value = infodata
    clearinf()

    tableSampleCheckedKeys.value = []

    linksSampleModal.value = false

}
//获取关联取样信息key值
const getrecordsamplegetData = async () => {
    const { data } = await dataApi.recordsamplegetData({
        sampleIds: listItemBaseData.value.sampleIds,
        nodePKeyId: routerQuery?.nodeId,
        contractId: contractId.value,

    })
    return data
}
//获取关联工程部位key值
const getpositiondata = async () => {
    const { error, code, data, msg } = await dataApi.recordprojectPositiongetData({
        projectPositionIds: checkrelationString.value,
        nodePKeyId: routerQuery?.nodeId,
        contractId: contractId.value,

    })
    if (!error && code === 200) {

        return data

    } else {
        window.$message?.error(msg || '操作失败')
    }

}
//关闭关联取样
const linksSampleModalClose = () => {
    linksSampleModal.value = false
}

//保存
const tableFormSaveLoading = ref(false)
const tableFormSaveClick = async () => {
    await useClick()
    //false是编辑
    if (tabTypeKey.value === '2' && listItemBaseData.value.detectionResult === '') {
        window.$message?.warning('请选择报告单是否合格')
    } else {
        let FormData
        let curform = await ListItemRef.value?.setFormChart()
        //let curform = ListItemRef.value?.getFormData()
        setAllListData(curform)
        let operTrue = alllistData.value.filter(e => e.oper) //操作的数据
        let types = []
        operTrue.forEach(e => {
            types.push(e.type)
        })
        let setTypes = Array.from(new Set(types))
        let type = setTypes.length > 0 ? setTypes[0] : ''
        if (newId.value?.length > 0) {
            isaddType = false
            listItemBaseData.value.id = newId.value
        }
        if (isaddType) { //新增
            if (setTypes.length > 1) {
                FormData = alllistData.value
                listItemBaseData.value.tableType = '1,2'
            } else {
                // FormData = alllistData.value.filter(e => e.type == type);
                if (!afterAdd.value) {
                    FormData = alllistData.value.filter(e => e.type == type)
                } else {
                    let filterType = type ? type : tabTypeKey.value
                    //   FormData =alllistData.value.filter(e => e.type == type);
                    FormData = alllistData.value.filter(e => e.type == filterType)
                    orgAlllistData.value.forEach((item1) => {
                        if (item1.tableType.toString() !== tabTypeKey.value) {
                            let data1 = {
                                projectId: item1.projectId,
                                contractId: contractId.value,
                                pkeyId: item1.pKeyId,
                                nodeId: routerQuery?.nodeId,
                                isCollapseLoad: false,
                                isBussShow: item1.isBussShow,
                                loadDataId: item1.loadDataId,
                            }
                            // 过滤存在的key_的键值
                            let ishasKey = Object.keys(item1).filter(e => e.indexOf('key_') >= 0)
                            if (ishasKey.length > 0) {
                                ishasKey.forEach(key => {
                                    data1[key] = item1[key]
                                })
                            }
                            FormData.push(data1)
                        }
                    })
                }
                listItemBaseData.value.tableType = type
            }
        } else { //编辑
            FormData = alllistData.value
            const info = getStoreValue('test-form')
            let recordNo = info?.recordNo || tabTypeKey.value == 1 ? listItemBaseData.value.id : ''
            let reportNo = info?.reportNo || tabTypeKey.value == 2 ? listItemBaseData.value.id : ''
            //组装type
            if (recordNo === '' && reportNo !== '') {
                listItemBaseData.value.tableType = '2'
            } else if (recordNo !== '' && reportNo === '') {
                listItemBaseData.value.tableType = '1'
            } else {
                listItemBaseData.value.tableType = '1,2'
            }
            let notChangeData = []
            if (setTypes.length == 0) { //没操作过页面数据
                console.log('没操作过页面数据')
                FormData = []
                notChangeData = orgAlllistData.value //默认就是原始左右全部数据
                if (listItemBaseData.value.tableType.length === 1) { //从原始数据过滤当前页面数据
                    notChangeData = orgAlllistData.value.filter(e => e.tableType === listItemBaseData.value.tableType)
                }
            } else if (setTypes.length == 1) {// 操作过一边的数据
                console.log('操作过一边的数据')
                orgAlllistData.value.forEach((item1) => {
                    if (item1.tableType.toString() !== tabTypeKey.value) {
                        let data1 = {
                            projectId: item1.projectId,
                            contractId: contractId.value,
                            pkeyId: item1.pKeyId,
                            nodeId: routerQuery?.nodeId,
                            isCollapseLoad: false,
                            isBussShow: item1.isBussShow,
                            loadDataId: item1.loadDataId,
                        }
                        // 过滤存在的key_的键值
                        let ishasKey = Object.keys(item1).filter(e => e.indexOf('key_') >= 0)
                        if (ishasKey.length > 0) {
                            ishasKey.forEach(key => {
                                data1[key] = item1[key]
                            })
                        }
                        FormData.push(data1)
                    }
                })
                let tableTypeArr = listItemBaseData.value.tableType.split(',')
                if (tableTypeArr[0] != tabTypeKey.value) { //两边都有数据/当前操作的数据不是进来时的选项，筛选另一边的数据
                    listItemBaseData.value.tableType = '1,2'
                }
            } else { //两边都操作
                listItemBaseData.value.tableType = '1,2'
            }
            notChangeData.forEach(item => {
                let data = {
                    projectId: item.projectId,
                    contractId: contractId.value,
                    pkeyId: item.pKeyId,
                    nodeId: routerQuery?.nodeId,
                    isCollapseLoad: false,
                    isBussShow: item.isBussShow,
                    loadDataId: item.loadDataId,
                }
                // 过滤存在的key_的键值
                let ishasKey = Object.keys(item).filter(e => e.indexOf('key_') >= 0)
                if (ishasKey.length > 0) {
                    ishasKey.forEach(key => {
                        data[key] = item[key]
                    })
                }
                FormData.push(data)
            })
        }
        let FormRegExpJson = ListItemRef.value?.getFormRegExpJson()
        if (newId.value?.length > 0) {
            isaddType = false
        }
        if (isaddType && FormData.length == 0 || !isaddType && FormData.length == 0) {
            console.log('什么都不操作新增或者编辑')
            if (tabTypeKey.value == 1) {
                FormData = alllistData.value.filter((itenel) => {
                    return itenel.type == 1
                })

            } else if (tabTypeKey.value == 2) {
                FormData = alllistData.value.filter((itenel) => {
                    return itenel.type == 2
                })
            } else {
                FormData = alllistData.value
            }
            listItemBaseData.value.tableType = tabTypeKey.value
        }
        console.log(FormData)
        //效验数据
        if (FormData.length > 0) {
            console.log(listItemBaseData.value.tableType, 'istItemBaseData.value.tableType')
            if (listItemBaseData.value.detectionResult === '' && listItemBaseData.value.tableType == '1,2') {
                window.$message?.warning('请选择报告单是否合格')
            } else {
                tableFormSaveLoading.value = true
                console.log(listItemData.value, 'listItemData.value')
                if (listItemData.value.id && listItemData.value.id.length < 0) {
                    listItemData.value.id = dataId
                }
                console.log(FormData, 'lastFormData')
                //过滤掉已经隐藏表的数据
                FormData = FormData.filter((item) => {
                    if (item.isBussShow !== 2) {
                        return item
                    }
                })

                console.log(FormData, 'lastFormData1')
                console.log(listItemBaseData.value.tableType, 'listItemBaseData.value.tableType')
                console.log(nodeIdvalue.value?.length, 'newId.value?.length')
                if (listItemBaseData.value.tableType && listItemBaseData.value?.tableType.length === 1 && nodeIdvalue.value?.length === 0) {
                    console.log('只要一边的数据')
                    // eslint-disable-next-line array-callback-return
                    FormData = FormData.filter((ele) => {
                        // eslint-disable-next-line eqeqeq
                        if (ele.type == listItemBaseData.value.tableType || Object.hasOwnProperty.call(ele, 'type')) {
                            return ele
                        }
                    })
                    console.log(FormData, 'FormDat4444444a')
                } else if (listItemBaseData.value.tableType && listItemBaseData.value?.tableType.length === 1 && nodeIdvalue.value?.length > 0) {
                    console.log('只要一边的数据11111')
                    // eslint-disable-next-line array-callback-return
                    FormData = FormData.filter((ele) => {
                        // eslint-disable-next-line eqeqeq
                        if (Object.hasOwnProperty.call(ele, 'type')) {
                            return ele
                        }
                    })
                    console.log(FormData, 'FormDat4444444a')
                }
                if (FormData.length === 0) {
                    window.$message.warning('暂无可保存的数据，请先操作填写表单再点保存')
                    tableFormSaveLoading.value = false
                    return

                }
                const { error, code, data, msg } = await dataApi.saveExcelBussData({
                    ...listItemBaseData.value,
                    isBatchSave: 1,
                    dataInfo: { orderList: FormData },
                    // deviceUseIds:listDeviceUseIds.value
                })

                nodeIdvalue.value = data
                newId.value = data
                tableFormSaveLoading.value = false
                if (!error && code === 200) {
                    window?.$message?.success('保存成功')

                    listItemBaseData.value.deviceUseIds = ''
                    checkTabId.value = ''
                    // alllistData.value.forEach(e => e.oper = false)
                    alllistData.value = []
                    if (!isaddType) {
                        // bussPdfsClick(router.currentRoute.value.query.id || listItemBaseData.value.id)
                        //   toBackClick()

                        listItemBaseData.value.id = data

                        await getSearchNodeTables()
                        await getSearchNodeTablesall()
                        await queryNodeStatus(data)
                    } else {
                        listItemBaseData.value.id = data

                        // bussPdfsClick(nodeIdvalue.value)
                        await getSearchNodeTables()
                        await getSearchNodeTablesall()
                        await queryNodeStatus(data)
                        await listItemNewId(data)
                        afterAdd.value = true
                        isaddType = false
                    }
                    //   await getTableDataAll()

                    const ActiveKey = getStoreValue('ActiveKey')
                    const names = ActiveKey ? ActiveKey.split('-') : []
                    let pid = names[2]
                    let iscanCollose = true
                    listItemData.value.forEach((ele) => {
                        if (ele.pKeyId === pid) {
                            if (ele.isBussShow === 2) {
                                iscanCollose = false
                            } else {
                                iscanCollose = true
                            }
                        }
                    })
                    if (iscanCollose) {
                        await nextTick(() => {
                            ListItemRef.value?.setCollapseKey(ActiveKey)
                        })
                    }
                } 
            }
        }
    }
}

//新的id
const isPageLoading = ref(false)
const listItemNewId = async (id) => {
    if (!isaddType || isNullES(id)) return
    isPageLoading.value = true
    const { code, data, msg } = await dataApi.trialSelfInById(id)
    if (code !== 200) {
        window.$message?.error(msg || '操作失败')
        isPageLoading.value = false
        toBackClick()
        return
    }
    setStoreValue('test-form', getObjValue(data))
    setTimeout(() => {
        isPageLoading.value = false
        router.push({
            path: '/tentative/detect/test-form',
            query: {
                id: id,
                nodeId: nodeId,
                dataType: dataType,
                tabTypeKey: '1',
                cid: currentCid,
            },
        })
    }, 2000)
}

const setAllListData = (curform) => {
    if (curform) {
        curform.forEach((item) => {
            let pkeyId = item.pkeyId
            item.oper = false

            let ishasKey = Object.keys(item).filter(e => e.indexOf('key_') >= 0)
            if (ishasKey.length > 0) { //筛出当前编辑过的数据
                item.oper = true
            }
            let orgData = orgAlllistData.value.filter(e => e.pKeyId === pkeyId)
            item.type = orgData[0]?.tableType
            alllistData.value = alllistData.value.filter(e => e.pkeyId != pkeyId) //去掉老数据
            if (orgData.length > 0) {
                ishasKey = Object.keys(orgData[0]).filter(e => e.indexOf('key_') >= 0)
            }
            if (!item.isCollapseLoad && ishasKey.length > 0) { //没操作过，并且存在KEY
                ishasKey.forEach(key => {
                    item[key] = orgData[0][key]
                })
            }
            alllistData.value.push(item) //加入新数据
        })
    }
}

//效验数据
const setFormRegExpJson = (FormRegExpJson) => {
    let nodeName = '', itemId = ''
    Object.keys(FormRegExpJson).forEach(key => {
        const name = FormRegExpJson[key]?.nodeName ?? ''
        if (name) {
            if (nodeName) {
                nodeName += ',' + name
            } else {
                nodeName = name
                itemId = FormRegExpJson[key]?.itemId
            }
        }
    })
    //const activeKey = ListItemRef.value?.getActiveKey()
    //弹出提示
    const val = '<div style="font-size: 16px;">请先完善  <span style="color:#1ECC95;">' + nodeName + '</span>  的数据内容</div>'
    window?.$messageBox?.alert(val, '表单完善提醒', {
        confirmButtonText: '确定',
        dangerouslyUseHTMLString: true,
        callback: (action) => {
            if (action === 'confirm') {
                ListItemRef.value?.setActiveKey(itemId)
                ListItemOffsetTop(0)
                setTimeout(() => {
                    const offsetTop = document.getElementById(itemId)?.offsetTop
                    ListItemOffsetTop(offsetTop)
                }, 350)
            }
        },
    })
}
//获取数据列表


const nodeItemInfo = ref({})
const nodeDataInfo = ref({})
//查询状态
const NodeStatus = ref('1')
const queryNodeStatus = async (newaddId) => {
    const info = getStoreValue('prenodeDataInfo') || {}
    const { error, code, data } = await wbsApi.queryNodeStatusTrial({
        // primaryKeyId: info['contractIdRelation'] ? info['id'] : info['primaryKeyId'],
        id: dataId.length > 0 ? dataId : nodeIdvalue.value || newaddId,
        classify: authBtnTabKey.value,
    })
    //1 未填报，2待上报，3已上报
    if (!error && code === 200) {
        NodeStatus.value = data ?? '1'
    } else {
        NodeStatus.value = '1'
    }
}
//批量上报
const reportIds = ref('')
const reportTaskName = ref('')
const reportAddition = ref({})
const showReportModal = ref(false)
const reportLoading = ref(false)
const reportTypeData = ref([])

// const reportModalClick = async () => {
//      showReportModal.value = true
// }

//上报完成
const showReportFinish = () => {
    showReportModal.value = false
    getTableDataAll()
}


const reportModalClick = async () => {
    const info = getStoreValue('prenodeDataInfo') || {}
    console.log(info, 'info')
    const rows = listItemData.value
    if (rows.length > 0) {
        reportLoading.value = true
        const taskCheck = await eVisaTaskCheckApi({
            projectId: projectId.value,
            contractId: contractId.value,
        })
        //处理数据
        let newArr = []
        // console.log(rows,'rows');
        for (let i = 0; i < rows.length; i++) {
            newArr.push(rows[i]['pKeyId'])
        }
        reportTypeData.value = newArr
        reportLoading.value = false
        if (taskCheck) {
            //初始弹出弹窗，防呆
            // reportIds.value = info['primaryKeyId'] dataId
            reportIds.value = dataId.length > 0 ? dataId : nodeIdvalue.value
            reportAddition.value = {
                classify: authBtnTabKey.value,
                contractIdRelation: info['contractIdRelation'],
            }
            showReportModal.value = true
            //请求文件题名
            const { data } = await wbsApi.queryDocumentTitle({
                // primaryKeyId: info['primaryKeyId'],
                primaryKeyId: dataId.length > 0 ? dataId : nodeIdvalue.value,
                classify: authBtnTabKey.value,
            })
            reportTaskName.value = isString(data) ? data : ''
        }
    } else {
        window.$message?.warning('暂无相关数据')
    }
}
//多表预览
const bussPdfsLoading = ref(false)
const nodeIdvalue = ref('')
const bussPdfsClick = async (nodeId, newaddId) => {
    bussPdfsLoading.value = true
    const { error, code, data } = await dataApi.getBussPdfs({
        projectId: projectId.value,
        contractId: contractId.value,
        classify: authBtnTabKey.value,
        tableType: tabTypeKey.value,
        // nodeId: router.currentRoute.value.query.id,
        nodeId: nodeId || newId.value,
    })
    bussPdfsLoading.value = false
    if (!error && code === 200) {
        toPdfPage(data)
        //window.open(data, '_blank')
    } else {
        window.$message?.warning('获取PDF失败')
    }
}

//撤回上报流程
// const abolishOneClick = () => {
//     window.$message?.warning('暂无接口')
// }
//撤回上报流程
const abolishOneClick = () => {
    window?.$messageBox?.alert('请谨慎考虑后，是否确定撤回？', '撤回上报', {
        showCancelButton: true,
        confirmButtonText: '确定撤回',
        cancelButtonText: '取消',
        callback: (action) => {
            if (action === 'confirm') {
                abolishOneSave()
            }
        },
    })
}
//撤回请求
const abolishOneSave = async () => {
    const info = getStoreValue('prenodeDataInfo') || {}
    const { error, code } = await wbsApi.abolishOne({
        // primaryKeyId:  info?.primaryKeyId || '',
        primaryKeyId: dataId.length > 0 ? dataId : nodeIdvalue.value,
        classify: authBtnTabKey.value,
        projectId: projectId.value,
        contractId: contractId.value,
    })
    if (!error && code === 200) {
        window.$message?.success('撤回成功')
        getTableDataAll()
    }
}

//返回
const toBackClick = () => {
    router.push({
        path: '/tentative/detect/test',
        query: { current: currentPage ?? '' },
    })
    // setTimeout(() => {
    //     window?.location?.reload()  //刷新页面
    // }, 1000);
}

const updeviceUseIds = (val) => {
    listItemBaseData.value.deviceUseIds = val
}
const treeProps = {
    label: 'fullName',
    children: 'hasChildren',
    isLeaf: 'notExsitChild',
}
//获取工程部位方法
const treeLoadNode = async ({ node, item, level }, resolve) => {
    let id = ''
    if (level !== 0) {
        const nodeData = getObjValue(item)
        id = nodeData?.id || ''
    }
    //获取数据
    const { data } = await divisionApi.getengineerInfoTree1({
        projectId: projectId.value,
        contractId: contractId.value,
        wbsId: projectInfo?.value.referenceWbsTemplateId,
        selfId: dataId,
        id: id,
    })
    checkrelationId.value = getArrValue(data['isSelectedStatus'])
    resolve(getArrValue(data))
}

const newlistdata = ref([])
const searchNodeAllTable1 = async (newaddId) => {
    const { error, code, data } = await dataApi.searchNodeTables({
        projectId: projectId.value,
        contractId: contractId.value,
        primaryKeyId: nodeId,
        type: authBtnTabKey.value,
        tableType: tabTypeKey.value,
        isAdd: 1,
    })
    //处理数据
    if (!error && code === 200) {
        newlistdata.value = getArrValue(data)
    } else {
        newlistdata.value = []
    }
}

//关联委托单
const isLinksAssociation = ref(false)
const linksAssociationModalClick = () => {
    isLinksAssociation.value = true
}

//委托单确定选择
const commissionChange = (id) => {
    console.log(id)
    listItemBaseData.value.commissionId = id
    listItemBaseData.value.entrustId = id
}
</script>

<style lang="scss" scoped>
@import "../../../styles/tentative/detect/test-form.scss";
.hc-table-form-action-tip {
    position: absolute;
    bottom: 77px;
    width: 100%;
}
.hc-table-form-action-tip .hc-alert {
    background-color: #f1f5f8;
    display: inline;
    vertical-align: middle;
    box-shadow: -2px 0 10px 0 rgba(32, 37, 50, 0.03), 0 10px 21px 20px rgba(32, 37, 50, 0.03);
}
</style>
