<template src="./mynavbar.html">

</template>
<script>
	const util = require('@/utils/util.js').default;
	import router from "@/router";
	// const config = require('../../static/config.js');
	// let app = getApp(); //获取应用实例
	export default {
		props: {
			// data
			// 由父页面传递的数据，变量名字自命名
			barData: {
				type: Object,
				default: {
					showCapsule: 1,
					navPadding: 0,
					navPaddingBg: '#fff',
					url: '',
					haveCallback: false,
					fromShare: false,
					fromProject: 0,
					pageId: null,
					shareToken: null,
					buildingStyleData: null,
					buildingCityStyleData: null,
					currentSelectCity: "",
					normalStatus: true, //常态组件，icon
					pageName: "",
					houseId: "",
					showNoticeBtn: false,
					friendTab: [], // 朋友列表
					friendIndex: 0, // 索引页
					hasImg: false,
				}
			},
			pageTheme: {
				type: [Object, Array],
				default: () => {
					return {
						textColor1: '', //主文字颜色
					}
				}
			},
		},
		watch: {
			barData: {
				handler(newVal, oldVal) {
					console.warn("***barData-change***", newVal);
					if(newVal && newVal.title){
						document.title = newVal.title;
					}
				},
				deep:true,
				// immediate:true,
			}
		},
		data() {
			return {
				hideNavbarFlag: false,
				height: '64px',
				statusBarHeight: '20px',
				// 默认值  默认显示左上角
				defaultData: {
					showCapsule: 1,
					navPadding: 0,
					navPaddingBg: '',
					url: '',
					haveCallback: false,
					fromShare: false,
					fromProject: 0,
					pageId: null,
					shareToken: null,
					buildingStyleData: null,
					buildingCityStyleData: null,
					currentSelectCity: "",
					normalStatus: true, //常态组件，icon
					pageName: "",
					houseId: "",
					showNoticeBtn: false,
					hasImg: false,
				},
				specialPage: false,
				baiduTitle: "",
				currentSelectCity: '',
				hide:false,
			}
		},
		mounted: function() {
			console.warn("***navbar***", this.height, this.statusBarHeight);
			document.title = this.barData.title;
			if (window.__wxjs_environment === 'miniprogram') {
				this.hide = true;
			}else{
				this.hide = false;
			}
		},
		methods: {
			// 朋友页选择tab
			tabChange(item) {
				this.$emit("tabChange", item.id);
			},
			compareVersion(v1, v2) {
				v1 = v1.split('.')
				v2 = v2.split('.')
				var len = Math.max(v1.length, v2.length)

				while (v1.length < len) {
					v1.push('0')
				}
				while (v2.length < len) {
					v2.push('0')
				}

				for (var i = 0; i < len; i++) {
					var num1 = parseInt(v1[i])
					var num2 = parseInt(v2[i])

					if (num1 > num2) {
						return 1
					} else if (num1 < num2) {
						return -1
					}
				}

				return 0
			},
			navigateFuc(e) {
				let eventOption = {};
				this.$emit("FloatCpClk", e, eventOption);
			},
			/**
			 * 跳转城市
			 */
			cityCpClk(e) {
				let eventOption = {};
				this.$emit("cityCpClk", e, eventOption);
			},
			//去往城市切换页面
			goCity() {

			},
			// 返回上一步
			navbackCallback() {
				const {
					haveCallback
				} = this.barData || this.defaultData;
				if (haveCallback) {
					this.$emit('navbarBackCallback');
					return true;
				}
				return false;
			},
			// 返回上一页面
			navback(e) {
				const {
					url
				} = this.barData || this.defaultData;
				const {
					fromShare
				} = this.barData || this.defaultData;
				const {
					houseId
				} = this.barData || this.defaultData;
				const {
					shareToken
				} = this.barData || this.defaultData;
				const {
					pageName
				} = this.barData || this.defaultData;
				// 如果有返回url
				if (url) {
					uni.navigateTo({
						url
					});
					return;
				}
				// 查看是否是回上一步
				if (this.navbackCallback()) return;
				// 是否通过分享进来的
				if (!fromShare) { //不是通过分享进入小程序的
					router.go(-1);
				} else { //当前用户是通过分享进入小程序的
					//如果当前页面不是项目首页 且存在 houseId 则意味着需要返回到项目首页去
					console.log('点击返回')
					router.go(-1);
				}
			},
		}
	}
</script>
<style lang="scss" scoped>
	@import "./mynavbar.scss";
</style>