<template>
	<view>
		<view class="suspension">
			<tm-badges v-if="num>0" :offset="[5,0]" :label="num" :dot="false"></tm-badges>
			<tm-button  @click="change" :width="80" :height="80" fab :icon-size="40"
				icon="icon-aliwangwang"></tm-button>
<!-- 			<view v-else>
				<tm-button v-if="user.nickname=='游客'" :open-type="user.nickname=='游客'?'getUserInfo':''"
					@getUserInfo='getUserInfo' :width="90" :height="90" fab :icon-size="50" icon="icon-aliwangwang" theme="blue"></tm-button>
				<tm-button v-else @click="goChat" :width="90" :height="90" fab :icon-size="50" icon="icon-aliwangwang" theme="blue"></tm-button>
			</view> -->

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		computed: {
			user() {
				return this.$tm.vx.state().user.userInfo || {}
			},
			num() {
				return this.$tm.vx.state().num.num
			}
		},
		methods: {
			change() {
				uni.navigateTo({
					url: "/pages/room/index"
				})
			},
			upData(name, avatar) {
				this.$tm.request.post('user/update', {
					nickname: name,
					avatar: avatar
				}).then(res => {
					this.$tm.vx.commit('user/setUserInfo', res.data)
					this.$tm.request.post('card/viewread', {
						card_id: this.$tm.vx.state().card.cardId
					}).then(res => {
						let {
							id,
							name,
							uid
						} = res.data.card
						this.chatClick(uid, name, id)
					})
				})

			},
			getUserInfo(e) {
				if (e) {
					this.upData(e.userInfo.nickName, e.userInfo.avatarUrl)
				}
			},
			goChat(){
				this.$tm.request.post('card/viewread', {
					card_id: this.$tm.vx.state().card.cardId
				}).then(res => {
					let {
						id,
						name,
						uid
					} = res.data.card
					this.chatClick(uid, name, id)
				})
			},
			chatClick(id, name, card_id) {
				uni.navigateTo({
					url: "/subpages/pages/card/cardChat?t_uid=" + id + '&name=' + name + '&card_id=' + card_id
				})
			}
		}

	}
</script>

<style lang="scss">
	.suspension {
		position: fixed;
		bottom: 200rpx;
		right: 50rpx;
	}
</style>
