import {
	mapGetters
} from 'vuex'


export default {
	data() {
		return {
			pageActive: false
		}
	},
	computed: {
		...mapGetters(['conversations','unReadMessageCount', 'unReadCommentNumber']),
	},
	watch: {
		unReadMessageCount(val) {
			if (this.pageActive) {
				this.setTabbar()
			}
		},
		unReadCommentNumber(val){
			if (this.pageActive) {
				this.setPyqTabbar()
			}
		}
	},
	onShow() {
		this.pageActive = true;
		this.setTabbar()
	},
	onHide() {
		this.pageActive = false;
	},
	methods: {
		/**
		 * 设置tabbar的未读消息数量
		 */
		setTabbar() {

			if (this.unReadMessageCount > 0) {
				uni.setTabBarBadge({
					index: 3,
					text: this.unReadMessageCount + '',
					fail: (err) => {
						console.log("unReadCount: ", err);
					}
				})
			} else {
				uni.removeTabBarBadge({
					index: 3
				})
			}
		},
		setPyqTabbar() {
			console.log("this.unReadCommentNumber: ",this.unReadCommentNumber);
			if (this.unReadCommentNumber > 0) {
				uni.setTabBarBadge({
					index: 2,
					text: this.unReadCommentNumber + '',
					fail: (err) => {
						console.log("unReadCount: ", err);
					}
				})
			} else {
				uni.removeTabBarBadge({
					index: 2
				})
			}
		}
	}

}