소재 패키지 - 고딕 시리즈 빈티지 다크 플라워 캐릭터
소재 패키지 - 고딕 시리즈 빈티지 다크 플라워 캐릭터
${function() {
const variantData = data.variant || {"id":"e5cc6700-e1ba-4439-abaf-441c0d29a2b3","product_id":"d7313461-9579-4341-828f-245c3794d89f","title":"set of 6","weight_unit":"kg","inventory_quantity":1020,"sku":"SCB-GT-01Z","barcode":"","position":1,"option1":"set of 6","option2":"","option3":"","note":"","image":{"src":"\/\/img.staticdj.com\/9673e656e17a9fc6b2e798260012818d.jpeg","path":"9673e656e17a9fc6b2e798260012818d.jpeg","width":1667,"height":1667,"alt":"\uc18c\uc7ac \ud328\ud0a4\uc9c0 - \uace0\ub515 \uc2dc\ub9ac\uc988 \ube48\ud2f0\uc9c0 \ub2e4\ud06c \ud50c\ub77c\uc6cc \uce90\ub9ad\ud130","aspect_ratio":1},"wholesale_price":[{"price":26538,"min_quantity":1}],"weight":"0.03","compare_at_price":"26538","price":"13269","retail_price":"26538","available":true,"url":"\/products\/material-package-gothic-series-vintage-dark-flower-character?variant=e5cc6700-e1ba-4439-abaf-441c0d29a2b3","available_quantity":1020,"options":[{"name":"Color","value":"set of 6"}],"off_ratio":"50","flashsale_info":{"variant_id":"e5cc6700-e1ba-4439-abaf-441c0d29a2b3","product_id":"","quantity":0,"discount_id":"","limit_time":0,"limit_buy":0,"user_limit_buy":0,"discount_sales":0,"discount_sales_rate":"","discount_stock":0,"ends_at":0,"starts_at":0,"allow_oversold":"","allocation_method":"","price":"13269","compare_at_price":"","discount_price":"13269","customary_saved_price":"","customary_off_ratio":"","discount_saved_price":"","discount_off_ratio":"50","use_before_price":false,"before_price":"","title":"","properties":"","color_setting_promotional_copy":"","discount_quantity":0,"is_need_split":false},"sales":0};
const saveType = null;
const productSaveLabel = null;
return `
-
${ variantData.off_ratio }%
`; }()}
${function(){
const isRTL = originData.isRTL;
const isMobile = originData.isMobile;
const inProductDetail = originData.inProductDetail;
if (!inProductDetail) {
return `
Flash sale cannot be displayed here. Please move it to the product detail area.
(This prompt will not be displayed on the client-side)
`;
}
const flashsaleData = originData.flashsaleData;
const image_domain = originData.image_domain;
const discount_info = flashsaleData.discount_info;
const setting = flashsaleData.product_setting;
if (!discount_info || !setting) return ``;
const displayType = setting.display_type;
const banner = setting.banner;
const productDisplay = setting.product_display;
const bannerConfig = JSON.parse(banner.config);
const productDisplayConfig = JSON.parse(productDisplay.config);
const colorConfig = productDisplayConfig.color;
const countdownConfig = productDisplayConfig.countdown;
let titleIcon = ``;
let bgImg = ``;
const deg = `${isRTL ? -90 : 90}deg`;
const { banner_bg_start, banner_bg_end, banner_text } = colorConfig;
let bgStyle = `background: linear-gradient(${deg}, ${banner_bg_start} 0%, ${banner_bg_end} 100%);`;
let bannerColor = `color: ${banner_text};`
if (banner.type === "TYPE_CUSTOM") {
const { desktop, mobile, image_render } = bannerConfig;
const bgSize = image_render === "fill" ? "background-size: cover;background-position: center;" : "background-position: center;background-size: auto 100%;";
if (isMobile && mobile) {
bgStyle = `background: URL(${image_domain + mobile});${bgSize}`;
} else if (!isMobile && desktop) {
bgStyle = `background: URL(${image_domain + desktop});${bgSize}`;
}
} else {
if (banner.type === "TYPE_ONE") {
titleIcon = productDisplay.text ? `
` : "";
bgImg = ``
}
if (banner.type === "TYPE_TWO") {
titleIcon = productDisplay.text ? `
` : ""
}
}
const { sale_bar_background_color, progress_sale_bar_background_color_start, progress_sale_bar_background_color_end } = colorConfig;
const rate = discount_info.discount_sales_rate;
const progressBarStyle = `background: linear-gradient(${deg}, ${progress_sale_bar_background_color_start} 0%, ${progress_sale_bar_background_color_end} 100%);`;
const saleCount = productDisplay.sales_progress.format === "FORMAT_NUMBER" ? discount_info.discount_sales : `${rate}%`;
const progressBarDom = productDisplay.sales_progress.enabled && rate > 0 ? `
` : ``;
const { countdown_bg, countdown_text } = colorConfig;
const { end_opened, end_format } = countdownConfig;
const tempMap = {
"DD_SSS": "DD:HH:mm:ss:SSS",
"HH_SSS": "HH:mm:ss:SSS",
"DD_ss": "DD:HH:mm:ss",
"HH_ss": "HH:mm:ss"
}
const isShowDD = [tempMap.DD_SSS, tempMap.DD_ss].includes(end_format);
const isShowSSS = [tempMap.DD_SSS, tempMap.HH_SSS].includes(end_format);
const countdown = discount_info.ends_remaining_seconds;
const countdownDom = end_opened ? `
${function() {
if (banner.type === "TYPE_TWO") return `
`
return ``;
}()}
` : ``;
const flashSaleDesc = discount_info.limit_user_product_discount > -1 ? `
프로모션 품목은 1인당 ${discount_info.limit_user_product_discount}개로 제한됩니다
` : "";
return `
${bgImg}
${titleIcon}
${productDisplay.text}
${progressBarDom}
${countdownDom}
${flashSaleDesc}
`}()}
${function(){
const dd = data.dd; const hh = data.hh; const mm = data.mm; const ss = data.ss; const sss = data.SSS;
const hours = data.d * 24 + data.h;
return `
${dd}D
·
${hours}
${hh}
:
${mm}
:
${ss}
.
${sss}
`
}()}
class SpzCustomDiscountFlashsale extends SPZ.BaseElement {
constructor(element) {
super(element);
this.xhr_ = SPZServices.xhrFor(this.win);
this.getFlashSaleApi = "\/api\/storefront\/promotion\/flashsale\/display_setting\/product_setting";
this.timer = null;
this.variantId = "e5cc6700-e1ba-4439-abaf-441c0d29a2b3";
// 促销活动数据
this.flashsaleData = {}
}
isLayoutSupported(layout) {
return layout == SPZCore.Layout.CONTAINER;
}
buildCallback() {
this.templates_ = SPZServices.templatesForDoc();
this.viewport_ = this.getViewport();
// 挂载bind函数 解决this指向问题
this.render = this.render.bind(this);
this.resize = this.resize.bind(this);
this.switchVariant = this.switchVariant.bind(this);
}
mountCallback() {
// 获取数据
this.getData();
this.element.onclick = (e) => {
const cur = this.win.document.querySelector(".app_discount_flashsale_desc");
if (this.flashsaleData.product_setting.is_redirection && appDiscountUtils.inProductBody(this.element) && e.target !== cur) {
this.win.open(`/promotions/discount-default/${this.flashsaleData.discount_info.id}`);
}
}
// 绑定
this.viewport_.onResize(this.resize);
// 监听子款式切换,重新渲染
this.win.document.addEventListener('dj.variantChange', this.switchVariant);
}
unmountCallback() {
// 解绑
this.viewport_.removeResize(this.resize);
this.win.document.removeEventListener('dj.variantChange', this.switchVariant);
// 清除定时器
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
resize() {
if (this.timer) {
clearTimeout(this.timer)
this.timer = null;
}
this.timer = setTimeout(() => {
this.render();
}, 200)
}
switchVariant(event) {
const variant = event.detail.selected;
if (variant.product_id == 'd7313461-9579-4341-828f-245c3794d89f' && variant.id != this.variantId) {
this.variantId = variant.id;
this.getData();
}
}
getData() {
const reqBody = {
product_id: "d7313461-9579-4341-828f-245c3794d89f",
product_type: "default",
variant_id: this.variantId
}
this.flashsaleData = {};
this.win.fetch(this.getFlashSaleApi, {
method: "POST",
body: JSON.stringify(reqBody),
headers: {
"Content-Type": "application/json"
}
}).then(async (response) => {
if (response.ok) {
this.flashsaleData = await response.json();
this.render();
} else {
this.clearDom();
}
}).catch(err => {
this.clearDom();
});
}
clearDom() {
const children = this.element.querySelector('*:not(template)');
children && SPZCore.Dom.removeElement(children);
}
render() {
this.templates_
.findAndRenderTemplate(this.element, {
isMobile: appDiscountUtils.judgeMobile(),
isRTL: appDiscountUtils.judgeRTL(),
inProductDetail: appDiscountUtils.inProductBody(this.element),
flashsaleData: this.flashsaleData,
image_domain: this.win.SHOPLAZZA.image_domain,
})
.then((el) => {
this.clearDom();
this.element.appendChild(el);
})
}
}
SPZ.defineElement('spz-custom-discount-flashsale', SpzCustomDiscountFlashsale);
${(function () {
const automatic_discount_list = originData.automatic_discount_list;
// 显示类型
const DISPLAY_TYPE = {
DTE_FOLD: 'DTE_FOLD', // 折叠
DTE_TILE: 'DTE_TILE' // 平铺
}
const DEFAULT_CONFIG = {
BG: 'rgba(235, 57, 27, 0.04)',
TEXT_COLOR: '#EB391B',
BORDER_COLOR: 'rgb(235, 57, 27)'
};
const isExist = automatic_discount_list?.length > 0 && automatic_discount_list.some(item => item.discount[0].product_enabled);
// 如果没有任何自动折扣,则隐藏,防止gap占位
if (!isExist) {
return `
`;
} else {
return `
${(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 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
const isHasDiscountIconWithNoTag = (template_type != 'tag' && 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;
// 兜底方案
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(",")}`);
}
} 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 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}`;
// 外层样式在标签样式下不展示颜色配置,除开标签类型,颜色都可以在外层覆盖
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) => {
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('');
})()}
`
}
})()}
const TAG = "spz-custom-product-automatic";
class SpzCustomProductAutomatic extends SPZ.BaseElement {
constructor(element) {
super(element);
this.variant_id = 'e5cc6700-e1ba-4439-abaf-441c0d29a2b3';
this.isRTL = SPZ.win.document.dir === 'rtl';
}
static deferredMount() {
return false;
}
buildCallback() {
this.action_ = SPZServices.actionServiceForDoc(this.element);
this.templates_ = SPZServices.templatesForDoc(this.element);
this.xhr_ = SPZServices.xhrFor(this.win);
this.setupAction_();
this.viewport_ = this.getViewport();
}
mountCallback() {
this.init();
// 监听事件
this.bindEvent_();
}
async init() {
this.handleFitTheme();
const data = await this.getDiscountList();
this.renderApiData_(data);
}
async getDiscountList() {
const productId = 'd7313461-9579-4341-828f-245c3794d89f';
const variantId = this.variant_id;
const productType = 'default';
const reqBody = {
product_id: productId,
variant_id: variantId,
discount_method: "DM_AUTOMATIC",
customer: {
customer_id: window.C_SETTINGS.customer.customer_id,
email: window.C_SETTINGS.customer.customer_email
},
product_type: productType
}
const url = `/api/storefront/promotion/display_setting/text/list`;
const data = await this.xhr_.fetchJson(url, {
method: "post",
body: reqBody
}).then(res => {
return res;
}).catch(err => {
this.setContainerDisabled(false);
})
return data;
}
async renderDiscountList() {
this.setContainerDisabled(true);
const data = await this.getDiscountList();
this.setContainerDisabled(false);
// 重新渲染 抖动问题处理
this.renderApiData_(data);
}
clearDom() {
const children = this.element.querySelector('*:not(template)');
children && SPZCore.Dom.removeElement(children);
}
async renderApiData_(data) {
const parentDiv = document.querySelector('.automatic_discount_container');
const newTplDom = await this.getRenderTemplate(data);
if (parentDiv) {
parentDiv.innerHTML = '';
parentDiv.appendChild(newTplDom);
} else {
console.log('automatic_discount_container is null');
}
}
doRender_(data) {
const renderData = data || {};
return this.templates_
.findAndRenderTemplate(this.element, renderData)
.then((el) => {
this.clearDom();
this.element.appendChild(el);
});
}
async getRenderTemplate(data) {
const renderData = data || {};
return this.templates_
.findAndRenderTemplate(this.element, { ...renderData, isRTL: this.isRTL })
.then((el) => {
this.clearDom();
return el;
});
}
setContainerDisabled(isDisable) {
const automaticDiscountEl = document.querySelector('.automatic_discount_container_outer');
if(isDisable) {
automaticDiscountEl.setAttribute('disabled', '');
} else {
automaticDiscountEl.removeAttribute('disabled');
}
}
// 绑定事件
bindEvent_() {
window.addEventListener('click', (e) => {
let containerNodes = document.querySelectorAll(".automatic-container .panel");
let bool;
Array.from(containerNodes).forEach((node) => {
if(node.contains(e.target)){
bool = true;
}
})
// 是否popover面板点击范围
if (bool) {
return;
}
if(e.target.classList.contains('drowdown-icon') || e.target.parentNode.classList.contains('drowdown-icon')){
return;
}
const nodes = document.querySelectorAll('.automatic-container');
Array.from(nodes).forEach((node) => {
node.classList.remove('open-dropdown');
})
// 兼容主题
this.toggleProductSticky(true);
})
// 监听变体变化
document.addEventListener('dj.variantChange', async(event) => {
// 重新渲染
const variant = event.detail.selected;
if (variant.product_id == 'd7313461-9579-4341-828f-245c3794d89f' && variant.id != this.variant_id) {
this.variant_id = variant.id;
this.renderDiscountList();
}
});
}
// 兼容主题
handleFitTheme() {
// top 属性影响抖动
let productInfoEl = null;
if (window.SHOPLAZZA.theme.merchant_theme_name === 'Wind' || window.SHOPLAZZA.theme.merchant_theme_name === 'Flash') {
productInfoEl = document.querySelector('.product-info-body .product-sticky-container');
} else if (window.SHOPLAZZA.theme.merchant_theme_name === 'Hero') {
productInfoEl = document.querySelector('.product__info-wrapper .properties-content');
}
if(productInfoEl){
productInfoEl.classList.add('force-top-auto');
}
}
// 兼容 wind/flash /hero 主题 (sticky属性影响 popover 层级展示, 会被其他元素覆盖)
toggleProductSticky(isSticky) {
let productInfoEl = null;
if (window.SHOPLAZZA.theme.merchant_theme_name === 'Wind' || window.SHOPLAZZA.theme.merchant_theme_name === 'Flash') {
productInfoEl = document.querySelector('.product-info-body .product-sticky-container');
} else if (window.SHOPLAZZA.theme.merchant_theme_name === 'Hero') {
productInfoEl = document.querySelector('.product__info-wrapper .properties-content');
}
if(productInfoEl){
if(isSticky) {
// 还原该主题原有的sticky属性值
productInfoEl.classList.remove('force-position-static');
return;
}
productInfoEl.classList.toggle('force-position-static');
}
}
setupAction_() {
this.registerAction('handleDropdown', (invocation) => {
const discount_id = invocation.args.discount_id;
const nodes = document.querySelectorAll('.automatic-container');
Array.from(nodes).forEach((node) => {
if(node.getAttribute('id') != `automatic-${discount_id}`) {
node.classList.remove('open-dropdown');
}
})
const $discount_item = document.querySelector(`#automatic-${discount_id}`);
$discount_item && $discount_item.classList.toggle('open-dropdown');
// 兼容主题
this.toggleProductSticky();
});
}
triggerEvent_(name, data) {
const event = SPZUtils.Event.create(this.win, `${ TAG }.${ name }`, data || {});
this.action_.trigger(this.element, name, event);
}
isLayoutSupported(layout) {
return layout == SPZCore.Layout.CONTAINER;
}
}
SPZ.defineElement(TAG, SpzCustomProductAutomatic);
${function(){
return `
Color을 선택하십시오.
`;
}()}
상품이 재고가 없을 때만 표시되며, 현재는 미리보기용으로만 제공됩니다.
나에게 알려주세요
소재 패키지 - 고딕 시리즈 빈티지 다크 플라워 캐릭터
set of 6
이메일
(function(){
function $(selector){
return document.querySelector(selector);
}
const EMAIL_REG = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
// 获取dom数据
const doms = {
button: $('#app-arrival-reminder-button'),
previewBox: $('#app-arrival-reminder-preview-box'),
toast: $('#app-arrival-reminder-toast'),
lightbox: $('#arrival-lightbox'),
datalist: $('#app-arrival-reminder-email-list'),
imgRender: $('#app-arrival-reminder-product-image-render'),
productVariant: $('#app-arrival-reminder-product-variant'),
emailInput: $('#app-arrival-reminder-form .reminder-email-input'),
emailWarn: $('#app-arrival-reminder-form .reminder-email-warn-wrap'),
emailWarnText: $('#app-arrival-reminder-form .reminder-email-warn-text'),
submitButton: $('#app-arrival-reminder-submit-button')
};
// 选中的sku数据
let selectedVariant = {"id":"e5cc6700-e1ba-4439-abaf-441c0d29a2b3","product_id":"d7313461-9579-4341-828f-245c3794d89f","title":"set of 6","weight_unit":"kg","inventory_quantity":1020,"sku":"SCB-GT-01Z","barcode":"","position":1,"option1":"set of 6","option2":"","option3":"","note":"","image":{"src":"\/\/img.staticdj.com\/9673e656e17a9fc6b2e798260012818d.jpeg","path":"9673e656e17a9fc6b2e798260012818d.jpeg","width":1667,"height":1667,"alt":"\uc18c\uc7ac \ud328\ud0a4\uc9c0 - \uace0\ub515 \uc2dc\ub9ac\uc988 \ube48\ud2f0\uc9c0 \ub2e4\ud06c \ud50c\ub77c\uc6cc \uce90\ub9ad\ud130","aspect_ratio":1},"wholesale_price":[{"price":26538,"min_quantity":1}],"weight":"0.03","compare_at_price":"26538","price":"13269","retail_price":"26538","available":true,"url":"\/products\/material-package-gothic-series-vintage-dark-flower-character?variant=e5cc6700-e1ba-4439-abaf-441c0d29a2b3","available_quantity":1020,"options":[{"name":"Color","value":"set of 6"}],"off_ratio":"50","flashsale_info":{"variant_id":"e5cc6700-e1ba-4439-abaf-441c0d29a2b3","product_id":"","quantity":0,"discount_id":"","limit_time":0,"limit_buy":0,"user_limit_buy":0,"discount_sales":0,"discount_sales_rate":"","discount_stock":0,"ends_at":0,"starts_at":0,"allow_oversold":"","allocation_method":"","price":"13269","compare_at_price":"","discount_price":"13269","customary_saved_price":"","customary_off_ratio":"","discount_saved_price":"","discount_off_ratio":"50","use_before_price":false,"before_price":"","title":"","properties":"","color_setting_promotional_copy":"","discount_quantity":0,"is_need_split":false},"sales":0};
// 上报
function reportData(params){
// 编辑/预览不上报
if(false){
return;
}
window.sa.track(params.event_name, {
business_type: 'product_plugin',
function_name: 'Back_in_Stock',
plugin_name: "Back_in_Stock",
template_name: "product",
template_type: 1,
module: "apps",
module_type: "Back_in_Stock",
event_info: JSON.stringify({
action_type: 'Back_in_Stock'
}),
...params
});
}
// 按钮曝光上报
function buttonPVReport(){
reportData({
event_name: 'function_expose',
event_type: 'expose',
event_desc: '无货商品时触发'
});
}
// 弹窗曝光上报
function popupPVReport(){
reportData({
event_name: 'function_expose',
event_type: 'popup_expose',
event_desc: '弹窗曝光时触发'
});
}
// submit按钮点击上报
function submitClickReport(){
reportData({
event_name: 'function_click',
event_type: 'popup_click',
event_desc: '填入邮箱之后,点击notify 触发',
event_info: JSON.stringify({
action_type: 'email_click'
}),
});
}
// -----------------------初始化-----------------
init();
// 初始化操作
function init(){
// 为确保window有后面添加的值例如window.sa 需要在DOMContentLoaded回调事件中执行逻辑
document.addEventListener("DOMContentLoaded", function() {
// 设置邮件联想
setDataList();
if(!true){
// 初始无货 按钮pv事件埋点上报
buttonPVReport();
}
});
}
// 设置邮件联想
function setDataList(){
const customer_email = window.C_SETTINGS.customer.customer_email;
if(customer_email){
const options = document.createElement('option');
options.setAttribute('value', customer_email);
doms.datalist.appendChild(options);
}
}
// -----------------------事件操作----------------
// 监听sku变化事件
document.addEventListener('dj.variantChange', variantChange);
// 监听提醒按钮点击事件
doms.button.addEventListener('click', reminderButtonClick);
// 监听提交按钮点击事件
doms.submitButton.addEventListener('click', submit);
// 监听input元素的keydown事件
doms.emailInput.addEventListener('keydown', function(e) {
// 判断是否按下了Enter键
if (e.keyCode === 13 || e.key === 'Enter') {
submit();
}
});
// 显示正常按钮
function showReminderButton(){
doms.button.classList.remove('app-arrival-hidden');
doms.previewBox.classList.add('app-arrival-preview-hidden');
buttonPVReport();
}
// 展示预览按钮
function showPreviewButton(){
doms.button.classList.remove('app-arrival-hidden');
doms.previewBox.classList.remove('app-arrival-preview-hidden');
}
// 隐藏按钮
function hiddenReminderButton(){
doms.button.classList.add('app-arrival-hidden');
doms.previewBox.classList.add('app-arrival-preview-hidden');
}
// 提交数据, 请求接口
function submit(){
// 获取邮箱数据
const email = doms.emailInput.value.trim();
if(!email){
doms.emailWarnText.innerText = "\uc774\uba54\uc77c \uc8fc\uc18c\ub97c \uc785\ub825\ud558\uc138\uc694";
doms.emailWarn.classList.remove('app-arrival-hidden');
return;
}
if(!EMAIL_REG.test(email)){
doms.emailWarnText.innerText = "\uc720\ud6a8\ud55c \uc774\uba54\uc77c \uc8fc\uc18c\ub97c \uc785\ub825\ud558\uc138\uc694";
doms.emailWarn.classList.remove('app-arrival-hidden');
return;
}
// 邮箱校验成功
doms.emailWarn.classList.add('app-arrival-hidden');
// 预览时不调接口
if(false){
SPZ.whenApiDefined(doms.toast).then(apis => {
apis.showToast("\ud604\uc7ac \ubbf8\ub9ac\ubcf4\uae30 \ud398\uc774\uc9c0\uc785\ub2c8\ub2e4. \uad6c\ub3c5\uc740 \ud14c\uc2a4\ud2b8\uc6a9\uc73c\ub85c\ub9cc \uc81c\uacf5\ub429\ub2c8\ub2e4.", 3000);
});
return;
}
// 加入loading样式
doms.submitButton.classList.add('reminder-submit-button-loading');
// 提交数据请求接口
let quantity = 1;
const quantityDom = $('#app-arrival-reminder-quantity-render ljs-quantity');
if(quantityDom){
quantity = Number(quantityDom.getAttribute('value')) || 1;
}
const params = {
customer_email: email,
product_num: quantity,
product_id: selectedVariant.product_id,
product_variant_id: selectedVariant.id
};
fetch(`${window.C_SETTINGS.routes.root}/api/front/gobbler/v1/subscribe`, {
method: 'POST',
body: JSON.stringify(params),
headers: {
'Content-Type': 'application/json'
}
}).then((res)=>res.json()).then((res)=>{
/* 后端错误提示 */
if(res.errors && res.errors.length){
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast(res.errors[0], 3000);
});
return;
}
/* code
* 0 SUCCESS 订阅成功
* 1 PRODUCT_OFFLINE 商品下架
* 2 INVENTORY_NOT_EMPTY 商品库存不为空
* 3 REPEAT_SUBSCRIBE 重复订阅
* 4 EMAIL_EMPTY 邮件为空
* 5 EMAIL_WRONG_FORMAT 邮件格式错误
* 99999 INVALID_PARAMS 其他参数错误
*/
const codeMap = {
SUCCESS: ()=>{
SPZ.whenApiDefined(doms.lightbox).then(apis=>{
apis.close();
});
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("\uad6c\ub3c5\ud574 \uc8fc\uc154\uc11c \uac10\uc0ac\ud569\ub2c8\ub2e4! \uc81c\ud488\uc774 \uc7ac\uc785\uace0\ub418\ub294 \ub300\ub85c \uc54c\ub824\ub4dc\ub9ac\uaca0\uc2b5\ub2c8\ub2e4!", 3000);
});
},
INVENTORY_NOT_EMPTY: ()=>{
SPZ.whenApiDefined(doms.lightbox).then(apis=>{
apis.close();
});
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("\uc0c1\ud488\uc740 \uc774\ubbf8 \uc7ac\uace0\uac00 \uc788\uc73c\uba70, \uad6c\ub3c5\uc5d0 \uc2e4\ud328\ud588\uc2b5\ub2c8\ub2e4. \uc9c1\uc811 \uad6c\ub9e4\ud574 \uc8fc\uc2dc\uae30 \ubc14\ub78d\ub2c8\ub2e4.", 3000);
});
setTimeout(()=>{
window.location.reload();
}, 3000);
},
REPEAT_SUBSCRIBE: ()=>{
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("\uc774\ubbf8 \uc774 \uc81c\ud488\uc744 \uad6c\ub3c5\ud558\uc168\uc2b5\ub2c8\ub2e4. \uc7ac\uc785\uace0\ub418\ub294 \ub300\ub85c \uc54c\ub824\ub4dc\ub9ac\uaca0\uc2b5\ub2c8\ub2e4. \ub2e4\ub978 \uc81c\ud488\ub3c4 \uc0b4\ud3b4\ubcf4\uc138\uc694.", 3000);
});
},
EMAIL_EMPTY: ()=>{
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("\uc774\uba54\uc77c \uc8fc\uc18c\ub97c \uc785\ub825\ud558\uc138\uc694", 3000);
});
},
EMAIL_WRONG_FORMAT: ()=>{
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("\uc720\ud6a8\ud55c \uc774\uba54\uc77c \uc8fc\uc18c\ub97c \uc785\ub825\ud558\uc138\uc694", 3000);
});
}
};
codeMap.PRODUCT_OFFLINE = codeMap.SUCCESS;
codeMap[res.code] && codeMap[res.code]();
}).finally(()=>{
doms.submitButton.classList.remove('reminder-submit-button-loading');
});
// submit点击上报
submitClickReport();
}
// 重新渲染dialog
function refreshRenderDialog(){
console.log('selectedVariant', selectedVariant);
const images = selectedVariant.image || {"src":"\/\/img.staticdj.com\/9673e656e17a9fc6b2e798260012818d.jpeg","path":"9673e656e17a9fc6b2e798260012818d.jpeg","width":1667,"height":1667,"alt":"\uc18c\uc7ac \ud328\ud0a4\uc9c0 - \uace0\ub515 \uc2dc\ub9ac\uc988 \ube48\ud2f0\uc9c0 \ub2e4\ud06c \ud50c\ub77c\uc6cc \uce90\ub9ad\ud130","aspect_ratio":1};
const imagePosition = images.aspect_ratio > 1 ? 'left top' : 'center center';
// 重新渲染图片
SPZ.whenApiDefined(doms.imgRender).then((apis)=>{
apis.render({
images,
imagePosition
});
});
// 邮件错误提示置空
doms.emailWarn.classList.add('app-arrival-hidden');
// 重新渲染款式说明
if(selectedVariant.title){
doms.productVariant.innerText = selectedVariant.title.split('-').join('/');
}
// 表单数据置空
doms.emailInput.value = '';
}
// sku变化 单一款式不会触发
function variantChange(e){
const selected = e.detail.selected;
// 子款式没变不执行操作 例如数量变化
if(selected.id === selectedVariant.id){
return;
}
selectedVariant = selected;
console.log('selectedVariant', selectedVariant);
// 数量变化
if(selected.available || selected.product_id === undefined){
// 有库存 编辑时展示预览按钮 否则隐藏按钮
if(false){
showPreviewButton();
}else {
hiddenReminderButton();
}
}else{
// 无库存 显示正常按钮
showReminderButton();
}
}
// 提醒按钮点击
function reminderButtonClick(){
refreshRenderDialog();
// 弹窗曝光上报
popupPVReport();
}
document.body.appendChild(doms.toast);
document.body.appendChild(doms.lightbox.parentElement);
})();
${currentFreeShippingCustomText}
${currencyTag}
번거로움 없는 반품 정책으로 안심하고 쇼핑하세요. 구매하신 상품에 만족하실 수 있도록 보장합니다.
지구를 생각하며 디자인된 모든 제품은 지속 가능한 방식으로 제작됩니다.
최첨단 암호화 결제 보안으로 귀하의 결제 정보는 항상 안전하게 보호됩니다.
${function(){
const variantData = data.variant || null;
return `
공급업체 :
${data.product && data.product.vendor}
무게 :
${variantData && variantData.weight}${variantData && variantData.weight_unit}
바코드 :
${variantData && variantData.barcode}
Sku :
${variantData && variantData.sku}
인벤토리 :
${variantData && variantData.available_quantity}
` }()}