import BaseFormControl from '../../baseFormControl'
import { singleSelectTpl } from './tpl'
import './style.scss'
class SingleSelect extends BaseFormControl {
    constructor(config) {
        super(config)
        this.render()
    }
    
    _getConfig(config) {
        return $.extend(
            true,
            {},
            {
                domData: {},
                moduleData: {},
            },
            config,
        )
    }
    
    render() {
        const { domData } = this.config
        if (domData.extConfig && domData.extConfig.selectList) {
            const elementStr = template.render(singleSelectTpl, {
                selectList: domData.extConfig.selectList,
                selectValue: this.config.moduleData['value'] || domData.extConfig['defaultSelect'] || 'yellow',
            })
            this.appendFormControl(elementStr)
        } else {
            console.log('singSelect配置项数据异常')
        }
    }
    
    getData() {
      const { name, extConfig } = this.config.domData
      const result = {}
      result[name] = {
        value: this.element.find('.cd-single-radio:checked').val(),
      }
      if (extConfig && extConfig['queryType']) {
        result[name]['queryType'] = extConfig['queryType']
      }
      return result
    }
}
export default SingleSelect