<template>
  <view class="dynamic_page pageBox">
    <view class="dynamic_index">
      <dynamicComponent_page 
        v-if="render"
        :page="store_config.pages[0]"
        @goto_page="(e:any)=>goto_page(e)"
      />
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, reactive, computed, onBeforeMount, onMounted, onUnmounted, watch, nextTick ,onBeforeUnmount} from 'vue'
import { onPullDownRefresh, onLoad, onBackPress } from '@dcloudio/uni-app'
import { get_dynamic_config_comm } from '@/common/apis/dynamic/index'
import { setPageData } from "@/common/views/pages/dynamic/js/index"
import { ConfigStore } from './stores/ConfigStore'
import { ParamsStore } from './stores/ParamsStore'



// store
const store_config = ConfigStore()

//render
const render = ref(false)

onLoad((option:any)=>{
  props_data.value = option
  getDynamicConfig()
})
const props_data = <any>ref('')
onBeforeMount(async() => {
})
onMounted(()=>{
})
onUnmounted(() => {
})
onBackPress(()=>{
})

// 获取该菜单的页面配置
const getDynamicConfig= () => {
  get_dynamic_config_comm({menu_id: props_data.value.id,}).then(result=>{
    let data = result.result
    uni.setNavigationBarTitle({
      title:data.menu_name
    })
    setPageData(data).then((pageData:any) => {
      store_config.set({menu_id:props_data.value.id, pages:pageData})
      render.value = true
      let store_params = ParamsStore()
      for(let page of pageData){
        for(let container of page.containers){
          store_params.set({page_code:container.page_code, container_code:container.container_code, data:{}})
        }
        if(page.container_query){
          store_params.set({page_code:page.container_query.page_code, container_code:page.container_query.container_code, data:{}})
        }
      }
    })
  })
}


// 页面跳转
const goto_page = ({page_code, params}:any) => {
  uni.navigateTo({
    url: `/common/views/pages/dynamic/child?page_code=${page_code}`,
  })
}
</script>

<style lang="scss">
.pageBox{
  background: #eaf1f7;
}
</style>
