<template>
	<view class="app">
		<view class="app-body fx-h fx-bc fx-ac" v-if="data != null">
			<view class="avatar">
				<image :src="data.img == '' ? '/static/chat/group_chat.png'  : data.img"></image>
			</view>
			<view class="text">{{data.name}}</view>
		</view>
		
		<view class="fx-h fx-bc fx-ac" v-if="isSub">
			<view class="tips" v-if="data.is_timeout">该邀请链接已过期了，请重新获取</view>
			<view class="tips" v-else-if="data.is_increase">你已经加入群聊了</view>
			<view class="btn" v-else @tap="tapAddQl">加入群聊</view>
		</view>
		<view class="fx-h fx-bc fx-ac" v-else>提交成功</view>
	</view>
</template>


<script>
	import {mapState,mapMutations} from 'vuex';
	export default {
		computed: mapState(['user','sysData']),
		data() {
			return {
				code:"",
				data : {
					is_timeout:false,
					is_increase:false
				},
				isSub : true
			}
		},
		
		onLoad(options) {
			this.code = decodeURIComponent(options.code || "");
			this.initView();
		},
		
		methods: {
			
			initView:function(){
				uni.showLoading({ title:"加载中.." });
				this
					.request
					.post("grouptoken",{token:this.code})
					.then(res=>{
						console.log(res)
						uni.hideLoading();
						if(res.code == 200) {
							this.data = res.data.groupData;
						} else {
							this.utils.Tip(res.msg);
						}
					})
					.catch(err=>{
						console.log(err,'errrr')
						this.utils.Tip("加载失败");
						uni.hideLoading();
					});
				
			},
			
			tapAddQl:function(){
				uni.showLoading({ title:"提交中.." });
				this
					.request
					.post("chatGroup_add_code",{token:this.code})
					.then(res=>{
						uni.hideLoading();
						if(res.code == 200) {
							this.isSub = false;
							uni.switchTab({
								url:"/pages/chat/index"
							})
							uni.showToast({
								title:"提交成功",
								icon:"success"
							})
						} else {
							this.utils.Tip(res.msg);
						}
					})
					.catch(err=>{
						this.utils.Tip("加载失败");
						uni.hideLoading();
					});
			}
				
		}
		
	}
</script>


<style lang="scss">
	.app-body{background: #fff;margin: 10px;border-radius: 8px;padding: 20px;}
	.app-body .avatar image{width: 80px;height: 80px;}
	.btn{background: $ic-appcolor;height: 40px;border-radius: 20px;width: 100px;text-align: center;line-height: 40px;color: #fff;font-size: 14px;position: fixed;bottom: 10px;}
	.tips{font-size: 14px;color: #787878;}
</style>