<template>
	<view class="page_v u-flex-col">
		<view class="lists_box u-m-b-20" v-if="show" v-for="(item,index) in list" :key="index"
			:class="item.isDefault ? 'active' : '' " @click="clickRadio(item)">
			<view class="icon-checked-box" v-if="item.isDefault">
				<text>默认</text>
				<view class="icon-checked">
					<u-icon name="checkbox-mark" color="#fff" size="28"></u-icon>
				</view>
			</view>
			<view class="list_inner">
				<text class="icon-ym" :class="item.icon"></text>
				<text class="txt">{{item.name}}</text>
			</view>
		</view>
		<JnpfEmpty v-if="!show"></JnpfEmpty>
	</view>
</template>

<script>
	import {
		getUserOrganizes,
		setMajor,
	} from '@/api/common'

	export default {
		data() {
			return {
				list: [],
				majorType: '',
				show: true,
				disabled: false,
				userInfo: {}
			}
		},
		onLoad(e) {
			this.userInfo = uni.getStorageSync('userInfo') || {}
			this.majorType = e.majorType
			this.getUserOrganizes()
			uni.setNavigationBarTitle({
				title: this.$t('app.my.myIdentity')
			})
		},
		methods: {
			getUserOrganizes() {
				let data = this.userInfo?.standingList || []
				if (!data.length) return this.show = this.list.length > 0
				this.list = JSON.parse(JSON.stringify(data));
				this.show = this.list.length > 0
				this.list.map(o => {
					if (o.currentStanding) o.isDefault = true
				})
			},
			clickRadio(item) {
				if (this.disabled || item.isDefault) return
				this.changeMajor(item.id)
			},
			change(id) {
				this.list.map((o, i) => {
					o.isDefault = false;
					if (o.id === id) o.isDefault = true;
				})
			},
			changeMajor(majorId) {
				let query = {
					majorId,
					majorType: this.majorType
				}
				setMajor(query).then(res => {
					this.$u.toast(res.msg)
					if (res.code === 200) {
						setTimeout(() => {
							uni.reLaunch({
								url: "/pages/index/index"
							})
						}, 500)
					}
				}).catch(() => {})
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f0f2f6;
	}

	.page_v {
		/* #ifdef MP */
		background-color: #f0f2f6;
		/* #endif */
		padding: 20rpx 20rpx 0 20rpx;

		.active {
			border: 1rpx solid #2979FF;
			color: #2979FF;

			.icon-ym-organization {
				&::before {
					color: #2979FF !important;
				}
			}
		}

		.lists_box {
			width: 100%;
			min-height: 160rpx;
			border-radius: 8rpx;
			position: relative;
			display: flex;
			flex-direction: column;
			justify-content: center;
			background-color: #FFFFFF;

			.icon-checked-box {
				display: flex;
				width: 140rpx;
				height: 80rpx;
				position: absolute;
				transform: scale(0.9);
				right: -4rpx;
				bottom: -2rpx;
				flex-direction: row;
				align-items: center;


				.icon-checked {
					width: 44rpx;
					height: 44rpx;
					border: 40rpx solid #1890ff;
					border-left: 40rpx solid transparent;
					border-top: 40rpx solid transparent;
					border-bottom-right-radius: 12rpx;
					position: absolute;
					transform: scale(0.95);
					right: -8rpx;
					bottom: -6rpx;
				}
			}

			.list_inner {
				width: 100%;
				min-height: 160rpx;
				display: flex;
				flex-direction: row;
				padding: 0 20rpx;
				align-items: center;

				.icon-ym-wf-outgoingApply {
					&::before {
						margin-right: 6rpx;
						font-size: 40rpx;
					}
				}

				.icon-ym-organization {
					&::before {
						margin-right: 6rpx;
						font-size: 40rpx;
						color: #606266;
					}
				}


				.txt_icon {}

				.txt {
					width: 100%;
					align-items: flex-end;
					word-wrap: break-word;
					margin-left: 20rpx;
				}
			}
		}
	}
</style>