<template>
	<view>
		<view class="w100 rows rowsc">
			<view class="w-710 rows rowsl rowsm bgff br-20">
				<view class="w-654 h-160 rows rowsm rowsb" style="border-bottom: 1rpx solid #f5f5f5;">
					<text class="fs-28">头像</text>
					<view class="rows rowsm" @click="upImg">
						<image class="w-96 h-96 br-20 mr-20" :src="$tools.oss(avatar)" mode="aspectFill"></image>
						<image class="w-28 h-28" src="/static/images/erf.png" mode=""></image>
					</view>
				</view>
				<view class="w-654 h-114 rows rowsm rowsb" style="border-bottom: 1rpx solid #f5f5f5;">
					<text class="fs-28">昵称</text>
					<input type="text" placeholder="请输入昵称" class="fs-28 trt" v-model="nickname"/>
				</view>
				<view class="w-654 h-114 rows rowsm rowsb" style="border-bottom: 1rpx solid #f5f5f5;">
					<text class="fs-28">手机号</text>
					<input type="number" placeholder="请输入手机号" maxlength="11" class="fs-28 trt" :disabled="true" v-model="mobile"/>
				</view>
				<!-- <view class="w-654 h-114 rows rowsm rowsb">
					<text class="fs-28">所在地址</text>
					<input type="text" placeholder="请输入所在地址" class="fs-28 trt" v-model="nickname"/>
				</view> -->
			</view>
		</view>
		<view class="w100 rows rowsl rowsm bgff fixed h-170 pt-30" style="bottom: 0rpx;">
			<view class="w-690 h-88 rows rowsm rowsc bg fw-b fs-30 br-100 colfff" @click="profile">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				nickname:'',
				avatar:'',
				user:{},
				mobile:''
			}
		},
		onShow() {
			this.index()
		},
		methods: {
			index(){
				this.$tools.axiosFrom("POST","user/index").then(res => {
					this.user = res.data
					this.nickname = res.data.nickname
					this.avatar = res.data.avatar
					this.mobile = res.data.mobile
				})
			},
			profile(){
				if(this.avatar=='') return this.$tools.showtt('请上传头像')
				if(this.nickname=='') return this.$tools.showtt('昵称不能为空')
				this.$tools.axiosFrom("POST","user/profile",{
					nickname:this.nickname,
					avatar:this.avatar
				}).then(res => {
					this.$tools.showtt(res.msg)
					if(res.code!=1) return
					setTimeout(() => {
						this.$tools.goBack()
					},1000)
				})
			},
			upImg(){
				uni.chooseImage({
					count:1,
					sourceType:["album","camera"],
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths; 
						uni.uploadFile({
							url: this.$tools.upload, 
							filePath: tempFilePaths[0], 
							name: 'file',
							formData: {
								'token': uni.getStorageSync('token')
							},
							success: (uploadFileRes) => {
								let q = JSON.parse(uploadFileRes.data)
								this.avatar = q.data.url
							}
						})
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background-color: #f7f6fa;
		padding-top: 20rpx;
	}
</style>
