<template>
	<!-- <view v-if="source=='WECHAT'"> -->
	<view>
		<template v-for="(col,index) in list" :key="index">
			<view class="title">{{col.title}}</view>
			<u-cell-group>
				<u-cell-item :title="item.title" v-for="(item,i) in col.columns" :key="i" @click="itemClick(item)"
					:titleStyle="titleStyle" borderBottom></u-cell-item>
			</u-cell-group>
		</template>
	</view>
	<!-- <view v-else>
		<template v-for="(col,index) in listALI" :key="index">
			<view class="title">{{col.title}}</view>
			<u-cell-group>
				<u-cell-item :title="item.title" v-for="(item,i) in col.columns" :key="i" @click="itemClick(item)"
					:titleStyle="titleStyle" borderBottom></u-cell-item>
			</u-cell-group>
		</template>
	</view> -->


	<button class="action" @click="loginOut">退出登录</button>
</template>

<script setup lang="ts">
	import { source } from "@/utils/network/difference";
	import { useUserStore } from '@/stores/user';
	import { msg, navTo } from '@/utils/utils';

	const userStore = useUserStore();
	const { loginOut } = userStore;
	import {
		request
	} from "@/utils/network/request.js";
	import {
		infoQuery, envs
	} from "@/utils/network/api.js";
	import {
		stringToJson
	} from "@/utils/network/encryption.js";
	const titleStyle = { fontSize: '28rpx', color: '#333333' };
	const basePath = "/subpackage/personal-center/setting/";
	const list = [
		{
			title: '个人信息管理',
			columns: [
				{ title: '个人信息更正', path: 'personal-information/corrections', login: true },
				{ title: '个人信息删除', path: 'information-deletion', login: true },
				{ title: '权限管理', path: 'permission-management', login: true },
				// {title:'撤销权限管理',path:'revoke-permission',login:true}, //无 UI
				{ title: '信息副本导出', path: 'info-export', login: true }, //无 UI
				{ title: '注销账户', path: 'account-cancellation', login: true },
				{ title: '车辆信息管理', path: '/subpackage/personal-center/vehicle-information', login: true }, //无 UI
				{ title: '收货地址管理', path: 'addressManager', login: true }, //有 UI 无界面
				// {title:'银行卡',path:'bank-card/bank-card',login:true},//有 UI 无界面
			]
		},
		{
			title: '隐私',
			columns: [
				{ title: '用户协议', path: 'user-agreement', login: true },//无 UI
				{ title: '隐私政策', path: 'conceal-agreement', login: true },//无 UI
				{ title: '风险提示告知书', path: 'risk-agreement', login: true },//无 UI
				{ title: '个人信息收集清单', path: 'info_connect', login: true },//无 UI
				{ title: '权限使用说明', path: 'usage-instructions', login: true }//无 UI
			]
		},
	]
	const listALI = [
		{
			title: '个人信息管理',
			columns: [
				{ title: '收货地址管理', path: 'addressManager', login: true }, //有 UI 无界面
				// {title:'银行卡',path:'bank-card/bank-card',login:true},//有 UI 无界面
			]
		},
		{
			title: '隐私',
			columns: [
				{ title: '用户协议', path: 'user-agreement', login: true },//无 UI
				{ title: '隐私政策', path: 'conceal-agreement', login: true },//无 UI
				{ title: '风险提示告知书', path: 'risk-agreement', login: true },//无 UI
				{ title: '个人信息收集清单', path: 'info_connect', login: true },//无 UI
				{ title: '权限使用说明', path: 'usage-instructions', login: true }//无 UI
			]
		},
	]

	/* item点击 */
	const itemClick = (item) => {
		console.log("item", item)

		if (!item.path) {
			msg('找不到该界面哦！');
			return;
		}
		if (item.title == '车辆信息管理') {
			navTo(item.path, item.login);
		} else if (item.title == '用户协议' || item.title == '隐私政策' || item.title == '风险提示告知书' || item.title == '权限使用说明') {
			let type = ""
			if (item.title == '用户协议') {
				type = "USER_AGREEMENT"
			} else if (item.title == '隐私政策') {
				type = "PRIVACY_POLICY"
			} else if (item.title == '风险提示告知书') {
				type = "RISK_NOTIFICATION"
			} else if (item.title == '权限使用说明') {
				type = "PRIVILEGE_USE"
			}
			getInfo(type).then((data) => {
				console.log("data", data)
				if (data.textType == "URL") {
					previewPdf(envs[process.env.NODE_ENV].baseUrl + data.text)
				} else {
					console.log("basePath + item.path", basePath + item.path)
					const params = encodeURIComponent(JSON.stringify(data.text))
					uni.navigateTo({
						url: `${basePath}${item.path}?params=${params}`
					})
				}
			})
		} else {
			navTo(basePath + item.path, item.login);
		}
	}
	const getInfo = (type) => {
		//参数说明
		let options = {
			type: 2, //type: 2,JSON格式提交数据(默认表单形式提交)
			data: {
				businessType: type
			}, //请求参数
			method: "POST", //提交方式(默认POST)
			showLoading: true, //是否显示加载中(默认显示)
		};
		return new Promise(async (resolve, reject) => {
			const res = await request(infoQuery, options);
			const data = stringToJson(res.bizContent);
			resolve(data);
		}).catch((error) => {
			reject(error);
		});
	}
	const previewPdf = (urll) => {
		const that = this
		let url = urll
		uni.showLoading({
			title: '加载中'
		});
		uni.downloadFile({
			url,
			success: ({
				tempFilePath: filePath
			}) => {
				uni.openDocument({
					filePath,
					fail: (err) => {
						console.log('这是打开报错值：' + err)
					},
					complete: () => {
						uni.hideLoading()
					}
				})
			},
			fail: (err) => {
				console.log('这是请求报错：', err)
				uni.hideLoading()
			}
		})
	}
</script>

<style>
	page {
		background: #EEF7F7;
		padding-bottom: 100rpx;
	}
</style>
<style lang="scss" scoped>
	.title {
		font-size: 26rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #666666;
		height: 80rpx;
		padding-top: 30rpx;
		padding-left: 30rpx
	}

	.action {
		margin-top: 30rpx;
		font-size: 28rpx;
		font-family: Microsoft YaHei;
		font-weight: 400;
		color: #333333;
		line-height: 88rpx;
		height: 88rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 4rpx 11rpx 1rpx rgba(223, 223, 223, 0.5);
	}
</style>