<template>
	<view class="yinsi">
		<view class="content">
			<view class="item">
				<view class="a">隐藏我的城市</view>
				<u-switch active-color="#000000" v-model="checked" @change="changeChecked"></u-switch>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				checked: false
			};
		},
		onLoad() {
			this.getUserInfo();
		},
		methods: {
			//查询个人信息
			async getUserInfo() {
				const { code, data , msg } = await this.$api.findUserInfo({userId: uni.getStorageSync("userInfo").id});
				if(code == 200){
					this.city_hide = (data.cityHide == 0?true:false)
					uni.setStorageSync("userInfo",data);
				}else{
					uni.showToast({
						title: msg,
						position: "bottom",
						icon: "none",
					})
				}
			},
			async changeChecked(e) {
				this.checked = e;
				console.log(e)
				const { code, data, msg } = await this.$api.privacyConfig({
					"userId": uni.getStorageSync("userInfo").id,
					"cityHide": this.checked?1:0 //隐藏我的城市：0不隐藏1隐藏
				});
				if(code == 200){
					uni.showToast({
						title: "修改成功"
					})
				}else{
					uni.showToast({
						icon: "none",
						position: "bottom",
						title: msg
					})
				}
			}
		}
	}
</script>

<style scoped lang="scss">
.yinsi{
	padding: 0 25rpx;
	overflow: hidden;
	.content{
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-top: 20rpx;
		.item{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx;
			box-sizing: border-box;
			width: 100%;
			height: 100rpx;
			box-sizing: border-box;
			font-weight: 500;
			font-size: 30rpx;
			color: #222222;
		}
	}
}
</style>
