import './style.scss'
import BaseFormControl from '../../baseFormControl'
import {JDNumPerRadioTpl} from "./tpl";
class JDNumPerLineRadio extends BaseFormControl {
    constructor(config) {
        super();
        
        this.radioSelected = null;
        this.setConfig(config);
        this.render();
    }
    
    setConfig(config) {
        this.config = $.extend(true, {}, {
            domData: {},
            defaultChecked: 2
        }, config);
    }
    render() {
        let radioNode = template.render(JDNumPerRadioTpl, {
            options: this.config.domData.formType.option,
            defaultChecked: this.config.defaultChecked
        });
        this.appendFormControl(radioNode);
        this.addEvent();
    }
    addEvent() {
        this.element.find('.line-radio-content').on('click', (evt) => {
            let $Node = $(evt.target);
            if (!$Node.hasClass('line-radio-content')) {
                $Node = $Node.parents('.line-radio-content');
            }
            let $ParentNode = $Node.parents('.line-radio-item');
            $ParentNode.siblings().removeClass('selected');
            $ParentNode.siblings().find('.line-radio-content').removeClass('cd-icons-link-radio-selected');
            $ParentNode.siblings().find('.line-radio-content').removeClass('cd-icons');
            this.setData(this.config.domData.name, $ParentNode.attr('value'));
            $ParentNode.addClass('selected');
            $Node.addClass('cd-icons cd-icons-link-radio-selected');
        })
    }
    
    setData(key, value) {
        let Obj = {};
        Obj[key] = value;
        this.radioSelected = Obj;
        console.log(this.getData());
    }
    getData() {
        if (this.radioSelected) {
            return this.radioSelected;
        }
    }
}
export default JDNumPerLineRadio;