<template>
	<view class="content">
		<view class="row1">
			<text class="tit">{{$t('set.a1')}}</text>
			<view
				class="background-img"
				@click="upload"
				><image
					class="background-img"
					v-model="avatar"
					:src="avatar"
					mode="aspectFill"></image
			></view>
		</view>
		<view class="row">
			<text class="tit">{{$t('set.a2')}}</text>
			<input
				class="input"
				type="button"
				v-model="name"
				placeholder-class="placeholder" />
		</view>
		<view class="row">
			<text class="tit">{{$t('set.a3')}}</text>
			<input
				class="input"
				disabled
				type="text"
				v-model="phone"
				placeholder-class="placeholder" />
		</view>
		<button
			class="add-btn"
			@click="confirm"
			>{{$t('set.a4')}}</button
		>
	</view>
</template>

<script>
	import { mapState, mapMutations } from "vuex";
	import { userEdit, logout } from "@/api/set.js";
	import { upload } from "@/api/order.js";
	export default {
		data() {
			return {
				name: "", // 昵称
				phone: "",
				avatar: "",
				countDown: 1,
			};
		},
		computed: {
			...mapState("user", ["userInfo"]),
			startDate() {
				console.log("start");
			},
			endDate() {
				console.log("end");
			},
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.$t("tab.a7"),
			});
		},
		onShow(option) {
			console.log("111", this.userInfo);
			this.name = this.userInfo.nickname + "";
			this.avatar = this.userInfo.avatar || "";
			this.phone = this.userInfo.phone || "";
		},
		methods: {
			...mapMutations("user", ["logout"]),
			// 上传头像
			upload() {
				console.log("111111");
				upload({
					filename: "",
				}).then(data => {
					this.avatar = data[0].url;
					console.log(this.avatar, "tup");
					setTimeout(() => {
						uni.hideLoading();
					}, 500);
				});
			},

			confirm() {
				userEdit({
					nickname: this.name,
					avatar: this.avatar,
					// password: this.password,
					// captcha: this.captcha,
					// account: this.account,
				})
					.then(e => {
						this.$api.msg("修改成功");
						// 清空输入框
						(this.password = ""),
							setTimeout(() => {
								uni.switchTab({
									url: "/pages/user/user",
								});
							}, 1000);
						console.log(e);
					})
					.catch(e => {
						console.log(e);
					});
			},
			loginout() {
				uni.navigateTo({
					url: "/pages/switch/switch",
				});
			},
		},
	};
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
	.content {
		background-color: #fff;
	}

	.row1 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		padding: 0 30upx;
		height: 110upx;
		background: #fff;
		.tit {
			flex-shrink: 0;
			width: 120upx;
			font-size: $font-lg;
		}
		.background-img {
			width: 80rpx;
			height: 80rpx;
			border-radius: 50%;
			background: #f2f2f2;
		}
	}
	.row {
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: relative;
		padding: 0 30upx;
		height: 110upx;
		background: #fff;

		.tit {
			flex-shrink: 0;
			font-size: $font-lg;
			color: $font-color-dark;
		}
		.tit1 {
			flex-shrink: 0;
			width: 150upx;
			font-size: $font-lg;
			color: $font-color-dark;
		}
		.input {
			text-align: right;
			flex: 1;
			font-size: $font-base;
			color: $color-gray;
		}
		.iconlocation {
			font-size: 36upx;
			color: $font-color-light;
		}
	}
	.add-btn {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 560upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: $font-lg;
		color: #fff;
		background: $base-color;
		border-radius: 40upx;
	}
	.loginout {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 560upx;
		height: 80upx;
		margin: 60upx auto;
		font-size: $font-lg;
		color: #fff;
	}
</style>
