<template>
	<view class="single_settings_container">
		<custom-nav-bar title="好友设置" />

		<view class="setting_row info_row">
			<view @click="toUserCard" class="user_info">
				<my-avatar :src="storeCurrentConversation.faceURL" :desc="storeCurrentConversation.showName"
					size="46" />
			</view>
			<view @click="invite2group" class="action">
				<image style="width: 46px; height: 46px" src="@/static/images/single_setting_add.png" alt="" />
			</view>
		</view>
		<u-gap></u-gap>
		<uni-list>
			<uni-list-item title="查找聊天内容" :to="'/pages/common/search/index?type=conversation&conversationID='+storeCurrentConversation.conversationID" showArrow></uni-list-item>
		</uni-list>
		<u-gap></u-gap>
		<uni-list>
			<uni-list-item title="消息免打扰" @switchChange="updateCoversation('recvMsgOpt',storeCurrentConversation.recvMsgOpt==0 ? 2: 0)" showSwitch :switchChecked="storeCurrentConversation.recvMsgOpt !== 0"></uni-list-item>
			<uni-list-item title="置顶聊天" @switchChange="updateCoversation('isPinned',!storeCurrentConversation.isPinned)" showSwitch :switchChecked="storeCurrentConversation.isPinned"></uni-list-item>
		</uni-list>
		<u-gap></u-gap>
		<uni-list>
			<uni-list-item title="删除聊天记录" @click="clearMsg" clickable></uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	import {mapGetters} from "vuex";
	import CustomNavBar from "@/components/CustomNavBar/index.vue";
	import MyAvatar from "@/components/MyAvatar/index.vue";
	import SettingItem from "@/components/SettingItem/index.vue";
	import IMSDK from "openim-uniapp-polyfill";
	export default {
		components: {
			CustomNavBar,
			MyAvatar,
			SettingItem,
		},
		props: {},
		data() {
			return {
				switchLoading: {
					pin: false,
					opt: false,
					readLimit: false,
				},
				showConfirm: false,
			};
		},
		computed: {
			...mapGetters(["storeCurrentConversation"]),
		},
		methods: {
			toUserCard() {
				//console.log(this.storeCurrentConversation);
				//return  ;
				uni.navigateTo({
					url: `/pages/common/userCard/index?sourceID=${this.storeCurrentConversation.userID}`,
				});
			},
			invite2group() {
				const checkedMemberList = JSON.stringify([{
					userID: this.storeCurrentConversation.userID,
					faceURL: this.storeCurrentConversation.faceURL,
					nickname: this.storeCurrentConversation.showName,
				}, ]);
				uni.navigateTo({
					url: `/pages/common/createGroup/index?checkedMemberList=${checkedMemberList}`,
				});
			},
			clearMsg(){
				IMSDK.asyncApi('clearConversationAndDeleteAllMsg',IMSDK.uuid(), this.storeCurrentConversation.conversationID).then(res=>{
					uni.navigateBack();
				}).catch(e=>{
					console.log(e);
				})
			},
			updateCoversation(field,value1){
				const data = {conversationID:this.storeCurrentConversation.conversationID};
				data[field] = value1;
				IMSDK.asyncApi('setConversation', IMSDK.uuid(),data).then(res=>{
					console.log(res);
				}).catch(e=>{
					console.log(e);
				})
			},
		},
	};
</script>

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

		.row_wrap {
			flex: 1;
			overflow-y: auto;
		}

		.setting_row {
			background: #fff;
			border-radius: 6px;
			overflow: hidden;
		}

		.info_row {
			display: flex;
			align-items: center;
			padding: 44rpx;

			.user_info {
				@include colBox(false);
				margin-right: 36rpx;

				.user_name {
					margin-top: 20rpx;
					color: #666;
				}
			}
		}
	}
</style>