<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>
			<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="#fa436a" @change="switchChange" />
			</view>
			
			<view class="list-cell m-t" v-if="isshowdy">
				<text class="cell-tit">店铺打烊</text>
				<switch :checked="ischeckedtwo" color="#fa436a" @change="switchChangetwo" />
			</view>
			
			
			<view class="list-cell m-t b-b" @tap="cleanstore" 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="todeleteStore"  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" 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>
			<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>
				<image class="jiantousi" src="/static/news/jiantousi.png" mode=""></image>
			</view>
			<view class="list-cell log-out-btn" >
				<view class="button" @tap="toLogout">
					<text class="cell-tit log-out-btncolor">退出登录</text>
				</view>
				
			</view>
		</view>
		
		<yomol-upgrade   ref="yomolUpgrade" :isshowmsg="true"></yomol-upgrade>
		<!-- 升级组件 -->
		
	</view>
</template>

<script>
	import {userLogout,deleteStore,storeOpenEle,storeEleInfo} from "@/utils/api/api.js";
	import yomolUpgrade from '@/components/yomol-upgrade/yomol-upgrade.vue';//升级组件 
	export default {
		components:{
			yomolUpgrade,
		},
		data() {
			return {
				//ischecked:false,//声音提醒开关
				version:"1.00",
				ischeckedtwo:false,//店铺打烊情况
				isshowdy:false,//是否显示打烊按钮
			};
		},
		onLoad() {
			this.getv();
			console.info(this.version);
			
			this.storeEleInfofun();//查询外卖店铺详情信息
		},
		computed:{
			//选中状态
			ischecked(){
				return this.$store.state.isvoice;
			}
		},
		methods:{
			//查询外卖店铺详情信息
		 	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);
				}
			},
			//关闭店铺
			todeleteStore(){
				console.info("关闭店铺");
				uni.showModal({
				    title: '提示',
				    content: '您确认要关闭店铺吗?',
					cancelText:"我点错了",
					confirmText:"确定关闭",
					cancelColor:"#ff6900",
					confirmText:"确定",
				    success:  (res)=> {
				        if (res.confirm) {
				            console.log('用户点击确定');
							//请求关闭店铺
							deleteStore({
								
							}).then((res)=>{
								if(res.code==0){
									this.$api.msg(res.msg);
								}else{
									this.$api.msg(res.msg);
								}
							})
							
				        } else if (res.cancel) {
				            console.log('用户点击取消');
				        }
				    }
				});
			},
			getv(){
				// #ifdef APP-PLUS
				plus.runtime.getProperty(plus.runtime.appid, (widgetInfo) => {
					this.version = widgetInfo.version;
				})
				// #endif
				
			},
			navTo(url){
				this.$api.msg(`跳转到${url}`);
			},
			//退出登录
			toLogout(){
				uni.showModal({
				    content: '确定要退出登录么',
				    success: (e)=>{
				    	if(e.confirm){
				    		//this.logout();
							//退出登录事件处理
				    		
							
							//退出登录
							userLogout({
								
							}).then((res)=>{
								if(res.code==0){
									this.$api.msg("退出成功");
									uni.setStorageSync('token',"");
									this.$store.commit('changetoken',"");
									this.$store.commit('changeuserInfo', {});
									uni.setStorageSync('userInfo', {});
									uni.clearStorage();
									
									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);
					
					console.info("循环消息列表2");
					//震动 调用//400ms//长震动
					uni.vibrateLong({
						success:(re)=> {
						},
						fail:(a)=> {
						}
					})
				})
				
				//console.info(e.detail.value,"e.detail.value ");
				
				this.$store.commit("changeisvoice",e.detail.value);//直接修改 双向绑定的
			},
			//店铺打烊
			switchChangetwo(e){
				console.info(e.detail.value,"打烊修改");
				//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);
					}
				})
				
			},
			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>
