<template>
	<view class="content">
		<!-- 头部 -->
		<view class="top" @click="navTo('/pageTwo/setting/setting')">
			<view class="headimg">
				<image :src="user.head_pic" class="image"></image>
				<view class="size20 bold">{{user.nickname}}</view>
			</view>
			<text class="t-icon t-icon-arrow-right-bold"></text>
		</view>
		<!--  -->
		<view class="wxlist borderRadius">
			<view class="list" @click="navTo('/pageTwo/my/manage')">
				<view class="item border-bottom">
					<view class="left">
						<view class="name">{{$t("common.titleManage")}}</view>
					</view>
					<view class="right">
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
			</view>
			<view class="list" @click="navTo('/pageTwo/history/history?acd_id=2')" v-if="language!= 'zh-Hans'">
				<view class="item border-bottom">
					<view class="left">
						<view class="name">{{$t("common.titleHistory")}}</view>
					</view>
					<view class="right">
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
			</view>
			<!-- <view class="list" @click="navTo('/pageTwo/business/business')">
				<view class="item border-bottom">
					<view class="left">
						<view class="name">{{$t("common.titlebBusiness")}}</view>
					</view>
					<view class="right">
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
			</view> -->
			<view class="list" @click="navTo('/pageTwo/score/history')" v-if="language== 'zh-Hans'">
				<view class="item border-bottom">
					<view class="left">
						<view class="name">{{$t("common.titleScoreHistory")}}</view>
					</view>
					<view class="right">
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
			</view>
			<!-- #ifdef APP-PLUS -->
			<view class="list" @click="navTo('/pageTwo/my/about')">
				<view class="item border-bottom">
					<view class="left">
						<view class="name">{{$t("common.titleAboutUs")}}</view>
					</view>
					<view class="right">
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
			</view>
			<view class="list">
				<view class="picker item">
					<view class="name">{{$t("common.titleLanguage")}}</view>
					<picker mode="selector" :range="languageList" :value="index" range-key="value"
						@change="languageClick">
						<view class="uni-input">{{languageList[index].value}}</view>
						<icon class="iconfont icon-arrow-down-bold"></icon>
					</picker>
				</view>
			</view>
			<!--  #endif -->
			<view class="list" v-for="(ite,ind) in CooperationUrl" :key="ind">
				<view class="item border-bottom" @click="navTo('/pageTwo/webview/webview?url=' + ite.url)">
					<view class="left">
						<view class="name">{{ite.title}}</view>
					</view>
					<view class="right">
						<uni-icons type="right"></uni-icons>
					</view>
				</view>
			</view>
		</view>
		<view class="btn mb-15" v-if="token" @click="handleOutLogin">{{$t("common.btnLogOut")}}</view>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	import headerIndex from "@/element/headerIndex.vue"
	export default {
		data() {
			return {
				token: "",
				user: {},
				language: "",
				index: 0,
			}
		},
		components: {
			headerIndex
		},
		computed: {
			...mapState(["accountNumber", "familayList", "CooperationUrl", 'languageList']),
			nickname() {
				return this.accountNumber.nickname
			},
			userList() {
				return this.familayList
			}
		},
		onLoad() {
			let that = this
			that.language = uni.getStorageSync('language')
			that.index = that.languageList.findIndex(ite => ite.key == that.language)
			console.log("language", that.language, that.index)
			that.token = uni.getStorageSync('token')
			that.handleAccountNumber()
		},
		onReady() {
			uni.setNavigationBarTitle({
				title: this.$t('common.titleMe'),
			})
		},
		watch: {
			nickname() {
				this.user = {}
				this.user = this.accountNumber
			}
		},
		onPullDownRefresh() {
			let that = this
			that.token = uni.getStorageSync('token')
			that.handleAccountNumber()
			setTimeout(() => {
				uni.stopPullDownRefresh()
			}, 1000);
		},
		methods: {
			handleAccountNumber() {
				let that = this
				that.$model.getAccountNumber({}).then(res => {
					console.log("账号信息", res)
					if (res.code != 0) {
						that.$tools.msg(res.msg)
						return
					}
					that.user = res.data
					that.$store.commit('changeAccountNumber', res.data)
				}).catch(err => {})
			},
			handleOutLogin() {
				let that = this
				uni.showModal({
					title: that.$t('tips.msgTitle'),
					content: that.$t('tips.verifyOutLogin'),
					cancelText: that.$t('tips.btnSancellation'),
					confirmText: that.$t('tips.btnConfirm'),
					success: function(res) {
						if (res.confirm) {
							that.$model.getloginOut({}).then((res) => {
								if (res.code != 0) return
								uni.$emit('need-login');
							})
						} else if (res.cancel) {
							that.$tools.msg(that.$t('tips.msgCancel'));
						}
					},
				})
			},
			languageClick(e) {
				let that = this
				that.index = e.detail.value
				that.language = that.languageList[that.index].key
				uni.setLocale(that.languageList[that.index].key)
				uni.setStorageSync('language', that.languageList[that.index].key)
				// that.$model.getSetLanguage({
				// 	language: that.languageList[that.index].key,
				// }).then(res => {
				// 	console.log("qqqqqqqqqqq", res)
				// 	uni.setLocale(that.languageList[that.index].key)
				// 	that.language = that.languageList[that.index].key
				// })
			},
			navTo(url) {
				uni.navigateTo({
					url
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.content {
		background-color: #F3F4F6;
		padding: 15px;
		min-height: 100vh;
	}

	.top {
		height: auto;
		background: #fff;
		border-radius: 10px;
		display: flex;
		padding: 10px;
		align-items: center;
		justify-content: space-between;

		.headimg {
			width: 80%;
			display: flex;
			align-items: center;

			view {
				width: calc(100% - 70px);
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
			}
		}

		image {
			width: 60px;
			height: 60px;
			border-radius: 50%;
			margin-right: 10px;
		}
	}

	.wxlist {
		height: auto;
		overflow: hidden;
		position: relative;

		.item {
			width: auto;
			font-size: 32rpx;
			line-height: 45px;
			height: 45px;
			display: flex;
			margin-top: 15px;
			background: #fff;
			padding: 0 10px;
			border-radius: 10px;
			justify-content: space-between;
			align-items: center;

			.left {
				display: flex;
				align-items: center;
			}
		}
	}

	.href {
		display: flex;
		width: 100%;
		color: #000;
		text-decoration: none;
		justify-content: space-between;
	}

	.btn {
		width: auto;
		background: $btncolor;
		margin: 50px 15px 0 15px;
	}

	/deep/picker {
		width: 50%;
		position: relative;

		.uni-input {
			display: flex;
			padding-right: 20px;
			text-align: right;
			justify-content: flex-end;
		}

		.iconfont {
			position: absolute;
			right: -1px;
			top: 3px;
		}
	}
</style>