${(function () {
return automatic_discount_list.map((item) => {
// 樔ēē±»å
const template_type = item.discount[0].template_type;
// ęÆå¦ę¾ē¤ŗčŖåØęę£
const is_show_automatic_discount = item.discount[0].product_enabled;
// ęÆå¦č·³č½¬č½å°é”µ
const is_redirection = item.discount[0].is_redirection;
// ęę£å¾ę
const discount_icon = item.discount_icon;
// 第äøäøŖčŖåØęę£
const first_automatic_discount = item.discount[0];
// ę¾ē¤ŗęå å±ē¤ŗ
const isFold = (item.discount[0].display_type || DISPLAY_TYPE.DTE_FOLD) === DISPLAY_TYPE.DTE_FOLD;
// ęę¬ę°ē»
const text_arr = item.discount[0].config.texts;
// ę”ä»¶å¼ę°ē»
const condition_values = item?.discount[0]?.condition_values || [];
// č½å°é”µé¾ę„
const first_landing_url = `/promotions/discount-default/${first_automatic_discount.discount_id}`;
// čŖåØęę£ę»ę°
const automatic_discount_total = item.discount.length;
// ęÆå¦ę¾ē¤ŗęę£å¾ę
const isHasDiscountIcon = discount_icon ? true : false;
// ęÆå¦ę¾ē¤ŗęę£å¾ę äøęØ”ēē±»åäøäøŗtagåadd_to_cart
const isHasDiscountIconWithNoTag = (template_type != 'tag' && template_type != 'add_to_cart' && isHasDiscountIcon)? true : false;
// ęę¬é¢č²
let text_color = DEFAULT_CONFIG.TEXT_COLOR;
// čęÆé¢č²
const bgFn = (curBg) => template_type === "text" ? "transparent" : curBg;
let bg_color = bgFn(DEFAULT_CONFIG.BG);
// č¾¹ę”é¢č²
const borderFn = (curBorder) => template_type == "tag" ? curBorder : "initial";
let border_color = borderFn(DEFAULT_CONFIG.BORDER_COLOR);
// 樔ēé
ē½®
let template_config = first_automatic_discount.template_config;
// äøé®å č“ę ·å¼
let addToCartBtnBgColor = DEFAULT_CONFIG.ADD_TO_CART_BG;
let addToCartBtnTextColor = DEFAULT_CONFIG.ADD_TO_CART_TEXT_COLOR;
let addToCartBtnBorderColor = DEFAULT_CONFIG.ADD_TO_CART_BORDER_COLOR;
// å
åŗę¹ę”
try {
if(template_config.length !== 0){
template_config = JSON.parse(template_config);
text_color= isHasDiscountIconWithNoTag ? template_config.color[template_type].icon_text_color : template_config.color[template_type].text_color;
bg_color = bgFn(template_config.color[template_type].background_color);
const arrayRgba = bg_color.split(",");
arrayRgba.splice(3, 1, " 1)");
border_color = borderFn(`${arrayRgba.join(",")}`);
addToCartBtnTextColor = template_config.color[template_type].button_text_color;
addToCartBtnBorderColor = template_config.color[template_type].button_border_color;
addToCartBtnBgColor = template_config.color[template_type].button_background_color;
}
} catch (error) {
console.error('template_config_error', error);
template_config = {
color: {
[template_type]: {
icon_text_color: DEFAULT_CONFIG.TEXT_COLOR,
text_color: DEFAULT_CONFIG.TEXT_COLOR,
background_color: DEFAULT_CONFIG.BG
}
}
};
}
// ę ē¾
const isTag = template_type == 'tag';
// ęåå横å¹
const isTextAndBanner = template_type == 'text' || template_type == 'banner';
// ęÆå¦äøé®å č“
const isAddToCart = template_type == 'add_to_cart';
// ęåę ·å¼
const textStyle = `color: ${text_color}; background-color: transparent; border: none;`;
// ę ē¾ę ·å¼
const labelStyle = `color: ${text_color};border: 1px solid ${border_color};background-color:${bg_color};padding: 4px;`;
// 横å¹
ę ·å¼
const bannerStyle = `color: ${text_color};border: none; background-color:${bg_color}`;
// äøé®å č“å个容åØę ·å¼ļ¼åŖå
å«åØęę ·å¼ļ¼
const addToCartSingleContainerStyle = `color: ${text_color}; background-color:${bg_color};`;
// äøé®å č“ęé®ę ·å¼ļ¼åŖå
å«é
ē½®ēåØęę ·å¼ļ¼
const addToCartBtnStyle = `color: ${addToCartBtnTextColor}; background-color:${addToCartBtnBgColor}; border:1px solid ${addToCartBtnBorderColor};`;
// å¤å±ę ·å¼åØę ē¾ę ·å¼äøäøå±ē¤ŗé¢č²é
ē½®ļ¼é¤å¼ę ē¾ē±»åļ¼é¢č²é½åÆä»„åØå¤å±č¦ē
let outerStyle = '';
if (template_type == 'text') {
outerStyle = textStyle;
} else if (template_type == 'tag') {
outerStyle = "border: none;";
} else if (template_type == 'banner') {
outerStyle = bannerStyle;
}
/**
* 1. ę ē¾äøå®ęÆåē¬ę ·å¼å±ē¤ŗē
* 2. ęå ļ¼ęØŖååøå±ļ¼ęåå横å¹
ļ¼åå¹¶ęäøč”ęę¬ļ¼ ę ē¾ļ¼åē¬ę ·å¼å¤ē
* 3. å¹³éŗļ¼ēŗµååøå±ļ¼ęåć横å¹
åę ē¾ļ¼ ę ē¾ļ¼åē¬ę ·å¼å¤ēļ¼äøé®å č“é»č®¤é½ęÆå¹³éŗ
*/
let txtHtml = ``;
if (isFold) {
if(isTag) {
// ę ē¾
const spanText = text_arr.map((text) => {
return `
${text} `;
}).join('');
txtHtml = `
${spanText}
`;
} else {
// ęåå横å¹
txtHtml = `
${first_automatic_discount.config.text}
`;
}
} else {
// ęåå横å¹
, ä½ę ē¾ęčŖå·±ēę ·å¼ļ¼äøäøé®å č“ęåē¬ę ·å¼
const spanText = text_arr.map((text, index) => {
const condition_value = condition_values[index];
if(isAddToCart) {
return `
${text}
Add to cart
`
} else {
return `
${text} `;
}
}).join('');
// é½ęÆēŗµååøå±ļ¼ę ē¾ęé“č·
txtHtml = `
${spanText}
`;
}
/**
* ę¾ē¤ŗå¾ę ēå¤ę
*/
const discount_type = item.discount_type;
const isShowRebateIcon = ["DT_REBATE_CTQ_OTP", "DT_REBATE_CTQ_OTR", "DT_REBATE_CTA_OTP", "DT_REBATE_CTA_OTR", "DT_M_N_DISCOUNT"].includes(discount_type) && isTextAndBanner
const isShowBxgyIcon = ["DT_BUY_ONE_GET_ONE", "DT_BUY_X_GET_Y"].includes(discount_type)
const isShowBundleIcon = ["DT_CLASSIC_BUNDLE","DT_MIX_MATCH_BUNDLE"].includes(discount_type);
/**
* ęø²ęäøęę”ęę½å±ēęę£å蔨
*/
const discount_list_html = (curItem) => {
return `
${function() {
return curItem.discount.map(childItem => {
return `
`}).join('');
}()}
`;
}
return `
${discount_list_html(item)}
${function() {
return text_arr.map((text) => {
return `
${text}
`;
}).join('');
}()}
`;
}).join('');
})()}
`
}
})()}