<template>
    <div class="change">
        <div class="title">{{ type === 'nickname' ? '我的昵称' : '简介' }}</div>
        <van-field
            v-model="message"
            :rows="type === 'nickname' ? 1 : 4"
            :type="type === 'nickname' ? 'text' : 'textarea'"
            :maxlength="type === 'nickname' ? 12 : 50"
            :placeholder="type === 'nickname' ? '请输入昵称' : '请添加介绍，让大家了解你'"
            show-word-limit
            clearable
            :border="false"
        />
        <div class="tips" v-if="type === 'nickname'">支持2-12位中英文、数字</div>
        <div class="btn">
            <van-button type="primary" block :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 0;
    font-size: 13px;
    color: #ffffff44;
    line-height: 18px;
}
.btn {
    padding: 100px 50px;
}
.van-cell {
    color: #fff;
    /deep/.van-field__control {
        color: #fff;
    }
}
/deep/.van-field__word-limit {
    border-top: 1px solid #ffffff10;
    padding-top: 10px;
}
.tips {
    font-size: 12px;
    color: #ffffff44;
    line-height: 18px;
    padding: 0 16px;
    margin-top: -26px;
}
</style>
