<template>
	<RefreshView id="mescrollRef" ref="mescrollRef" text="我的队伍" :useDownScroll="false" :useUpScroll="false">
		<view class="list" v-for="(teamItem,index) in page.list " :key="index">
			<view class="team">
				<view class="info">
					<view >
						<text class="team-name">{{teamItem.name}}</text>	
					</view>
					<view class="label-list">
						<text class="label">{{teamItem.adName}}</text>
						<text class="label">{{teamItem.sportCategoryName}}</text>
						<text class="label">{{teamItem.memberNumber}}/{{teamItem.memberNumberLimit}}</text>
					</view>
				</view>
				<scroll-view class="scorll" scroll-x="true">
					<view v-for="(memberItem,pos) in teamItem.listTeamMemberArea" :key="pos" class="user-info-list"  scroll-x="true">
						<view class="user-info  margin-left20">
							<image  class="head-image" :src="memberItem.headImage" mode="scaleToFill"></image>
							<text class="real-name">{{memberItem.realName}}</text>
						</view>
					</view>
				</scroll-view>
				<view class="operation"  v-if="teamItem.isAdmin == 1">
						<text  @click="toExamineMember(teamItem.sid)" >申请入队({{teamItem.applyNumber}})</text>
						<text  @click="toDeleteMember(teamItem.sid)" >成员管理</text>
						<text  @click="disbandTeam(teamItem.sid)" >解散队伍</text>
						<!-- <text  @click="invitation(item.sid)">邀请成员</text> -->
				</view>
			</view>
		</view>
		
		<view class="team-join-nav">
			<view class="left">
				<text class="font-tips">进入队伍后可报名发布的团体活动</text>
				<text class="font-explain margin-top20">点击右侧按钮可进行创建及申请加入。</text>
			</view>
			<view class="right">
				<button @click="toMyTeamCreate()">创建队伍</button>
				<button @click="toWaitJoin()" class="margin-top20">加入队伍</button>
			</view>
		</view>
	</RefreshView>
</template>
<script>
	export default {
		data() {
			return {
				isAdmin:0,
				page: {
					state: "",
					current:1,
					menuList: [{
						'title': '默认活动类型',
						'key': 'state',
						'reflexTitle': true,
						'defaultSelectedIndex': 0,
						detailList: [{
							'title': '全部运动项目',
							'value': ""
							}]
						}
					],
					list:[]
				},
			}
		},
		onShow() {
			this.refresh()
		},

		methods: {
			refresh() {
				let _this = this
				this.HTTP({
					url: 'aos/v1/aosUser/getMyTeamAreaPagerList',
					paramsType: "JSON",
					method: "POST",
					data: {
						current: _this.page.current,
						size: 10,
						params: {
							sysUserSid: getApp().globalData.sysUserSid,
							type: 0,
						}
					},
					loading: true
				})
				.then((res) => {
					_this.page.list = res.data.records
					// 追加数据.concat
					console.log("我的队伍:",_this.page.list )
				});
			},
			clickItem(index) {
				let raceSid = this.list[index].sid
				console.log(raceSid)
				uni.navigateTo({
					url: '../find/DetailActivity?raceSid=' + raceSid
				});
			
			},
			
			result(val) {
				console.log("aaa", val);
				if (!this.IsEmpty(val.state)) {
					this.page.state = val.state;
					this.list = []
					console.log("this.page.state", this.page.state);
				} else {
					this.page.state = val.state;
					this.list = []
				}


			},
			isShow(sid) {
				if (!this.IsEmpty(sid)) {
					return true
				} else {
					return false
				}
			},
			disbandTeam(teamSid){
				let _this = this
				uni.showModal({
					title: '提示',
					content: '您确定要解算队伍吗？',
					success: function(res) {
						if (res.confirm) { 
							//这里是点击了确定以后
							_this.HTTP({
								url: 'aos/v1/aosUser/disbandTeam',
								paramsType: "FORM",
								method: "PUT",
								data: {
									teamSid:teamSid,
									sysUserSid: getApp().globalData.sysUserSid,
								},
								loading: true
							})
							.then((res) => {
								console.log("res", res);
								console.log("teamSid", teamSid);
								console.log("sysUserSid", getApp().globalData.sysUserSid);
								_this.refresh()
								// uni.navigateBack({
								// 	delta: 0
								// })
							});
						} else { //这里是点击了取消以后
							console.log('用户点击取消')
						}
					}})
			},
			toExamineMember(sid) {
				// 查看申请
				uni.navigateTo({
					url: 'MemberManage?sid=' + sid+"&type="+0
				})
			},
			toDeleteMember(sid) {
				// 查看申请
				uni.navigateTo({
					url: 'MemberManage?sid=' + sid+"&type="+1
				})
			},
			manage(sid) {
				// 管理
				let newList = []
				newList.push("修改信息")
				newList.push("删除队员")
				newList.push("解散队伍")
				uni.showActionSheet({
					itemList: newList,
					success: function(res) {
						switch (res.tapIndex) {
							case 0:
							console.log("res==修改")
								break;
							case 1:
							// 查看申请
							uni.navigateTo({
								url: 'examineMember?sid=' + sid+"&type="+1
							})
								break;
							case 2:
							uni.showModal({
								title: '提示',
								content: '是否要解算队伍吗',
								success: function(res) {
									if (res.confirm) { //这里是点击了确定以后
									
									} else { //这里是点击了取消以后
										console.log('用户点击取消')
									}
								}
							})
							console.log("res==集散")
								break;
						}
					},
					fail(e) {
						console.log("reeees==" + JSON.stringify(e))
					}
				});

			},
			detail(sid) {
				// 活动详情
				uni.navigateTo({
					url: '../index/DetailActivity?raceSid=' + sid
				})
			},
			toMyTeamCreate(){
				uni.navigateTo({
					url: 'MyTeamCreate'
				})
			},
			toWaitJoin(){
				uni.navigateTo({
					url: '../team/WaitJoin'
				})
			}

		}
	}
</script>

<style lang="scss">
	@import url("../../static/columns.css");
	.show_view {
	  display: inline;
	}
	.hide_view {
	  display: none;
	}
</style>
