<template>
	<view>
		<index v-if="curPageCode === 'indexPage'" @changeCurPageCode="changeCurPageCode"></index>
		<goods-manage v-else-if="curPageCode === 'supplyChainPage'"></goods-manage>
		<my-home v-else-if="curPageCode === 'myPage'"></my-home>
		<msg-home v-else-if="curPageCode === 'msgPage'"></msg-home>
		<module-bar ref="moduleBar" :moduleBarInfos="moduleBarInfos"></module-bar>
	</view>
</template>

<script>
	import moduleBar from '@/components/custom-bar/module-bar.vue';
	import index from '@/pages/index/index-home.vue';
	import myHome from '@/pages/index/my-home.vue';
	import msgHome from '@/pages/index/msg-home.vue';
	import goodsManage from '@/pages/index/goods-manage.vue';

	export default {
		components: {
			moduleBar,
			index,
			myHome,
			msgHome,
			goodsManage
		},
		data() {
			return {
				moduleBarInfos: [],
				curPageCode: 'indexPage'
			}
		},
		onLoad() {
			this.loadData();
			this.bindEvent();
		},
		onUnload() {
			this.offEvent();
		},
		methods: {
			async loadData() {
				// uni.getSystemInfo({
				// 	success: function(res) {
				// 		console.log('DPR：' + res.pixelRatio)
				// 		console.log('宽度：' + res.screenWidth)
				// 		console.log('高度：' + res.screenHeight)
				// 	}
				// })

				this.moduleBarInfos = await this.$api.data('moduleBarInfos');
			},
			bindEvent() {
				uni.$on('getCurPageInfo', function(data) {
					if (data.curPageCode === 'publishPage') {
						this.isShowPublish = true;
					} else {
						this.isShowPublish = false;
						this.curPageCode = data.curPageCode;
					}
				}.bind(this));
			},
			offEvent() {
				uni.$off('getCurPageInfo')
			},
			changeCurPageCode(targetPageCode) {
				this.$refs.moduleBar.navChangeByCode(targetPageCode, true);
			}
		}
	}
</script>

<style scoped>
</style>
