<template>
	<view>
		<cu-custom bgColor="bg-white" :isBack="true">
			<block slot="content">
				用户名
			</block>
			<block slot="right">
				<view class="" style="color: #FC6035;font-size: 32rpx;margin-right: 35rpx;" @click="update()">
					完成
				</view>
			</block>
		</cu-custom>

		<view class="" style="margin: 30rpx;
			                      padding-bottom: 10rpx;
			                      border-bottom: #CCCCCC 1rpx solid;">
			<view class="" style="font-size: 30rpx; color: #000000;font-weight: bold;">
				<input type="text" v-model="name" maxlength="8" />
			</view>
		</view>
		<view class="" style="margin-left: 30rpx;">
			<view class="" style="font-size: 24rpx;color: #999999;">
				注：字数限2-8个字符
			</view>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				name: ''
			}
		},
		onLoad(options) {
			console.log(options)
			if (options.name) {
				this.name = options.name
			} else {
				this.name = ''
			}

		},
		methods: {
			update() {
				const param = {
					memberId: 10001, //会员id
					nikeName: this.name //姓名
				}
				if (this.name.length < 2) {
					this.$api.msg('用户名不能少于2个字符')
				} else if (this.name.length > 16) {
					this.$api.msg('用户名不能大于8个字符')
				} else {
					this.$u.api.changeUserInfo(param).then(res => {
						// console.log(res)
						if (res.code == 200) {
							this.$api.msg('用户名修改成功')
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1000)
						}
					}).catch(error => {
						console.log(error)
					})
				}

			}
		}
	}
</script>

<style>
	page {
		background-color: #FFFFFF;
	}
</style>

<style>

</style>
