<template>
	<view class="page">
		<navBar title="设置" :back="true" color="black" background="white" />
		<!-- <u-switch v-model="value1" activeColor="#5ac725" loading></u-switch> -->
		<view class="content">
			<view class="item" style="border-radius: 0rpx 0rpx 0rpx 24rpx;;">
				<view class="line">
					<view class="left">
						显示售价
					</view>
					<view class="right">
						<u-switch v-model="value1" @change="change1" activeColor="#F7790C"
							inactiveColor="#E6E6E6"></u-switch>
					</view>
				</view>
				<view class="line" v-if="role!='svip'">
					<view class="left">
						显示会员价
					</view>
					<view class="right">
						<u-switch v-model="value2" @change="change2" activeColor="#F7790C"
							inactiveColor="#E6E6E6"></u-switch>
					</view>
				</view>
				<view class="line" v-if="role!='cydg'">
					<view class="left">
						显示VIP价
					</view>
					<view class="right">
						<u-switch v-model="value3" @change="change3" activeColor="#F7790C"
							inactiveColor="#E6E6E6"></u-switch>
					</view>
				</view>
			</view>
			<u-button text="退出登录" @click="logoOut" color="#333"></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				role: '',
				role: '',
				value1: true,
				value2: false,
				value3: false,
				// switchs: uni.getStorageSync('switchs')
			}
		},
		onLoad(o) {
			this.role = o.role
		},
		onShow() {
			this.value1 = Boolean(this.switchs[0])
			this.value2 = Boolean(this.switchs[1])
			this.value3 = Boolean(this.switchs[2])

			console.log(this.switchs);
		},
		computed: {
			switchs() {
				return uni.getStorageSync('switchs')
			}
		},
		methods: {
			logoOut() {
				uni.showModal({
					title: '提示',
					content: '确认退出?',
					confirmColor: '#F7790C',
					success: function(res) {
						if (res.confirm) {
							uni.removeStorageSync('token')
							uni.setStorageSync('switchs', [1, 0, 0])
							uni.reLaunch({
								url: '/pages/my'
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			change1(e) {
				if (e) {
					this.switchs[0] = 1
					if (this.value2) {
						this.value2 = false
						this.switchs[1] = 0
					}
					if (this.value3) {
						this.value3 = false
						this.switchs[2] = 0
					}
				} else {
					this.switchs[0] = 0
				}
				uni.setStorageSync('switchs', this.switchs)
				console.log(this.switchs);
			},
			change2(e) {
				if (e) {
					this.switchs[1] = 1
					if (this.value1) {
						this.value1 = false
						this.switchs[0] = 0
					}
					if (this.value3) {
						this.value3 = false
						this.switchs[2] = 0
					}
				} else {
					this.switchs[1] = 0
				}
				uni.setStorageSync('switchs', this.switchs)
				console.log(this.switchs);
			},
			change3(e) {
				if (e) {
					this.switchs[2] = 1
					if (this.value1) {
						this.value1 = false
						this.switchs[0] = 0
					}
					if (this.value2) {
						this.value2 = false
						this.switchs[1] = 0
					}
				} else {
					this.switchs[2] = 0
				}
				uni.setStorageSync('switchs', this.switchs)
				console.log(this.switchs);
			},
		}
	}
</script>

<style lang="scss" scoped>
	@import "./index.scss";
</style>