import BaseFormControl from '../../baseFormControl';
import LinkTool from '../../../linkTool';
import JDImageWH from '../../formType/imageWH/imageWH';
import JDInput from '../../formType/input';
import shopCallTpl from './tpl';
import './style.scss';
import { getShopType } from '../../../../util/channelUtil';
class ShopCall extends BaseFormControl {
    constructor(config) {
        super(config);
        this.config = $.extend(true, {}, config);
        this.render();
        this.bindEvent();
    }
    render() {
        this.appendFormControl(shopCallTpl);
        this.shopLogo = new JDImageWH({
            domData: {
                node: this.element.find('.J_shopLogo'),
                name: 'shopLogoImg',
                title: '店铺Logo',
                dateType: 'J_NEW_IMAGE_WH',
                formType: {
                    type: 'imageWH',
                },
                tips: `店铺Logo图片尺寸要求宽度为180px，高度为60px；大小不超过${window.page_config.chooseSizeLimit}KB，格式为JPG、PNG`,
            },
            defaultImage: this.config.moduleData && this.config.moduleData.shopLogoImg ? this.config.moduleData.shopLogoImg : {},
            format: '180-180,60-60',
        });
        this.shopLink = new JDInput({
            domData: {
                node: this.element.find('.J_shopLink'),
                name: 'shopLink',
                title: '店铺Logo链接',
                dateType: 'J_NORMAL_TEXT',
            },
            placeholder: '请输入店铺Logo链接',
            defaultValue: this.config.moduleData && this.config.moduleData.shopLink ? this.config.moduleData.shopLink.link : '',
        });
        $(this.shopLink).data('linkObj', this.config.moduleData && this.config.moduleData.shopLink);
    };
    bindEvent() {
        this.element.on('click', '.J_shopLink', (event) => {
            this.linkTool = new LinkTool({
                node: $(event.currentTarget),
                env: {
                    platformId: page_data.clientType === 'PC' ? 0 : 1,
                    shopType: getShopType(),
                },
                onConfirm: (link, linkObj) => {
                    this.shopLink.setData(link);
                    $(this.shopLink).data('linkObj', linkObj);
                },
            });
        });
    }
    getData() {
        const { name } = this.config.domData;
        const data = {};
        data[name] = {
            ...this.shopLogo.getData(),
            shopLink: $(this.shopLink).data('linkObj'),
        };
        return data;
    }
}
export default ShopCall;