<template>
	<view class="dt-page" style="padding: 20upx;height: 100vh;">
		<view v-if="emptyType==0" class="item" v-for="(item,index) in dataList" :key="index" @tap="openMap(item)">
			<image :src="item.organizeicon" mode="aspectFit" ></image>
			<view class="center">
				<view class="title">{{item.organizename}}</view>
				<view class="bottom_text">当前群人数{{item.num}}员</view>
			</view>
			<view class="add" @tap.stop="join(item)" v-if="!item.isJoin">
				加入此团
			</view>
			<view class="unadd" v-if="item.isJoin">
				已加入
			</view>
		</view>
		<DtNoMore v-if="isNoMore" />
		<DtEmpty :type="emptyType" />
	</view>
</template>

<script>
	import DtEmpty from '../comps/dt_empty.vue'
	import DtNoMore from '../comps/dt_no_more.vue'
	export default {
		components: {
		  DtEmpty,
		  DtNoMore
		},
		data() {
			return {
				dataList:[],
				memberId:'',
				jumpType:null
			};
		},
		methods:{
			
			onLoadPage(options) {
				wx.hideShareMenu();
				this.memberId = this.$auth.getMemberId();
				this.jumpType = options.jumpType;
				this.requestData();
			},
			join(item){
				this.$dialog.confirm({
				  content:"确认加入该团",
				  success: res => {
				    if (res.confirm) {
				      this.replaceOranization(item)
				    }
				  }
				})
			},
			async replaceOranization(item){
				let resp = await this.$api.replaceOranization({
				  _isShowLoading: true,
				  memberId:this.memberId,
				  deId:item.id,
				});
				if(resp){
					this.$dialog.success('加入成功')
					if (this.jumpType == 1) {
						let lastPage = this.$util.getPageCtx(1).$vm;
						lastPage.disabled = false;
						uni.navigateBack({ delta: 1 });
					}
				}
			},
			async requestData(param){
				let resp = await this.$api.getOrganizationList({
				  _isShowLoading: true,
				  _isPull: this.isPull,
				  pageNo: this.pageIndex,
				  pageSize: this.pageSize
				});
				let list = this.getDataList(resp)
				this.dataList = this.dataList.concat(list)
			},
			openMap(item){
				console.log(item)
				uni.navigateTo({
					url:"nearby_team_map?info="+encodeURIComponent(JSON.stringify(item))
				})
			}
		},
		onReachBottom() {
		  this.onReachBottomPage()
		}
	}
</script>

<style lang="scss">
	.item{
		border-radius: 20upx;
		background-color: #fff;
		margin-bottom: 20upx;
		display: flex;
		align-items: center;
		image{
			width: 80upx;
			height: 80upx;
			margin: 20upx;
			border-radius: 50%;
			background-color: #F7F7F7;
		}
		.center{
			flex: 1;
			.title{
				font-size: 28upx;
				font-weight: bold;
				margin-bottom: 6upx;
			}
			.bottom_text{
				font-size: 24upx;
				color: #666666;
			}
		}
		.add{
			width: 146upx;
			height: 120upx;
			text-align: center;
			line-height: 120upx;
			font-size: 28upx;
			color: #fff;
			background-color: $dt-color-primary;
			border-top-right-radius: 10upx;
			border-bottom-right-radius: 10upx;
		}
		.unadd{
			width: 146upx;
			height: 120upx;
			text-align: center;
			line-height: 120upx;
			font-size: 28upx;
			color: #999;
			background-color: #dbdbdb;
			border-top-right-radius: 10upx;
			border-bottom-right-radius: 10upx;
		}
	}
</style>
