<script>
	export default {
		onLaunch: function() {
			console.log('App Launch',this.$WebIM)
			
			if (uni.getStorageSync("token")) {
				this.$u.post('/api/Member/member_info').then(res => {
					if (res.code == 1) {
						if (uni.getStorageSync("token") && uni.getStorageSync("hx_username")) {
							this.$WebIM.conn.open({
								user: uni.getStorageSync("hx_username"),
								pwd: "888888",
							}).then(() => {
								console.log("login success");
							}).catch((reason) => {
								console.log("login fail", reason);
							});
						}
					} else {
						this.$u.toast(res.msg)
						uni.removeStorageSync("token")
						uni.removeStorageSync("hx_username")
					}
				})
			}

			if (uni.getStorageSync("city") && uni.getStorageSync("city").city_id) {
				this.$store.commit('setdefaultcity', uni.getStorageSync("city"))
			}

			this.$u.post('/api/Index/platform_config').then(res => {
				if (res.code == 1) {
					this.$store.commit('setconfig', res.data)
					if (!uni.getStorageSync("config")) {
						uni.setStorageSync("config", res.data)
					} else {
						var config = uni.getStorageSync("config")
						config.floor_price_switch = res.data.floor_price_switch
						config.sunlight_appraisal_switch = res.data.sunlight_appraisal_switch
						config.room_price_switch = res.data.room_price_switch
						uni.setStorageSync("config", config)
					}
				}
			})
			this.$u.post('/api/Index/popularity').then(res => {
				this.$store.commit('setpopularity', res.data)
			})
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "uview-ui/index.scss";
</style>