export default {
    data() {
        return {
            medals: [
                {
                    start: 0,
                    end: 9,
                    color1: '#717171',
                    color: '#3B445D',
                    vicon: 'https://cdn.raex.vip/medals/v.png',
                    icon: 'https://cdn.raex.vip/medals/LV0-1-icon.png',
                    hide: true,
                    textColor: '#ffffff',
                    startColor: '#A5AEC9',
                    endColor: '#9DA6C1'
                },
                {
                    start: 10,
                    end: 19,
                    color: '#557595',
                    startColor: '#AAD4FF',
                    endColor: '#C5E2FF',
                    icon: 'https://cdn.raex.vip/medals/LV10-19-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V10-19.png'
                },
                {
                    start: 20,
                    end: 29,
                    color: '#A65F3B',
                    startColor: '#fec391',
                    endColor: '#fde9cb',
                    icon: 'https://cdn.raex.vip/medals/LV20-29-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V20-29.png'
                },
                {
                    start: 30,
                    end: 39,
                    color: '#3C62FF',
                    startColor: '#B6C2FF',
                    endColor: '#A8B7FF',
                    icon: 'https://cdn.raex.vip/medals/LV30-39-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V30-39.png'
                },
                {
                    start: 40,
                    end: 49,
                    color: '#663FA7',
                    startColor: '#CEAFFF',
                    endColor: '#C19AFF',
                    icon: 'https://cdn.raex.vip/medals/LV40-49-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V40-49.png'
                },
                {
                    start: 50,
                    end: 59,
                    color: '#1076E1',
                    startColor: '#B3EAFF',
                    endColor: '#7CDAFF',
                    icon: 'https://cdn.raex.vip/medals/LV50-59-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V50-59.png'
                },
                {
                    start: 60,
                    end: 69,
                    color: '#DB31CA',
                    startColor: '#FFBEF8',
                    endColor: '#FF8DF5',
                    icon: 'https://cdn.raex.vip/medals/LV60-69-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V60-69.png'
                },
                {
                    start: 70,
                    end: 79,
                    color: '#3D26D2',
                    startColor: '#B6AAFC',
                    endColor: '#9F8EFF',
                    icon: 'https://cdn.raex.vip/medals/LV70-79-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V70-79.png'
                },
                {
                    start: 80,
                    end: 89,
                    color: '#DF1637',
                    startColor: '#FFB2B9',
                    endColor: '#F89BA3',
                    icon: 'https://cdn.raex.vip/medals/LV80-89-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V80-89.png'
                },
                {
                    start: 90,
                    end: 99,
                    color: '#FA6802',
                    startColor: '#FFE3BB',
                    endColor: '#FFCF8C',
                    icon: 'https://cdn.raex.vip/medals/LV90-99-icon.png',
                    bg: 'https://cdn.raex.vip/medals/V90-99.png'
                }
            ],
            levels: [],
            money: 0,
            showSwiper: false
        };
    },
    computed: {
        levelInfo() {
            if (this.isLogin) {
                let level = Math.floor(this.money / this.$rating);
                console.log(level);
                if (level > 99) {
                    level = 99;
                }
                let info = {};
                [...this.medals].forEach(item => {
                    if (level >= item.start) {
                        info = { ...item };
                    }
                });
                let _info = {};
                [...this.levels].forEach(item => {
                    if (level >= (item.startLevel || 0)) {
                        _info = item;
                    }
                });
                return { level, ...info, ..._info };
            } else {
                return {};
            }
        },
        isMore() {
            if (this.isLogin) {
                let level = Math.floor(this.money / this.$rating);
                return level >= 99;
            } else {
                return false;
            }
        }
    },
    mounted() {
        this.$http.post('/purchaseLevel/all', {}, { body: 'json' }).then(res => {
            this.levels = res.content.map((item, index) => {
                let start = index - 1 >= 0 ? res.content[index - 1].endLevel : 0;
                return {
                    ...item,
                    startLevel: item.startLevel
                };
            });

            if (this.setSwiper) {
                this.setSwiper();
            }

            if (this.isLogin) {
                this.$http.get('/asset/breakdown').then(res => {
                    this.money = res.buy;
                    setTimeout(() => {
                        this.showSwiper = true;
                    }, 1000);
                    this.$nextTick(() => {
                        if (this.$store.state.userInfo.level !== this.levelInfo.level && this.changeLevel) {
                            this.changeLevel(this.levelInfo.level);
                        }
                    });
                });
            }
        });
    }
};
