<template>
	<view class="wrap">
		<u-cell-group :border="false" :title="$t('homePage.mine.messageAlerts')">
			<u-cell-item :title="$t('homePage.mine.acceptMessageAlerts')" :arrow="false">
				<u-switch v-model="message" slot="right-icon" class="u-m-l-20"></u-switch>
			</u-cell-item>
			<u-cell-item :title="$t('homePage.mine.messageDetail')" :arrow="false">
				<u-switch v-model="messageBar" slot="right-icon" class="u-m-l-20"></u-switch>
				<text slot="label">{{this.$t('homePage.mine.closeMessage')}}</text>
			</u-cell-item>
		</u-cell-group>
		<u-cell-group :border="false" :title="$t('homePage.mine.sound')">
			<u-cell-item :title="$t('homePage.mine.acceptSound')" @click="openSettings">
				<text slot="label">{{ this.$t('homePage.mine.settingSound') }}</text>
			</u-cell-item>
		</u-cell-group>
		<u-cell-group :border="false" :title="$t('homePage.mine.update')">
			<u-cell-item :title="$t('homePage.mine.update')" :arrow="false">
				<u-switch v-model="upgrade" slot="right-icon" class="u-m-l-20"></u-switch>
				<text slot="label">{{ this.$t('homePage.mine.updateAlerts') }}</text>
			</u-cell-item>
		</u-cell-group>
	</view>
</template>
<script>
export default {
	data() {
		return {
			message: true,
			messageBar: true,
			upgrade: true
		};
	},
	onLoad() {
	  this.updateTitle()
	},
	onShow() {
	  this.updateTitle()
	},
	computed: {
		language(){
			return this.vuex_language 
		}
	},
	watch:{
		language: {
			immediate: true,
			deep:true,
			handler(val) {
				uni.setNavigationBarTitle({
					title: this.$t('homePage.mine.general')
				});
			}
		}
	},
	
	methods: {
		
		updateTitle() {
		    uni.setNavigationBarTitle({
		      title: this.$t('homePage.mine.general')
		    });
		},
		openSettings() {
			// #ifdef APP-PLUS
			uni.getSystemInfo({  
				success(res) {  
					if(res.platform == 'ios'){
						plus.runtime.openURL("app-settings://");
					} else if (res.platform == 'android'){
						var main = plus.android.runtimeMainActivity();  
						var Intent = plus.android.importClass("android.content.Intent");
						var mIntent = new Intent('android.settings.SOUND_SETTINGS');
						main.startActivity(mIntent);
					}
				}
			});
			// #endif
			// #ifndef APP-PLUS
			this.$u.toast(this.$t('homePage.mine.noUpdate'));
			// #endif
		},
		logout() {
			this.$u.api.logout().then(res => {
				this.$u.toast(res.msg);
				if (res.code == '200') {
					let self = this;
					setTimeout(() => {
						uni.reLaunch({
							url: '/pages/sys/login/index'
						});
					}, 500);
				}
			});
		}
	}
};
</script>
<style lang="scss">


page {
	background-color: #f8f8f8;
}

/deep/ .u-cell-title {
	padding: 25rpx 30rpx;
	font-size: 30rpx;
}
</style>
