import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { base_ui } from '../fw/base_ui';
import { rankData } from '../data';
import { tools } from '../tools';
import { imageCacheManager } from '../manager/imageCacheManager';
const { ccclass, property } = _decorator;

@ccclass('user_info_view')
export class user_info_view extends base_ui {
    @property(Node) btn_close:Node = null
    @property(Node) img_avatar:Node = null
    @property(Node) lab_region:Node = null
    @property(Node) lab_nickname:Node = null
    @property(Node) img_car:Node = null
    @property(Node) lab_car_pai:Node = null
    @property(Node) number_bg:Node = null
    @property(Node) number_img:Node = null
    @property(SpriteFrame) sf_number_rank_1:SpriteFrame = null
    @property(SpriteFrame) sf_number_rank_2:SpriteFrame = null
    @property(SpriteFrame) sf_number_rank_3:SpriteFrame = null
    @property(Node) lab_score:Node = null
    @property(Node) lab_car_name:Node = null
    start() {
        this.btn_close.on(Node.EventType.TOUCH_END, ()=>{
            this.close()
        })
    }

    initView(data:rankData) {
        if(data.number>0&&data.number<=3) {
            this.number_bg.active = true
            switch (data.number) {
                case 1:
                    this.number_img.getComponent(Sprite).spriteFrame = this.sf_number_rank_1
                    break;
                case 2:
                    this.number_img.getComponent(Sprite).spriteFrame = this.sf_number_rank_2
                    break;
                case 3:
                    this.number_img.getComponent(Sprite).spriteFrame = this.sf_number_rank_3
                    break;
                default:
                    break;
            }
        } else {
            this.number_bg.active = false
        }

        tools.loadRemoteImg(data.avatarUrl, (d)=>{
            this.img_avatar.getComponent(Sprite).spriteFrame = d.sf
        })
        this.lab_region.getComponent(Label).string = data.province_name + ' - ' + data.city_name
        this.lab_nickname.getComponent(Label).string = data.nickName
        this.img_car.getComponent(Sprite).spriteFrame = imageCacheManager.getRankCarImageById(data.car_id)
        this.lab_car_pai.getComponent(Label).string = data.license_code
        this.lab_score.getComponent(Label).string = data.score + '分'
        this.lab_car_name.getComponent(Label).string = imageCacheManager.getCarNameById(data.car_id) //data.car_name
    }
}

