import BaseFormControl from '../../baseFormControl'
import JDImage from '../../formType/image/image'
import JDLink from '../../formType/link'
class JDCustomBi extends BaseFormControl {
	constructor(config) {
		super(config)
		this.config = this._getConfig(config)
		this.render()
	}
	_getConfig(config) {
		return $.extend(
			true,
			{},
			{
				domData: {},
				moduleData: {},
			},
			config,
		)
	}
	render() {
		this.appendFormControl(`
                <div class="J_oldCustomer">
                    <div class="cd-title">老客图片 </div>
                    <p class="cd-form-tips J_formTips">180天内在店铺有购买的用户可见，建议图片宽度为1125px，高度为570px；大小不超过500KB，格式为JPG、PNG。</p>
                    <div class="J_image"></div>
                    <div class="J_link"></div>
                </div>
                <div class="J_newCustomer">
                    <div class="cd-title">新客图片 </div>
                    <p class="cd-form-tips J_formTips">180天内未购买的用户可见，建议图片宽度为1125px，高度为570px；大小不超过500KB，格式为JPG、PNG。</p>
                    <div class="J_image"></div>
                    <div class="J_link"></div>
                </div>`)
		let imgConfig = {
			domData: {
				name: 'value',
				title: '',
				dateType: 'JDT_IMAGE',
				formType: {
					type: 'image',
				},
			},
			format: `${this.config.domData.validate.width || 1125},${
				this.config.domData.validate.height || '570'
			}`,
			hasMakeImage: true, 
		}
		let oldImg, newImg, oldLink, newlink
		try {
			oldImg = this.config.moduleData.oldCustomer.image.value
		} catch (error) {
			oldImg = ''
		}
		try {
			newImg = this.config.moduleData.newCustomer.image.value
		} catch (error) {
			newImg = ''
		}
		try {
			oldLink = this.config.moduleData.oldCustomer.linkInfo
		} catch (error) {
			oldLink = ''
		}
		try {
			newlink = this.config.moduleData.newCustomer.linkInfo
		} catch (error) {
			newlink = ''
		}
		let oldImgConfig = {
			...imgConfig,
			domData: {
				...imgConfig.domData,
				node: this.element.find('.J_oldCustomer .J_image')[0],
			},
			defaultImage: oldImg,
			moduleConfg: {
				...this.config,
				domData: {
					...this.config.domData,
					customType: 'custom_old',
				},
			},
		}
		let newImgConfig = {
			...imgConfig,
			domData: {
				...imgConfig.domData,
				node: this.element.find('.J_newCustomer .J_image')[0],
			},
			defaultImage: newImg,
			moduleConfg: {
				...this.config,
				domData: {
					...this.config.domData,
					customType: 'custom_new',
				},
			},
		}
		this.oldImg = new JDImage(oldImgConfig)
		this.newImg = new JDImage(newImgConfig)
		let JDLinkConfig = {
			domData: {
				name: 'linkInfo',
				title: '',
			},
			linkName: false,
			addLink: false,
			operation: false,
			tab: ['custom', 'frequent', 'product', 'activity', 'shopCategory'],
		}
		let oldLinkConfig = {
			...JDLinkConfig,
			domData: {
				...JDLinkConfig.domData,
				node: this.element.find('.J_oldCustomer .J_link')[0],
			},
			moduleData: oldLink,
		}
		let newLinkConfig = {
			...JDLinkConfig,
			domData: {
				...JDLinkConfig.domData,
				node: this.element.find('.J_newCustomer .J_link')[0],
			},
			moduleData: newlink,
		}
		this.oldLink = new JDLink(oldLinkConfig)
		this.newLink = new JDLink(newLinkConfig)
	}
	
	getData() {
		let result = {}
		result[this.config.domData.name] = {
			newCustomer: {
				...this.newLink.getData(),
				image: this.newImg.getData(),
			},
			oldCustomer: {
				...this.oldLink.getData(),
				image: this.oldImg.getData(),
			},
		}
		return result
	}
	
	validateData() {
		
	}
	
	dispose() {}
}
export default JDCustomBi