<template>
	<view class="client-my-page">
		<view class="jzgs-name-box">
			<text>{{myInfoData.jzName}}</text>
		</view>
		<view class="admin-head-box">
			<view class="head-img-box">
				<img class="head-img" :src="myInfoData.userImg" v-if="myInfoData.userImg">
				<icon class="phone-default-userImg" v-else></icon>
			</view>
			<view class="head-content-box">
				<text>{{myInfoData.realName}}</text>
				<view class="head-content-row-box" v-if="myInfoData.userName">
					<icon class="tel-icon"></icon>
					<text class="content-text">{{myInfoData.userName}}</text>
				</view>
			</view>
		</view>

		<view class="my-list-box">
			<view class="list-row" @click="goToPage('grcj')">
				<icon class="list-icon user-icon"></icon>
				<text>修改个人信息</text>
			</view>
			<view class="list-row" @click="goToPage('jzxx')">
				<icon class="list-icon jzxx-icon"></icon>
				<text>家政信息维护</text>
			</view>
			<view class="list-row" @click="xgmmBtn">
				<icon class="list-icon mm-icon"></icon>
				<text>修改密码</text>
			</view>
			<view class="list-row" @click="ewmBtn">
				<icon class="list-icon code-icon"></icon>
				<text>二维码</text>
			</view>
			<view class="list-row" @click="kfdhBtn">
				<icon class="list-icon kfdh-icon"></icon>
				<text>客服电话</text>
			</view>
			<view class="list-row" @click="yszcBtn">
				<icon class="list-icon ysxy-icon"></icon>
				<text>隐私协议</text>
			</view>
			<view class="list-row" @click="yhzxBtn">
				<icon class="list-icon yhzx-icon"></icon>
				<text>用户注销</text>
			</view>
			<view class="list-row" @click="exitLogin">
				<icon class="list-icon login-out-icon"></icon>
				<text>退出登录</text>
			</view>
		</view>
		<!-- 底部区域 -->
		<customTabbarClient :currentTab="3"></customTabbarClient>
		<common-dialog ref="commonDialogRef" :title="exitTitle" :content="exitContent"
			@confirm-btn="exitBtn"></common-dialog>
		<common-dialog ref="zhuxiaoDialogRef" :title="zhuxiaoTitle" :content="zhuxiaoContent"
			@confirm-btn="zhuxiaoBtn"></common-dialog>	
		<common-dialog ref="kfdhDialogRef" :title="kfdhTitle" :content="kfdhContent"></common-dialog>		
		<shexiangDialogVue ref="shexiangRef" title="摄像头说明"></shexiangDialogVue>
		<password-dialog ref="passwordDialogRef" @confirm-btn="passwordBtn"></password-dialog>
		<image-dialog ref="imageDialogRef"></image-dialog>
		<!-- 摄像头确认 -->
		<zhuapaiConfrimVue ref="zpRef" @error="zpConfirmError" title="摄像头测试"></zhuapaiConfrimVue>
	</view>
</template>

<script setup>
	import {
		toast
	} from "@/utils/common";
	import {
		onLoad,
		onShow
	} from '@dcloudio/uni-app';
	import cacheManager from '@/utils/cacheManager.js';
	import {
		getGlMineUser,
		getGlMineLogout,
		getGlPasswordUpdate,
		getGlMineDisable
	} from '@/api/my.js'
	import {
		reactive,
		ref
	} from "vue";
	import customTabbarClient from "@/components/custom-tabbar/custom-tabbar-admin.vue"
	import commonDialog from '@/components/dialog/commonDialog.vue';
	import passwordDialog from './passwordDialog.vue';
	import imageDialog from './imageDialog.vue';
	import shexiangDialogVue from "@/components/dialog/shexiangDialog.vue";
	import zhuapaiConfrimVue from "@/components/zhuapaiConfirm/index.vue";
	import {
		useIsCanBack
	} from "@/store/isCanBack.js"
	// #ifndef APP-HARMONY
	import UniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
	const uniShare = new UniShare();
	// #endif
	// #ifdef APP-HARMONY
	import {
		uniShare
	} from "@/uni_modules/uni-share"
	// #endif
	let myInfoData = reactive({
		jzName: '',
		userImg: '',
		realName: '',
		idcard: '',
		userName: '',
		from: ''
	});
	const passwordDialogRef = ref(null);
	const imageDialogRef = ref(null);
	const shexiangRef = ref(null);
	const zpRef = ref(null);
	const commonDialogRef = ref(null);
	const exitContent = '你确定要执行这个操作吗？';
	const exitTitle = '退出登录';
	const zhuxiaoDialogRef = ref(null);
	const zhuxiaoContent = '你确定要执行这个操作吗？';
	const zhuxiaoTitle = '用户注销';
	const kfdhDialogRef = ref(null);
	const kfdhTitle = '客服电话';
	const kfdhContent = '梁经理：13911569583';

	const store = useIsCanBack();

	function getMyInit() {
		getUserInfo();
	}
	// 获取用户头像
	function goToPage(data) {
		switch (data) {
			case 'grcj':
				uni.navigateTo({
					url: '/pages/admin/my/myInfo?from=my'
				})
				break;
				case 'jzxx':
				uni.navigateTo({
					url: '/pages/admin/my/jzInfo'
				})
				break;
		}
	}

	function getUserInfo() {
		getGlMineUser({}).then(res => {
			myInfoData.userImg = res.data.icon;
			myInfoData.realName = res.data.realName;
			myInfoData.idcard = res.data.idcard;
			myInfoData.userName = res.data.userName;
			myInfoData.jzName = res.data.jzName;
		})
	}

	function exitLogin() {
		commonDialogRef.value.handleShow();
	}
	
	function yszcBtn(){
		uni.navigateTo({
		  url: `/pages/admin/my/yszc?from=my`
		})
	}
	
	function yhzxBtn() {
		zhuxiaoDialogRef.value.handleShow();
	}
	
	function kfdhBtn() {
		kfdhDialogRef.value.handleShow();
	}

	function xgmmBtn() {
		passwordDialogRef.value.handleShow();
	}

	function ewmBtn() {
		imageDialogRef.value.handleShow();

		// if (!plus.runtime.isApplicationExist({
		// 		pname: 'com.tencent.mm'
		// 	})) {
		// 	uni.showToast({
		// 		title: '请先安装微信',
		// 		icon: 'none'
		// 	});
		// 	return;
		// }
		
		// // 分享到小程序  我想加个参数  
		// uni.share({
		//     provider: 'weixin',
		//     scene: "WXSceneSession",
		//     type: 5,
		//     imageUrl: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/share-logo@3.png',
		//     title: '欢迎体验uniapp12312',
		//     miniProgram: {
		//         id: 'gh_fa5889151e7d',
		//         path: 'pages/Login/clientIndex?from=appcx',
		//         type: 2,
		//         webUrl: 'http://uniapp.dcloud.io'
		//     },
		//     success: ret => {
		//         console.log(JSON.stringify(ret));
		//     }
		// });
		// // #ifdef APP-HARMONY
		// uniShare(['https://img-cdn-aliyun.dcloud.net.cn/stream/icon/__UNI__HelloUniApp.png'])
		// // #endif
		// // #ifndef APP-HARMONY
		// uniShare.show({
		// 	content: { //公共的分享参数配置  类型（type）、链接（herf）、标题（title）、summary（描述）、imageUrl（缩略图）
		// 		type: 5,
		// 		href: 'https://uniapp.dcloud.io/',
		// 		title: '标题',
		// 		summary: '描述阿斯顿发啥发啥发',
		// 		imageUrl: 'https://img-cdn-aliyun.dcloud.net.cn/stream/icon/__UNI__HelloUniApp.png',
		// 		miniProgram: {
		// 			id: 'gh_abcdefg',
		// 			path: 'pages/index/index',
		// 			type: 0,
		// 			webUrl: 'http://uniapp.dcloud.io'
		// 		},
		// 	},
		// 	menus: [{
		// 		"img": "/static/app-plus/sharemenu/wechatfriend.png",
		// 		"text": "微信好友",
		// 		"share": { //当前项的分享参数配置。可覆盖公共的配置如下：分享到微信小程序，配置了type=5
		// 			"provider": "weixin",
		// 			"scene": "WXSceneSession"
		// 		}
		// 	}, {
		// 		"img": "/static/app-plus/sharemenu/wechatmoments.png",
		// 		"text": "微信朋友圈",
		// 		"share": {
		// 			"provider": "weixin",
		// 			"scene": "WXSceneTimeline"
		// 		}
		// 	}],
		// 	cancelText: "取消分享",
		// }, e => { //callback
		// 	console.log(uniShare.isShow);
		// 	console.log(e);
		// })
		// // #endif
	}

	function passwordBtn(data) {
		console.log(data, 'data');
		const opt = {
			passwordOld: data.oldPassWord,
			passwordNew: data.newPassWord,
		}
		getGlPasswordUpdate(opt).then(res => {
			if (res.data) {
				uni.showToast({
					title: '更新成功'
				})
				passwordDialogRef.value.handleClose();
			}
		})
	}

	function exitBtn() {
		getGlMineLogout().then(res => {
			toast('退出登录成功')
			cacheManager.clearAll();
			uni.reLaunch({
				url: '/pages/Login/index'
			});
			store.setIsCanBack(true)
		}).catch(err => {
			toast('退出登录失败，请稍后重试')
			store.setIsCanBack(false)
		})
	}
	
	function zhuxiaoBtn(){
		getGlMineDisable().then(res => {
			toast('用户注销成功')
			cacheManager.clearAll();
			uni.reLaunch({
				url: '/pages/Login/index'
			});
			store.setIsCanBack(true)
		}).catch(err => {
			toast('用户注销失败，请稍后重试')
			store.setIsCanBack(false)
		})
	}

	function showMessageDl() {
		console.log(shexiangRef.value)
		shexiangRef.value.handleShow()
	}

	function showZhuaPaiConfirm() {
		zpRef.value.showDialog()
	}

	function zpConfirmSuccess() {
		zpRef.value.showDialog()
	}

	function zpConfirmError() {
		uni.showToast({
			title: '摄像头唤起异常',
			icon: 'none'
		})
	}

	onLoad(() => {

	})

	onShow(() => {
		getMyInit()
	})
</script>

<style>
</style>