<template>
	<view>
		<view class='flex'>
			<text>允许他人分享我的名片</text>
			<u-switch  v-model="value1" :activeValue='true' :inactiveValue='false' @change="change($event,1)"></u-switch>
		</view>
		<view class="flex">
			<text>允许圈子成员查看我的主页</text>
			<u-switch v-model="value2"  @change="change($event,2)"></u-switch>
		</view>
		<view class="flex">
			<text>自动接受换名片邀请</text>
			<u-switch v-model="value3"  @change="change($event,3)"></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)
				var 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)
					this.$refs.uToast.show({
						type: 'error',
						message: failres.errmsg,
					})
					uni.hideLoading()
				}).then(res => {
					this.$refs.uToast.show({
						type: 'success',
						message: '设置成功',
					})
					var 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">

</style>
