<template>
	<!-- 设置页面 -->
	<view class="setup">
		
		<view class="container">
			<navigator url="/pages/edit/shop/shop" class="list-cell b-b m-t"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">门店信息</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			
			<!-- <view  class="list-cell b-b m-t" v-if="platform=='android'"  hover-class="cell-hover" :hover-stay-time="50" @click="qiDong">
				<text class="cell-tit">允许后台自启</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view> -->
			
			<!-- <view  class="list-cell b-b m-t" v-if="platform=='ios'"  hover-class="cell-hover" :hover-stay-time="50" @click="qiDong">
				<text class="cell-tit">允许后台启动</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view> -->
			
			<navigator url="/pages/edit/Qualifications/Qualifications" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">相关资质</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			
			
			<view class="list-cell m-t">
				<text class="cell-tit">接收订单提醒</text>
				<switch :checked="ischecked" color="#ff6900" @change="switchChange" />
			</view>
			
			<view class="list-cell m-t">
				<text class="cell-tit">接收消息提醒</text>
				<switch :checked="isvoicemsg" color="#ff6900" @change="switchChangesmg" />
			</view>
			
			
			
			<navigator url="/pages/Course/Courselist" class="list-cell m-t" >
				<text class="cell-tit">收不到语音提示?</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			
			<view class="list-cell m-t" v-if="isshowdy">
				<text class="cell-tit">店铺打烊</text>
				<switch :checked="ischeckedtwo" color="#ff6900" @change="switchChangetwo" />
			</view>
			
			
			<view class="list-cell m-t b-b" @tap="cleanstoreone" hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">清除缓存</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view>
			<navigator url="/pages/tagglestore/tagglestore" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">切换门店</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			<!-- <view  class="list-cell b-b" @tap="oneTodeleteStore"  hover-class="cell-hover" >
				<text class="cell-tit">关闭店铺</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view> -->
			<navigator url="/pages/setPassword/setPassword?is_pay=0" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">修改登录密码</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			<navigator url="/pages/setPassword/setPayPassword" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">修改支付密码</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			<navigator url="/pages/about/about" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">关于我们</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			<navigator url="/pages/Agreement/Agreementuser" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">用户协议</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			<navigator url="/pages/Agreement/Agreement" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">隐私策略</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			<view class="list-cell b-b"  hover-class="cell-hover" @click="go" :hover-stay-time="50">
				<text class="cell-tit">联系客服</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view>
			<navigator url="/pages/feedback/feedback" class="list-cell b-b"  hover-class="cell-hover" :hover-stay-time="50">
				<text class="cell-tit">意见反馈</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</navigator>
			
			<view class="list-cell ali-c" @tap="ToUpdate">
				<text class="cell-tit">检查更新</text>
				<text class="cell-tip">当前版本 {{version}}</text>
				<text class="cell-tip" v-if="debug.isdebug"> 测试版</text>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view>
			<view class="list-cell log-out-btn" >
				<view class="button" @tap="toLogoutone">
					<text class="cell-tit log-out-btncolor">退出登录</text>
				</view>
				
			</view>
		</view>
		
		<yomol-upgrade   ref="yomolUpgrade" :isshowmsg="true"></yomol-upgrade>
		<!-- 升级组件 -->
		
		
		<moduPopup ref="moduPopup" title="关闭店铺" infotext="你确认要关闭店铺吗？关闭后余额将会自动转到佣金" @confirm="todeleteStore" @cancel="gdcancel"></moduPopup>
		<!-- 提示信息组件  关店的-->
		
		
		<moduPopup ref="moduPopupTwo" title="退出登录" infotext="确认要退出登录吗~" @confirm="toLogout" @cancel="gdcancel"></moduPopup>
		<!-- 提示信息组件  退出登录-->
		
		<moduPopup ref="cleanstoreone" title="清除缓存" infotext="清除缓存后你的账号将会退出~" @confirm="cleanstore" @cancel="gdcancel"></moduPopup>
		<!-- 提示信息组件  清除缓存-->
		
	</view>
</template>

<script>
	
	import {userLogout,deleteStore,storeOpenEle,storeEleInfo} from "@/utils/api/api.js";
	import yomolUpgrade from '@/components/yomol-upgrade/yomol-upgrade.vue';//升级组件 
	import moduPopup from "@/components/moduPopup/moduPopup.vue";
	import debug from "@/utils/debug.js";
	export default {
		components:{
			yomolUpgrade,
			moduPopup,
		},
		data() {
			return {
				//ischecked:false,//声音提醒开关
				version:"1.00",
				ischeckedtwo:false,//店铺打烊情况
				isshowdy:false,//是否显示打烊按钮
				platform:'ios',
				isvoicemsg:true,//是否打开消息提醒  短信消息
			};
		},
		onLoad() {
			this.platform=uni.getSystemInfoSync().platform;
			this.getv();
			this.storeEleInfofun();//查询外卖店铺详情信息
			
			let isvoicemsg = uni.getStorageSync("isvoicemsg");
			if(isvoicemsg==-1){
				this.isvoicemsg = false;
			}
		},
		computed:{
			//选中状态
			ischecked(){
				return this.$store.state.isvoice;
			},
			debug(){
				return debug;
			},
			
			
		},
		
		methods:{	
			qiDong(){
				if(this.platform=='ios'){
					getApp().getIosLocation(2);
				}else{
					const pushLive = uni.requireNativePlugin('push-live');
					pushLive.gotoWhiteListSetting();// 自启动
				}
				

				
			},
			//联系客服
			go(){
				let service_tel = uni.getStorageSync("service_tel");
			 	uni.makePhoneCall({
					phoneNumber: service_tel,//这个是从首页获取到的
				});
			},
			
			//查询外卖店铺详情信息
		 	async storeEleInfofun(){
				let res = await storeEleInfo({});
				if(res.data==null){
					this.isshowdy = false;
					return false;
				}else{
					this.isshowdy = true;
				}
				
				if(res.code==0){
					let is_open = res.data.is_open;//1营业，0打烊
					if(is_open==1){//营业
						this.ischeckedtwo = false;
					}else{//false 打烊中
						this.ischeckedtwo = true;
						
					}
				}else{
					this.$api.msg(res.msg);
				}
			},
			//点击关闭店铺
			oneTodeleteStore(){
				this.$refs.moduPopup.show();
			},
			gdcancel(){
				//取消
				console.info('取消');
			},
			//关闭店铺 点击确认后
			todeleteStore(){
				console.info("关闭店铺");
				
				//请求关闭店铺
				deleteStore({
					
				}).then((res)=>{
					if(res.code==0){
						this.$api.msg(res.msg);
					}else{
						this.$api.msg(res.msg);
					}
				})
				
				
				
			},
			getv(){
				// #ifdef APP-PLUS
				plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
					this.version = widgetInfo.version;
				})
				// #endif
				
			},
			navTo(url){
				this.$api.msg(`跳转到${url}`);
			},
			//显示弹窗 清除缓存的
			toLogoutone(){
				// console.log(this.$store.state.Timer,'退出登入')
				// this.$store.Timer
				this.$refs.moduPopupTwo.show();
			},
			//退出登录
			toLogout(){
				//退出登录
				userLogout({
					
				}).then((res)=>{
					if(res.code==0){
						if(this.platform!='ios'){
							const pushLive = uni.requireNativePlugin('push-live');
							pushLive.closeService(function(res) {
								console.log(res,'停止保活');
							});
						}
						
						
						this.$api.msg("退出成功");
						uni.setStorageSync('token',"");
						this.$store.commit('changetoken',"");
						this.$store.commit('changeuserInfo', {});
						uni.setStorageSync('userInfo', {});
						uni.clearStorage();
						clearInterval(this.$store.state.Timer)
						this.$store.state.Timer = ''
						setTimeout(()=>{
							// uni.navigateBack();
							uni.navigateTo({
								url:"/pages/login/login",
							})
						}, 500)
					}else{
						this.$api.msg(res.msg);
					}
				})
			},
			//switch
			switchChange(e){
				let statusTip = e.detail.value ? '打开': '关闭';
				this.$api.msg(`已${statusTip}语音提示`);
				
				this.$store.dispatch('AudioVoice',`已${statusTip}语音提示`).then((e) => {
					console.log(e);
					//震动 调用//400ms//长震动
					uni.vibrateLong({
						success:(re)=> {
						},
						fail:(a)=> {
						}
					})
				})
				
				this.$store.commit("changeisvoice",e.detail.value);//直接修改 双向绑定的
			},
			//消息提醒
			switchChangesmg(e){
				// console.info(e,"eeee");
				let val = e.detail.value;
				if(val){
					this.isvoicemsg = true;
					uni.setStorageSync("isvoicemsg","")
				}else{
					this.isvoicemsg = false;
					uni.setStorageSync("isvoicemsg","-1")
				}
			},
			//店铺打烊
			switchChangetwo(e){
				//is_open  是否打烊（0默认打烊，1营业）
				let is_open = e.detail.value?0:1;
				storeOpenEle({
					is_open:is_open,
				}).then((res)=>{
					if(res.code==0){
						this.$api.msg(res.msg);
					}else{
						this.$api.msg(res.msg);
					}
				})
				
			},
			cleanstoreone(){
				this.$refs.cleanstoreone.show();
			},
			cleanstore(){
				//清除缓存
				uni.clearStorage();
				this.$api.msg("操作成功");

				setTimeout(()=>{
					uni.navigateTo({
						url:"/pages/login/login",
					})
				},1000)
				
			},
			//更新检测事件
			ToUpdate(){
				
				// #ifdef APP-PLUS
				//this.checkVersionClick();//自动检测更新
				this.$refs.yomolUpgrade.checkVersionClick();
				// #endif
				
				// #ifdef H5
				this.$api.msg("已是最新版本");
				// #endif
			}
		}
	}
</script>

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