<template>
	<view style="padding: 28rpx 0;">
		<view class="other_guide">
			<block v-for="(item,i) in myOaData" :key="i">
				<view class="other_item flex_a_c_j_sb" @click="clickItem(item)">
					<view class="flex_a_c left">
						<!-- <view class="iconfont2" :class="item.icon"></view> -->
						<image v-if="item.icon" :src="item.icon"></image>
						<view class="text">{{ item.name }}</view>
					</view>
					<view style="display: flex;align-items: center;">
						<view v-if="i==0">{{version}}</view>
						<uni-icons type="forward"></uni-icons>
					</view>
				</view>
			</block>
		</view>
		<view class="us" @click="copyPhone">
			<view>联系我们</view>
			<view>0830-2669767</view>
		</view>
	</view>
</template>

<script>
	import {
		Toast
	} from '../../libs/uniApi';
	import {
		destroyAccount
	} from '@/api/oaUser.js';
	export default {
		data() {
			return {
				myOaData: [{
						name: '版本更新'
					},
					{
						name: '注销账户'
					},
					{
						name: '隐私政策',
						url: 'https://worker-task.lihaink.cn/pc/policy/privacy'
					},
					{
						name: '用户协议',
						url: 'https://worker-task.lihaink.cn/pc/policy/service'
					},
					{
						name: '投诉反馈',
						url: '/subpkg/complaint/complaint'
					},
					{
						name: '联系我们'
					},
				],
				version: '',
				us: "0830-2669767",
			};
		},
		onLoad() {
			let os = uni.getSystemInfoSync();
			this.version = 'v' + (os?.appWgtVersion || os?.appVersion);
		},
		methods: {
			clickItem(e) {
				switch (e.name) {
					case '版本更新':
						this.updateVersion();
						break;
					case '注销账户':
						this.unsubscribe();
						break;
					case '联系我们':
						this.connectUs();
						break;
					case '隐私政策':
						this.navToWebView(e.url, '隐私政策');
						break;
					case '用户协议':
						this.navToWebView(e.url, '用户协议');
						break;
					case '投诉反馈':
						uni.navigateTo({
							url: e.url
						});
						break;
				}
			},
			updateVersion() {
				this.$store.dispatch('initConfig', true);
			},
			async unsubscribe() {
				uni.showModal({
					content: '注销账号后不可恢复,确认要注销吗?',
					success: async (e) => {
						if (e.confirm) {
							let res = await destroyAccount();
							uni.reLaunch({
								url: '/pages/oaLogin/oaLogin'
							})
						}
					}
				})
			},
			connectUs() {
				//拨打电话
				uni.makePhoneCall({
					phoneNumber: this.us + "",
					success: (e) => {
						console.log(e);
					},
					fail: (e) => {
						Toast('页面跳转失败,请检查是否开启权限');
						this.copyPhone();
					}
				});
			},
			copyPhone() {
				//复制号码
				uni.setClipboardData({
					data: this.us + "",
					showToast: false,
					success: (e) => {
						Toast('号码已复制')
					},
					fail: (e) => {
						Toast('复制失败')
					}
				})
			},
			navToWebView(uri, title) {
				uni.navigateTo({
					url: `/pages/webView/webView?title=${title}&uri=${uri}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.other_guide {
		width: 694.74rpx;
		margin: 0 auto;
		padding: 28.07rpx;
		background-color: #fff;
		border-radius: 12px;

		.other_item {
			height: 87.72rpx;
			border-bottom: 1px solid #F0F5F7;

			.text {
				font-size: 28.07rpx;
				margin-left: 20.56rpx;
			}

			.left {
				align-items: center;
			}

			image {
				width: 42rpx;
				height: 42rpx;
			}

			.iconfont2 {
				font-size: 42.11rpx;
			}
		}
	}

	.us {
		margin: 60rpx 0;
		text-align: center;
		color: #aaa;
	}
</style>