import './style.scss';
import BaseFormControl from '../../baseFormControl';
import { JVipInfoTpl } from './tpl';
import JDRadio from "../../formType/radio";
import JDColor from "../../formType/color";
import JDImage from "../../formType/image/image";
class JDVipInfo extends BaseFormControl{
    constructor(config) {
        super();
        this.config = $.extend(true, {}, {
            domData: {},
            moduleData: null,
        }, config);
        this.render();
    }
    
    render(){
        let node = template.render(JVipInfoTpl);
        this.appendFormControl(node);
        this.bgImgInstance = new JDImage({
            domData: {
                node: this.element.find('.J_bgImg'),
                name: 'background',
                title: '',
                formType: {
                    type: 'image',
                },
                tips: `图片尺寸要求宽度为1125px，高度为120px；大小不超过${window.page_config.chooseSizeLimit}KB，格式为JPG、PNG`,
            },
            defaultImage: this.config.moduleData && this.config.moduleData.backgroundType === 2 && this.config.moduleData.background ? this.config.moduleData.background : '',
            format: '1125-1125,120-120',
        });
        this.bgColorInstance = new JDColor({
            domData: {
                name: 'background',
                title: '背景色值',
                node: this.element.find('.J_bgColorSelect'),
            },
            value: this.config.moduleData && this.config.moduleData.backgroundType === 1 && this.config.moduleData.background ? this.config.moduleData.background : '#ffffff',
        })
        this.bgTypeInstance = new JDRadio({
            domData: {
                name: 'backgroundType',
                node:this.element.find('.J_bgType'),
                title: '标题背景设置',
                validate: {
                    must: true
                },
                formType:{
                    option:[
                        {text:"背景色", value:1},
                        {text:"背景图",value:2}
                    ]
                }
            },
            defaultChecked: this.config.moduleData && this.config.moduleData.backgroundType === 2 ? 2 : 1,
            change: (state) => {
                state ===1 ?
                    this.bgColorInstance.element.show():
                    this.bgColorInstance.element.hide();
                state ===2 ?
                    this.bgImgInstance.element.show():
                    this.bgImgInstance.element.hide();
            }
        })
    }
    getData() {
        const { name } = this.config.domData;
        const data = {};
        let background = this.bgTypeInstance.getData().backgroundType === 1 ? this.bgColorInstance.getData().background : this.bgImgInstance.getData().background;
        data[name] = {
            ...this.bgTypeInstance.getData(),
            background :background
        };
        return data;
    }
}
export default JDVipInfo;