<template>
	<view class="content">
		<view class='flex bottom flex-between' style="padding: 20rpx;">
			<text>允许他人分享我的名片</text>
			<u-switch v-model="value1" activeColor="#112253" :activeValue='true' :inactiveValue='false' @change="change($event,1)"
				size="20"></u-switch>
		</view>
		<view class='flex bottom flex-between' style="padding: 20rpx;">
			<text>允许圈子成员查看我的主页</text>
			<u-switch v-model="value2" activeColor="#112253" @change="change($event,2)" size="20"></u-switch>
		</view>
		<view class="flex flex-between" style="padding: 20rpx;">
			<text>自动接受交换名片邀请</text>
			<u-switch v-model="value3" activeColor="#112253" @change="change($event,3)" size="20"></u-switch>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				value1: false,
				value2: false,
				value3: false
			};
		},
		onShow() {
			this.value1 = (uni.getStorageSync("userInfo").shareCard == 1 ? true : false)
			this.value2 = (uni.getStorageSync("userInfo").lookPage == 1 ? true : false)
			this.value3 = (uni.getStorageSync("userInfo").autoAccept == 1 ? true : false)
		},
		methods: {
			change(e, status) {
				console.log(e)
				let data = {
					id: uni.getStorageSync("userInfo").id
				}
				if (status == 1) {
					if (e) {
						data.shareCard = 1
					} else {
						data.shareCard = 0
					}
				} else if (status == 2) {
					if (e) {
						data.lookPage = 1
					} else {
						data.lookPage = 0
					}
				} else if (status == 3) {
					if (e) {
						data.autoAccept = 1
					} else {
						data.autoAccept = 0
					}
				}
				this.$request.baseRequest('admin.unimall.commonUserInfo', 'update', {
					commonUserInfo: JSON.stringify(data)
				}, failres => {
					console.log('res+++++', failres.errmsg)
					uni.showToast({
					  icon:"none",
					  title: failres.errmsg,
					  duration: 3000
					});
					uni.hideLoading()
				}).then(res => {
					uni.showToast({
					  icon:"success",
					  title: '设置成功！',
					  duration: 2000
					});
					let userInfo = uni.getStorageSync("userInfo")
					if (status == 1) {
						if (e) {
							userInfo.shareCard = 1
						} else {
							userInfo.shareCard = 0
						}
					} else if (status == 2) {
						if (e) {
							userInfo.lookPage = 1
						} else {
							userInfo.lookPage = 0
						}
					} else if (status == 3) {
						if (e) {
							userInfo.autoAccept = 1
						} else {
							userInfo.autoAccept = 0
						}
					}
					uni.setStorageSync("userInfo", userInfo)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		background: #fff;
		margin: 20rpx;
		padding: 0rpx 20rpx 0 20rpx;
		border-radius: 20rpx;

		.bottom {
			border-bottom: 1px solid #E6E6E6;
		}
	}
</style>