import { Component, Input, Output, EventEmitter } from '@angular/core';
import { CodeList } from '@global/service/codelist';

@Component({
    selector: 'app-radio',
    templateUrl: 'app-radio.html',
    styleUrls: ['app-radio.scss']
})
export class AppRadio{
    

    /**
     * 代码表集合
     */
    public items:any;

    constructor(private $codelist:CodeList){
        
    }

    /**
     * 是否禁用
     *
     * @type {boolean}
     * @memberof AppRadio
     */
    @Input()
    disabled: boolean = false;
    /**
     * 代码表
     *
     * @type {*}
     * @memberof AppRadio
     */
    @Input() set config(val:any){
        if(val){
            this.items = this.$codelist.getCodeItemByTag(val).items;
        }
    }
    /**
     * 输入值
     *
     * @type {string}
     * @memberof AppRadio
     */
    @Input()
    value: string;
    /**
     * 值改变
     *
     * @type {EventEmitter<any>}
     * @memberof AppRadio
     */
    @Output()
    valueChange: EventEmitter<any> = new EventEmitter();

    /**
     * 选中项值
     *
     * @param {string} val
     * @memberof AppRadio
     */
    public selectChange(val: string) {
        if (this.disabled) {
            return;
        }
        this.valueChange.emit(val);
    }
}