${(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}
`
} 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('');
})()}
`
}
})()}