<template>
	<view class="group_settings_container">
		<u-navbar :autoBack="true" bgColor="#ECECEC" title="群管理" safeAreaInsetTop placeholder fixed></u-navbar>
		<uni-list>
			<uni-list-item title="群主管理权转让" @click="toTransfer" showArrow clickable></uni-list-item>
			<uni-list-item title="设置管理员" @click="setAdmin" showArrow clickable></uni-list-item>
			<uni-list-item title="进群验证" @switchChange="updateGroupInfo('needVerification',storeCurrentGroup.needVerification==1 ? 2: 1)" showSwitch :switchChecked="!(storeCurrentGroup.needVerification != 1)"></uni-list-item>
			<!-- <uni-list-item title="进群验证" :rightText="verifyTypeText" @click="changeVerify" clickable></uni-list-item> -->
			<uni-list-item title="允许查看成员资料" @switchChange="updateGroupInfo('lookMemberInfo',storeCurrentGroup.applyMemberFriend == 1 ? 0 : 1)" showSwitch :switchChecked="storeCurrentGroup.applyMemberFriend==0"></uni-list-item>
			<uni-list-item title="允许群内添加好友" @switchChange="updateGroupInfo('applyMemberFriend',storeCurrentGroup.applyMemberFriend == 1 ? 0 : 1)" showSwitch :switchChecked="storeCurrentGroup.applyMemberFriend==0"></uni-list-item>
			<uni-list-item title="全员禁言" @switchChange="updateMute" showSwitch :switchChecked="isMute"></uni-list-item>

		</uni-list>
	</view>
</template>

<script>
	import {mapGetters} from "vuex";
	import IMSDK, {GroupMemberRole,GroupStatus,GroupVerificationType,IMMethods,MessageReceiveOptType,} from "openim-uniapp-polyfill";
	import {GroupMemberListTypes} from "@/constant";
	export default {
		data() {
			return {
				isMute:false,
			};
		},
		computed: {
			...mapGetters([
				"storeCurrentConversation",
				"storeCurrentMemberInGroup",
				"storeCurrentGroup",
			]),
			verifyTypeText(){
				if(this.storeCurrentGroup.needVerification === 0){
					return '0'
				}
				if(this.storeCurrentGroup.needVerification === 1){
					return '1'
				}
				return '2';
			}
		},
		onLoad() {
			this.isMute = this.storeCurrentGroup.status == 3;
			//console.log(this.storeCurrentGroup);
			// IMSDK.asyncApi('getSpecifiedGroupsInfo', IMSDK.uuid(), [this.storeCurrentGroup.groupID]).then(res=>{
			// 	console.log(res);
			// }).catch(e=>{
			// 	console.log(e);
			// })
		},
		methods: {
			toTransfer() {
				uni.navigateTo({
					url: `/pages/conversation/groupMemberList/index?type=${GroupMemberListTypes.Transfer}&groupID=${this.storeCurrentGroup.groupID}`,
				});
			},
			setAdmin(){
				uni.navigateTo({
					url: `/pages/conversation/groupMemberList/index?type=${GroupMemberListTypes.setAdmin}&groupID=${this.storeCurrentGroup.groupID}`,
				});
			},
			updateMute(){
				this.isMute = !this.isMute;
				IMSDK.asyncApi('changeGroupMute', IMSDK.uuid(), {
					groupID: this.storeCurrentGroup.groupID,
					isMute: this.isMute
				}).then(res=>{
					console.log(res);
				}).catch(e=>{
					console.log(e);
				})
			},
			updateGroupInfo(field,value1){
				const data = {groupID:this.storeCurrentGroup.groupID};
				data[field] = value1;
				IMSDK.asyncApi('setGroupInfo', IMSDK.uuid(),data).then(res=>{
					console.log(res);
				}).catch(e=>{
					console.log(e);
				})
			},
			changeVerify(){
				uni.showActionSheet({
					itemList:[
						'申请进群需要群主或管理员同意；群成员邀请可以直接进群',
						'申请进群需要群主或管理员同意；群主和管理员邀请可以直接进群；普通成员邀请进群需群主或管理员同意',
						'直接进群'
					],
					success(res){
						console.log(res);
					}
				})
			}
		},
	};
</script>

<style lang="scss" scoped>
	.group_settings_container {
		@include colBox(false);
		height: 100vh;
		background-color: #f6f6f6;

		.setting_row {
			background-color: #fff;
			margin: 24rpx 24rpx 0;
			border-radius: 6px;
			overflow: hidden;
		}
	}
</style>