<template>
    <div class="change">
        <van-field v-model="message" :rows="1" :maxlength="10" placeholder="请输入昵称" clearable />
        <div class="tips">最多12个字符，仅可使用中文，英文，数字，下划线</div>
        <div class="btn">
            <van-button type="primary" block round :disabled="!message" @click="save">保存</van-button>
        </div>
    </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
    computed: {
        ...mapState(['userInfo'])
    },
    data() {
        return {
            type: 'nickname',
            message: ''
        };
    },
    mounted() {
        this.type = this.$route.query.type;
        this.message = this.userInfo[this.type];
    },
    methods: {
        save() {
            if (this.message) {
                this.updateUser({ [this.type]: this.message }).then(() => {
                    setTimeout(() => {
                        this.$router.back();
                    }, 1500);
                });
            }
        }
    }
};
</script>

<style lang="less" scoped>
.title {
    padding: 23px 16px;
}
.btn {
    padding: 100px 12px;
}
.change {
    padding: 16px;
}
.van-cell {
    background-color: @bg2;
}
.tips {
    font-size: 12px;
    color: #6a6d83;
    line-height: 24px;
    padding: 10px 0;
}
</style>
