<template>
    <div class="change">
        <div class="title" v-if="type === 'nickname'">{{ type === 'nickname' ? '我的昵称' : '简介' }}</div>
        <van-field
            v-model="message"
            :rows="type === 'nickname' ? 1 : 7"
            :type="type === 'nickname' ? 'text' : 'textarea'"
            :maxlength="type === 'nickname' ? 12 : 50"
            :placeholder="type === 'nickname' ? '记得填写昵称' : '请添加介绍，让大家了解你'"
            show-word-limit
            clearable
            :border="false"
            :class="type === 'nickname' ? 'my_nickname' : 'personal_signature'"
        />
        <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: 20px 15px 0;
    font-size: 13px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    opacity: 0.3;
    line-height: 18px;
}
.personal_signature {
    padding: 18px 15px 0px;
    /deep/ .van-field__body {
        padding: 16px 15px;
        height: 160px;
        background: #2F2519;
        border-radius: 12px;
        font-size: 16px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #ffffff;
        line-height: 22px;
        textarea::placeholder {
            color: #ffffff;
            opacity: 0.3;
        }
    }
    /deep/.van-field__word-limit {
        padding-top: 10px;
    }
}
.my_nickname {
    padding: 18px 15px 0px;
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 22px;
    /deep/ .van-field__body {
        padding-bottom: 10px;
        input::placeholder {
            color: #ffffff;
            opacity: 0.3;
        }
    }
    /deep/.van-field__word-limit {
        border-top: 1px solid #ffffff10;
        padding-top: 10px;
    }
}
.btn {
    padding: 100px 50px;
}
.van-cell {
    color: #fff;
    /deep/.van-field__control {
        color: #fff;
    }
}
.tips {
    font-size: 12px;
    color: #ffffff44;
    line-height: 18px;
    padding: 0 16px;
    margin-top: -16px;
}
</style>
