<template>
	<view style="display: flex;flex-direction: column;width: 100vw;height: 100vh;">
		<u-navbar
            :autoBack="true"
			title="群公告"
			safeAreaInsetTop
			placeholder
			fixed
		>
			<view class="u-nav-slot" slot="right" v-if="isOwner || isAdmin">
				<u-button type="primary" size="mini" @click="save">确定</u-button>
			</view>
		</u-navbar>
		<u--textarea :disabled="!isOwner && !isAdmin" count confirmType="done" focus autoHeight maxlength="-1" border="none" v-model="announcement"></u--textarea >
	</view>
</template>

<script>
	import {mapGetters} from "vuex";
	import IMSDK,{GroupMemberRole,} from "openim-uniapp-polyfill";
	export default {
		computed: {
			...mapGetters([
				"storeCurrentConversation",
				"storeCurrentMemberInGroup",
				"storeCurrentGroup",
			]),
			isOwner() {
				return this.storeCurrentMemberInGroup.roleLevel === GroupMemberRole.Owner;
			},
			isAdmin() {
				return this.storeCurrentMemberInGroup.roleLevel === GroupMemberRole.Admin;
			},
		},
		data() {
			return {
				announcement:"",
			}
		},
		onLoad() {
				this.announcement = this.storeCurrentGroup.notification;
		},
		methods: {
			back(){
				uni.navigateBack();
			},
			save(){
				if(!isOwner && !isAdmin){
					return ;
				}
				IMSDK.asyncApi(IMSDK.IMMethods.SetGroupInfo, IMSDK.uuid(), {
					groupID: this.storeCurrentGroup.groupID,
					notification: this.announcement
				}).then(res=>{
					console.log(res);
					uni.navigateBack();
				}).catch(e=>{
					console.log(e);
				})
			}
		}
	}
</script>

<style>

</style>