bhdbr.com
Open in
urlscan Pro
54.254.129.54
Public Scan
URL:
https://bhdbr.com/V3/common/assets/js/addcart06.js
Submission: On December 05 via api from US — Scanned from SG
Submission: On December 05 via api from US — Scanned from SG
Form analysis
0 forms found in the DOMText Content
// JavaScript Document (function($){ var LANG_PACKAGE = { "addcart_no_x" : "第$X件", "addcart_total" : "åˆè¨ˆï¼š", "addcart_disable_add_spec" : "商å“å·²åŠ è³¼ï¼Œä¸å¯å†æ›´æ”¹è¦æ ¼", "addcart_no_spec_stock" : "æ¤è¦æ ¼å·²ç„¡åº«å˜", "addcart_title" : "é¸æ“‡è¦æ ¼", "addcart_nosel_spec" : "é‚„æ²’é¸æ“‡", "addcart_total_with" : "å…± ", "addcart_unit" : " 件", "addcart_has_gift" : "å«è´ˆ ", "addcart_gift_other" : "å¦è´ˆ " , "addcart_append_other" : "å¦å¾— ", "addcart_number" : "æ•°é‡ï¼š", "addcart_total_number" : "总数é‡ï¼š", "addcart_gift" : "贈,", "addcart_gift_title" : "è´ˆå“", "addcart_only" : ",僅剩 ", "addcart_has_sel" : "å·²é¸", "addcart_full_reduce" : "立減", "addcart_full_reduce_img" : "https://gcdn.giikin.com/ueditor/20180308/990c6fb8e2b072307de6458ef36f5169.jpg", "addcart_remove_cart" : "确实è¦åˆ 除æ¤è®°å½•å—?", "addcart_add_cart": "åŠ å…¥è³¼ç‰©è»Š", "addcart_promtype_1": "滿折", "addcart_promtype_2": "滿減", "addcart_promtype_3": "滿減", "addcart_promtype_4": "è²·è´ˆ", "addcart_promtype_5": "åŠ åƒ¹è³¼", "addcart_promtype_6": "è²·è´ˆ", "addcart_promtype_7": "åŠ åƒ¹è³¼", "addcart_promtype_8": "åŠ åƒ¹è³¼", "addcart_promtype_9": "åŠ åƒ¹è³¼", "addcart_promtype_10": "åŠ åƒ¹è³¼", "addcart_promtype_11": "滿折", "addcart_promtype_12": "滿折", "addcart_promtype_20": "滿減", "addcart_promtype_21": "滿折", "addcart_promtype_22": "å…é‹è²»", "addcart_invalid_promcode" : "ç„¡æ•ˆçš„å„ªæƒ ç¢¼", "addcart_shipping_free": "滿#yf#<span>å…é‹è²»</span>", "addcart_buynow": "ç«‹å³è³¼è²·", "addcart_confirm":"確定", "addcart_again_buy":"å†è²·", "addcart_able_reduce": "立減", "addcart_able_reduce2": " ", "addcart_go_x" : "å…±$X件", "addcart_select_spce":"è¯·é€‰æ‹©è§„æ ¼", "addcart_price_hint": "原價" }; var Constant = { SaleRule: { discount: 1,//1 商å“打折 fullAmountReduced: 2,//2 金é¢æ»¡å¤šå°‘å‡ä»€ä¹ˆä»· fullNumberReduced: 3,//3 商å“数满多少å‡å‡ 个 buyXGetX: 4,//4 ä¹°å‡ é€å‡ (åŒä¸€å•†å“ afterNumberPrice: 5,//5 ç¬¬å‡ ä»¶åŽä»€ä¹ˆä»· buyXGetY: 6,//6 ä¹°å‡ é€å‡ (ä¸åŒå•†å“) fullAmountGetX:7,// 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(åŒä¸€å•†å“) fullAmountGetY:8,// 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(ä¸åŒå•†å“) addAmountGetX:9,// åŠ å¤šå°‘é’±é€å‡ 个产å“(åŒä¸€ä¸ªå•†å“) addAmountGetY:10,// åŠ å¤šå°‘é’±é€å‡ 个产å“(ä¸åŒå•†å“) bindingX:11,// æ†ç»‘(åŒä¸€å•†å“) bindingY:12,// æ†ç»‘(ä¸åŒä¸€å•†å“) afterNumberDiscount: 13,//5 ç¬¬å‡ ä»¶åŽä»€ä¹ˆæŠ˜æ‰£ }, DisCompRule: { percent: "percent", donate: "donate", money: "money" }, ChangePriceSource: { specOffset: 1, discount: 2 } } var productIndex = 0; var productIndexId = 0; var currency = 'NTD'; var symbolStr = ""; var subStock = -1 ; var sinfo = ""; var currentId = ""; var Map = function(){ var map = new Array(); this.map = map; this.put = function(k, v){ for(var o=0; o<map.length;o++){ if(map[o].key==k){ map[o].value = v; return v; } } var obj = {"key": k, "value": v}; map.push(obj); }; this.get = function(k, defVal){ for(var o=0; o<map.length;o++){ if(map[o].key==k){ return map[o].value; } } if(defVal) return defVal(); return null; }; this.exist = function(k){ for(var o=0; o<map.length;o++){ if(map[o].key==k){ return true; } } return false; }; this.sort = function(){ return map.sort(function(a, b){ if(a.value.sort&&b.value.sort){ return parseInt(a.value.sort) - parseInt(b.value.sort); }else if(a.value.id&&b.value.id){ return parseInt(a.value.id) - parseInt(b.value.id); } return 0; }); } this.each = function(callback){ map = this.sort(); for(var o=0;o<map.length;o++){ callback(o, map[o], map[o].key, map[o].value); } }; // this.random = function(callback){ // map = this.sort(); // let random = parseInt(Math.random() * map.length); // callback(random,map[random],map[random].key, map[random].value) // } }; var showMessage = function(msg, delay, callback, isClose){ var dialog = $("#addcart_message_dialog"); delay = delay?delay: 3000; if(dialog.size()==0){ dialog = $("<div id='addcart_message_dialog' class='giikin-hide'/>"); $("body").append(dialog); } dialog.text(msg); dialog.addClass("giikin-on"); setTimeout(function(){ dialog.removeClass("giikin-on"); if(callback) callback(); }, 3000); }; // 数组ä¸æŒ‰ç…§å¯¹è±¡çš„æŸä¸€å±žæ€§é€’å‡æŽ’åº var Objectcompare = function (prop) { return function (obj1, obj2) { var val1 = obj1[prop]; var val2 = obj2[prop]; return val2 - val1; } } // 定制商å“,cod支付éšè— function hideCodPayment() { var payMethods = $('[name="payment"]'); if (payMethods.length && payMethods.length != 1) { var checkedPayId = Number($('[name="payment"]:checked').val()) === 1; payMethods.each(function () { var payId = Number($(this).val()); if (payId === 1) { $(this).parents('li.method').remove(); } else if(checkedPayId && payId !== 1) { $(this).attr('checked', true) $(this).click().trigger('change'); checkedPayId = false; } }) } } var stayCouponParams = ''; var _CartSpec = function(_addc, _pinfo, _group, _price, _rule, _number, _rid){ stayCouponParams = _addc.opts.stayCouponParams; var noOption = !_pinfo.options||_pinfo.options.length==0 || _pinfo.skus.length <= 1; //if(_pinfo.options.length<=1&&_pinfo.skus.length<=1 && _rule && (_rule.rule==4 || _rule.rule==5 || _rule.rule==6)) noOption = true; var $this = this; this.container = $(`<div class='addcart-specs' />`); this.title = $("<div class='addcart-specs-title'/>"); this.image = $("<img class='addcart-specs-title-image'/>"); this.tname = $("<span class='addcart-specs-title-name'/>"); this.gift = $("<span class='addcart-specs-title-gift'></span>"); this.number = $("<span class='addcart-specs-title-number'/>"); this.descript = $("<span class='addcart-specs-descript'/>"); this.status = $("<span class='addcart-specs-status'/>"); this.arrow = $("<span class='addcart-specs-arrow'>-</span>"); this.body = $("<div class='addcart-specs-body'/>"); this.singleSkuTitle = $("<span class ='addcart-single-sku'>()</span>"); _price = parseFloat(_price?_price:"0"); _number = _number?_number:1; var _onChangeItem = _addc.opts.onChangeItem; var _optionIndex = productIndex; var _ruleId = _rule?_rule.rule:0; //所使用的促销id var promId = _rule?_rule.id:0; var _gift = _price>0?0:1; var _optionFlag = _pinfo.id + "#" + _gift; _ruleId = _rid===undefined ? _ruleId : _rid; //å¸ç§åˆ‡æ¢ // _price = $.currencyCh(_price,_addc.opts.remark); this.container.attr("data-id", _pinfo.id); this.container.attr("data-number", _number); this.container.attr("data-price", _price); this.container.attr("data-rule", _ruleId); this.container.attr("data-prom", promId); this.container.attr("data-gift", _gift); this.container.attr("data-option", _optionFlag); this.container.data("pinfo", _pinfo); this.container.append(this.title); // èµ å“是å¦å±•ç¤º if(_gift && typeof _pinfo.isShow !== 'undefined') { this.container.attr('data-giftShow', _pinfo.isShow); } // èµ å“æ— åº“å˜åˆ¤æ– if(_gift == 1){ var flag = _pinfo.skus.every(v=>v.stock <= 0) if(flag) return; } this.transName = function(name){ var p1 = name.indexOf('】'); if(p1>name.length - 3) p1=-1; var p2 = name.indexOf('('); if(p1<0) p1 = name.indexOf(']'); if(p1<0) p1 = name.indexOf(' '); p1 = p1<0 ? 0: p1 + 1; if(p2<0) p2 = name.indexOf('(', p1); if(p2<0) p2 = name.indexOf('[', p1); if(p2<0) p2 = name.indexOf('ã€', p1); p2 = p2<0 ? name.length - p1: p2 - p1; if(p1>p2) return name; return name.substr(p1, p2); } if(noOption && !_addc.opts.default){ var specs = _group.find(".addcart-specs[data-option='" + _optionFlag +"']"); //è¶…å‡ºä¿ƒé”€æœ€å¤§å€¼æŒ‰åŽŸä»·æ ¼è®¡ç®— if(!_ruleId && $(".addcart-specs-group.first").length>0) specs = $(".addcart-specs-group.first").find(".addcart-specs[data-option='" + _optionFlag +"']"); if(specs.size()>0 && !_group.hasClass("after-discount")){ specs.attr("data-number", parseInt(specs.attr("data-number")) + _number); specs.find(".addcart-specs-title-number").text("×" + specs.attr("data-number")); return; }else{ var img = _pinfo.image; if(_pinfo.options.length>=1&&_pinfo.skus.length==1){ img = _pinfo.skus[0].option[0].image || _pinfo.skus[0].option[0].img || img; } if(_addc.opts.imagePath && img && img.substring(0,4)!='http'){ img = _addc.opts.imagePath + img; } if(_pinfo.id==_addc.opts.data.id) _addc.header.changeImage(img); this.image.attr("src", img); var skuSpec = ""; if(_pinfo.skus.length==1){ var op = _pinfo.options[0]; var ov = _pinfo.skus[0]; this.container.data("op", op); this.container.data("ov", ov); $.each(ov.option,function(i,v){ console.log(v); if(i==ov.option.length-1){ skuSpec += v.name; }else{ skuSpec += v.name + "*"; } }); } this.tname.text(this.transName(_pinfo.name || _pinfo.title) +"(" +skuSpec+")"); if(_group.hasClass("after-discount")||(_group.hasClass("appends")&&_pinfo.id==_addc.opts.data.id)){ this.tname.text(this.transName(_rule.name) +"(" +skuSpec+")"); } this.title.append(this.image); this.title.append(this.tname); this.number.text("×" + _number); this.title.append(this.number); if(_gift){ this.gift.text(_addc.lang("gift_title")); this.title.append(this.gift); } this.container.addClass("image-list"); if(_group.hasClass("binding")&&_pinfo.id==_addc.opts.data.id){ //this.container.hide(); } } }else{ _group.attr("has-option", true); if(_group.css('display')=='none') _group.show(); this.title.append(this.tname); this.title.append(this.arrow); if( !_addc.opts.default){ this.title.append(this.descript); this.title.append(this.status); }else{ this.tname.addClass("text-space") } this.container.append(this.body); } if(noOption && _addc.opts.default){ var specs = _group.find(".addcart-specs[data-option='" + _optionFlag +"']"); //è¶…å‡ºä¿ƒé”€æœ€å¤§å€¼æŒ‰åŽŸä»·æ ¼è®¡ç®— if(!_ruleId && $(".addcart-specs-group.first").length>0) specs = $(".addcart-specs-group.first").find(".addcart-specs[data-option='" + _optionFlag +"']"); if(specs.size()>0 && !_addc.opts["isComposite"] && !_group.hasClass("after-discount")){ if (_rule &&( _rule.nosuit == '2' || _rule.nosuit == '4')) { specs.attr("data-number", _number); } else { specs.attr("data-number", parseInt(specs.attr("data-number")) + _number); } if(_gift && _pinfo.id !=_addc.opts.data.id){ specs.find(".addcart-specs-size span").text(specs.attr("data-number")); }else { specs.find(".addcart-specs-title-name").text(_addc.lang("go_x").replace("$X", specs.attr("data-number"))); } return; }else{ if(_pinfo.skus.length==1){ var op = _pinfo.options[0]; var ov = _pinfo.skus[0]; this.container.data("op", op); this.container.data("ov", ov); } this.tname.text(_addc.lang("go_x").replace("$X", _number)); this.title.append(this.tname); if(_gift){ this.gift.text(_addc.lang("gift_title")); this.title.append(this.gift); } this.container.addClass("image-list"); } }else if(_addc.opts.default && !_gift){ this.singleSkuTitle.text(_addc.lang("addcart_total")); this.title.append(this.singleSkuTitle); } if(_group){ var _close = _group.find(".addcart-specs-group-close"); if(_close.size()>0&&_close.css("display")!='none'&&_group.find(".addcart-specs").size()==0){ this.arrow.addClass("left-offset"); } _group.append(this.container); _addc.body.find(".line1px").removeClass("line1px"); _addc.body.find(".addcart-specs-group").last().addClass("line1px"); if(_group.data("appendOther")){ _group.insertBefore($(".addcart-float-buttons-block").first()); }else{ _addc.body.append(_group); } }else{ _addc.body.append(this.container); } if(!_addc.opts.default ){ if(noOption) return; } if(_pinfo.id ==_addc.opts.data.id||_price>0){ if(!noOption){ productIndex++; } } if(_group.hasClass("first")&&_optionIndex==0&&_price>0){ if(!_addc.opts.default || (_addc.opts.default && !noOption)){ this.tname.text(_addc.lang("no_x").replace("$X", 1)); } if(_addc.opts.skip==1) this.container.hide(); }else{ if(_pinfo.id!=_addc.opts.data.id&&_price==0){ // this.tname.text(_addc.lang("gift_title")); }else{ var ord = _optionIndex + 1; if(_addc.opts.default ){ if(!noOption){ if(_gift && _pinfo.id == _addc.opts.data.id){ this.tname.text(_addc.lang("no_x").replace("$X", ord) +" " + _addc.lang("gift_other") + ":"); }else{ this.tname.text(_addc.lang("no_x").replace("$X", ord)); } }else{ if(_gift){ this.tname.text(_addc.lang("go_x").replace("$X", _number)); }else{ this.tname.text(_addc.lang("go_x").replace("$X", ord)); } } }else{ this.tname.text(_addc.lang("no_x").replace("$X", ord)); } } } this.title.click(function(){ if($(this).hasClass("unfold")){ $(this).removeClass("unfold"); $this.body.slideDown(200); }else{ $(this).addClass("unfold"); $this.body.slideUp(200); } }); this.specItems = []; this.AddCart = _addc; // console.log(_ruleId,_rule.nosuit); // if(!noOption){ // } this.container.attr("product-index", _optionIndex); if(!$this.AddCart.opts.isComposite){ this.container.attr("id", "skuLocation" + productIndexId++) } if(_ruleId>10&&(_rule.nosuit=='1' || _rule.nosuit=='4')) this.container.hide(); if(_ruleId>10&&_rule.nosuit=='2'&&_optionIndex>0) this.container.hide(); var ops = sort(_pinfo.options); var skus = _pinfo.skus; var selVal = ""; var noDef = false; // SGKS_06_checkoutèµ å“ if($this.AddCart.opts.default && _pinfo.id !=_addc.opts.data.id && _gift && _rule.nosuit == 1){ var contentGift = $("<div class='addcart-specs-gift'/>"); var giftImg =$("<div class='addcart-gift-img'/>"); var giftInfo = $("<div class='addcart-specs-info' />") var giftTitle = $("<p class='addcart-gift-title' />"); var specsSize = $("<p class='addcart-specs-title-number addcart-specs-size' />"); var giftSign = $("<span class='addcart-specs-sign' />"); giftTitle.text(this.transName(_pinfo.name || _pinfo.title) ); giftSign.html(_addc.lang("gift_title")) giftInfo.append(giftTitle); giftInfo.append(specsSize); contentGift.data("data-po", po); contentGift.data("data-po", po); contentGift.append(giftImg); contentGift.append(giftInfo); contentGift.append(giftSign); this.body.append(contentGift); this.container.addClass("addcart-gift"); this.container.removeAttr("id") } // 定制功能,商å“包å«è™šæ‹Ÿè§„æ ¼åˆ™ä¸å¯ç”¨ var noHasVirtual = true; if(_pinfo.fakeSkus &&_pinfo.fakeSkus.virtualSkus && _pinfo.fakeSkus.virtualSkus.length && _pinfo.fakeSkus.virtualOptions && _pinfo.fakeSkus.virtualOptions.length){ var virtualSellOut = _pinfo.fakeSkus.virtualSkus.every(v=>v.stock <= 0) noHasVirtual = virtualSellOut; } if (!$this.AddCart.opts.isComposite && noHasVirtual && _pinfo.productDiy && _pinfo.productDiy.length) { var diyTitle = ''; var diyHint = ''; var diyType = _pinfo.productDiy[0].diyType; // type:1æ ‡é¢˜ã€2:æ示è¯ï¼ŒdiyType:1æ–‡å—ã€2图片ã€3æ–‡å—+图片 var diyT = _pinfo.productDiy.find(v => v.type == 1) || ''; var diyH = _pinfo.productDiy.find(v => v.type == 2) || ''; if (diyT) { diyTitle = `<p class="diy-title"><span class="red">*</span>${diyT.content}</p>` } if (diyH) { diyHint = `<p class="diy-hint">${diyH.content}</p>` } this.productDiy = $(`<div class="addcart-diy"/>`); this.container.append(this.productDiy); var diyImage = _pinfo.productDiy.find(v=> Number(v.diyType) === 2); var diyCharacter = _pinfo.productDiy.find(v=> Number(v.diyType) === 1); hideCodPayment(); if(diyCharacter || diyType === 3) { // å®šåˆ¶æ–‡å— this.productDiy.append(` <div class="addcart-diy-character">${diyTitle} <input class="addcart-diy-value" name="product-diy" type="text" max-length="200" placeholder="${diyH.content}"></div>`); this.productDiy.find('input[name="product-diy"]').on("change", function(){ var value = $(this).val(); if (!value) { return; } $(this).val(value.slice(0,200)); $(this).parents(".addcart-diy").removeClass('no-select-content') // $this.AddCart.getData(); $this.AddCart.header.changePrice(); }) } if(diyImage || diyType === 3) { // 定制图片 var diyImgT = diyType === 3 ? '' : diyTitle; var diyImgH = diyType === 3 ? '' : diyHint; diyImg($this, this.productDiy, diyImgT, diyImgH); } } function diyImg($this, productDiy,diyTitle, diyHint){ productDiy.addClass('diy-upload-box'); var diyImg = $('<div class="addcart-diy-image"/>'); var uploadDiy = $('<div class="addcart-diy-upload"/>'); productDiy.append(diyImg); diyImg.append(diyTitle) diyImg.append(uploadDiy) diyImg.append(diyHint) // åˆ é™¤ã€æŸ¥çœ‹å¤§å›¾æŒ‰é’® var bigPrevMask = $('<div class="diy-mask"/>'); bigPrevMask.append(`<i class="iconfont icongonggong-DEL diy-delet"/><i class="iconfont iconsousuo1 diy-prev"/>`); var inputFile = $('<input class="addcart-diy-value" name="product-diy" type="file" accept="image/png,image/jpeg,image/webp">'); var loading = $(`<div class='post-loading'/>`) var uploadIcon = $(`<i class="iconfont iconshangchuan upload-icon"/>`) uploadDiy.append(`<img class="upload-img" src="">`).append(loading).append(uploadIcon).append(inputFile).append(bigPrevMask); inputFile.change(function(){ try{ var file = this.files[0]; if (!file) { $(this).val(''); return; } // æ£€æŸ¥å›¾ç‰‡æ ¼å¼ var type = ['image/jpeg', 'image/png', 'image/webp']; if (!type.includes(file.type)) { toast(_addc.lang('diy_type') || 'Only images in jpg and png format can be uploaded'); $(this).val(''); return; } // æ£€æŸ¥å›¾ç‰‡å¤§å° if (file.size > 20 * 1024 * 1024) { toast(_addc.lang('diy_size') || 'Image size cannot exceed 20M'); $(this).val(''); return; } productDiy.addClass('addcart-diy-loading'); uploadImg(file).then(res=>{ if (res.imageUrl) { var img = res.imageUrl; uploadDiy.addClass('upload-success').attr('data-image', img).removeClass('no-select-content').find('.upload-img').attr('src', img); $(this).parents('.addcart-diy').removeClass('no-select-content'); $this.AddCart.header.changePrice(); } else { uploadDiy.removeClass('upload-success'); toast(_addc.lang('diy_upload_fail') || 'Upload failed, please upload again'); } $(this).val(''); productDiy.removeClass('addcart-diy-loading'); }).catch(err=>{ uploadDiy.removeClass('upload-success'); toast(_addc.lang('diy_upload_fail') || 'Upload failed, please upload again'); $(this).val(''); productDiy.removeClass('addcart-diy-loading'); }) }catch(err){ console.log(err); uploadDiy.removeClass('upload-success'); $(this).val(''); productDiy.removeClass('addcart-diy-loading'); } }) // ä¸Šä¼ å›¾ç‰‡åŽé¼ æ ‡åœ¨å›¾ç‰‡ä¸Šç§»å…¥ç§»å‡º $('body').on('mouseover touchstart','.upload-success', function() { $(this).find('.diy-mask').css('display', 'flex'); }) $('body').on('mouseout touchend','.upload-success', function() { $(this).find('.diy-mask').hide(); }) // åˆ é™¤ bigPrevMask.on('click', '.diy-delet', function(e) { e.stopPropagation(); var hasCache = _addc.lang['diy_delete']; initConfirm( hasCache ? _addc.lang['diy_delete'] : 'Confirm deletion of altered image' , hasCache ? _addc.lang['diy_ok'] : 'Confirm', hasCache ? _addc.lang['diy_cancel'] : 'Cancel', () => { $(this).parents('.upload-success').attr('data-image', '').removeClass('upload-success').find('.upload-img').attr('src', ''); $(this).parents('.diy-mask').hide(); }, ()=> { }, 'page-back' ); }) //查看大图 bigPrevMask.on('click', '.diy-prev', function(e) { e.stopPropagation(); var img = $(this).parents('.upload-success').attr('data-image'); $('.prev-img-mask').find('img').attr('src', img); $('.prev-img-mask').css('display', 'flex'); $(this).parents('.diy-mask').hide(); }) } this.body.attr('data-options', JSON.stringify(ops)); this.body.attr('data-skus', JSON.stringify(skus)); for(var s=0; s<ops.length; s++){//å¾ªçŽ¯è§„æ ¼ç»„ var po = ops[s]; if(po.stock==''||po.stock <= 0){ continue; } var content = $("<dl class='addcart-specs-content'/>"); var dt = $("<dt/>"); dt.text(po.name); dt.attr('data-name', po.name); var skuNote = $("<div class='sku-note line-1' style='margin:0 8px;flex:1;'></div>"); if(po.note){ let curArr=["1","14","25","34","38","40"]; if(currencyId && curArr.includes(currencyId)){ po.note = po.note.replace("font-size:22px", "font-size:16px"); //ä¸ä¸œåœ°åŒºå—体大å°æ‰¹é‡æ“作需求 } skuNote.html("("+po.note+")"); dt.append(skuNote); dt.css("display","flex") } dt.attr("data-id", po.id); dt.attr("data-sort", po.sort); content.data("data-po", po); content.append(dt); var dd = $("<dd/>"); content.append(dd); this.body.append(content); var oval = new Map(); if(skus){ for(var sk=0; sk<skus.length;sk++){ /**循环产å“SKUåˆ—è¡¨ï¼Œæ‰¾å‡ºæœ¬ç»„è§„æ ¼çš„æ‰€æœ‰è§„æ ¼å€¼å’Œå…¶ç»„åˆçš„å…¶å®ƒè§„æ ¼å€¼*/ var sku = skus[sk]; var obj = {}; //è§„æ ¼å€¼å¯¹è±¡ var sortOption = sort(sku.option); var ids = []; if ($this.AddCart.opts.isComposite) sku.id = _pinfo.id ; for(var so=0; so<sortOption.length;so++){ var sop = sortOption[so]; if(sop.pid==po.id){ if(oval.exist(sop.name)){ obj = oval.get(sop.name); }else{ obj.sku = sku; // obj. obj = $.extend(obj, sop); obj.other = []; oval.put(sop.name, obj); } // æ‹ä¸‹å‡åº“å˜ // if(subStock/1 && skus[sk].stock <= 0) continue; // æ— åº“å˜ç½®ç° // if(skus[sk].stock <= 0) continue; for(var p=0; p<sortOption.length;p++){ var pp = sortOption[p]; if(pp.pid!=po.id){ if(skus[sk].stock <= 0){ obj.other.push({name:pp.name,show:false}); }else{ obj.other.push({name:pp.name,show:true}); } } } } ids.push(sop.id); } sku.ids = ids; } }else{ for(var i=0; i<po.values.length;i++){ var pov = po.values[i]; oval.put(pov.name, pov); } } this.specItems.push(oval); var _this = this; var giftRandom = parseInt(Math.random() * oval.map.length); oval.each(function(index, obj, key, val){ var span = $("<span/>"); span.attr("data-id", val.id); span.attr("data-details", JSON.stringify(val.details)); if(val.image&&(_ruleId<=10||(_ruleId>10&&_group.find(".addcart-specs").size()>=1)||_pinfo.id !=_addc.opts.data.id)){ if($this.AddCart.opts.default && _pinfo.id !=_addc.opts.data.id && _gift && _rule.nosuit == 1){ if(index == giftRandom){ var img = val.image; if($this.AddCart.opts.imagePath && img && img.substring(0,4)!='http'){ img = $this.AddCart.opts.imagePath + img; } giftImg.append("<img src='" + addImgSize(img, 200, 200) + "'/>"); if(specsSize.text()){ if(specsSize.find(".gift-number")){ specsSize.find(".gift-number").remove() } let text = specsSize.text().replace("*"," ") specsSize.html(text+ "/" + val.name + "* " + "<span class='gift-number'>1</span>") }else{ specsSize.html( val.name + "* " +"<span class='gift-number'>1</span>") } giftImg.data("option", JSON.stringify(val)); span.addClass("gift-img"); } } var img = val.image; if($this.AddCart.opts.imagePath && img && img.substring(0,4)!='http'){ img = $this.AddCart.opts.imagePath + img; } span.append("<img src='" + addImgSize(img, 200, 200) + "'/>"); span.append("<font>" + val.name + "</font>"); span.addClass("addcart-spec-img"); var viewImg = $("<i class='view-bg hide'><i class='iconfont iconfangda prev-img'></i></i>"); viewImg.click(function(e){ e.stopPropagation(); // $(".big-sku img").attr("src",img); $(".big-sku").addClass("gui-big-show"); $("body").addClass("disabled-scroll"); var curImgId = val.id; var options = _this.body.data('options'); var skus = _this.body.data('skus'); var imgs = options.find(v=>{ return v.values.some(k=> k.id == curImgId) }) if(imgs){ var html = ""; var index = 0; imgs.values.forEach((v, i)=>{ var flag = skus.some(k=>{ return k.option.some(j => j.id == v.id) }); if(flag){ html += '<div class="swiper-slide"><img src="' + v.img + '" class="lazy"><span>' + v.name + '</span></span></div>'; } if(v.id == curImgId){ index = i } }) $(".sku-swiper").html(html); initSkuSwiper(index); } }) span.append(viewImg); }else{ if($this.AddCart.opts.default && _pinfo.id !=_addc.opts.data.id && _gift && _rule.nosuit == 1){ if(index == giftRandom){ if(specsSize.text()){ if(specsSize.find(".gift-number")){ specsSize.find(".gift-number").remove() } let text = specsSize.text().replace("*"," ") specsSize.html(text+ "/" + val.name + "* " + "<span class='gift-number'>1</span>") }else{ specsSize.html( val.name + "* " + "<span class='gift-number'>1</span>") } specsSize.data("option", JSON.stringify(val)); span.addClass("gift-img"); } } span.text(val.name); }; if( $this.AddCart.opts.default){ _this.title.append(_this.singleSkuTitle); } dd.append(span); span.data("option", JSON.stringify(val)); // if(subStock && (val.sku.stock == "" || val.sku.stock <= 0)){ // span.addClass("unava") // } // åªæœ‰ä¸€ä¸ªè§„æ ¼ if(!val.other.length && val.sku.stock <= 0){ span.addClass("unava") } // å¤šè§„æ ¼æ—¶ï¼Œå…¶ä¸ä¸€é¡¹åº“å˜å…¨éƒ¨<=0 if(val.other.length){ var allUnava = val.other.every(v=>v.show == false) if(allUnava){ span.addClass("unava"); } } span.click(function(e) { if($this.container.hasClass("status-added")){ showMessage(_addc.lang("disable_add_spec")); return; } if($(this).hasClass("unava")){ if($(this).hasClass("gift-img")){ let have = $(this).parents(".addcart-specs-content").find("span:not(.unava)"); var haveRandom = parseInt(Math.random() * have.length); have[haveRandom].click(); return; }else{ showMessage(_addc.lang("no_spec_stock")); return; } } if($(this).hasClass("active")){ return; }else{ if(_gift == 1 && val.image && _rule && _rule.nosuit == 1){ var image = val.image; if($this.AddCart.opts.imagePath && image && image.substring(0,4)!='http'){ image = $this.AddCart.opts.imagePath + image; } $(this).parents(".addcart-specs-body").find(".addcart-gift-img img").attr("src", image); } $(this).addClass("active").siblings("span").removeClass("active"); var option = {}; if($(this).data("option")) option = JSON.parse($(this).data("option")); if(option.image){ var img = option.image; if(img && img.substring(0,4)!='http') img = _addc.opts.imagePath + img; if(_pinfo.id==_addc.opts.data.id) _addc.header.changeImage(img); } var others = option.other; var $span = $(this); if(others){ $(this).parents("dl.addcart-specs-content").nextAll("dl").each(function(index, element) { var isSelected = false; $(this).find("span").each(function(index, element) { var _option=$(this).parents("dl.addcart-specs-content").prev().find('.active'); var _option2 = ''; if(_option.data("option")) _option2 = JSON.parse(_option.data("option")).other; others=_option2; $(this).addClass("unava"); var able = false; var spec = $(this).text(); for(var o = 0; o<others.length;o++){ if(spec==others[o].name && others[o].show){ able = true; break; } } if(able){ $span.parents("dl.addcart-specs-content").prevAll("dl").each(function(index, element) { var option = {"other":[]}; if($(this).find(".active").data("option")) option = JSON.parse($(this).find(".active").data("option")); var a2 = false; if(option.other){ for(var o = 0; o<option.other.length;o++){ if(spec==option.other[o].name && option.other[o].show){ a2 = true; break; } } able = able && a2; } }); if(able) $(this).removeClass("unava"); } // 商å“ä¸å…³è”éšè— $(this).addClass("nonentity"); var checkSku = true; if(option.other){ for(var o = 0; o<option.other.length;o++){ if(spec == option.other[o].name){ checkSku = false; } } } if(!checkSku){ $span.parents("dl.addcart-specs-content").prevAll("dl").each(function(index, element) { var option = {"other":[]}; if($(this).find(".active").data("option")) option = JSON.parse($(this).find(".active").data("option")); var checkSku2 = false; if(option.other){ for(var o = 0; o<option.other.length;o++){ for(var o = 0; o<option.other.length;o++){ if(spec == option.other[o].name){ checkSku = false; } } } checkSku = checkSku && checkSku2; } }); if(!checkSku) $(this).removeClass("nonentity"); } }); if($(this).find(".active").hasClass("unava")){ $(this).find(".active").removeClass("active"); if(!_addc.opts.default || $(this).parents(".addcart-gift").length){ $(this).find("span:not(.unava)").first().click(); } }; }); } changeDescript(_price); if(!$this.AddCart.opts.isComposite){ if(_onChangeItem){ _onChangeItem(po, index, obj, key, val); } } } if(_ruleId>10&&_rule.nosuit=='2'){ _group.find('.addcart-specs').each(function (item, index) { if($(this).attr('product-index')>0){ $(this).find("dl.addcart-specs-content").each(function (item, index) { $(this).find("span[data-id='" + span.attr("data-id") + "']:not(.unava)").click(); }); } }); } // 处ç†éšæœºèµ å“æ— åº“å˜ if($(this).parents(".addcart-specs-content").find(".gift-img").length){ let giftParant = $(this).parents(".addcart-gift"); giftParant.find(".addcart-specs-info .addcart-specs-size").text(""); let skuS = ""; giftParant.find(".addcart-specs-content").each((i,v)=>{ console.log($(v).find(".active").text()); if(skuS){ skuS = skuS + "/" + $(v).find(".active").text(); }else{ skuS = $(v).find(".active").text(); } }) skuS = skuS + "*" + `<span class="gift-number">1</span>`; giftParant.find(".addcart-specs-info .addcart-specs-size").html(skuS) } // 选ä¸çš„商å“è§„æ ¼ä¿¡æ¯ if ($this.AddCart.opts.default) { let skuSpce = $(this).parents(".addcart-specs-body").find(".addcart-specs-content"); var contentLen = $(this).children(); var skuContent = ''; var skuType = $(this).parents(".addcart-specs-content").find("dt").attr('data-name'); //有两个skuå¯ä»¥é€‰æ‹©æ—¶ if (skuSpce.length > 1) { var sku = $(this).parents(".addcart-specs").find(".addcart-single-sku").html(); var skuSave = []; sku = sku.slice(1, sku.length - 1) skuSave = sku.split("/."); if (!/span/.test(sku)) { sku = "" } if (sku) { sku = sku.replace('<span class="sku-title-hidden">', "") sku = sku.replace('<span class="sku-title-hidden">', "") sku = sku.replace('</span>', ""); sku = sku.replace('</span>', ""); // var skuPart = sku.split("/."); } var reg = new RegExp(skuType) if (sku.length) { if (/\/./.test(sku)) { var index = -1; skuSave.forEach((v, i) => { if (!reg.test(v)) { index = i; } }) if(index){ if (contentLen.length) { skuContent = `( <span class="sku-title-hidden">${skuType}:</span>${$(this).find("font").html()}/. ${skuSave[index]} )` } else { skuContent = `(<span class="sku-title-hidden">${skuType}:</span>${$(this).html()}/. ${skuSave[index]} )`; } }else{ if (contentLen.length) { skuContent = `( ${skuSave[index]}/. <span class="sku-title-hidden">${skuType}:</span>${$(this).find("font").html()} )` } else { skuContent = `(${skuSave[index]}/. <span class="sku-title-hidden">${skuType}:</span>${$(this).html()})`; } } } else { if (!reg.test(sku)) { if (contentLen.length) { skuContent = `( ${skuSave[skuSave.length - 1]}/. <span class="sku-title-hidden">${skuType}:</span>${$(this).find("font").html()} )` } else { skuContent = `(${skuSave[skuSave.length - 1]}/. <span class="sku-title-hidden">${skuType}:</span>${$(this).html()})`; } } else { if (contentLen.length) { skuContent = `( <span class="sku-title-hidden">${skuType}:</span>${$(this).find("font").html()} )` } else { skuContent = `(<span class="sku-title-hidden">${skuType}:</span>${$(this).html()})`; } } } } else { if (contentLen.length) { skuContent = `( <span class="sku-title-hidden">${skuType}:</span>${$(this).find("font").html()})` } else { skuContent = `( <span class="sku-title-hidden">${skuType}:</span>${$(this).html()})` } } } else { if (contentLen.length) { skuContent = `(<span class="sku-title-hidden">${skuType}:</span>${$(this).find("font").html()})`; } else { skuContent = `(<span class="sku-title-hidden">${skuType}:</span>${$(this).html()})`; } } $(this).parents(".addcart-specs").find(".addcart-single-sku").html(skuContent); } let noSelect = $(this).parents(".addcart-specs").hasClass("no-select"); if (noSelect) { let allLen = 0; let content = $(this).parents(".addcart-specs").find(".addcart-specs-content") content.each(function (i) { $(this).find("span").each(function (i) { if ($(this).attr("class") && $(this).hasClass("active")) { $(this).parents(".addcart-specs-content").removeClass("no-select-content"); allLen += 1; } }) }) if (allLen == content.length) { $(this).parents(".addcart-specs").removeClass("no-select") } } if($this.AddCart.opts.isComposite){ var sku = JSON.parse(JSON.stringify(obj.value.sku)); var option = sku.option; sku.option = option.filter(v=>v.id == obj.value.id) $this.AddCart.opts.onSkuChange(sku); $this.AddCart.getData(true); } // sku切æ¢å移价更新 var isGift = parseInt($(this).parents(".addcart-specs").attr("data-gift")); if($this.AddCart.opts.data.id == sinfo.id && !isGift){ var goodSku = $(this).parents(".addcart-specs").find(".addcart-specs-content"); var skuInfo = []; goodSku.each(function() { if($(this).find(".active").length){ skuInfo.push($(this).find(".active").attr("data-id")); } }) var offsetPrice = 0; if(skuInfo.length && skuInfo.length == goodSku.length){ var sku = skus.find(v=> skuInfo.every(k=> v.option.some(j=>j.id == k))); offsetPrice = sku ? sku.price : 0; var productPrice = $this.AddCart.opts.data.finalPrice + offsetPrice/1; var productOrginPrice = $this.AddCart.opts.data.price/1 + offsetPrice/1; if($this.AddCart.opts.symbolBefore){ $(".product-price span").html($this.AddCart.opts.symbol + " " + $.formatCurrency(productPrice)); $(".product-price .old-price").html($this.AddCart.opts.symbol + " " + $.formatCurrency(productOrginPrice)); }else{ $(".product-price span").html($.formatCurrency(productPrice) + " " + $this.AddCart.opts.symbol); $(".product-price .old-price").html($.formatCurrency(productOrginPrice) + " " + $this.AddCart.opts.symbol); } } } }); if(_ruleId>10&&_rule.nosuit=='1'){ if(index==(_group.find('.addcart-specs').size()-1)%oval.map.length){ span.click(); } }else if(_ruleId>10&&_rule.nosuit=='2'){ _group.find('.addcart-specs').each(function (item, index) { if(index>0){ $this.find("dl.addcart-specs-content").each(function (item, index) { $(this).find("span[data-id='" + span.attr("data-id") + "']:not(.unava)").click(); }); } }); }else{ if(val.defualt=="1"){ isDef = true; if(!noDef) selVal += val.name + " "; //span.click(); span.attr("data-def", true); } } }); } // nosuit 1éšè— 2显示一个 0显示所有 if(_ruleId<=10||_rule.nosuit =='0'||_rule.nosuit =='2') { $this.container.find("dl.addcart-specs-content").each(function (item, index) { var isGift = Number($(this).parents('.addcart-specs').attr('data-gift')); if($this.AddCart.opts.default ){ if(noOption || (isGift === 1 && Number(_pinfo.isShow) === 0)){ if ($(this).find("span[data-def='true']:not(.unava)").size() > 0) { $(this).find("span[data-def='true']:not(.unava)").click(); } else { $(this).find("span:not(.unava)").first().click(); } if(isGift === 1 && Number(_pinfo.isShow) === 0){ $(this).parents('.addcart-specs').hide(); } }else{ $(this).parents(".addcart-specs").find(".addcart-single-sku").text("(" + $this.AddCart.lang("select_spce") + ")" ) } if( $(this).find(".gift-img").length){ $(this).find("span.gift-img").first().click(); } }else{ if ($(this).find("span[data-def='true']:not(.unava)").size() > 0) { $(this).find("span[data-def='true']:not(.unava)").click(); } else { $(this).find("span:not(.unava)").first().click(); } } }); // å¤šè§„æ ¼ä¸å…¶ä¸åªæœ‰ä¸€ä¸ªæ—¶ if(!noOption){ $this.container.find("dl.addcart-specs-content").each(function (item, index) { var _this = this; if($(_this).prevAll("dl.addcart-specs-content").length){ if($(this).find("dd").children().length == 1 && $(this).find("dd").children().not(".unava").length == 1){ $(this).find("span").first().click(); } }else if($(this).find("dd").children().not(".unava").length == 1){ $(this).find("span:not(.unava)").first().click(); } }); } } if(_rule&&(_rule.rule==Constant.SaleRule.addAmountGetX||_rule.rule==Constant.SaleRule.addAmountGetY)){ var __body = $this.AddCart.body; __body.animate({ //scrollTop: __body.scrollTop() + $this.container.offset().top }); } function changeDescript(price){ var ids = []; var nosel = ""; var hasNosel = false; $this.container.find("dl.addcart-specs-content").each(function(){ var span = $(this).find("span.active"); if(span.size()==0){ nosel = _addc.lang("nosel_spec") + $(this).find("dt").text(); hasNosel = true; }else{ ids.push(span.attr("data-id")); if(!hasNosel) nosel += span.text() + " "; } }); if(!hasNosel){ nosel = _addc.lang("has_sel") + nosel.trim(); if(skus){ nosel += _addc.lang("only"); for(var sk=0; sk<skus.length;sk++){ var sortOption = sort(skus[sk].option); var oids = []; for(var so=0;so<sortOption.length;so++){ oids.push(sortOption[so].id); } if(ids.sort().toString()==oids.sort().toString()){ if(skus[sk].stock){ nosel += skus[sk].stock; }else{ nosel += skus[sk].poid % 10; } $this.container.attr("data-poid", skus[sk].poid); var offset = skus[sk].price ? parseInt(skus[sk].price) : 0; $this.container.attr("data-offset-price", offset); if(price>0&&(_ruleId<9||_ruleId==5)){ // offset = $.currencyCh(offset,$this.AddCart.opts.remark); if(Math.abs(offset)>0&&_rule&&_ruleId==5&&_price<_addc.opts.data.finalPrice){ if(_rule.distype==Constant.DisCompRule.percent){ offset = parseInt(offset*_rule.value/100); }else{ offset = 0; } } $this.container.attr("data-offset", offset); if(Math.abs(offset)>0){ price = parseFloat(price) + offset; } } break; } } nosel += _addc.lang("unit"); } } $this.container.attr("hasNosel", hasNosel); if($this.AddCart.opts.symbolBefore){ nosel = "<i>"+$this.AddCart.opts.symbol + $.formatCurrency(parseFloat(price)) + "</i>," + nosel; }else{ nosel = "<i>"+$.formatCurrency(parseFloat(price)) + " " + $this.AddCart.opts.symbol + "</i>," + " " + nosel; } if(parseInt(price)==0){ nosel = _addc.lang("gift") + nosel; $this.descript.html("(" + nosel + ")").attr("cur-data",parseInt(price)); }else{ $this.descript.html("(" + nosel + ")").attr("cur-data",parseInt(price)); } $this.AddCart.header.changePrice(nosel); } $(".skeleton").hide(); $(".product-result").show(); function initSkuSwiper(initialSlide){ new Swiper(".big-sku",{ initialSlide, pagination: { el: '.big-sku .swiper-pagination', type: 'fraction' }, navigation: { prevEl: '.big-sku.swiper-container .swiper-button-prev', nextEl: '.big-sku.swiper-container .swiper-button-next', }, }) } }; /*random*/ function getRandom(minNum, maxNum) { var timer = new Date().getTime().toString().slice(4) var fakeIndex = minNum + parseInt(Math.random() * (maxNum - minNum))+timer; return fakeIndex; } function getRandomIndex(minNum, maxNum) { var fakeIndex = minNum + parseInt(Math.random() * (maxNum - minNum)); return fakeIndex; } /*random*/ var _AddCart = function(options, e){ subStock = typeof options.data.subStock != 'undefined' ? options.data.subStock / 1 : -1; currentId = options.data.id; sinfo = JSON.parse(store.get("sinfo")); if(subStock == 1){ var skusList =[]; options.data.skus.forEach(function (v,i){ if(v.stock <= 0){ skusList.push(v); }else{ skusList.unshift(v); } }) options.data.skus = skusList; } var $this = this; var defualts ={ currency: "NTD", symbol: "NT$", symbolBefore: true, barType: 0, onlyAddTo: false, displayDialog: true, saleTip: true, cartCount: 0, skip:0, logiFee: 0, style: 1, isCache:false, singlePay:false, allProm:false, lang: LANG_PACKAGE, onChangeQuantity: function(o, n){ //alert(o + '=>' + n); }, onChangeItem: function(po, index, obj, key, val){ //alert(key + '=>' + val); }, onGiftChangeItem: function(po, index, obj, key, val){ //alert(key + '=>' + val); } }; if(!e){ e = $("<div id='_addcart'/>"); $("body").append(e); } e.addClass("gk-addcart"); this.maxNum = options.data ? options.data.maxBuyNum : 0; this.container = e; this.opts = $.extend({}, defualts, options); if(options.data&&options.data.currency){ currency = options.data.currency; } this.opts.data.finalPrice = parseFloat(this.opts.data.finalPrice); if(this.opts.data.skip) this.opts.skip = this.opts.data.skip; if(!this.opts.mask){ this.opts.mask = $("<div class='addcart-mask giikin-hide'/>"); $("body").append(this.opts.mask); } productIndex = 0; this.opts.lang = $.extend({}, LANG_PACKAGE, options.lang); this.lang = function(key){ return this.opts.lang["addcart_" + key]; } // this.opts.hasOption = !(!options.data.options||options.data.options.length==0||(options.data.options.length==1&&options.data.skus.length<=1)); this.opts.hasOption = !(!options.data.options||options.data.options.length==0||(options.data.options.length>=1 && options.data.skus.length<=1)); this.init(); if(this.opts.form) $.loadStorage(this.opts.form); var imgUrl = options.data.image; if(imgUrl && !options.isComposite){ if( imgUrl.substr(0, 4) != "http"){ imgUrl = this.opts.imagePath + imgUrl; } if(this.opts.data.id == sinfo.id){ $(".product-detail .pro-img").attr("src", addImgSize(imgUrl, 100, 100)); } $(".addcart-header-image").attr("src", addImgSize(imgUrl, 100, 100)); } }; _AddCart.prototype = { init: function(){ var $this = this; var $events = [];//æ•°é‡æ”¹å˜äº‹ä»¶é˜Ÿåˆ— this.amount = parseFloat(this.opts.data.finalPrice); this.number = parseInt(this.opts.data.qty)||1; productIndex = this.number - 1; this.body = $("<div class='addcart-body'/>"); // è§„æ ¼å›¾æ”¾å¤§ var bigSku = $('<div class="big-sku swiper-container"><div class="swiper-pagination"></div><div class="swiper-button-prev swiper-arrow"></div><div class="swiper-button-next swiper-arrow"></div></div>'); var skuSwiper = $('<div class="sku-swiper swiper-wrapper"></div>'); bigSku.append(skuSwiper); bigSku.on("click", ".swiper-slide",function(){ bigSku.removeClass("gui-big-show"); $("body").removeClass("disabled-scroll"); }) // 大图 var prevImg = $('<div class="prev-img-mask" style="display:none;"/>'); prevImg.append(`<img class="upload-img" src="">`); prevImg.click(function(){ $(this).hide(); }) this.body.append(bigSku).append(prevImg); this.header = { container: $this.opts.header || $('<div></div>'), image: $("<img class='addcart-header-image'/>"), price: $("<div class='addcart-header-price'/>"), ptotal: $("<span class='addcart-header-price-total'/>"), ntotal: $("<span class='addcart-header-number-total'/>"), stock: $("<span class='addcart-header-stock'/>"), close: $('<span class="addcart-header-close iconfont icon-close"></span>'), close2: $('<span class="addcart-header-close iconfont iconguanbi2"></span>'), oldPrice: $("<span class='addcart-header-old-price'/>"), bar: $('<div class="addcart-header-bar"\>'), init: function(){ this.container.addClass("addcart-header"); this.container.append(this.image); this.container.append(this.price); this.price.append(this.ptotal); if($this.opts.newAddcartHeader) { var salePrice = currencyPos ? '<i class="symbol">' + $this.opts.symbol + '</i>' + publiceFormatCurrency( $this.opts.data.price) : publiceFormatCurrency( $this.opts.data.price) + '<i class="symbol">' + $this.opts.symbol + '</i>'; var saleOff = parseInt(( $this.opts.data.price - $this.opts.data.finalPrice) / $this.opts.data.price * 100) this.oldPrice.html(`<i class="old-price">${salePrice}</i> ${$this.lang('price_hint')}</i><i class="addcart-header-price-off"> ${saleOff}%OFF</i>`); this.price.append(this.oldPrice); $this.container.addClass("new-addcart-header"); } this.price.append(this.ntotal); this.price.append(this.stock); this.close.hide(); this.ntotal.html($('#addcart-promotion-html').html()); if($this.opts.style==1){ this.close.click(function () { $this.hide(); }); this.container.append(this.close); }else if($this.opts.style==2 && !$this.opts.newAddcartHeader){ this.bar.html('<span class="iconfont icon-fanhui"></span>' + $this.lang('title')); this.bar.find('span').click(function () { $this.hide(); }) this.container.append(this.bar); } else if($this.opts.newAddcartHeader) { this.price.append(this.close2); this.close2.click(function () { $this.hide(); }); } $this.container.append(this.container); }, changeImage: function(img){ this.image.attr('src', img); if($this.opts.data.id == sinfo.id){ $(".product-detail .pro-img").attr('src', addImgSize(img, 100, 100)); } }, changePrice: function(text){ var money = 0; var number = 0; $(".addcart-specs").each(function(index, element) { var price = $(this).attr("data-price")?parseFloat($(this).attr("data-price")):0; var offset = $(this).attr("data-offset")?parseFloat($(this).attr("data-offset")):0; var n = $(this).attr("data-number")?parseInt($(this).attr("data-number")):1; if(price==0) offset = 0; money = accAdd(money, accMul(n, price + offset)); number += n; }); if(text){ var s = text.split(','); if(s.length==3){ this.ptotal.html(s[0]); //this.ntotal.text(s[1]); //this.stock.text(s[2]); } } $this.amount = money; $this.footer.changeTotal(number, money); var saleFinalPrice = $this.opts.symbolBefore ? $this.opts.symbol + ' ' + $.formatCurrency(money) : $.formatCurrency(money)+ ' ' + $this.opts.symbol; $("#spe-price").html(saleFinalPrice); if($this.opts.onChangeHeader){ $this.opts.onChangeHeader($this, number, Math.round($this.amount)); } } } this.footer = { container: $("<div class='addcart-footer'/>"), price: $("<div class='addcart-footer-price'/>"), ptotal: $("<span class='addcart-footer-price-total'/>"), ntotal: $("<span class='addcart-footer-number-total'/>"), init: function(){ this.container.append(this.price); this.price.append(this.ntotal); this.price.append(this.ptotal); $this.container.append(this.container); }, changeTotal: function(number, amount, fullReduce){ symbolStr = $this.opts.symbol; amount += parseFloat($this.opts.logiFee); if($this.opts.symbolBefore){ this.ptotal.html($this.lang("total") + "<font>" + $this.opts.symbol + $.formatCurrency(amount) + "</font>"); }else{ this.ptotal.html($this.lang("total") + "<font>" + $.formatCurrency(amount) + $this.opts.symbol + "</font>"); } $this.amount = amount; $("input[name='amount']").val(amount); if(!fullReduce&&$this.promotion.rules){ for(var i=0;i<$this.promotion.rules.length;i++){ var rule = $this.promotion.rules[i].config.rule; if(rule==Constant.SaleRule.fullAmountReduced){ var reduce = $this.promotion.rules[i].change(); if(reduce>0 && !$this.opts.singlePay){ amount = amount - reduce; this.changeTotal(number, amount, reduce); }else if(reduce>0 && $this.opts.singlePay){ $("#checkout-coupon").removeClass("hide"); if($this.opts.symbol){ if($this.opts.symbolBefore){ $(".checkout-coupon").html($this.opts.symbol+$.formatCurrency(reduce)).attr("cur-data",reduce); }else{ $(".checkout-coupon").html($.formatCurrency(reduce)+" "+$this.opts.symbol).attr("cur-data",reduce); } }else{ $(".checkout-coupon").html($.formatCurrency(reduce)).attr("cur-data",reduce); } }else{ $("#checkout-coupon").addClass("hide"); } return false; } } }else if(fullReduce){ this.ptotal.html($this.lang("full_reduce") + ":<font>-" + $this.opts.symbol + $.formatCurrency(fullReduce) + "</font><br/>" + this.ptotal.html()); } } } this.quantity = { container: $('<div class="addcart-quantity"/>'), content: $('<div class="addcart-quantity-content"/>'), label:$('<label class="addcart-quantity-title">' + $this.lang("number") + '</label>'), increase: $('<span id="addcart-quantity-inc" ga-src="tankuang" ga-type="tankuang-shuliang"> + </span>'), decrease: $('<span id="addcart-quantity-dec"> - </span>'), number: $('<input type="text" name="specNumber" id="addcart-quantity-val" value="' + $this.number + '" readonly/>'), numberBox:$('<div class="totalNum"></div>'), PrimaryNumber: 1, GiftNumber: 0, AppendNumber: 0, GiftOtherNumber: 0, AppendOtherNumber: 0, init: function(){ this.content.append(this.label); this.content.append(this.total); this.container.append(this.content); if($this.opts.default){ this.numberBox.append(this.decrease); this.numberBox.append(this.number) this.numberBox.append(this.increase); this.content.append(this.numberBox); this.container.append(this.raisePrice) }else{ this.content.append(this.decrease); this.content.append(this.number); this.content.append(this.increase); } $this.container.append(this.container); var _this = this; this.increase.click(function(e){ if ($this.maxNum && $this.maxNum <= _this.PrimaryNumber) { toast($this.lang('over_max')); return; } // let skuLength =$(".addcart-body").find(".addcart-specs-content").length; // let activeLength =0; // $(".addcart-body").find(".addcart-specs-content").each(function(){ // $(this).find("span").each(function(){ // if($(this).attr("class") && $(this).hasClass("active")){ // activeLength += 1; // } // }) // }) // if(activeLength !== skuLength){ // showMessage($this.lang("select_spce")); // return; // } if (!judgeSkuSelected($this.opts, false)) { return; }; var scrollHeight = $this.body.prop("scrollHeight"); var n = parseInt($this.quantity.number.val()); if($this.opts.limit&&$this.opts.limit>=n) return; for(var i=0;i<$this.promotion.rules.length;i++){ var rule = $this.promotion.rules[i].config.rule; if(rule==Constant.SaleRule.addAmountGetX||rule==Constant.SaleRule.afterNumberPrice || rule==Constant.SaleRule.afterNumberDiscount){ $this.promotion.rules[i].increase(); $this.body.animate({scrollTop: scrollHeight + 'px'}, 300); return; } if(rule==Constant.SaleRule.addAmountGetY&&$this.promotion.rules[i].productNumber>0){ $this.promotion.rules[i].increase(); $this.body.animate({scrollTop: scrollHeight + 'px'}, 300); return; } } var incp = false; for(var i=0;i<$this.promotion.rules.length;i++){ var rule = $this.promotion.rules[i].config.rule; if(rule==Constant.SaleRule.addAmountGetX) continue; if(rule==Constant.SaleRule.addAmountGetY) continue; if(rule==Constant.SaleRule.fullAmountReduced) continue; $this.promotion.rules[i].increase(); incp = true; } if($this.promotion.rules.length==0||!incp){ if(this.PrimaryNumber==0) this.PrimaryNumber = 1; var group = $(".addcart-specs-group.primary"); if($this.opts.hasOption){ $this.addSpecs($this.opts.data, group, $this.opts.data.finalPrice); }else{ var specs = group.find(".addcart-specs[data-option='" + $this.opts.data.id + "#0']"); var number = parseInt(specs.attr("data-number")) + 1; specs.attr("data-number", number); if($this.opts.default){ specs.find(".addcart-specs-title-name").text($this.lang("go_x").replace("$X", number)); }else{ specs.find(".addcart-specs-title-number").text("×" + number); } } $this.quantity.changeNumber(1); } $this.body.animate({scrollTop: scrollHeight + 'px'}, 300); }); this.decrease.click(function(e){ var n = parseInt($this.quantity.number.val()); if(n<=1) return; for(var i=0;i<$this.promotion.rules.length;i++){ var rule = $this.promotion.rules[i].config.rule; if(rule==Constant.SaleRule.addAmountGetX||rule==Constant.SaleRule.afterNumberPrice ||rule==Constant.SaleRule.afterNumberDiscount){ $this.promotion.rules[i].decrease(); return; } if(rule==Constant.SaleRule.addAmountGetY&&$this.promotion.rules[i].productNumber>0){ $this.promotion.rules[i].decrease(); return; } } var decp = false; for(var i=0;i<$this.promotion.rules.length;i++){ var rule = $this.promotion.rules[i].config.rule; if(rule==Constant.SaleRule.addAmountGetY&&$this.promotion.rules[i].productNumber==0) continue; if(rule==Constant.SaleRule.fullAmountReduced) continue; $this.promotion.rules[i].decrease(); decp = true; } if($this.promotion.rules.length==0||!decp){ if($this.opts.hasOption && $(".addcart-specs-group.primary").find(".addcart-specs[data-gift='0']").length>1){ $(".addcart-specs-group.primary").find(".addcart-specs[data-gift='0']").last().remove(); }else{ var group = $(".addcart-specs-group.primary"); var specs = group.find(".addcart-specs[data-option='" + $this.opts.data.id + "#0']"); if(specs.attr("data-number") == 1){ return; } var number = parseInt(specs.attr("data-number")) - 1; specs.attr("data-number", number); if($this.opts.default){ specs.find(".addcart-specs-title-name.text-space").text($this.lang("go_x").replace("$X", number)); }else{ specs.find(".addcart-specs-title-number").text("×" + number); } } $this.quantity.changeNumber(-1); productIndex--; } }); }, changeNumber: function(changeNumber){ if(this.PrimaryNumber>0){ var n = parseInt(this.number.val()); this.number.val(n + changeNumber); } this.PrimaryNumber += changeNumber; // if($("input[name='compositionNum']").length){ // this.PrimaryNumber += $("input[name='compositionNum']").val()/1 // } if ($(".footer-btn .piece .singular-piece").length) { $(".footer-btn .piece span.num").html(this.PrimaryNumber); if(typeof languageId !== 'undefined' && languageId == '9'){ if (this.PrimaryNumber > 2) { $(".footer-btn .piece .singular-piece").hide(); $(".footer-btn .piece .two-piece").addClass('hide'); $(".footer-btn .piece .pular-piece").removeClass('hide'); } else if (this.PrimaryNumber > 1){ $(".footer-btn .piece .singular-piece").hide(); $(".footer-btn .piece .two-piece").removeClass('hide'); $(".footer-btn .piece .pular-piece").addClass('hide'); } else { $(".footer-btn .piece .singular-piece").show(); $(".footer-btn .piece .two-piece").addClass('hide'); $(".footer-btn .piece .pular-piece").addClass('hide'); } } } else { $(".footer-btn .piece span").html(this.PrimaryNumber); } this.changeTotal(); $this.BuyXGetYRule(); return this.PrimaryNumber; }, changeGiftNumber: function(changeNumber){ this.GiftNumber += changeNumber; this.changeTotal(); $this.BuyXGetYRule(); return this.GiftNumber; }, changeGiftOtherNumber: function(changeNumber){ this.GiftOtherNumber += changeNumber; this.changeTotal(); return this.GiftOtherNumber; }, changeAppendNumber: function(changeNumber){ this.AppendNumber += changeNumber; var n = parseInt(this.number.val()); this.number.val(n + changeNumber); this.changeTotal(); $this.BuyXGetYRule(); return this.AppendNumber; }, changeAppendOtherNumber: function(changeNumber){ this.AppendOtherNumber += changeNumber; this.changeTotal(); return this.AppendOtherNumber; }, changeTotal: function(){ var str = ""; var gifts = this.GiftNumber + this.GiftOtherNumber + this.AppendOtherNumber; if(gifts > 0){ str = "," + $this.lang("has_gift") + "<font>" + gifts + "</font>"; } /*if(this.GiftOtherNumber>0){ str += "," + $this.lang("gift_other") + this.GiftOtherNumber; } if(this.AppendOtherNumber>0){ str += "," + $this.lang("append_other") + this.AppendOtherNumber; }*/ var n = this.PrimaryNumber + this.AppendNumber + this.GiftNumber + this.GiftOtherNumber + this.AppendOtherNumber; if(n==0) n = 1; $this.footer.ntotal.html($this.lang("total_number") + "<font>" + n + "</font>" + str + $this.lang("unit")); $this.header.changePrice(); } } this.buttons = { container: $('<div class="addcart-group-buttons"/>'), position: 1,//1 init: function(){ if(this.position==1){ this.container.insertBefore($this.body); }else if(this.position==2){ if($this.opts.default){ this.container.insertAfter($this.quantity.container); }else{ this.container.insertBefore($this.quantity.container); } }else if(this.position==3){ this.container.insertAfter($this.quantity.container); $this.quantity.container.addClass("splitter"); $this.body.find(".addcart-specs-group").last().addClass("line1px"); } } } this.bar = { container: $('<div class="addcart-bar" />'), btnAddcart: $('<button class="addcart-bar-add ga-event fb-event" fb-type="TCaddtocart" ga-src="tankuang" ga-type="tankuangcart"/>'), btnBuynow: $('<button class="addcart-bar-buynow ga-event fb-event" fb-type="TCpurchase" ga-src="tankuang" ga-type="tankuangbuynow"/>'), btnConfirm: $('<button class="addcart-bar-buynow ga-event fb-event" fb-type="purconfirm" ga-src="buynow" ga-type="detailbuynow-confirm"/>'), btnBuynowPosition:this.opts.btnBuynowPosition, init: function () { var form = $this.opts.form || (function(){var f = $('<form method="post"/>'); $('body').append(f);return f;})(); $this.opts.form = form; var submit = function(action){ if(!$this.getData()){ return false; } form.attr('action', action); form.submit(); } // 判æ–商å“åº“å˜ var hasSkuStock = true; if ($this.opts.data && $this.opts.data.skus) { hasSkuStock = $this.opts.data.skus.some(v => v.stock > 0) } var keyT = "buynow"; var checkUrl = window.App.getHref('/checkout'); var cartUrl = window.App.getHref('/cart/index'); if($this.opts.barType === 0) return; if($this.opts.barType === 8 || $this.opts.barType ===9){ this.btnConfirm.text(hasSkuStock ? $this.lang("confirm") : ($this.lang("empty_product") || 'Sold out, return to home page')); if($this.opts.barType === 8){ this.btnConfirm.attr("fb-type","TCaddtocart"); this.btnConfirm.attr({"ga-src":"addtocart","ga-type":"detailcart-confirm"}); }else if($this.opts.barType === 9){ this.btnConfirm.attr("fb-type","purconfirm"); this.btnConfirm.attr({"ga-src":"buynow","ga-type":"detailbuynow-confirm"}); } this.btnConfirm.click(function(){ if (!hasSkuStock) { form.attr('action', '/'); form.submit(); return; } if(!judgeSkuSelected($this.opts)) return; if($this.opts.onConfirm && !$this.opts.onConfirm($this)) return; keyT = $this.opts.barType===8 ? 'addcart' : 'buynow'; store.set('__gui_key', keyT, 3600000*24*10); if (keyT == 'buynow') { try { var isFlash = store.get("__gk_isflash"); var activityId = getQuery('activityId'); if (isFlash && activityId) { store.set('__gk_flashsales', [{ "activityId": activityId, "saleId": $this.opts.data.id, "number": $this.quantity.PrimaryNumber }]) } else { store.remove('__gk_flashsales') } } catch (error) {} } if($this.opts.onlyAddTo && $this.opts.barType===8) { //åŠ è´æ•°æ® if(!$this.getData()) return false; var cart_s = '<p class="add-cart-s"><i class="iconfont iconS-YG3"></i>' + $this.lang('success') + '</p>'; toast(cart_s); $this.container.removeClass("anim-up"); $this.opts.mask.removeClass("giikin-on"); var cartCount = $this.opts.cartCountEle || $("#cartCount"); if($this.opts.remark){ cartCount.text(_AddCart.getCartCount($this.opts.remark.toCurrencyId)); }else{ cartCount.text(_AddCart.getCartCount()); } }else{ // $('.addcart-bar-buynow').attr('disabled',true).html(`<i class="loader-03"></i>`); submit($this.opts.barType===8 ? cartUrl : checkUrl); } }); this.container.append(this.btnConfirm); } if($this.opts.barType === 2 || $this.opts.barType === 5) { this.btnAddcart.text($this.lang("add_cart")); this.btnAddcart.click(function () { if(!judgeSkuSelected($this.opts)) return; if($this.opts.onAddCart && !$this.opts.onAddCart($this)){ return; } keyT = "addcart"; store.set('__gui_key', keyT, 3600000*24*10); if(!$this.opts.onlyAddTo){ submit(cartUrl); }else{ if(!$this.getData()) return false; } //åŠ è´æ•°æ® var cart_s = '<p class="add-cart-s"><i class="iconfont iconS-YG3"></i>' + $this.lang('success') + '</p>'; toast(cart_s); $this.container.removeClass("anim-up"); $this.opts.mask.removeClass("giikin-on"); //$this.opts.cartCountEle页é¢ä¸æ˜¾ç¤ºè´ç‰©è½¦æ•°æ® var cartCount = $this.opts.cartCountEle || $("#cartCount"); if($this.opts.remark){ cartCount.text(_AddCart.getCartCount($this.opts.remark.toCurrencyId)); }else{ cartCount.text(_AddCart.getCartCount()); } }); this.container.append(this.btnAddcart); } if($this.opts.barType === 3 || $this.opts.barType === 5) { this.btnBuynow.text(hasSkuStock ? $this.lang("buynow") : ($this.lang("empty_product") || 'Sold out, return to home page')); if($this.opts.barType === 3){ this.btnBuynow.attr("fb-type","purconfirm"); } this.btnBuynow.click(function () { if (!hasSkuStock) { form.attr('action', '/'); form.submit(); return; } if(!judgeSkuSelected($this.opts)) return; if($this.opts.onBuynow && !$this.opts.onBuynow($this)){ return; } $('.footer-btn .buynow').addClass('loading'); keyT = 'buynow'; store.set('__gui_key', keyT, 3600000*24*10); // $('.addcart-bar-' + keyT).attr('disabled',true).html(`<i class="loader-03"></i>`); submit(checkUrl); }); if(this.btnBuynowPosition){ this.container.prepend(this.btnBuynow); }else{ this.container.append(this.btnBuynow); } } if(!this.isInit){ $this.container.append(this.container); this.isInit = true; } }, reload: function (style) { $this.opts.barType = style; this.container.empty(); this.init(); }, canContinue: function() { return judgeSkuSelected($this.opts); } } this.addSpecs = function(pinfo, group, price, rule, number, rid){ var cs = new _CartSpec(this, pinfo, group, price, rule, number, rid); $(".addcart-spec-img").siblings("span").addClass("addcart-spec-noimg").siblings(".addcart-spec-img").removeClass("addcart-spec-noimg"); return cs; } this.changeGroupName = function(){ $(".addcart-specs-title-name").each(function(index, item){ $this.body.find(".addcart-specs-group.line1px").removeClass("line1px"); $this.body.find(".addcart-specs-group").last().addClass("line1px"); if($(this).parents(".addcart-specs-group").data("appendOther")) return; if($(this).siblings(".addcart-specs-title-number").size()>0) return; var n = index + 1; $(this).text($this.lang("no_x").replace("$X", n)); }); } this.showTip = function(msg, callback){ var tip = $("#saleTip"); if(tip.size()==0){ tip = $("<div id='saleTip' class='giikin-hide'/>"); var content = $("<div class='tip-content'>" + msg + "</div>"); var cb = $("<span>×</span>"); content.append(cb); tip.append(content); $('body').append(tip); cb.click(function(){ tip.removeClass("giikin-on"); return false; }); } tip.addClass("giikin-on"); tip.unbind(); tip.click(function(){ if(callback) callback(); }); } /* discount: 1,//1 商å“打折 fullAmountReduced: 2,//2 金é¢æ»¡å¤šå°‘å‡ä»€ä¹ˆä»· fullNumberReduced: 3,//3 商å“数满多少å‡å‡ 个 buyXGetX: 4,//4 ä¹°å‡ é€å‡ (åŒä¸€å•†å“ afterNumberPrice: 5,//5 ç¬¬å‡ ä»¶åŽä»€ä¹ˆä»· buyXGetY: 6,//6 ä¹°å‡ é€å‡ (ä¸åŒå•†å“) fullAmountGetX:7,// 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(åŒä¸€å•†å“) fullAmountGetY:8,// 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(ä¸åŒå•†å“) addAmountGetX:9,// åŠ å¤šå°‘é’±é€å‡ 个产å“(åŒä¸€ä¸ªå•†å“) addAmountGetY:10// åŠ å¤šå°‘é’±é€å‡ 个产å“(ä¸åŒå•†å“) */ this.promotion = function(){ var index = 0; function getDiscount(rule, price, total){ switch(rule.distype){ case Constant.DisCompRule.percent: return compDiscount1();break;//比例折扣 case Constant.DisCompRule.donate: return compDiscount2();break;//å•ä»¶å›ºå®šä»·æ ¼ case Constant.DisCompRule.money: return compDiscount3();break;//å•ä»¶å›ºå®šä»·æ ¼ } function compDiscount1(){ return parseInt(price*rule.value/100); } function compDiscount2(){ return rule.value; } function compDiscount3(){ return rule.value; } } function createGroup(ruleObject, price, onClose){ var group = $("<div class='addcart-specs-group'/>"); var closeGroup = $("<span class='addcart-specs-group-close'>×</span>"); group.attr("rule", ruleObject.config.rule); group.append(closeGroup); closeGroup.click(function(){ if(!group.data("appendOther")){ productIndex -= group.find(".addcart-specs:not(.image-list)").size(); } if($this.opts.onCloseGroup) $this.opts.onCloseGroup($(this), group); --index; if(onClose) onClose(); group.remove(); $this.header.changePrice(); $this.changeGroupName(); }); return group; } function changeNoopNumber(rule, group, f){ for(var i=0;i<rule.items.length;i++){ var r = rule.items[i]; var specs = group.find(".addcart-specs[data-='" + r.id + "#" + r.rule + "']"); var number = parseInt(specs.attr("data-number")); number = number - rule.value; if(number==0){ specs.remove(); }else{ specs.attr("data-number", number); specs.find(".addcart-specs-title-number").text("×" + number); } } var specs = group.find(".addcart-specs[data-option='" + $this.opts.data.id + "#0']"); var number = parseInt(specs.attr("data-number")); specs.attr("data-number", number); specs.find(".addcart-specs-title-number").text("×" + number); } //1 商å“打折 var DiscountRule = function(rule){ var $self = this; this.config = rule; this.decrease = function(){ } this.increase = function(){ } } //2 金é¢æ»¡å¤šå°‘å‡ä»€ä¹ˆä»· //3 商å“数满多少å‡å‡ 个 var FullReducedRule = function(rule, prom){ var $self = this; this.config = rule; this.change = function(){ //二次修改,满å‡ä¿ƒé”€å¯ä»¥å åŠ ä½¿ç”¨ if(prom != ''){ var reach=0; for(var r=0; r<prom.length;r++){ if($this.amount>= prom[r].reach && reach<prom[r].reach && prom[r].rule == 2){ reach=prom[r].reach; rule=prom[r]; } } } var offset = $this.amount - rule.reach; if(rule.rule != 2){ if(!this.desc){ this.desc = $("<div class='addcart-full-reduce'/>"); this.reduce = $("<span class='reduce-amount'/>"); this.desc.append(this.reduce); this.desc.append($("<span class='yhq'><span>" + $this.lang('again_buy') + Math.abs(offset) + $this.lang('able_reduce') + "<span class='red'>" + this.config.value + "</span>"+ $this.lang('able_reduce2') +"</span>")); // this.desc.insertBefore($this.footer.container); this.desc.insertBefore($this.quantity.container); } if(offset>=0){ //éš±è— this.desc.hide(); offset = rule.value; }else{ this.desc.show(); this.reduce.html('<em class="small-yuan yuan-l"></em>' + rule.name.replace('$offset', Math.abs(offset)) + '<em class="small-yuan yuan-r"></em>'); offset = 0; } }else{ if(!this.desc){ this.desc = $("<div class='addcart-full-reduce'/>"); this.reduce = $("<span class='reduce-amount'/>"); this.desc.append(this.reduce); var yhq = $("<span class='yhq yhq-buy'></span>"); this.desc.append(yhq); yhq.html("<span>" + $this.lang('again_buy') + ($this.opts.symbolBefore ? $this.opts.symbol + $.formatCurrency(Math.abs(offset)) : $.formatCurrency(Math.abs(offset)) + " " + $this.opts.symbol) + $this.lang('able_reduce') + "<span class='red'>" +($this.opts.symbolBefore ? $this.opts.symbol + $.formatCurrency(Math.abs(this.config.value)) : $.formatCurrency(Math.abs(this.config.value)) + " " + $this.opts.symbol) + "</span>") this.desc.insertBefore($this.body); } if(offset>=0){ //éš±è— offset = rule.value; $(".yhq").html("<span>" + $this.lang("already_buy").replace("$X", $this.opts.symbolBefore ? $this.opts.symbol + $.formatCurrency(Math.abs(rule.reach)) : $.formatCurrency(Math.abs(rule.reach)) + " " + $this.opts.symbol) + "</span>"+ "<span class='red already-minus'>" + $this.lang("already_minus").replace("$X", $this.opts.symbolBefore ? $this.opts.symbol + $.formatCurrency(Math.abs(offset)) : $.formatCurrency(Math.abs(offset)) + " " + $this.opts.symbol) + "</span>"); $(".yhq").removeClass("yhq-buy"); }else{ $(".yhq").html("<span>" + $this.lang('again_buy') +($this.opts.symbolBefore ? $this.opts.symbol + $.formatCurrency(Math.abs(offset)):($.formatCurrency(Math.abs(offset)) + " " + $this.opts.symbol)) + $this.lang('able_reduce') + "<span class='red'>" + ($this.opts.symbolBefore ? $this.opts.symbol + $.formatCurrency(Math.abs(this.config.value)):$.formatCurrency(Math.abs(this.config.value))+" " + $this.opts.symbol)+ "</span>"); offset = 0; } } return offset; } this.decrease = function(){ } this.increase = function(){ } } //5 ç¬¬å‡ ä»¶åŽä»€ä¹ˆä»· var AfterDiscountRule = function(rule){ var $self = this; this.config = rule; var block = $("<div class='addcart-float-buttons-block'/>"); var add = $("<button type='button' class='addcart-float-buttons-block-button ga-event' ga-src='tankuang' ga-type='tankuang-cuxiao'/>"); block.append(add); add.html(rule.name); if (rule.iconfont) { add.prepend('<i class="promotion-icon iconfont ' + rule.iconfont + '"></i>').addClass("has-icon"); } block.attr("data-id", rule.id); $this.buttons.container.append(block); $this.buttons.position = 2; $this.buttons.container.show(); block.click(function(e){ $self.increase(); var scrollHeight = $this.body.prop("scrollHeight"); $this.body.animate({scrollTop: scrollHeight + 'px'}, 300); }); // this.group = $(".addcart-specs-group.after-discount"); // if(this.group.size()==0){ // this.group = $("<div class='addcart-specs-group after-discount' />"); // } this.increase = function(){ productIndex = $(".addcart-specs").not(".addcart-gift").length == productIndex ? productIndex : $(".addcart-specs").not(".addcart-gift").length; if ($this.maxNum && $this.maxNum <= $this.quantity.PrimaryNumber) { return toast($this.lang('over_max')) } var price = $this.opts.data.finalPrice; var n = $this.quantity.PrimaryNumber + 1; // if(n >= rule.reach&&n<=rule.max) price = getDiscount(rule, price, 0); var hasBuyGet = false; // for(var i=0;i<$this.promotion.rules.length;i++){ // var r0 = $this.promotion.rules[i].config; // if(r0.rule==Constant.SaleRule.afterNumberPrice){ // hasBuyGet = true; // if(n>rule.max){ // $this.addSpecs($this.opts.data, this.group, price); // }else{ // $this.addSpecs($this.opts.data, this.group, price, rule, 1); // } // // $this.addSpecs($this.opts.data, this.group, price, rule, 1); // $this.quantity.changeNumber(1); // } // } var group = $(".addcart-specs-group.after-discount"); if(group.size()==0){ group = $("<div class='addcart-specs-group after-discount' />"); } var rules = []; var ruleArr = []; $this.promotion.rules.map(function(rule){ if(rule.config.rule == 5){ ruleArr.push(rule.config); } }) for (var i = 0; i < ruleArr.length; i++) { var current = ruleArr[i]; var next = ruleArr[i + 1]; if (next) { current.max = current.max >= next.reach ? next.reach - 1 : current.max; } rules.push(current); } var item = rules.find(function(rule) { return n >= rule.reach&&n<=rule.max }) if(item){ price = getDiscount(item, price, 0); hasBuyGet = true; $this.addSpecs($this.opts.data, group, price, rule, 1); $this.quantity.changeNumber(1) } if(!hasBuyGet){ var group = $(".addcart-specs-group.primary.first"); $this.addSpecs($this.opts.data, group, price); $this.quantity.changeNumber(1); } } this.decrease = function(){ var hasBuyGet = false; function decNum(g, id, gift, flag){ if($this.opts.hasOption){ if(id==$this.opts.data.id) productIndex--; g.find(".addcart-specs").last().remove(); }else{ var specs = g.find(".addcart-specs[data-option='" + id + "#" + gift + "']"); if(flag){ g.find(".addcart-specs").last().remove(); }else{ var number = parseInt(specs.attr("data-number")) - 1; if(number==0){ // specs.remove(); return; }else{ specs.attr("data-number", number); specs.find(".addcart-specs-title-number").text("×" + number); } } } } // for(var i=0;i<$this.promotion.rules.length;i++){ // var r0 = $this.promotion.rules[i].config; // if(r0.rule==Constant.SaleRule.afterNumberPrice){ // hasBuyGet = true; // decNum(this.group, $this.opts.data.id, 0); // $this.quantity.changeNumber(-1); // } // } var rules = []; var ruleArr = []; $this.promotion.rules.map(function(rule){ if(rule.config.rule == 5){ ruleArr.push(rule.config); } }) for (var i = 0; i < ruleArr.length; i++) { var current = ruleArr[i]; var next = ruleArr[i + 1]; if (next) { current.max = current.max >= next.reach ? next.reach - 1 : current.max; } rules.push(current); } var n = $this.quantity.PrimaryNumber; var item = rules.some(function(rule) { return n >= rule.reach && n <= rule.max; }) if(item){ hasBuyGet = true; var group = $(".addcart-specs-group.after-discount"); decNum(group, $this.opts.data.id, 0, true); $this.quantity.changeNumber(-1); } if(!hasBuyGet){ var group = $(".addcart-specs-group.primary.first"); decNum(group, $this.opts.data.id, 0, false); $this.quantity.changeNumber(-1); } } } //7 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(åŒä¸€å•†å“) 8 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(ä¸åŒå•†å“) var FullGetRule = function(rule){ var $self = this; this.config = rule; this.decrease = function(){ } this.increase = function(){ } } //4 ä¹°å‡ é€å‡ (åŒä¸€å•†å“ 6ä¹°å‡ é€å‡ (ä¸åŒå•†å“) var BuyGetRule = function(rule){ var $self = this; this.config = rule; this.group = $(".addcart-specs-group.primary"); this.endFlag = false; this.giftNumber = 0; this.giftOtherNumber = 0; this.increase = function(isInit){ if ($this.maxNum && $this.maxNum <= $this.quantity.PrimaryNumber) { return toast($this.lang('over_max')) } if($this.quantity.PrimaryNumber>=rule.max){ return; } var group = this.group; var n = $this.quantity.PrimaryNumber + 1; console.log(rule); if((n%rule.reach==0)){//是å¦åŠ èµ å“ if(!isInit){ if(rule.reach==1&&$this.opts.hasOption){ this.group = createGroup(this, $this.opts.data.finalPrice, function(){ $this.quantity.changeNumber(-1); if($self.giftNumber>0) $this.quantity.changeGiftNumber(-1*$self.giftNumber); if($self.giftOtherNumber>0) $this.quantity.changeGiftOtherNumber(-1*$self.giftOtherNumber); }); group = this.group; } $this.addSpecs($this.opts.data, group, $this.opts.data.finalPrice, rule, 1, 0); } var giftNumber = 0; var giftOtherNumber = 0; for(var i=0;i<rule.items.length;i++){ var r = rule.items[i]; if(r.id==$this.opts.data.id){ for(var j=0;j<rule.value;j++){ $this.addSpecs($this.opts.data, group, 0, rule); } giftNumber += rule.value; $this.quantity.changeGiftNumber(rule.value); }else{ // for(var j=0;j<r.giftNum;j++){ // $this.addSpecs(r, group, 0, rule); // } // giftOtherNumber += r.giftNum; // $this.quantity.changeGiftOtherNumber(r.giftNum); } } this.giftNumber = giftNumber; this.giftOtherNumber = giftOtherNumber; this.endFlag = true; }else if(!isInit){ if(this.endFlag&&$this.opts.hasOption){ this.group = createGroup(this, $this.opts.data.finalPrice, function(){ $this.quantity.changeNumber(-1*parseInt(rule.reach)); if($self.giftNumber>0) $this.quantity.changeGiftNumber(-1*$self.giftNumber); if($self.giftOtherNumber>0) $this.quantity.changeGiftOtherNumber(-1*$self.giftOtherNumber); }); this.endFlag = false; } $this.addSpecs($this.opts.data, this.group, $this.opts.data.finalPrice, rule); } $this.quantity.changeNumber(1); this.group.find(".addcart-specs-group-close").hide(); return 1; } this.decrease = function(){ var n = $this.quantity.PrimaryNumber; if(n%rule.reach==0){//是å¦å‡èµ å“ // console.log($this.opts); // console.log($this.opts.hasOption); if($this.opts.hasOption){ var group = this.group.prev(); if(rule.reach==1){ this.group.find(".addcart-specs-group-close").click(); }else{ $this.quantity.changeNumber(-1); productIndex--; this.group.remove(); } this.group = group; }else{ for(var i=0;i<rule.items.length;i++){ var r = rule.items[i]; var specs = this.group.find(".addcart-specs[data-option='" + r.id + "#1']"); if(specs.find(".addcart-specs-title-name").size()==0){ specs.last().remove(); }else{ var number = parseInt(specs.attr("data-number")); number = number - rule.value; if(number==0){ specs.remove(); }else{ specs.attr("data-number", number); if($this.opts.default){ if(r.id==$this.opts.data.id){ specs.find(".addcart-specs-title-name").text($this.lang("go_x").replace("$X",number) ); }else{ specs.find(".addcart-specs-size span").text(number); } }else{ specs.find(".addcart-specs-title-number").text("×" + number); } } } if(r.id==$this.opts.data.id){ $this.quantity.changeGiftNumber(-1*rule.value); }else{ // $this.quantity.changeGiftOtherNumber(-1*rule.value); } } var specs = this.group.find(".addcart-specs[data-option='" + $this.opts.data.id + "#0']"); var number = parseInt(specs.attr("data-number")); number = number - rule.value; specs.attr("data-number", number); if($this.opts.default){ specs.find(".text-space").text($this.lang("go_x").replace("$X", number)); }else{ specs.find(".addcart-specs-title-number").text("×" + number); } $this.quantity.changeNumber(-1); } }else{ if ($this.quantity.PrimaryNumber%rule.reach!=0) { $this.quantity.changeNumber(-1); this.group.find(".addcart-specs").last().remove(); productIndex--; return } $this.quantity.changeGiftNumber(-1*this.giftNumber); $this.quantity.changeGiftOtherNumber(-1*this.giftOtherNumber); if($this.opts.hasOption){ productIndex = productIndex - this.giftNumber; for(var i = 0;i <= this.giftNumber + this.giftOtherNumber; i++){ this.group.find(".addcart-specs").last().remove(); if(this.group.find(".addcart-specs").size()==0){ var group = this.group.prev(); this.group.remove(); this.group = group; this.endFlag = false; } } }else{ // for(var i=0;i<rule.items.length;i++){ // var r = rule.items[i]; // var specs = this.group.find(".addcart-specs[data-option='" + r.id + "#1']"); // if(specs.find(".addcart-specs-title-number").size()==0){ // specs.last().remove(); // }else{ // var number = parseInt(specs.attr("data-number")); // number = number - rule.value; // if(number==0){ // specs.remove(); // }else{ // specs.attr("data-number", number); // specs.find(".addcart-specs-title-number").text("×" + number); // } // } // } var specs = this.group.find(".addcart-specs[data-option='" + $this.opts.data.id + "#0']"); var number = parseInt(specs.attr("data-number")); number = number - rule.value; specs.attr("data-number", number); if($this.opts.default){ specs.find(".addcart-specs-title-number.text-space").text($this.lang("go_x".replace("$X",number))); }else{ specs.find(".addcart-specs-title-number").text("×" + number); } } $this.quantity.changeNumber(-1); } return 1; } this.increase(true); } //9 åŠ å¤šå°‘é’±é€å‡ 个产å“(åŒä¸€ä¸ªå•†å“) 10 åŠ å¤šå°‘é’±é€å‡ 个产å“(ä¸åŒå•†å“) var AddGetRule = function(rule){ var $self = this; var block = $("<div class='addcart-float-buttons-block'/>"); var add = $("<button type='button' class='addcart-float-buttons-block-button'/>"); var text = $("<div class='addcart-float-buttons-block-text'/>"); var tag = $("<div class='addcart-float-buttons-block-count'/>"); block.append(add); add.text(rule.name); if (rule.iconfont) { add.prepend('<i class="promotion-icon iconfont ' + rule.iconfont + '"></i>').addClass("has-icon"); } block.attr("data-id", rule.id); $this.buttons.container.append(block); $this.buttons.container.show(); this.config = rule; /*if($this.quantity.PrimaryNumber==0){ $this.quantity.changeNumber(1); }*/ tag.text(index); block.click(function(e){ var n = $this.quantity.PrimaryNumber + $this.quantity.AppendNumber if ($this.maxNum && $this.maxNum <= n) { return toast($this.lang('over_max')) } // let skuLength =$(".addcart-specs-content").length; // let activeLength =0; // $(".addcart-specs-content").each(function(){ // $(this).find("span").each(function(){ // if($(this).attr("class") && $(this).hasClass("active")){ // activeLength += 1; // } // }) // }) // if(activeLength !== skuLength){ // showMessage($this.lang("select_spce")); // return; // } if (!judgeSkuSelected($this.opts, false)) { return; }; var _price = rule.reach; if (n >= rule.max) { _price = $this.opts.data.finalPrice; } var appendNumber =0, appendOtherNumber = 0; tag.text(++index); var group = $(".addcart-specs-group.appends"); if($this.opts.hasOption||group.size()==0||rule.rule==Constant.SaleRule.addAmountGetY){ group = createGroup($self, _price, function(){ tag.text(index); if(appendNumber>0) $this.quantity.changeAppendNumber((-1)*rule.value); if(appendOtherNumber>0) $this.quantity.changeAppendOtherNumber((-1)*rule.value); }); if(!$this.opts.hasOption&&rule.rule==Constant.SaleRule.addAmountGetX) group.find(".addcart-specs-group-close").hide(); group.addClass("appends"); }else{ group.find(".addcart-specs-group-close").hide(); } if($self.productNumber==0) group.data("appendOther", true); var groupGiftCount = 0; var mainGiftCount = 0; var _cnt = 0, _giftCnt = 0; for(var i=0; i<rule.items.length;i++){ if(rule.items[i].price&&parseInt(rule.items[i].price)==0) continue; if(rule.items[i].id==$this.opts.data.id) _cnt += rule.value; if(rule.items[i].id!=$this.opts.data.id) _giftCnt += rule.value; } if(_cnt>0){ _price = _price/_cnt; }else{ _price = _price/_giftCnt; } if (n >= rule.max) { _price = $this.opts.data.finalPrice; } for(var i=0; i<rule.items.length;i++){ if(rule.items[i].id==$this.opts.data.id){ for(var j=0;j<rule.value;j++){ $this.addSpecs($this.opts.data, group, _price, rule); } $this.quantity.changeAppendNumber(rule.value); appendNumber += rule.value; }else{ if(rule.items[i].price&&parseInt(rule.items[i].price)==0) _price = 0; for(var j=0;j<rule.value;j++){ $this.addSpecs(rule.items[i], group, _cnt>0?0:_price, rule); } $this.quantity.changeAppendOtherNumber(rule.value); appendOtherNumber += rule.value; } } var scrollHeight = $this.body.prop("scrollHeight"); $this.body.animate({scrollTop: scrollHeight + 'px'}, 300); }); this.productNumber = 0; for(var i=0; i<rule.items.length;i++){ if(rule.items[i].id==$this.opts.data.id){ this.productNumber = rule.value; } } if(this.productNumber==0){ $this.buttons.position = 3; }else{ $this.buttons.position = 2; } this.rule = rule; this.increase = function(){ var n = $this.quantity.PrimaryNumber + $this.quantity.AppendNumber if ($this.maxNum && $this.maxNum <= n) { return toast($this.lang('over_max')) } if($this.quantity.PrimaryNumber>=rule.max){ return; } block.click(); return this.productNumber; } this.decrease = function(){ if($this.opts.hasOption||rule.rule==Constant.SaleRule.addAmountGetY){ var cls = ".addcart-specs-group[rule='" + rule.rule + "']"; $(cls).last().find(".addcart-specs-group-close").click(); }else{ var group = $(".addcart-specs-group.appends"); var specs = group.find(".addcart-specs");//[data-option='" + $this.opts.data.id + "#" + rule.rule + "']"); var number = parseInt(specs.attr("data-number")); number = number - rule.value; if(number==0){ group.find(".addcart-specs-group-close").click(); return; } specs.attr("data-number", number); if($this.opts.default){ specs.find(".text-space").text($this.lang("go_x").replace("$X", number)); }else{ specs.find(".addcart-specs-title-number").text("×" + number); } $this.quantity.changeAppendNumber((-1)*rule.value); } return this.productNumber; } } //11 12 æ†ç»‘促销 var Binding = function(rule){ var $self = this; this.config = rule; this.group = $(".addcart-specs-group.binding"); if(this.group.size()==0){ productIndex -= $(".addcart-specs-group.primary").find(".addcart-specs:not(.image-list)").size(); if(productIndex<0) productIndex = 0; --index; $this.quantity.changeNumber(-1); $(".addcart-specs-group.primary").remove(); this.group = $('<div class="addcart-specs-group binding"/>'); $this.body.append(this.group); } if(rule.nosuit == 3){ this.button = $('<button class="unava btn-binding" type="button"/>'); }else{ this.button = $('<button class="btn-binding" type="button"/>'); } var promDesc = rule.desc || rule.name; this.button.html(promDesc); // ä¿ƒé”€å›¾æ ‡ if (rule.iconfont) { this.button.prepend('<i class="promotion-icon iconfont ' + rule.iconfont + '"></i>').addClass("has-icon"); } if (rule.rule === 11 && window.__gk_tpl_path === 'SGKS_07') { var offsetBag = $('<div class="binding-bag" />'); var offsetPercent = Math.round(rule.reach / (rule.value * $this.opts.data.finalPrice) * 100); offsetBag.text(offsetPercent + "%"); // this.button.append(offsetBag); } $this.buttons.container.append(this.button); if(rule.nosuit=='') rule.nosuit = '0'; this.button.click(function(){ if($(this).hasClass("active")) return; if($(this).hasClass("unava")){ return; }; $(".btn-binding.active").removeClass("active"); $(this).addClass("active"); var noOption = ! $this.opts.data.options|| $this.opts.data.options.length==0 || $this.opts.data.skus.length <= 1; if(!$this.opts.default || ($this.opts.default && noOption )){ productIndex = 0;//$self.group.find(".addcart-specs").size(); } $this.quantity.changeNumber(-1*$this.quantity.PrimaryNumber); $this.quantity.changeGiftOtherNumber(-1*$this.quantity.GiftOtherNumber); var _price = rule.reach/parseInt(rule.value); if($this.opts.default){ if (rule.nosuit == '2' || rule.nosuit == '4') { $self.group.empty(); productIndex = 0; $this.addSpecs($this.opts.data, $self.group, _price, rule, rule.value); $(".addcart-specs-title-name.text-space").text($this.lang("go_x").replace("$X", rule.value)) } else { if(noOption){ $self.group.empty(); for(var j=0;j<rule.value;j++){ $this.addSpecs($this.opts.data, $self.group, _price, rule); } }else{ $self.group.find(".addcart-specs").each(function(){ if($(this).attr("data-gift")!= 1){ $(this).attr("data-price",_price); $(this).attr("data-prom",rule.id); } }) // let groupLen = $(".addcart-specs").length; let groupAll = $(".addcart-specs").filter((v,item)=>$(item).attr("data-id")== $this.opts.data.id && $(item).attr("data-gift") !=1); groupLen = groupAll.length; if(rule.value == 1 && groupLen < rule.value){ $self.group.empty(); var _price = rule.reach/parseInt(rule.value); for(var j=0;j<rule.value;j++){ $this.addSpecs($this.opts.data, $self.group, _price, rule); } }else if(groupLen < rule.value){ for(var j=0;j< rule.value - groupLen ;j++){ $this.addSpecs($this.opts.data, $self.group, _price, rule); } }else if(groupLen > rule.value){ let removeLen = groupLen - rule.value; for(var i = 1; i <= removeLen; i++){ $(groupAll[groupLen - i]).remove(); } productIndex = rule.value ; } } } }else{ $self.group.empty(); if (rule.nosuit == '2' || rule.nosuit == '4') { $this.addSpecs($this.opts.data, $self.group, _price, rule, rule.value); } else { for(var j=0;j<rule.value;j++){ $this.addSpecs($this.opts.data, $self.group, _price, rule); } } } $this.quantity.changeNumber(parseInt(rule.value)); var giftAll = $(".addcart-specs").filter((v,item)=>$(item).attr("data-id") != $this.opts.data.id); var giftLen = giftAll.length; for(var i=0; i<rule.items.length;i++){ if(rule.items[i].id!=$this.opts.data.id){ var noOptionGift = ! rule.items[i].options|| rule.items[i].options.length==0 || rule.items[i].skus.length <= 1; var giftNum = rule.items[i].giftNum ? rule.items[i].giftNum : 1; if(noOptionGift){ if(giftAll.length){ for(var j=0;j<giftAll.length;j++) { $(giftAll[i]).remove() } } for(var j=0;j<giftNum;j++) { $this.addSpecs(rule.items[i], $self.group, 0, rule); $this.quantity.changeGiftOtherNumber(1); } }else{ if(giftNum == 1 && giftLen < giftNum){ for(var j=0;j<giftNum;j++) { $this.addSpecs(rule.items[i], $self.group, 0, rule); $this.quantity.changeGiftOtherNumber(1); } }else if(giftLen < giftNum){ for(var j=0;j<giftNum -giftLen;j++) { $this.addSpecs(rule.items[i], $self.group, 0, rule); $this.quantity.changeGiftOtherNumber(1); } }else if(giftLen > giftNum){ var removeLen = giftLen - giftNum; for(var i = 1; i <= removeLen; i++){ $(giftAll[giftLen - i]).remove(); } } } } } if(rule.nosuit=='1'){ $self.group.append($("<span class='suit-desc'>" + rule.desc + "</span>")); } }); $this.quantity.container.hide();//éšè—æ•°é‡æŽ§åˆ¶æŒ‰é’® if(productIndex==0){ $this.buttons.container.insertBefore($this.body); var hadIsDef = $this.opts.data.promotion.find(v => v.rule == 11 && Number(v.isDef)) if (hadIsDef && hadIsDef.id == rule.id || (!hadIsDef && $(".btn-binding.active").size() <= 0)) { //ä¿®å¤é»˜è®¤ç¬¬äºŒä¸ª this.button.click(); } } this.increase = function(){ } this.decrease = function(){ } } var po = this.opts.data; if(!po.promotion) return; var prom = sort(po.promotion); if(prom.length>0) $this.quantity.PrimaryNumber = 0; this.promotion.rules = new Array(); for(var r=0; r<prom.length;r++){ prom[r].value = parseInt(prom[r].value); prom[r].rule = parseInt(prom[r].rule); prom[r].reach = parseFloat(prom[r].reach); var pdesc = $('.gk-promotion');//如果页é¢æœ‰ä¿ƒé”€è§„则æ述则显示促销å称 if(pdesc.length > 0){ var _name = prom[r].desc; if(!_name||_name=='null') _name = prom[r].name; if(_name&&_name!='null'){ pdesc.append($('<span class="promotion-desc"><i>' + this.lang('promtype_' + prom[r].rule) + '</i>' + _name + '</span>')); pdesc.show(); } } switch(prom[r].rule){ case Constant.SaleRule.discount: //1 商å“打折 this.promotion.discount = new DiscountRule(prom[r]); this.promotion.rules.push(this.promotion.discount); break; case Constant.SaleRule.fullAmountReduced: //2 金é¢æ»¡å¤šå°‘å‡ä»€ä¹ˆä»· this.promotion.fullAmountReduced = new FullReducedRule(prom[r],prom); this.promotion.rules.push(this.promotion.fullAmountReduced); break; case Constant.SaleRule.fullNumberReduced: //3 商å“数满多少å‡å‡ 个 this.promotion.fullNumberReduced = new FullReducedRule(prom[r]); this.promotion.rules.push(this.promotion.fullNumberReduced); break; case Constant.SaleRule.buyXGetX: //4 ä¹°å‡ é€å‡ (åŒä¸€å•†å“ this.promotion.buyXGetX = new BuyGetRule(prom[r]); this.promotion.rules.push(this.promotion.buyXGetX); break; case Constant.SaleRule.afterNumberPrice: //5 ç¬¬å‡ ä»¶åŽä»€ä¹ˆä»· this.promotion.afterNumberPrice = new AfterDiscountRule(prom[r]); this.promotion.rules.push(this.promotion.afterNumberPrice); break; // case Constant.SaleRule.buyXGetY: //6 ä¹°å‡ é€å‡ (ä¸åŒå•†å“) // this.promotion.buyXGetY = new BuyGetRule(prom[r]); // this.promotion.rules.push(this.promotion.buyXGetY); // break; case Constant.SaleRule.fullAmountGetX: //7 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(åŒä¸€å•†å“) this.promotion.fullAmountGetX = new FullGetRule(prom[r]); this.promotion.rules.push(this.promotion.fullAmountGetX); break; case Constant.SaleRule.fullAmountGetY: //8 金é¢æ»¡å¤šå°‘é€å‡ 个产å“(ä¸åŒå•†å“) this.promotion.fullAmountGetY = new FullGetRule(prom[r]); this.promotion.rules.push(this.promotion.fullAmountGetY); break; case Constant.SaleRule.addAmountGetX: //9 åŠ å¤šå°‘é’±é€å‡ 个产å“(åŒä¸€ä¸ªå•†å“) this.promotion.addAmountGetX = new AddGetRule(prom[r]); this.promotion.rules.push(this.promotion.addAmountGetX); break; case Constant.SaleRule.addAmountGetY: //10 åŠ å¤šå°‘é’±é€å‡ 个产å“(ä¸åŒå•†å“) this.promotion.addAmountGetY = new AddGetRule(prom[r]); this.promotion.rules.push(this.promotion.addAmountGetY); break; case Constant.SaleRule.bindingX: //11 åŒäº§å“æ†ç»‘ this.promotion.bindingX = new Binding(prom[r]); this.promotion.rules.push(this.promotion.bindingX); break; case Constant.SaleRule.bindingY: //12 æ†ç»‘(ä¸åŒå•†å“) this.promotion.bindingY = new Binding(prom[r]); this.promotion.rules.push(this.promotion.bindingY); break; } } } // 6ä¹°å‡ é€å‡ (ä¸åŒå•†å“) this.BuyXGetYRule = function(){ // this.promotion.BuyXGetYRule var po = $this.opts.data; if(!po.promotion || !po.promotion.length) return; var list = po.promotion.filter(function(rule) { return rule.rule == 6 }) if (!list.length) return; var PrimaryNumber = $this.quantity.PrimaryNumber + $this.quantity.AppendNumber + $this.quantity.GiftNumber list = list.filter(function(rule) { return rule.reach <= PrimaryNumber }) if (!list.length) { $(".addcart-specs[data-gift='1']").each(function() { if ($(this).attr('data-id') != $this.opts.data.id) { $(this).remove(); } }); return } list.sort(function(a,b) { return b.reach - a.reach }) var rule = list[0] var group = $(".addcart-specs-group.primary").length ? $(".addcart-specs-group.primary").eq(0) : $(".addcart-specs-group").eq(0); var giftOtherNumber = 0; var n = PrimaryNumber >= rule.max ? rule.max : PrimaryNumber; var giftNum = parseInt(n / rule.reach); if (giftNum <= 0) return; for(var i=0;i<rule.items.length;i++){ var r = rule.items[i]; if (rule.nosuit == 2 || r.skus.length === 1) { var number = r.giftNum * giftNum; if ($('.addcart-specs[data-id="'+ r.id +'"]').size()) { $('.addcart-specs[data-id="'+ r.id +'"]').attr('data-number', number); } else { $this.addSpecs(r, group, 0, rule, number); } // èµ å“æ•°é‡ä¸ºç©ºæ—¥å¿— if (number === null || number < 0) { customerApi.jsErrorLog({ logType: 'number_null', data: { primaryNumber: $this.quantity.PrimaryNumber, appendNumber: $this.quantity.AppendNumber, giftNumber: $this.quantity.GiftNumber, href: location.href, rule, data: $this.opts.data } }); } } else { var num = 0; $('.addcart-specs[data-id="'+ r.id +'"]').each(function () { num += Number($(this).attr('data-number')); }); var n = r.giftNum * giftNum - num; if (n < 0) { $('.addcart-specs[data-id="'+ r.id +'"]').each(function (i) { if (i >= r.giftNum * giftNum) { $(this).remove(); } }); } else { for(var j=0;j<n;j++){ $this.addSpecs(r, group, 0, rule); } } } giftOtherNumber += r.giftNum * giftNum; $(group).append($('.addcart-specs[data-id="'+ r.id +'"]')); } $this.quantity.changeGiftOtherNumber(giftOtherNumber); } this.show = function(style, animate){ if($this.opts.onShow && !$this.opts.onShow(this.container)) return; $this.opts.animate = animate || 'anim-up'; $this.bar.reload(style); $this.header.close.show(); // this.top = -1 * $(document).scrollTop(); var mLeft = -1 * ($(".body-box").width())/2; // $(".body-box").css({"position":"fixed","top":this.top,"left":"50%","right":0,"bottom":0,"margin-left":mLeft}); if($this.opts.displayDialog){ $this.opts.mask.addClass("giikin-on"); } $this.container.addClass($this.opts.animate); } this.hide = function(){ this.opts.mask.removeClass("giikin-on"); if($this.opts.onHide){ if($this.opts.onHide(this.container)){ return; } } this.top = $(".body-box").offset().top; // $(".body-box").css({"position":"static","margin-left":"auto","left":"auto"}); // $(document).scrollTop(-1 * this.top); this.container.removeClass($this.opts.animate); } this.destory = function(){ $this.container.remove(); $this.opts.mask.remove(); $this.opts.mask = null; } /** var product = {pid:1,skip:1, amount:100, number:5,"rules":[1,2], items:[{ "id": 1011, "price": 1200.00, "gift": 0, "number": 1, "append": 1, "poid": 1, "options":[{"id":1, "name":"颜色", "vid": 11, "vname":"黑色", "sort": 1},{"id":2, "name":"å°ºç ", "vid":"12","vname":"42","sort":2}] }]}; */ this.guid = function() { function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } var ms = (new Date()).getTime(); return (ms + S4() + S4() + S4()); } this.getData = function(composeFlag = false){ var nosel = false; // $(".addcart-specs-content dd").each(function(index, element) { // console.log($(this).find("span.active").size()); // if($(this).find("span").size()>0&&$(this).find("span.active").size()==0){ // showMessage($this.lang("nosel_spec") + $(this).prev("dt").text()); // nosel = true; // return; // } // }); if(nosel) return false; if($this.opts.form) $.storage($this.opts.form); var product = this.opts.data; var guid = this.opts.guid||this.guid(); //this.opts.guid = guid; var data = {"pid": product.id, "name": product.name, "amount": this.amount, "guid": guid, "poid":0, "rules":[], "items":[]}; /* if FakeSkus*/ if(product.fakeSkus && product.fakeSkus.length){ var __obj ={ "fakeSkus": product.fakeSkus, "skus": product.copySkus, "options": product.copyOpts } data = Object.assign(data,__obj); } /* end FakeSkus*/ // data.price = $.currencyCh(this.opts.data.finalPrice , this.opts.remark); data.price = this.opts.data.finalPrice; data.originPrice = this.opts.data.price; data.offset = 0; data.promotion = []; data.number = this.quantity.PrimaryNumber + this.quantity.AppendNumber + this.quantity.GiftNumber; // 金é¢ä¸ºç©ºæ—¥å¿— if (data.amount === null || data.amount < 0) { var money = 0; var error = null; var errorArr = []; try{ $(".addcart-specs").each(function() { var price = 0; var offset = 0; var n = 1; if ($(this).attr("data-price")) { price = parseFloat($(this).attr("data-price")); } if ($(this).attr("data-offset")) { offset = parseFloat($(this).attr("data-offset")); } if ($(this).attr("data-number")) { n = parseInt($(this).attr("data-number")); } if(price==0) offset = 0; money = accAdd(money, accMul(n, price + offset)); if (!$(this).attr("data-price") || !$(this).attr("data-offset") || !$(this).attr("data-number")) { errorArr.push({ id: $(this).attr("data-id") || null, price: $(this).attr("data-price")|| null, offset: $(this).attr("data-offset") || null, number: $(this).attr("data-number") || null }) } }); }catch(err){ error = err; } customerApi.jsErrorLog({ logType: 'amount_null', data: { money, error, errorArr, href: location.href, data: this.opts.data } }); } if(this.opts.skip==1){ data.skip = 1;//跳过主产å“,åªåŠ è´èµ å“ }else{ this.opts.cartCount += parseInt(this.quantity.number.val()); } if(this.opts.data.promotion){ var prom = sort(this.opts.data.promotion); for(var r=0; r<prom.length;r++){ data.rules.push(prom[r].id); data.promotion.push(prom[r]); //å¦‚æžœæ˜¯åŠ é’±å¾—ç¬¬äºŒä»¶ï¼Œå¯åœ¨è´ç‰©è½¦åŠ è´äº§å“ if(prom[r].rule==Constant.SaleRule.addAmountGetX || prom[r].rule==Constant.SaleRule.addAmountGetY || prom[r].rule==Constant.SaleRule.afterNumberPrice){ data.allowCartAdd = true; data.allowCartName = prom[r].name; var obj = {data: this.opts.data, lang: this.opts.lang, currency: this.opts.currency, symbol: this.opts.symbol, guid: this.opts.guid}; store.set(data.pid, obj); } } } this.container.find(".addcart-specs").each(function(index, item){ var p = {}; p.id = $(this).attr("data-id"); p.gift = 1; if($(this).hasClass("status-added")){ return; } p.price = parseFloat($(this).attr("data-price")); p.offset = $(this).attr("data-offset") ? parseInt($(this).attr("data-offset")) : 0; p.offsetPrice = $(this).attr("data-offset-price"); p.number = parseInt($(this).attr("data-number") ? $(this).attr("data-number") : "1"); p.rule = $(this).attr("data-rule")?$(this).attr("data-rule"):"0"; p.ruleId = $(this).attr("data-prom")?$(this).attr("data-prom"):"0"; if(p.price>0) p.gift = 0; if (p.gift && $(this).attr('data-giftShow')) { p.giftShow = $(this).attr('data-giftShow') } $this.opts.cartCount += p.number; if($(this).parent(".addcart-specs-group").attr("appends")){ p.append = 1; } p.options = []; var s = "", spec = ""; if($(this).hasClass("image-list")){ var sku = $(this).data("ov"); if(sku){ for(var u=0;u<sku.option.length;u++){ var opt = {}; var op = sku.option[u]; opt.id = op.pid; opt.name = op.pname; opt.vid = op.id; opt.vname = op.name; opt.sort = 0; s += opt.vid + "#"; spec += (op.name.trim() || op.id) + " "; p.options.push(opt); } } }else{ $(this).find(".active").each(function(index, item){ var opt = {}; // p.options = []; var dt = $(this).parent().prev("dt"); opt.id = dt.attr("data-id"); opt.number = $(this).parents('.addcart-specs').attr('data-number'); opt.name = dt.text(); opt.vid = $(this).attr("data-id"); opt.vname = $(this).text(); opt.sort = dt.attr("data-sort"); s += opt.vid + "#"; spec += (opt.vname.trim() || opt.vid) + " "; p.options.push(opt); }); } var pinfo = $(this).data("pinfo"); for(var j=0; j<pinfo.skus.length;j++){ var sku = pinfo.skus[j]; var flag = false; for(var k=0; k<sku.option.length;k++){ var f2 = false; var skuop = sku.option[k]; for(var i=0; i<p.options.length;i++){ if(skuop.id==p.options[i].vid){ f2 = true; if(skuop.image) p.image = skuop.image; if(skuop.details) p.details = skuop.details; break; } } if(!f2){ flag = false; break; }else{ flag = true; } } if(flag){ p.poid = sku.poid; break; } } if(!p.image) p.image = pinfo.image; if(p.poid==undefined) p.poid = 0; if(p.guid==undefined) p.guid = guidF(); p.price = p.price + p.offset; p.price = p.price.toFixed(2); p.name = pinfo.name; p.spec = spec; p.optvs = s; p.isBlindBox = $this.opts.data["isBlindBox"] ? $this.opts.data["isBlindBox"] : false; data.offset += p.offset * p.number; //åŠ è´§å¸ç¬¦å· p.symbol = $this.opts.symbol; if(subStock != -1){ p.subStock = product.subStock; } if ($(this).find('input[name="product-diy"]').length) { p.product_sku_diy = { image: '', content: '' }; $(this).find('input[name="product-diy"]').each(function(){ if($(this).attr('type') === 'file' && $(this).parent('.addcart-diy-upload').attr('data-image')) { p.product_sku_diy.image = $(this).parent('.addcart-diy-upload').attr('data-image'); } else if ($(this).val()) { p.product_sku_diy.content = $(this).val(); } }) } data.items.push(p); }); var items = []; for(var i=0;i<data.items.length;i++){ var isAdd = true; for(var j=0;j<items.length;j++){ if(data.items[i].id==items[j].id&&data.items[i].optvs==items[j].optvs&&data.items[i].rule==items[j].rule){ items[j].number += data.items[i].number; if (data.items[i].product_sku_diy) { items[j].product_sku_diy.content += items[j].product_sku_diy.content ? "%" + data.items[i].product_sku_diy.content : data.items[i].product_sku_diy.content; items[j].product_sku_diy.image += items[j].product_sku_diy.image ? "%" + data.items[i].product_sku_diy.image : data.items[i].product_sku_diy.image; } isAdd = false; } } //data.items[i].symbol = $this.opts.symbol; if(isAdd) items.push(data.items[i]); } //å•å“促销结算 // å˜å‚¨ç»„åˆå•†å“ if(composeFlag){ var selectSkus = ($.cookie("_select_skus_items")&& $.cookie("_select_skus_items").length) ? JSON.parse($.cookie("_select_skus_items")) : []; items.forEach(v=>v.fid = this.opts.data.fid) if(selectSkus.length){ items.forEach(function (item,i) { var index = selectSkus.findIndex(k=>k.id == item.id); if(index != -1){ selectSkus[index] = item; }else{ selectSkus.push(item); } }); }else{ selectSkus = [...items]; } $.cookie("_select_skus_items", JSON.stringify(selectSkus)); return false; } data.items = items; // data.items = items; data.promotion.map(function(v){ v.discount = 0; }); for(var i = 0 ; i < items.length ; i++){ var item = items[i]; data.rules = data.promotion.filter(function(v,i) { if(v.id == item.ruleId){ var discount = v.discount ? v.discount : 0; v.type = 'single'; v.pid = data.pid; v.discount = discount + Math.round((data.price - item.price) * item.number); } return v.id == item.ruleId; }); } var obj = $this.opts.form.find("input[name='data']"); if(obj.size()==0){ obj = $("<input type='hidden' name='data'>") $this.opts.form.append(obj); } var isCache = $this.opts.form.find("input[name='isCache']"); if(isCache.size()==0){ isCache = $("<input type='hidden' name='isCache'>") $this.opts.form.append(isCache); } var cacheVal = typeof templateCache != "undefined" ? templateCache : false; isCache.val(cacheVal); var d = JSON.stringify(data); obj.val(d); if($this.opts.remark){ $.addToCart(data,$this.opts.remark); }else{ $.addToCart(data); } return d; } // 判æ–组åˆå•†å“是å¦é€‰ä¸ this.selectComposite = function(){ if($("input[name='composition']").length && $("input[name='data-composite']").val()){ var data = JSON.parse($("input[name='data-composite']").val()); $("input[name='composition']").each(function(i,v){ if(!$(this).is(':checked')){ var fid = $(this).parents(".figure").data("pid"); $(this).parents(".figure").find(".product-item").each(function(k){ var id = $(this).attr("data-id"); var index = data.findIndex(k=>(k.id == id && k.fid == fid)) if(index != -1){ data.splice(index,1); } }) } }) return data; }else{ return [] } } this.processData = function(){ $(".addcart-specs[product-index='0']").find(".active").each(function(index, item){ var dt = $(this).parent().prev("dt"); var s = "options[" + dt.attr("data-id") + "]"; var opt = $this.opts.form.find("input[name='" + s + "']"); if(opt.size()==0){ opt = $("<input type='hidden' name='" + s + "'>"); $this.opts.form.append(opt); } opt.val($(this).attr("data-id")); var qty = $this.quantity.number.val(); $this.opts.form.find("input[name='qty']").val(qty); }); this.getData(); } this.header.init(); this.container.append(this.body); var group = $("<div class='addcart-specs-group primary first'/>"); this.opts.isComposite ? this.addSpecs(this.opts.data, group, this.opts.data.finalPrice,null,this.opts.data.quantity) : this.addSpecs(this.opts.data, group, this.opts.data.finalPrice); this.promotion(); this.quantity.init(); this.buttons.init(); this.footer.init(); this.bar.init(); if($this.quantity.PrimaryNumber==0) $this.quantity.PrimaryNumber = 1; this.quantity.changeTotal(); this.BuyXGetYRule(); this.judgeSkuSelected = judgeSkuSelected; } } function sort(arrayData){ if(!arrayData) return []; return arrayData.sort(function(a, b){ if(a.sort&&b.sort){ return parseInt(a.sort) - parseInt(b.sort); }else if(a.id&&b.id){ return parseInt(a.id) - parseInt(b.id); } return 0; }); } $.fn.addcart = function(options){ this.addc = new _AddCart(options, $(this)); return this.each(function(){ }); }; $.formatCurrency = function(money, symbol = '') { if (!money) { return money; } symbolStr = symbol ? symbol : symbolStr; var finalMoney = publiceFormatCurrency(money, symbolStr); money = money.toString().replace(/\$|\,/g,''); if (isNaN(money)){ money = '0'; }; var sign = (money == (money = Math.abs(money))); return ((sign ? '' : '-') + finalMoney); }; $.currencyCh = function(money,remark) { if(remark){ var sign = parseFloat(money); var rate = parseFloat(remark.rate); if(!rate) rate = 1; sign = sign.toString().replace(/\$|\,/g,''); sign = sign*parseFloat(rate); sign = Math.round(sign*(1+parseFloat(remark.offset))); } if(!sign){ sign = money; } return sign; } //åŠ è´æ•°æ® var addCartInfo = function(data){ var infoArr = {}; infoArr.params = store.get('__guid__params'); if(infoArr.params == null) infoArr.params ={}; infoArr.params = JSON.stringify(infoArr.params); //用户id var uId = $.cookie('_gkuid'); infoArr.uid = uId ? uId :""; var url = window.location.href; //链接 infoArr.url = url; infoArr.referrer = document.referrer; if(data){ infoArr.event_type = data.eventType; //商城Id infoArr.coll_id =data.collId; infoArr.currency_id = data.currencyId; if(data.saleIds) infoArr.sale_ids = data.saleIds; var ttStr = ['tankuangcart','tankuangbuynow','detailbuynow-confirm','detailcart-confirm']; if(ttStr.indexOf(data.eventType) !== -1){ infoArr.amount = data.amount; infoArr.quantity = data.number; infoArr.sale_ids = data.pid; var saleId = data.pid , saleIds = ''; for(var i = 0 ; i < data.items.length ; i++){ if(i != 0) saleIds += "," if(data.items[i].gift == 0) saleIds += saleId + "-" + data.items[i].poid; } infoArr.sale_sku_ids = saleIds; } } if(typeof pixelArr!="undefined"){ infoArr.pixel = pixelArr; } $.ajax({url:"/shopapi/v1/pixelEvent/pushEvent",type: 'post',data:infoArr,success:function(result){ console.log(result); }}); // return infoArr; } function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } $.showLoading = function(hasShowMask){ var loading = $("#loading"); if(loading.size()==0){ loading = $("<div id='loading'/>"); loading.html('<img src="/skin/frontend/yisainuo/wap/img/loading.gif"><p>loading</p>'); $('body').append(loading); } loading.show(); if(hasShowMask){ $(".addcart-mask").removeClass("giikin-on"); } } $.closeLoading = function(hasShowMask){ $("#loading").hide(); } _AddCart.addToCart = function(data,remark){ var cart = store.get('__gui_addcart'); var keyT = store.get('__gui_key'); if(cart==null) cart = []; /*var isadd = true; for(var i=0;i<cart.length;i++){ if(cart[i].pid==data.pid){ for(var j=0;j<cart[i].items.length;j++){ for(var m=0;m<data.items.length;m++){ if(cart[i].items[j].poid==data.items[m].poid&&cart[i].items[j].rule==data.items[m].rule){ cart[i].items[j].number = cart[i].items[j].number + data.items[m].number; isadd = false; } } } if(!isadd) { cart[i].amount += data.amount; cart[i].number += data.number; } } } if(isadd){ cart.push(data); }*/ if(remark){ data.currencyId = remark.toCurrencyId; } if(keyT=='buynow'){ store.set('__gui_buynow', data, 3600000*24*10); } if(!(cart instanceof Array)){ cart = [cart]; } //ç»Ÿè®¡åŠ è´æ•°æ® // if(keyT=='addcart'){ // var cartInfo = data; // if(!cartInfo.currencyId) cartInfo.currencyId = opts.remark.toCurrencyId; // addCartInfo(cartInfo); // } if(keyT != null && keyT != 'buynow'){ cart.push(data); store.set('__gui_addcart', cart, 3600000*24*10); } } _AddCart.getCartCount = function(curId){ var carts = store.get('__gui_addcart'); if(!carts) return 0; var number = 0; for(var i=0;i<carts.length;i++){ if(curId){ if(carts[i].currencyId != curId) continue; } number += carts[i].number; } return number; } _AddCart.promotion = function(amount, pcode, opts, carts){ var guid = function() { function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } var ms = (new Date()).getTime(); return (ms + S4() + S4() + S4()); } var now = '2019-11-01'; try{ now = Util.dateFormat(); if (typeof(cartProm) == "undefined") return {'discount': 0, 'items': []}; }catch (e){ return {'discount': 0, 'items': []}; } if(!(carts instanceof Array)) carts = [carts]; for (var i = 0; i < carts.length; i++) { var v = carts[i]; if (v.amount == 0 && !canNotAmount(v)) { carts.splice(i, 1); i--; } } function canNotAmount(cart) { if (!cart.rules || !cart.rules.length) { return false } var flag = false; cart.rules.forEach(function(v) { if (v.rule == 11) { flag = true; } }) return flag; } var number = 0; for(var i=0;i<carts.length;i++) { if(opts.remark){ if(carts[i].currencyId && carts[i].currencyId != opts.remark.toCurrencyId) continue; } number += carts[i].number; } var discount = 0, items = [], promType = 'site' ,mj = 0, mjId = 0, mjs = {}, mjType = 'site' , mz = 0 , mzId = 0 , mzType = 'site' ,coupons = 0, yf = 0, mzs = {}, jz =0 , jzId = 0 , jzs = {} , jzType = 0 , code = [], msg = ''; var temp = amount; var yfList = [],promList = [],mzList = [], yfBuyNumList = []; cartProm = cartProm.filter(v => { var nowTime = new Date(); return (nowTime >= new Date(v.start.replace(/-/g,'/'))) && (nowTime <= new Date(v.end.replace(/-/g,'/'))); }); cartProm.map(function(v){ if(v.rule == 22){ yfList.push(v); } else if (v.rule == 8) { mzList.push(v) } else if (v.rule == 30) { yfBuyNumList.push(v) } else{ promList.push(v); } }) promList = promList.sort(Objectcompare("reach")); for (var i = 0; i < promList.length; i++) { var noa = 0; promType = 'site'; if(promList[i].items && promList[i].items.length>0 && carts){ for(var j=0; j<carts.length; j++) { if (promList[i].items.indexOf(carts[j].pid) != -1){ noa += carts[j].amount; } } } if(promList[i].isActivity) promType = 'activity'; if(promList[i].items.length > 0) amount = noa; // if(amount == 0){ // amount = temp; continue; // } // if(promList[i].start > now || promList[i].end < now) continue; if(promList[i].rule==20){//全场满å‡ï¼ˆé‡‘é¢ï¼‰ var stayCouponValue = 0; var disc = parseInt(promList[i].value); if(amount >= parseInt(promList[i].reach)){ coupons= disc; if(disc > mj){ mjs = promList[i].name; mjId = promList[i].id; mj = disc; mjType = promType; if(!opts.singlePay && opts.singleFull){ if (stayCouponParams && stayCouponParams.value) { stayCouponValue = Math.round(stayCouponParams.value); } if(opts.symbol){ if(opts.symbolBefore){ $(".checkout-coupon").html(opts.symbol+$.formatCurrency(promList[i].value + stayCouponValue)).attr("cur-data",promList[i].value + stayCouponValue); }else{ $(".checkout-coupon").html($.formatCurrency(promList[i].value + stayCouponValue)+" " +opts.symbol).attr("cur-data",promList[i].value + stayCouponValue); } }else{ $(".checkout-coupon").html(promList[i].value).attr("cur-data",promList[i].value); } $("#checkout-coupon").removeClass("hide"); // $(".addcart-full-reduce").remove(); if($(".yhq").length){ var minusNum = parseInt($(".yhq .red").text().match(/\d+/g)[0]) if(disc >= minusNum){ $(".yhq").html("<span>" + opts.lang["addcart_already_buy"].replace("$X", opts.symbolBefore ? opts.symbol + $.formatCurrency(promList[i].reach) : $.formatCurrency(promList[i].reach) + " " + opts.symbol) + "</span>"+ "<span class='red already-minus' >" + opts.lang["addcart_already_minus"].replace("$X", opts.symbolBefore ? opts.symbol + $.formatCurrency(disc) : $.formatCurrency(disc) + " " + opts.symbol) + "</span>"); } }else{ this.desc = $("<div class='addcart-full-reduce'/>"); this.reduce = $("<span class='reduce-amount'/>"); this.desc.append(this.reduce); var yhq = $("<span class='yhq'></span>"); this.desc.append(yhq); yhq.html("<span>" + opts.lang["addcart_already_buy"].replace("$X", opts.symbolBefore ? opts.symbol + $.formatCurrency(promList[i].reach) : $.formatCurrency(promList[i].reach) + " " + opts.symbol) + "</span>"+ "<span class='red already-minus' >" + opts.lang["addcart_already_minus"].replace("$X", opts.symbolBefore ? opts.symbol + $.formatCurrency(disc) : $.formatCurrency(disc) + " " + opts.symbol) + "</span>"); this.desc.insertBefore($(".addcart-body")); } $(".yhq").removeClass("yhq-buy"); } } }else{ if(opts&&opts.onPromotion){ if(!opts.singlePay && opts.singleFull){ $("#checkout-coupon").addClass("hide"); } opts.onPromotion(promList[i], amount, parseInt(promList[i].reach),opts.singlePay); } } }else if(promList[i].rule==21){//全场满å‡ï¼ˆæŠ˜æ‰£ï¼‰ if(amount >= parseInt(promList[i].reach)){ var disc = amount * (1 - parseFloat(promList[i].value)/100); if(disc > mz){ mzs = promList[i].name; mzId = promList[i].id; mz = disc; mzType = promType; } }else{ if(opts&&opts.onPromotion) opts.onPromotion(promList[i], amount, parseFloat(promList[i].reach)); } }else if(promList[i].rule==25){//全场满å‡ï¼ˆæŠ˜æ‰£ï¼‰ if(number >= parseFloat(promList[i].reach)){ var disc = amount * (1 - parseFloat(promList[i].value)/100); if(disc > jz){ jzs = promList[i].name; jzId = promList[i].id; jz = disc; jzType = promType; } }else{ if(opts&&opts.onPromotion) opts.onPromotion(promList[i], amount, parseFloat(promList[i].reach) , number); } } else if (stayCouponParams && stayCouponParams.value) { var stayCouponValue = Math.round(stayCouponParams.value); $("#checkout-coupon").removeClass("hide"); if(opts.symbol){ if(opts.symbolBefore){ $(".checkout-coupon").html(opts.symbol+$.formatCurrency(stayCouponValue)).attr("cur-data", stayCouponValue); }else{ $(".checkout-coupon").html($.formatCurrency(stayCouponValue)+" " +opts.symbol).attr("cur-data", stayCouponValue); } } } amount = temp; } if(!promList.length && stayCouponParams && stayCouponParams.value) { var stayCouponValue = Math.round(stayCouponParams.value); $("#checkout-coupon").removeClass("hide"); if(opts.symbol){ if(opts.symbolBefore){ $(".checkout-coupon").html(opts.symbol+$.formatCurrency(stayCouponValue)).attr("cur-data", stayCouponValue); }else{ $(".checkout-coupon").html($.formatCurrency(stayCouponValue)+" " +opts.symbol).attr("cur-data", stayCouponValue); } } } if(opts.tip){ opts.tip(msg); } if(mj > 0 && (opts.singlePay && opts.singleFull) || !opts.singleFull) { discount += mj; items.push({'name': mjs, 'discount': mj , 'rule': 20 , 'id': mjId , 'type': mjType}); } if(mz > 0) { discount += mz; items.push({'name': mzs, 'discount': mz, 'rule': 21, 'id': mzId , 'type': mzType}); } if(jz > 0) { discount += jz; items.push({'name': jzs, 'discount': jz, 'rule': 25, 'id': jzId , 'type': jzType}); } if(mzList.length){ amount -= discount; mzList.sort(function(a,b){ return a.reach - b.reach; }) var currentMz = mzList.filter(function (v) { return parseFloat(v.reach) <= amount }) if(currentMz.length){ currentMz.sort(function(a,b){ return b.reach - a.reach }); var giftNum = currentMz[0].value; var gift = currentMz[0].items ? currentMz[0].items[0] ? currentMz[0].items[0] : null : null; if(gift){ var optvs = "", spec = "", sku = {}; for(var i = 0; i < gift.skus.length; i++){ if(gift.skus[i].stock){ sku = gift.skus[i]; break; } } var options = sku.option.map(function(v){ optvs += (v.id + "#"); spec += (v.name + " ") return { id:v.pid, name:v.pname, vid:v.id, vname:v.name, sort:0 } }); var giftItem = { "id": gift.id, "gift": 1, "price": "0.00", "offset": 0, "number": giftNum, "rule": "8", "options": options, "poid": sku.poid, "image": gift.image, "name": gift.name, "spec": spec, "optvs": optvs } var item = { amount:0, guid: guid(), name: gift.title, number: giftNum, pid: gift.id, price: 0, items: [giftItem] } carts.push(item); if(opts.onGiftPromotion) opts.onGiftPromotion(currentMz[0],carts) var ruleIndex = items.findIndex(function (item) { return item.rule == 8; }) if (ruleIndex > -1) { items.splice(index, 1, { 'name': currentMz[0].name, 'id': currentMz[0].id, 'discount': 0, 'rule': 8, 'type': promType }) } else { items.push({ 'name': currentMz[0].name, 'id': currentMz[0].id, 'discount': 0, 'rule': 8, 'type': promType }); } } // if (opts && opts.onPromotion) opts.onPromotion(currentMz[0], amount, parseFloat(currentMz[0].reach)); if(currentMz.length < mzList.length){ if (opts && opts.onPromotion) opts.onPromotion(mzList[currentMz.length], amount, parseFloat(mzList[currentMz.length].reach)); } }else{ if (opts && opts.onPromotion) opts.onPromotion(mzList[0], amount, parseFloat(mzList[0].reach)); } amount = temp; } if(yfList.length){ yfList.sort(function (a, b) { return parseFloat(a.reach) - parseFloat(b.reach); }) var currentYf = yfList.filter(function (v) { return parseFloat(v.reach) > amount; }) if (currentYf.length) { currentYf.sort(function (a, b) { return parseFloat(a.reach) - parseFloat(b.reach); }) var disc = parseFloat(currentYf[0].value); yf = disc; discount -= disc; var index = items.findIndex(function (item) { return item.rule == 22; }) if (index > -1) { items.splice(index, 1, { 'name': currentYf[0].name, 'id': currentYf[0].id, 'discount': disc, 'rule': 22, 'type': promType }) } else { items.push({ 'name': currentYf[0].name, 'id': currentYf[0].id, 'discount': disc, 'rule': 22, 'type': promType }); } var yfM = currentYf[0]; if (opts && opts.onPromotion) opts.onPromotion(currentYf[0], amount, parseFloat(currentYf[0].reach)); } amount = temp; } else if (yfBuyNumList.length) { yfBuyNumList.sort(function (a, b) { return parseFloat(a.reach) - parseFloat(b.reach); }) var currentYf = yfBuyNumList.filter(function (v) { return parseFloat(v.reach) > number; }) $(".piece-reduce").remove(); if (currentYf.length) { currentYf.sort(function (a, b) { return parseFloat(a.reach) - parseFloat(b.reach); }) var disc = parseFloat(currentYf[0].value); yf = disc; discount -= disc; var index = items.findIndex(function (item) { return item.rule == 30; }) if (index > -1) { items.splice(index, 1, { 'name': currentYf[0].name, 'id': currentYf[0].id, 'discount': disc, 'rule': 30, 'type': promType }) } else { items.push({ 'name': currentYf[0].name, 'id': currentYf[0].id, 'discount': disc, 'rule': 30, 'type': promType }); } var yfM = currentYf[0]; if (opts && opts.onPromotion) opts.onPromotion(currentYf[0], number, parseFloat(currentYf[0].reach)); } amount = temp; } discount = discount > amount ? amount : discount; return {'discount': discount, 'yf': yf, 'coupons':coupons, 'items': items}; } _AddCart.checkout = function(cart, opts){ var number = 0, amount = 0, total = 0, originTotal = 0; if($("input[name='compositionPrice']").length){ amount = total = $("input[name='compositionPrice']").val()/1; number = $("input[name='compositionNum']").val()/1 } var carts = cart; if(opts.remark && cart instanceof Array){ cart = carts.filter(function (x) { return (!x.currencyId || x.currencyId == opts.remark.toCurrencyId); }); } var hasDiyProduct = cart.some(v=>v.items.some(item=>item.product_sku_diy)) if(hasDiyProduct) { hideCodPayment(); } if(cart instanceof Array){ for(var i=0;i<cart.length;i++){ number += cart[i].number; amount += cart[i].amount; total += cart[i].number*cart[i].price; originTotal += cart[i].number*cart[i].originPrice; if(cart[i].offset) total += cart[i].offset; } }else{ number += cart.number; amount += cart.amount; total += cart.number*cart.price; originTotal += cart[i].number*cart[i].originPrice; if(cart.offset) total += cart.offset; carts = [cart]; } var proms = _AddCart.promotion(amount, null, opts, carts); if(opts.number){ opts.number.text(number); $('.footer-btn .total-pieces').length && $('.footer-btn .total-pieces').text(number); if ($(".footer-btn .piece .singular-piece").length) { $(".footer-btn .piece span.num").html(number); if(typeof languageId !== 'undefined' && languageId == '9'){ if (number > 2) { $(".footer-btn .piece .singular-piece").hide(); $(".footer-btn .piece .two-piece").addClass('hide'); $(".footer-btn .piece .pular-piece").removeClass('hide'); } else if (number > 1){ $(".footer-btn .piece .singular-piece").hide(); $(".footer-btn .piece .two-piece").removeClass('hide'); $(".footer-btn .piece .pular-piece").addClass('hide'); } else { $(".footer-btn .piece .singular-piece").show(); $(".footer-btn .piece .two-piece").addClass('hide'); $(".footer-btn .piece .pular-piece").addClass('hide'); } } } else { $(".footer-btn .piece span").html(number); } } //已使用的促销 if (opts.promItemsFun) opts.promItemsFun(proms.items,total,number); if(opts.symbol){ symbolStr= opts.symbol; if(opts.total){ opts.total.attr("cur-data",total); if(opts.symbolBefore){ opts.total.html(opts.symbol + ' ' + $.formatCurrency(total)); }else{ opts.total.html($.formatCurrency(total)+" "+opts.symbol); } } if(opts.yf){ if(opts.symbolBefore){ opts.yf.html(opts.symbol + ' ' + $.formatCurrency(proms.yf)) }else{ opts.yf.html($.formatCurrency(proms.yf)+" "+opts.symbol) } } if(opts.symbolBefore){ opts.amount.html(opts.symbol + ' ' + $.formatCurrency(amount - proms.discount)) }else{ opts.amount.html($.formatCurrency(amount - proms.discount)+" "+opts.symbol) } opts.amount.attr("data-value", amount).attr("cur-data",(amount - proms.discount)); var dism = proms.discount; var discountTotal = dism + total - amount + proms.yf; if (discountTotal <= 0) { $('.discount-total').hide() } if(opts.symbolBefore){ opts.discount.html(opts.symbol + ' ' + $.formatCurrency(discountTotal)) }else{ opts.discount.html($.formatCurrency(discountTotal)+" "+opts.symbol) } opts.discount.attr("data-value", total - amount).attr("cur-data",(discountTotal)); if(opts.onlineSaveArr && opts.onlineSaveFun) opts.onlineSaveFun(amount); }else{ if(opts.total){ opts.total.text($.formatCurrency(total)); } if(opts.yf){ opts.yf.text($.formatCurrency(proms.yf)); } opts.amount.text($.formatCurrency(amount - proms.discount)); opts.amount.attr("data-value", amount); var dism = proms.discount; opts.discount.text($.formatCurrency(dism + total - amount + proms.yf)); opts.discount.attr("data-value", total - amount); } if($('.cart-toatal-item .checkout-off').length) { var discountOff = Math.round((originTotal - (amount - proms.discount)) / originTotal * 100); if (discountOff) { $('.cart-toatal-item .checkout-off').html(`${discountOff}%OFF`); } else { $('.cart-toatal-item .checkout-off').remove(); } } if(opts.serviceCharge || opts.onlineSave || opts.payOnlineFree || opts.onlineSaveArr || opts.onlineService){ if(typeof opts.onlineSave == "undefined") opts.onlineSave=0; if(typeof opts.onlineService == "undefined") opts.onlineService=0; opts.payment = opts.payment || $("input[name='payment']"); opts.iCharge = opts.iCharge || $("input[name='service_charge']"); opts.eCharge = opts.eCharge || $("#eServiceCharge"); opts.eCoupon = opts.eCoupon || $(".chechout-coupon"); var showServiceCharge = function (hasCharge) { var charge = hasCharge ? opts.serviceCharge : Number(opts.onlineSave) + Number(opts.onlineService); var coupon = opts.eCoupon ? opts.eCoupon.attr('data-value') : 0; coupon = coupon ? parseInt(coupon) : 0; opts.iCharge.val(charge); opts.amount.text($.formatCurrency(amount - proms.discount + charge - coupon)); opts.eCharge.html($.formatCurrency(charge)); if(hasCharge){ opts.eCharge.closest("li").removeClass("hide"); }else{ opts.eCharge.closest("li").addClass("hide"); } } var pm = opts.payment.filter(':checked').val(); if(pm == "1"){ showServiceCharge(true); } opts.payment.change(function(){ showServiceCharge($(this).val()=="1"); if(opts.onPaymentChange) opts.onPaymentChange($(this).val()); }); } opts.onFreightChange(proms.yf); return proms.discount; } _AddCart.loadCart = function (opts) { var cart = store.get('__gui_addcart'); if(cart==null) cart = []; var number = 0, amount = 0, total = 0; for(var i=0;i<cart.length;i++){ if(opts.remark){ if(cart[i].currencyId && cart[i].currencyId != opts.remark.toCurrencyId) continue; } var li = $("<li class=\"cart-block\"/>"); var title = $("<div class='title'></div>"); var btndel = $("<span data-id=\"" + cart[i].guid + "\">" + opts.delbtn + "</span>"); var check = $("<label class=\"check\"> <i class=\"iconfont icon-duigou\"></i></label>"); if(!cart[i].offset) cart[i].offset = 0; check.attr("data-id", cart[i].guid); check.attr("data-number", cart[i].number); check.attr("data-amount", cart[i].amount); check.attr("data-discount", cart[i].price*cart[i].number + cart[i].offset - cart[i].amount); check.click(function () { if(opts.onCheckItem){ if(opts.onCheckItem(li)) return; } $(this).toggleClass('check'); var syml = -1; if($(this).hasClass("check")){ var syml = 1; } var n = parseInt(opts.number.attr("data-value")) + (syml)*parseInt($(this).attr("data-number")); var a = parseFloat(opts.amount.attr("data-value")) + (syml)*parseFloat($(this).attr("data-amount")); var d = parseFloat(opts.discount.attr("data-value")) + (syml)*parseFloat($(this).attr("data-discount")); var carts = []; for(var j=0;j<cart.length;j++){ if(li.parent().find('label[data-id="' + cart[j].guid + '"]').hasClass("check")){ carts.push(cart[j]); } } var proms = _AddCart.promotion(a, null, opts, carts); opts.proms = proms; opts.number.text(n); opts.number.attr("data-value", n); var total = a - proms.discount; if(a==0) total = 0; opts.amount.attr("data-value", a); var dis0 = proms.discount + d + proms.yf; if(dis0 < 0) dis0 = 0; opts.discount.attr("data-value", d); if(opts.symbol){ if(opts.total) opts.total.text(opts.symbol+$.formatCurrency(a + d)).attr("cur-data",a + d); if(opts.yf) opts.yf.text(opts.symbol+$.formatCurrency(proms.yf)).attr("cur-data",proms.yf); opts.amount.text(opts.symbol+$.formatCurrency(total)).attr("cur-data",total); opts.discount.text(opts.symbol+$.formatCurrency(dis0)).attr("cur-data",dis0); }else{ if(opts.total) opts.total.text($.formatCurrency(a + d)); if(opts.yf) opts.yf.text($.formatCurrency(proms.yf)); opts.amount.text($.formatCurrency(total)); opts.discount.text($.formatCurrency(dis0)); } if(opts.onCheckChange){ opts.onCheckChange(); } //if(proms.discount < 1) opts.discount.hide(); }) btndel.click(function () { // if(!confirm(opts.deltip)){ // return; // } var confirmBtn = $(this); if($.isPlainObject(opts.deltip)){ Confirm(opts.deltip.confirm,opts.deltip.ok,opts.deltip.cancal,function(){ var li = confirmBtn.parents(".cart-block"); var carts = []; var label = li.find("label"); if(label.hasClass('check')){ label.click(); } li.remove(); $.removeCart([confirmBtn.attr("data-id")]); if(opts.onRemoveItem) opts.onRemoveItem(li); },function(){ return; }) }else{ if(!confirm(opts.deltip)){ return; } var li = confirmBtn.parents(".cart-block"); var carts = []; var label = li.find("label"); if(label.hasClass('check')){ label.click(); } li.remove(); $.removeCart([confirmBtn.attr("data-id")]); if(opts.onRemoveItem) opts.onRemoveItem(li); } }); number += cart[i].number; amount += cart[i].amount; total += cart[i].number*cart[i].price + cart[i].offset; title.append(check); title.append(btndel); li.append(title); //cart[i].price = Math.round(cart[i].price); var item = $("<div class=\"sku-container\">"); var html = template("sku-item", cart[i]); item.html(html); li.append(item); if(cart[i].allowCartAdd && opts.onCartAddTo){ opts.onCartAddTo(cart[i], li); } opts.container.append(li); li.find('a.sku-link').each(function(index, item){ try{ var sno = $(this).attr('data-id'); if(opts.isStatic && opts.collId){ var href = getDetailUrl(sno, opts.isStatic, opts.collId); }else{ if(sno) sno = Base64.encode(sno); var href = $(this).attr('data-link'); if(href.lastIndexOf('&') != href.length - 1) href += '&'; href += 'sno=' + sno; } $(this).attr('href', href); }catch(e){console.log(e);} }); li.find('img.sku-img').each(function(index, item){ try{ var src = $(this).attr('data-src') var cdn = $(this).attr('data-cdn'); if(src.indexOf('http') == -1) src = cdn + src; $(this).attr('src', src); }catch(e){} }) } if(opts.onRender) opts.onRender(opts.container); var proms = _AddCart.promotion(amount, null, opts, cart); opts.proms = proms; opts.number.text(number); opts.number.attr("data-value", number); var t = amount - proms.discount; if(amount==0) t = 0; opts.amount.attr("data-value", amount); var dism = proms.discount; dism = dism + total - amount + proms.yf; if(dism < 0) dism = 0; opts.discount.attr("data-value", total - amount); if(opts.symbol){ var amountText = opts.symbolBefore ? opts.symbol+$.formatCurrency(t) : $.formatCurrency(t,opts.symbol) + `<b>${opts.symbol}</b>`; var discountText = opts.symbolBefore ? opts.symbol+$.formatCurrency(dism) : $.formatCurrency(dism,opts.symbol) + `<b>${opts.symbol}</b>`; if(opts.total) opts.total.text(opts.symbol+$.formatCurrency(total)).attr("cur-data",total); if(opts.yf) opts.yf.text(opts.symbol+$.formatCurrency(proms.yf)).attr("cur-data",proms.yf); // opts.amount.text(opts.symbol+$.formatCurrency(t)).attr("cur-data",t); // opts.discount.text(opts.symbol+$.formatCurrency(dism)).attr("cur-data",dism); opts.amount.html(amountText).attr("cur-data",t); opts.discount.html(discountText).attr("cur-data",dism); }else{ if(opts.total) opts.total.text($.formatCurrency(total)); if(opts.yf) opts.yf.text($.formatCurrency(proms.yf)); opts.amount.text($.formatCurrency(t)); opts.discount.text($.formatCurrency(dism)); } } _AddCart.removeCart = function (guids) { var cart = store.get('__gui_addcart'); if (cart == null) cart = []; if(cart instanceof Array){ var tmp = []; for(var i=0;i<cart.length;i++){ var isRemove = false; for(var j=0;j<guids.length;j++){ if(cart[i].guid == guids[j]){ isRemove = true; break; } } if(!isRemove){ tmp.push(cart[i]); } } store.set('__gui_addcart', tmp, 0); }else{ store.remove('__gui_addcart'); } } // 判æ–是å¦é€‰ä¸è§„æ ¼ function judgeSkuSelected(opts, jump = true){ var flag = true; var scrollTop = 0; var toastIndex = 0; $(".addcart-specs-group").each(function () { $(this).find(".addcart-specs").each(function () { var hasNoSel = true; $(this).find(".addcart-specs-content").each(function () { var skuSelected = false; $(this).find("span").each(function () { skuSelected = skuSelected || $(this).hasClass('active'); }) if (!skuSelected ) { hasNoSel = skuSelected; $(this).addClass("no-select-content"); toastIndex = 1; scrollTop = scrollTop || $(this).offset().top; } }) var hasDiyInfo = true; if($(this).find('.addcart-diy').length) { hasDiyInfo = false; $(this).find('.addcart-diy input[name="product-diy"]').each(function(){ if($(this).attr('type') === 'file') { hasDiyInfo = hasDiyInfo || $(this).parents('.addcart-diy-upload').attr('data-image'); } else { hasDiyInfo = hasDiyInfo || $(this).val(); } }) if(!hasDiyInfo) { $(this).find('.addcart-diy').addClass("no-select-content"); toastIndex = toastIndex || 2; scrollTop = scrollTop || $(this).offset().top; } } if(!hasNoSel || !hasDiyInfo){ $(this).addClass("no-select"); flag = false; return false; } }) }) if (scrollTop) { toastIndex === 1 ? showMessage(opts.lang['addcart_select_spce'],300) : showMessage(opts.lang['addcart_null_diy'],300); $(".checkout-box").css("scroll-behavior", "smooth") if ($(".product-detail")) { scrollTop = scrollTop -90; } else if($(".addcart-header").css("position") == "fixed" || $(".addcart-header").css("position") == "sticky") { scrollTop = scrollTop - $(".addcart-header").height() - 40; } else { scrollTop = scrollTop -20; } if (jump) { $(document).scrollTop(scrollTop) } } return flag; } function formatData(data) { var fakeData = JSON.parse(JSON.stringify(data)); var copyData = []; if (!(fakeData instanceof Array)) { fakeData = [fakeData]; } console.log(fakeData); for (var f = 0; f < fakeData.length; f++) { var __data = JSON.parse(JSON.stringify(fakeData[f])); if (__data.fakeSkus && __data.fakeSkus.length) { var __list = []; var __items = __data.items; for (var i = 0; i < __items.length; i++) { var __vid = __items[i].options[0].vid; var __index = __data.fakeSkus.findIndex(function (v) { return v.id == __vid; }); // console.log(__index) var fakesku = JSON.parse(JSON.stringify(__data.fakeSkus[__index])); if (fakesku.isRandom == 0) { if (!(fakesku.details instanceof Array)) { fakesku.details = [fakesku.details]; } for (var j = 0; j < fakesku.details.length; j++) { var __poid = fakesku.details[j].poid, __number = fakesku.details[j].number, gift = fakesku.details[j].isGift ? fakesku.details[j].isGift : 0; var price = fakesku.details[j].salePrice >= 0 ? fakesku.details[j].salePrice : 0; var index = __data.skus.findIndex(function (v) { return v.poid == __poid; }); if (index != -1) { var obj = { gift: gift, id: __items[i].id, image: __items[i].image, name: __items[i].name, number: __number * __items[i].number, offset: 0, // options:, // optvs: "550854#550856#", poid: __poid, price: price, rule: __items[i].rule, // spec: "コーヒー 24.5 ", } var __sku = JSON.parse(JSON.stringify(__data.skus[index])); var __options = JSON.parse(JSON.stringify(__sku.option)); var __optvs = '', __spec = ''; for (var o = 0; o < __options.length; o++) { var __option = { id: __options[o].pid, name: __options[o].pname, sort: "50", vid: __options[o].id, vname: __options[o].name } __options[o] = __option __optvs += __options[o].vid + '#'; __spec += __options[o].vname + ' '; } obj.options = __options; obj.optvs = __optvs; obj.spec = __spec; __list.push(obj); } else { var obj = { gift: gift, id: fakesku.details[j].saleId + '', image: '', name: fakesku.details[j].saleTitle, number: __number * __items[i].number, offset: 0, // options:, // optvs: "550854#550856#", poid: __poid, price: price, rule: __items[i].rule, // spec: "コーヒー 24.5 ", } var __optvs = '', __spec = ''; var __options = []; if (fakesku.details[j].skuVal && fakesku.details[j].skuVal.length) { for (var opt = 0; opt < fakesku.details[j].skuVal.length; opt++) { __optvs += fakesku.details[j].skuVal[opt].optionValId + '#'; __spec += fakesku.details[j].skuVal[opt].optValName + ' '; __options.push({ id: fakesku.details[j].skuVal[opt].optionId, name: fakesku.details[j].skuVal[opt].optionName, vid: fakesku.details[j].skuVal[opt].optionValId, vname: fakesku.details[j].skuVal[opt].optValName }) } } obj.options = __options; obj.optvs = __optvs; obj.spec = __spec; __list.push(obj); } } } else { for (var num = 0; num < __items[i].number; num++) { var randomIndex = getRandomIndex(0, fakesku.details.length); var __poid = fakesku.details[randomIndex].poid, __number = fakesku.details[randomIndex].number, gift = fakesku.details[randomIndex].isGift ? fakesku.details[randomIndex].isGift : 0, price = fakesku.details[randomIndex].salePrice >= 0 ? fakesku.details[randomIndex].salePrice : 0 var __obj = { gift: gift, id: __items[i].id, image: __items[i].image, name: __items[i].name, number: __number, offset: 0, // options:, // optvs: "550854#550856#", poid: __poid, price: price, rule: __items[i].rule, // spec: "コーヒー 24.5 ", } var __skuIndex = __data.skus.findIndex(function (v) { return v.poid == __poid; }); var __sku = JSON.parse(JSON.stringify(__data.skus[__skuIndex])); // console.log(__sku) var __options = JSON.parse(JSON.stringify(__sku.option)); // console.log(__options) var __optvs = '', __spec = ''; for (var o = 0; o < __options.length; o++) { var __option = { id: __options[o].pid, name: __options[o].pname, sort: "50", vid: __options[o].id, vname: __options[o].name } __options[o] = __option __optvs += __options[o].vid + '#'; __spec += __options[o].vname + ' '; } __obj.options = __options; __obj.optvs = __optvs; __obj.spec = __spec; __list.push(__obj); } } } __data.items = __list; delete __data.fakeSkus; delete __data.skus; delete __data.options; } copyData[f] = __data; } if (copyData.length == 1) { copyData = copyData[0] } return copyData; } // //兼容è€ç‰ˆæœ¬ $.addToCart = _AddCart.addToCart $.getCartCount = _AddCart.getCartCount; $.promotion = _AddCart.promotion; $.checkout = _AddCart.checkout; $.loadCart = _AddCart.loadCart; $.removeCart = _AddCart.removeCart; window.Map = Map; window.AddCart = _AddCart; window.Cart = _AddCart; window.showMessage = showMessage; //å¸ç§åˆ‡æ¢ window.currencyCh = $.currencyCh; window.formatData = formatData; window.addCartInfo = addCartInfo; //ä¿®å¤ä¸èƒ½é€‰çš„组åˆåˆèƒ½è¢«é€‰ä¸é—®é¢˜ $(document.body).on('mousedown','.addcart-specs-content span',function(){ setTimeout(function(){ $dl = $(".addcart-specs-content"); if($dl.length>2) { $span = $dl.eq(1).find('span'); $.each($span,function(){ if($(this).hasClass('active')) { var index = $(this).index(); $(this).removeClass('active'); $span.eq(index).click(); } }); } },500); }); })(window.jQuery||{}) function Confirm(text,ok,cancal,confirmCb,cancalCb){ var gkMask; if ($(".gui-mask").length < 1) { gkMask = $("<div class='gui-mask'></div>"); }else{ gkMask = $('.gui-mask') } gkMask.addClass('gui-show'); var gkModel = $('<div class="confirm"><p class="confirm-t">' + text +'</p><div class="confirm-btn"><span id="confirm-ok">'+ok+'</span><span id="confirm-cancle">'+cancal+'</span></div></div>'); gkMask.append(gkModel); $("body").append(gkMask); var width = -(($(".confirm").width()+40) / 2), height = -(($(".confirm").height() + 20) / 2); $(".confirm").css({ "margin-left": width + "px", "margin-top": height + "px" }); gkModel.on('click',"#confirm-ok",function(){ $(".confirm").remove(); $(".gui-mask").removeClass("gui-show"); confirmCb(); }); gkModel.on('click',"#confirm-cancle",function(){ $(".confirm").remove(); $(".gui-mask").removeClass("gui-show"); cancalCb(); }); } function accMul(arg1, arg2) { var m = 0, s1 = arg1.toString(), s2 = arg2.toString(); try { m += s1.split(".")[1].length } catch (e) {} try { m += s2.split(".")[1].length } catch (e) {} return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m) } function accAdd(arg1, arg2) { var r1, r2, m; try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 } try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 } m = Math.pow(10, Math.max(r1, r2)) return (arg1 * m + arg2 * m) / m } var guidF = function() { function S4() { return (((1+Math.random())*0x10000)|0).toString(16).substring(1); } var ms = (new Date()).getTime(); return (ms + S4() + S4() + S4()); } function getQuery(key) { var search = window.location.search.substr(1); if (!search) return null; var list = search.split('&'); if (!list.length) return null; var obj = {}; list.forEach(function (v) { var query = v.split('='); obj[query[0]] = query[1]; }) if (!key) return obj; return obj[key] || null; }