<template>
	<view class="page">
		<view class="input">
			<uni-easyinput v-model.trim="info.userName" placeholder="请输入姓名"></uni-easyinput>
		</view>
		<button type="primary" @click="submit">确认</button>
	</view>
</template>

<script>
	import { viewUserDetails, updateAvatars } from '@/apis/modules/user.js'
	export default {
		data() {
			return {
				platformId: uni.getStorageSync('platformId'),
				info: {
					userName: ''
				},
				openId: uni.getStorageSync('openId'),
			}
		},
		onShow() {
			this.getInfo()
		},
		methods: {
			// 个人信息
			async getInfo() {
				const { result } = await viewUserDetails({
					openId: this.openId
				})
				if (result.hrUserInfo) {
					this.info = result.hrUserInfo
				}
			},
			async submit() {
				const { userName } = this.info
				if(!userName) return this.$util.errMsg('请输入姓名')
				await updateAvatars({
					url: '',
					userName,
					openId: this.openId,
					platformId: this.platformId,
				})
				this.$util.sucMsg('修改成功！')
				setTimeout(() => {
					uni.navigateBack()
				}, 1000)
			}
		}
	}
</script>

<style scoped lang="scss">
.page {
	padding: 20px;
	background-color: #fff;
}
/deep/.input {
	margin-bottom: 15px;
	.is-input-border {
		border-color: #dedede !important;
	}
}
</style>
