<template>
	<view class="app">
		<view class="centercontent">
			<view class="Commodity" @tap="uploadImag()">
				头像
				<image class="picture" :src="baseurl+appPersonallist.avatar" mode=""></image>
				<image class="pictureA" src="../../static/jiantou.png" mode=""></image>
			</view>
			<view class="content">
				<view class="name">昵称：
					<input type="text" placeholder="请填写" v-model="appPersonallist.userName" />
				</view>
				<view class="name">姓名:
					<input type="text" placeholder="请输入" v-model="appPersonallist.nickName" />
				</view>
				<view class="name">电话：
					<input type="text" placeholder="请输入" v-model="appPersonallist.phonenumber" />
				</view>
				<view class="nursetype name" style="border: none;" >
					护理站:{{getNurseStationName(appPersonallist)}}
				</view>
				

			</view>
			<view class="finish" @tap="gofinish()">完成
			</view>
		</view>
			<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		userPassWord,
		nursePerson
	} from '@/api/Modifyinformation/Modifyinformation.js';
	import baseurl from '@/api/baseurl.js'

	export default {
		data() {
			return {
				baseurl: '', //url
				appPersonallist: {
					userId: '',
					userName: '',
					nickName: '',
					phonenumber: '',
					avatar: '',
					File: '',
				},

			}
		},
		computed:{
			getNurseStationName() {
				return data => data?.nurseStationSysUserVOList?.[0]?.nurseStationName || ''
			},
		},
		onLoad(options) {
			this.baseurl = baseurl;
			const that = this
			this.baseurl = baseurl;
			uni.getStorage({
				key: 'phonenumber',
				success: function(res) {
					that.phonenumber = res.data
					console.log(that.phonenumber)
				}
			});
			uni.getStorage({
				key: 'password',
				success: function(res) {
					that.password = res.data
					console.log(that.password)
				}
			});
			console.log(that.password, '-----', that.phonenumber)
			this.myInfo()
		},
		methods: {
			//上传头像
			uploadImag() {
				var that = this;
				uni.chooseImage({
					count: 1,
					sizeType: ['original'],
					sourceType: ['album'],
					success(res) {
						//blob
						console.log(res)
						uni.uploadFile({
							url: baseurl + '/nurseApp/PersonLogin/updateHeadAvatarHead',
							filePath: res.tempFilePaths[0], //file: 二进制(filePath)
							name: 'file',
							formData: { //多余值
								'userId': '13',
							},
							timeout: 5000,
							success(res) {
								console.log(JSON.parse(res.data))
								that.appPersonallist.avatar = JSON.parse(res.data).imgUrl
							}
						})
					}
				})
			},
			// 引入一下
			myInfo() {
				nursePerson(this.phonenumber, this.password).then(res => {
					console.log(res, 'resresres')
					this.appPersonallist = res.data
					console.log(this.appPersonallist)
				})
			},
			gofinish() {
				// this.appPersonallist = JSON.stringify(this.appPersonallist)
				// console.log(this.appPersonallist, 'this.appPersonallist')
				userPassWord(this.appPersonallist).then(res => {
						if (res.code == 200) {
							this.$refs.uToast.show({
								title: '修改成功',
								type: 'success',
								url: '/pages/personal/personal',
								duration: '1500'
							})
						} else {
							console.log(res)
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error'
							})
						}
					
				})
			},
		},
	}
</script>
<style lang="scss">
	.app {
		background-color: #F4F5F7;
		width: 100%;
		height: 100vh;
		color: #000000;
		padding: 3%;
		font-size: 36rpx;

		.centercontent {
			width: 99%;
			height: 521rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 9rpx 31rpx 9rpx rgba(0, 0, 0, 0.03);
			border-radius: 20rpx;
			margin: 0 auto;

			.finish {
				width: 217rpx;
				font-size: 32rpx;
				color: #FFFFFF;
				height: 68rpx;
				line-height: 68rpx;
				text-align: center;
				margin-top: 60%;
				margin-left: 70%;
				background: #4C7BC9;
				border-radius: 26rpx;
			}

			.content {
				line-height: 100rpx;

				.name {
					margin-left: 5%;
					height: 100rpx;
					border-bottom: 1rpx solid #D8D4D4;

					input {
						font-size: 36rpx;
						margin-top: -11%;
						margin-left: 15%;
					}
				}

				.nursetype {
					input {
						margin-left: 25%;
					}
				}
			}

			.Commodity {
				line-height: 110rpx;
				margin-left: 5%;
				border-bottom: 1rpx solid #D8D4D4;

				.picture {
					vertical-align: middle;
					margin-left: 60%;
					width: 103rpx;
					height: 103rpx;
					border-radius: 50%;
				}

				.pictureA {
					margin-left: 3%;
					width: 18rpx;
					height: 27rpx;
				}

				.head {
					line-height: 140rpx;
					margin-left: 5%;
					display: inline-block;
				}
			}
		}
	}
</style>
