<template>
    <hc-body split :project-nmae="projectInfo?.projectName" class="hc-test-sample-body">
        <template #tree>
            <TestTree
                :auto-expand-keys="treeAutoExpandKeys" :project-id="projectId" :tenant-id="userInfo?.tenant_id"
                :wbs-temp-id="projectInfo?.referenceWbsTemplateIdTrial" :wbs-type="2" @node-tap="wbsElTreeClick"
            />
        </template>
        <hc-tab-card :tabs="tabsData" :tab-key="tabsKey" @change="tabsChange">
            <SampleFlow v-if="tabsKey === 'flow'" :tree="treeInfo" />
            <SampleInventory v-if="tabsKey === 'inventory'" :tree="treeInfo" />
            <SampleTested v-if="tabsKey === 'tested'" :tree="treeInfo" />
            <SampleTestUnder v-if="tabsKey === 'testUnder'" :tree="treeInfo" />
            <SampleLeave v-if="tabsKey === 'leave'" :tree="treeInfo" />
            <SampleDispose v-if="tabsKey === 'dispose'" :tree="treeInfo" />
        </hc-tab-card>
    </hc-body>
</template>

<script setup>
import { onActivated, ref } from 'vue'
import { useAppStore } from '~src/store'
import { getStoreValue, setStoreValue } from '~src/utils/storage'
import { getObjValue } from 'js-fast-way'
import TestTree from './components/TestTree.vue'
import SampleFlow from './modules/testSample/flow.vue'
import SampleInventory from './modules/testSample/inventory.vue'
import SampleTested from './modules/testSample/tested.vue'
import SampleTestUnder from './modules/testSample/testUnder.vue'
import SampleLeave from './modules/testSample/leave.vue'
import SampleDispose from './modules/testSample/dispose.vue'

//变量
const store = useAppStore()
const userInfo = ref(store.getUserInfo)
const projectId = ref(store.getProjectId)
const projectInfo = ref(store.getProjectInfo)

//自动展开缓存
const treeAutoExpandKeys = ref(getStoreValue('testTreeExpandKeys') || [])

//渲染完成
onActivated(() => {

})

//树被点击
const treeInfo = ref({})
const wbsElTreeClick = ({ data, keys }) => {
    treeInfo.value = getObjValue(data)
    // data['primaryKeyId'] || ''
    //缓存自动展开
    treeAutoExpandKeys.value = keys
    setStoreValue('testTreeExpandKeys', keys)
}

//选项卡卡片
const tabsKey = ref('flow')
const tabsData = ref([
    { key: 'flow', name: '样品流转' },
    { key: 'inventory', name: '样品库存' },
    { key: 'tested', name: '待测样品' },
    { key: 'testUnder', name: '在测样品' },
    { key: 'leave', name: '留样样品' },
    { key: 'dispose', name: '已处理样品' },
])
const tabsChange = ({ key }) => {
    tabsKey.value = key
}
</script>

<style lang="scss">
@import '~src/styles/tentative/material/testSample';
</style>
