<template>
	<scroll-view class="g_bg_page" style="box-sizing: border-box; padding-bottom: 120px" scroll-y="true" hover-class="none">
		<view style="padding: 12px 12px">
			<view class="g_flex_row_between flex_center g_bg_f g_p_12 g_radius_6 g_mb_8" hover-class="thover" v-for="item in teamList" @click="toogleTeam(item)">
				<view class="g_flex_row_start flex_center">
					<view>
						<img class="g_w_48 g_h_48 g_radius_50" :src="item.logo || 'https://matripe-cms.oss-cn-beijing.aliyuncs.com/ibocai/storeDefault.jpg'" alt="" />
					</view>
					<view class="g_fs_16 g_ml_12">{{ item.fullName || item.agencyName }}</view>
				</view>

				<view class style="color: #00b666" hover-class="none">{{ item.checked ? "当前" : "" }}</view>
			</view>
		</view>

		<!-- 
		<view class="g_mt_10 g_position_rela">
			<g-panel-form-item
				:list="[
					{
						icon: 'add',
						label: '合并团队',
						result: readed && readed > 0 ? readed : '',
						path: '',
						tip: 'margeGroup',
					},
				]"
				@clickItem="goMarge"
			/>
		</view> -->
	</scroll-view>
	<g-panel-fixed>
		<slot>
			<view class="g_ml_10 g_mr_10 g_position_rela">
				<div class="g_w_8 g_h_8 g_radius_50 g_bg_f0a g_position_abso" style="right: 50px; top: 0px" v-if="readed && readed > 0"></div>
				<g-button btnText="合并团队" type="primary" size="default" @clickBtn="goMarge" />
			</view>
		</slot>
	</g-panel-fixed>
</template>

<script>
export default {
	// 组件名称
	name: "",
	// 局部注册的组件
	components: {},
	// 组件参数 接收来自父组件的数据
	props: {},
	// 组件状态值
	data() {
		return {
			readed: false,
			teamList: [], // 团队列表
		};
	},
	onLoad() {
		uni.showLoading({
			title: "加载中...",
		});
		this.getTeamList();
		this.getNum();
	},
	// 计算属性
	computed: {},
	// 侦听器
	watch: {},
	created() {},
	mounted() {},
	// 组件方法
	methods: {
		getNum() {
			let that = this;
			that.G.Get(that.api.person_applyNum, {}, (res) => {
				that.readed = res;
			});
		},
		goMarge() {
			uni.navigateTo({
				url: "/root/person/marge",
			});
		},
		/**
		 * 获取团队列表
		 */
		getTeamList() {
			let that = this;
			that.G.Get(that.api.user_getTeamList, {}, (res) => {
				console.log("res", res);
				res.forEach((item) => {
					if (item.id == uni.getStorageSync("apply-agencyId")) {
						item.checked = true;
					}
				});
				uni.hideLoading();
				that.teamList = res;
			});
		},
		/**
		 * 切换团队
		 */
		toogleTeam(item) {
			let that = this;
			console.log(item);
			if (wx.getStorageSync("apply-agencyId") == item.id) {
				return false;
			}
			wx.showLoading({
				title: "切换中...",
			});
			that.G.Get(that.api.user_toggleTeam + `/${item.id}`, {}, (res) => {
				uni.setStorageSync("apply-agencyId", item.id);
				console.log("res", res);
				that.G.checkTokenNew().then(() => {
					uni.hideLoading();
					uni.showToast({
						title: "切换成功",
						icon: "success",
						duration: 2000,
					});
					let userInfo = uni.getStorageSync("apply-userinfo");
					uni.$emit("isGlogin", {
						uid: userInfo.user.id,
					});
					that.getTeamList();
				});
			});
		},
	},
};
</script>

<style scoped lang="less"></style>
