import { Modal, Message, Confirm } from '@hot/pc-es-cn-shop-ui'
import set from 'lodash/set';
import BaseFormControl from '../../baseFormControl'
import SourceManage from '../../../sourceManage'
import FileUpload from '../../../fileUpload'
import linkTool from '../../../linkTool/index';
import Tpl from './tpl'
import JDLink from "../../formType/link";
import JDImage from "../../formType/image/image";
const DefaultConfig = {
    picScale: page_data.clientType == 'PC'? 1: 375/1125,
	platformId: 0,
	shopType: 1,
    chooseSizeLimit: window.page_config.chooseSizeLimit,       
	format: page_data.clientType == 'PC' ? '50-2000,50-2000' : '1125,210-1440',
	typeLimit: page_data.clientType === 'PC' ? 'jpg,png,gif' : 'jpg,png',
	minWidth: page_data.clientType == 'PC' ? 50 : 1125,
	maxWidth: page_data.clientType == 'PC' ? 2000 : 1125,
	minHeight: page_data.clientType == 'PC' ? 50 : 210,
	maxHeight: page_data.clientType == 'PC' ? 2000 : 1440,
	maxPicNum: 10,
    tip: page_data.clientType == 'PC' ? `支持宽度范围50px~2000px，高度范围50px~2000px，大小不超过${window.page_config.chooseSizeLimit}KB的JPG、PNG、GIF图片`: `支持宽度1125px，高度范围210px~1440px，大小不超过${window.page_config.chooseSizeLimit}KB的JPG、PNG图片`
}
class JDsanRenew extends BaseFormControl {
	constructor(config) {
		super()
		this.config = $.extend(true, {}, DefaultConfig, config)
        this.keyName = this.config.domData.name;
        this.render();
        this._initEvent()
	}
	
	_getConfig(config) {
		return $.extend(
			true,
			{},
			{
				domData: {},
				moduleData: {},
				minDate: ''
			},
			config
		)
	}
	
	render() {
        let self = this;
        let JDImageConfig = {
            domData: {
                name: "imgUrl",
                title: "图片(必填)",
                formType: {
                    type: "image"
                },
                tips: DefaultConfig.tip
            },
            format: DefaultConfig.format,
            typeLimit: DefaultConfig.typeLimit,
            defaultImage: this.config.moduleData && this.config.moduleData.image? this.config.moduleData.image.value : '',
            formContent: this.config.formContent,
        };
        this.instanceImage = new JDImage(JDImageConfig);
        let JDLinkConfig = {
            domData: {
                name: 'linkInfo',
                title: '链接(必填)',
            },
            tab: ['custom', 'frequent'],
            linkName: false,
            addLink: false,
            operation: false,
            moduleData: this.config.moduleData ? this.config.moduleData.link : {},
            formContent: this.config.formContent,
        };
        this.instanceLink = new JDLink(JDLinkConfig);
	}
	_initEvent() {
           
	}
	
	getData() {
        let result = {},
            imgData = this.instanceImage.getData(),
            linkData = this.instanceLink.getData(),
            image = imgData? {value: imgData.imgUrl, picWidth: Math.round(imgData.picWidth * DefaultConfig.picScale), picHeight: Math.round(imgData.picHeight * DefaultConfig.picScale)}: null,
            link = linkData? linkData.linkInfo: null,
            obj = {image, link, image, showSwitch: 1};
        result[this.keyName] = $.extend({}, obj);
        return result;
	}
	
	validateData() {}
}
export default JDsanRenew