<template>
    <div class="change">
        <div class="title">{{ type === 'nickname' ? '昵称' : '简介' }}</div>
        <van-field
            v-model="message"
            :rows="type === 'nickname' ? 1 : 4"
            type="textarea"
            :maxlength="type === 'nickname' ? 10 : 50"
            :placeholder="type === 'nickname' ? '请输入昵称' : '请添加介绍，让大家了解你'"
            :show-word-limit="type !== 'nickname'"
            clearable
        />
        <div class="btn">
            <van-button
                type="primary"
                block
                round
                :disabled="!message"
                color="linear-gradient(to right, #FDFB60, #FF8F3E)"
                @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 50px;
}
</style>
