<template>

	<view class="content">
		<form @submit="save">

			<view class="hg24px">
			</view>

			<view class="list ft28 box-pack-between bgf flex-y-center border-b">
				<text>注册手机号</text>
				<view class="ft30">
					{{my_uerInfo.tel}}
				</view>
			</view>

			<view class="hg24px">
			</view>

			<view @click="uploadFile" class="list ft28 box-pack-between bgf flex-y-center border-b">
				<text>我的头像</text>
				<image class="header" :src="my_uerInfo.logo?URL+''+my_uerInfo.logo:'../../static/images/my/header-title.png'" mode=""></image>
			</view>

			<view class="list ft28 box-pack-between bgf flex-y-center border-b">
				<text>我的名称</text>
				<input type="text" name='nick_name' :value="my_uerInfo.nick_name" placeholder-class="placeholder-class"
				 placeholder="请输入名称" class="tr" />
			</view>

			<view class="hg100px">
			</view>
			<button class="login-btn flex-center" form-type="submit">保存</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				my_uerInfo: {},
				URL: getApp().globalData.URL,
				islogo: false,
			}
		},

		onLoad(e) {
			uni.getStorage({
				key: 'my_uerInfo',
				success: (res) => {
					console.log(res, "res")
					this.my_uerInfo = res.data;
				},
				fail(res) {}
			});

		},

		onShareAppMessage(e) {

		},

		methods: {
			save(e) {
				this.request({
					url: "user/save_edit",
					data: {
						token: uni.getStorageSync("token"),
						face: this.my_uerInfo.logo,
						nick_name: e.detail.value.nick_name,
					},
				}).then(res => {
					console.log(res, "res")
					if (res.code === '200') {
                          uni.showToast({
                          	title: "保存成功",
                          	icon: 'none'
                          })
						  setTimeout(()=>{
							  uni.navigateBack({
							  	delta:1
							  })
						 },2e3)
					}
				}).catch((res)=>{
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},

			uploadFile(e) {
				uni.chooseImage({
					success: (res) => {
					res.tempFilePaths.forEach((v, i) => {
						this.Upload({
							url: "Spread/upload_img",
							data: {
								url: v,
								type: 0,
								token: uni.getStorageSync("token"),
							}
						}).then(res => {
							console.log(res, "res")
							this.my_uerInfo.logo = res.file;
						}).catch({
							
						});
					   })
					}
				});
			}

		}
	}
</script>

<style lang="scss">
	.list {
		width: 100%;
		height: 100rpx;
		padding: 0 20rpx;
	}

	.list input {
		text-align: right;
	}

	.header {
		width: 70rpx;
		height: 70rpx;
		border-radius: 500px;
	}

	.login-btn {
		width: 630rpx;
		height: 90rpx;
		background: linear-gradient(132deg, rgb(64, 158, 255) 0%, rgb(64, 158, 255) 100%);
		box-shadow: 0px 2rpx 12rpx rgb(64, 158, 255);
		opacity: 1;
		border-radius: 45rpx;
		margin: 0 auto;
		color: #FFFFFF;
		font-size: 30rpx;
		font-family: Source Han Sans CN;
		font-weight: 500;
		opacity: 1;
	}
	.hg100px{
		height: 100px;
	}
</style>
