<template>
	<view class="">
		<navbar ref="navbar" :config="config" backColor="#666666"></navbar>
		
		<template v-if="!loading">
			<template v-if="!themeVo.styleType || themeVo.styleType === 1">
				<aggregatedOne :themeVo="themeVo" :themeModuleVoList="themeModuleVoList" />
			</template>
			
			<template v-else-if="themeVo.styleType === 2">
				<aggregatedTwo :themeVo="themeVo" :themeModuleVoList="themeModuleVoList" />
			</template>
		</template>

	</view>
</template>

<script>
	import {
		getThemeInfo
	} from "@/api/government.js"
	import aggregatedOne from "@/components/aggregated/aggregated_1.vue"
	import aggregatedTwo from "@/components/aggregated/aggregated_2.vue"
	export default {
		components: {
			aggregatedOne,
			aggregatedTwo
		},
		data() {
			return {
				config: {
					back: true,
					title: '',
					color: 'black',
					backgroundColor: [1, '#fff'],
				},
				loading:false,
				themeId: null,
				themeModuleVoList: [],
				themeVo: {}
			}
		},
		onLoad(opt) {
			this.themeId = opt.themeId || null;
			this.getList()
		},
		watch:{
			loading:{
				handler:function(newLoad){
					if(newLoad){
						uni.showLoading()
					}else{
						uni.hideLoading()
					}
				},
				immediate:true
			}
		},
		methods: {
			getList() {
				if (!this.themeId) return
				this.loading = true;
				getThemeInfo(this.themeId).then(res => {
					if (res && res.code == 200) {
						this.themeModuleVoList = res.data.themeModuleVoList
						this.$set(this.config, 'title', res.data.themeVo.themeName);
						this.themeVo = res.data.themeVo
						try{
							this.$refs.navbar.init();
						}catch(e){
							//TODO handle the exception
						}
					}
				}).finally(() => {
					setTimeout(() => {
						this.loading = false
					},500)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>