Race Yay Brown Contact Lens | Half-Yearly
$38.00
$20.00
More Colors
${data.targetOption}
Left
-1.00
0.00/Plano
-1.00
-1.25
-1.50
-1.75
-2.00
-2.25
-2.50
-2.75
-3.00
-3.25
-3.50
-3.75
-4.00
-4.25
-4.50
-4.75
-5.00
-5.25
-5.50
-5.75
-6.00
-6.50
-7.00
-7.50
-8.00
Right
-1.00
0.00/Plano
-1.00
-1.25
-1.50
-1.75
-2.00
-2.25
-2.50
-2.75
-3.00
-3.25
-3.50
-3.75
-4.00
-4.25
-4.50
-4.75
-5.00
-5.25
-5.50
-5.75
-6.00
-6.50
-7.00
-7.50
-8.00
Quantity
The current produc does not participate any Rebate. Switch the participating product to check the design.
(This prompt will not be displayed on the client-side.)
(This prompt will not be displayed on the client-side.)
${function() {
const show = rebate.format_rules.length > data.maxShowCount;
return `
${rule}
${function() {
if(!show) return "";
return `
`;
}()}
`;
}()}
${originData.rebate.format_rules.join(", ")}
(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":"9b8924fe-0b67-4e35-a1f7-44b69baccad3","product_id":"89d7f7fe-c09b-479d-af65-dd2ec74a1aa2","title":"-1.00--1.00","weight_unit":"g","inventory_quantity":13,"sku":"KCB100040100-100","barcode":"6974880409342342","position":28,"option1":"-1.00","option2":"-1.00","option3":"","note":"","image":null,"wholesale_price":[{"price":20,"min_quantity":1}],"weight":"40","compare_at_price":"38","price":"20","retail_price":"38","available":true,"url":"\/products\/kilala-race-yay-brown?variant=9b8924fe-0b67-4e35-a1f7-44b69baccad3","available_quantity":13,"options":[{"name":"left","value":"-1.00"},{"name":"right","value":"-1.00"}],"off_ratio":47,"flashsale_info":[],"sales":297};
// 上报
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 = "Please enter your email address";
doms.emailWarn.classList.remove('app-arrival-hidden');
return;
}
if(!EMAIL_REG.test(email)){
doms.emailWarnText.innerText = "Please enter a valid email address";
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("Currently in preview mode, subscription is for testing only", 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("Thank you for your subscription! We will notify you as soon as the product is back in stock!", 3000);
});
},
INVENTORY_NOT_EMPTY: ()=>{
SPZ.whenApiDefined(doms.lightbox).then(apis=>{
apis.close();
});
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("Subscription failed. Product back in stock, please proceed to checkout.", 3000);
});
setTimeout(()=>{
window.location.reload();
}, 3000);
},
REPEAT_SUBSCRIBE: ()=>{
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("You've already subscribed to this product. We'll let you know as soon as it's back in stock. Feel free to explore our other products.", 3000);
});
},
EMAIL_EMPTY: ()=>{
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("Please enter your email address", 3000);
});
},
EMAIL_WRONG_FORMAT: ()=>{
SPZ.whenApiDefined(doms.toast).then(apis=>{
apis.showToast("Please enter a valid email address", 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\/3962aff098316f8aed8f6a55392147ae.jpg","path":"3962aff098316f8aed8f6a55392147ae.jpg","width":1000,"height":1000,"alt":"","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);
})();
Visible only when the product is out of stock. Currently in preview mode.
Notify me when back in stock!
Race Yay Brown Contact Lens | Half-Yearly
/1.00//1.00
Email