PageSourceSearch

https://www.audew.com/templates/common/src/shopCart/js/shopCart.js?v=c51d832b

js audew.com collected 2026-10-06 07:18:32 UTC 179,570 bytes, 4,021 lines download raw bytes

1(function (doc, win, $, undefined) {
2
3    Array.prototype.unique = function () {
4        var res = [];
5        var json = {};
6        for (var i = 0; i < this.length; i++) {
7            if (!json[this[i]]) {
8                res.push(this[i]);
9                json[this[i]] = 1;
10            }
11        }
12        return res;
13    }
14
15    //每隔三位小数加逗号
16    function toThousands(nStr) {
17        nStr += '';
18        x = nStr.split('.');
19        x1 = x[0];
20        x2 = x.length > 1 ? '.' + x[1] : '';
21        var rgx = /(\d+)(\d{3})/;
22        while (rgx.test(x1)) {
23            x1 = x1.replace(rgx, '$1' + ',' + '$2');
24        }
25        return x1 + x2;
26    }
27
28    //每隔三位小数加空格
29    function toThousands2(nStr) {
30        nStr += '';
31        x = nStr.split('.');
32        x1 = x[0];
33        x2 = x.length > 1 ? '.' + x[1] : '';
34        var rgx = /(\d+)(\d{3})/;
35        while (rgx.test(x1)) {
36            x1 = x1.replace(rgx, '$1' + ' ' + '$2');
37        }
38        return x1 + x2;
39    }
40
41    function getTime(seconds, type) {
42        if (seconds == '' || seconds == 0) return '';
43        var date = new Date(parseInt(seconds) * 1000);
44        var time = '';
45        if (!type) {
46            Y = date.getFullYear() + '-';
47            M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
48            D = date.getDate();
49            h = date.getHours();
50            m = date.getMinutes();
51            s = date.getSeconds();
52            D = D < 10 ? "0" + D : D;
53            h = h < 10 ? "0" + h : h;
54            m = m < 10 ? "0" + m : m;
55            s = s < 10 ? "0" + s : s;
56            time = Y + M + D + " " + h + ":" + m + ":" + s;
57            return time;
58        } else {
59            var month = new Array(12);
60            month[0] = "01",
61                month[1] = "02",
62                month[2] = "03",
63                month[3] = "04",
64                month[4] = "05",
65                month[5] = "06",
66                month[6] = "07",
67                month[7] = "08",
68                month[8] = "09",
69                month[9] = "10",
70                month[10] = "11",
71                month[11] = "12";
72    
73            Y = date.getFullYear();
74            M = month[date.getMonth()];
75            D = date.getDate();
76            D = D < 10 ? "0" + D : D;
77            time = D + "/" + M + "/" + Y;
78            return time;
79        }
80    
81    }
82
83    /* 节流函数 */
84    function throttle (fn, delay) {
85      var args = arguments,
86        context = this,
87        timer = null,
88        remaining = 0,
89        previous = new Date();
90
91      return function () {
92        var now = new Date();
93        remaining = now - previous;
94
95        if (remaining >= delay) {
96          if (timer) {
97            clearTimeout(timer);
98          }
99
100          fn.apply(context, args);
101          previous = now;
102        } else {
103          if (!timer) {
104            timer = setTimeout(function () {
105              fn.apply(context, args);
106              previous = new Date();
107            }, delay - remaining);
108          }
109        }
110      };
111    }
112
113    function PoaHandler(options) {
114        this.checkEquipment();
115        this.shippingModalPositon();
116        this.$wrapper = $('.js-product-info').eq(0);
117        this.theme = $("#theme").val();
118        this.pid = options.pid;//产品ID
119        this.poaCodeList = options.poaCodeList;//属性组合对应的poa码
120        this.wsData = options.wsData;
121        this.defaultPoaVid = options.defaultPoaVid ? JSON.parse(options.defaultPoaVid) : {};//默认选择的属性字符串,用.间隔
122        this.semData = options.semData ? JSON.parse(options.semData) : null;//sem参数,优先级最高,默认选中属性值
123        this.cur_warehouse = options.cur_warehouse;//产品所在仓库
124        this.isWsdataNull = this.wsData.length == 0 ? true : false;
125        this.stockQty = 0;//库存数量
126        this.shopCartNum = 0; //购物车数量
127        this.poaNum = options.defaultPoa == '' ? options.selPoa : options.defaultPoa;//当前商品poa,若无poa则为sku
128        this.poaAttr = $(".poaItem");//属性wrapper对象
129        this.poaLength = this.poaAttr.length;//属性数量
130        this.activeNameArr = [];//属性名数组
131        this.activeIndex = new Array(this.poaLength);//存放data-vid的数组
132        this.activeIndex2 = new Array(this.poaLength);//存放data-pid的数组
133        this.activeSortVid = new Array(this.poaLength);//存放data-vid的数组,并将数值从大到小排序
134        this.addBtnDisabled = false;//add to cart按钮是否可用;
135        this.shopStatus = $("#shopStatus").val() == 1 ? true : false;
136        this.wishId = $("#wishId").val();
137        this.defaultSel = $('#currencyDefault').val();
138        this.usPrice = Number($("#usPrice").val()); //产品初始价格(美元)
139        this.fbsendPrice = Number($("#usPrice").val()); //产品sku/poa美元价格,fb埋点时提交该价格
140        this.oldUsPrice = Number($("#oldUsPrice").val());
141        this.sel = null;//手动切换的币种值
142        this.selIcon = $.trim(this.$wrapper.find(".product_price .price_datalist").find('b').text());//当前币种符号
143        this.isFTLoaded = false;//是否调用过getPoaData方法
144        this.isDefaultSelected = false;//是否已经进行默认选中属性
145        this.defaultPoa =options.defaultPoa;//默认poa值
146        this.shippingCode = '';//邮寄方式id
147        this.pcCountDownTimer = null;
148        this.mCountDownTimer = null;
149
150        this.poaCache = {};//缓存请求过的poa信息
151
152        // var promos_allPage = Number($("#activity-total").attr('data-all-total'));
153        // this.promos_pageSize = 20;
154        // this.promos_allPage = promos_allPage % this.promos_pageSize === 0 ? (promos_allPage / this.promos_pageSize) : ( Number.parseInt(promos_allPage/this.promos_pageSize) + 1);//所有页数
155        this.promos_pager = 1; //loadMore请求页数
156        this.pro_loading = false;
157        this.pro_isLoadOver = false;//是否没有更多页数加载
158        
159      
160        if (this.shopStatus) {
161            this.CurrencyCfg = CurrencyCfg;//币种汇率;
162            this.CurrencyLoss = CurrencyLoss;//转换损失率;
163            this.CurrencyBGLoss = CurrencyBGLoss;//转换损失率;
164            this.CurrencyBGEurLoss = CurrencyBGEurLoss;//欧元损失率
165            this.CurrencyBGMxnLoss = CurrencyBGMxnLoss;//欧元损失率
166        }
167        this.SKUResult = {};
168        this.giftResult = {};
169
170        if (this.isPc) {
171            this.$qtyBox = $(".js-product-info .quantity-container");
172            this.$addBtn = $('.js-product-info .addToCart').eq(0);
173            this.$buyNowBtn = $('.js-product-info .js-buynow');
174            this.$paypalBtn = $('.js-product-info .js-paypal');
175            this.$startMyGroupBtn = $('.js-product-info .js-start-group');
176            this.$wishlistWrap = $('.wishlist_wrap').eq(0);
177            this.$isMultiWishWrap = $('.isMultiPurpose-addWish');
178        } else {
179            this.$qtyBox = $(".qty_box_m");
180            this.$addBtn = $('.addToCart_m');
181            this.$buyNowBtn = $('.js-buynow');
182            this.$paypalBtn = $('.js-paypal');
183            this.$startMyGroupBtn = $('.js-start-group');
184            this.$wishlistWrap = $('.wishlist_m').eq(0);
185            this.$shareBtn = $('#share_m');
186            this.$bottomBar = $('.fixed_bottom_btnWrap');
187        }
188
189        this.$qtyInput = this.$qtyBox.find('.quantity_input');//数量输入框
190        this.$minusBtn = this.$qtyBox.find('.minus');//数量减少按钮
191        this.$plusBtn = this.$qtyBox.find('.plus');//数量增加按钮
192        //this.$previewImg = $(".single_pic").find('img');//用于预览的img对象
193        this.$giftList = $(".js-product-info .item_box.gift").find('.gift_list');
194        this.$poaWrapper = $('.js-product-info .poa_wrap');
195        this.$giftWrapper = $('.js-product-info .gift_wrap');
196        this.$wholesaleWrap = $("#wholesale");
197        this.dianzanPopTip = $('.js-dianzan-pop');
198        this.productId = $('#product_id').val();
199
200        this.initHeaderInfo();//初始化用户信息接口数据
201        this.hasAccessory = false;
202        this.recordClickParams();//相关推荐埋点参数
203        this.checkAccessory();//检查是否开启商品组合
204        this.init();
205        
206    }
207
208    PoaHandler.prototype = {
209        init: function () {
210            var _this = this;
211            this.initSKU(); //初始化得到poa结果集
212            this.failedEdmLink();//edm邮件链接跳转处理
213            this._buildEvent(); //事件绑定
214            this.checkAmazonBtn();
215            if (!this.isPc) {
216                this.buyWayInit(true);//M端初始化第三方按钮
217                //this.btnOrderInit();//M端不同模板,下方按钮顺序不同
218                if (this.poaLength > 0) {
219                    this.attrPreviewInit();//M端有属性时,POA入口初始化
220                }
221            }
222
223            this.productBindEvent();//详情页事件绑定
224            this.keyCodeStockLimit();//数量加购交互处理
225            this.sizeChartDialog();//尺码表交互处理
226            this.sizeChange();//尺码属性切换
227
228            this.judgeGaProductDetail();//衡量产品详情查看
229            this.initDefaultClick();
230            this.checkShippingMethod();//获取默认仓库的邮寄方式
231            
232            if(!this.isPc && this.getCookie('isChangedWarehouse') 
232== '1'){
233                $('.poa_wrap_title').click()
234                this.setCookie('isChangedWarehouse', '0', 0.5)
235            }
236            this.groupBuyRule_m();
237            if(!this.isPc){
238              this.scrollBind_m();
239            }
240        },
241        //n95产品,邮件链接失效处理,链接包含utm_medium=audew10074_1734,跳转至page_not_found
242        failedEdmLink: function(){
243            var url = win.location.href
244            var len = (url.split('?')).length-1;//连接中?的长度
245            if(len>1 && url.indexOf('utm_medium=audew10074_1734')> -1){
246                win.location.href = '/page_not_found'
247            }
248        },
249        recordClickParams:function(){
250            var rmmds = this.getQueryString("rmmds");
251            var rp_url = localStorage.getItem("referer");
252            var regObj = {
253                c: /-c-(.+)(?=\.html)/,
254                p: /-p-(.+)(?=\.html)/,
255            };
256            this.recObj = {};
257            if(localStorage.getItem("rec_keywords") != null){
258              this.recObj.r_keywords = localStorage.getItem("rec_keywords");
259            }
260            if(rmmds !== null && rmmds !== undefined ){
261              this.recObj.r_position = rmmds
262            }
263            try{
264                if(rp_url && rp_url != "null"){
265                    if (rp_url.indexOf('-c-') > -1) {
266                        var rp_cs = rp_url.match(regObj.c),
267                            rp_cid = rp_cs ? encodeURIComponent(rp_cs[1]) : 0;
268                        this.recObj.r_cid = rp_cid;
269                    }
270        
271                    if (rp_url.indexOf('-p-') > -1) {
272                        var rp_cs = rp_url.match(regObj.p),
273                            rp_pid = rp_cs ? encodeURIComponent(rp_cs[1]) : 0;
274                        this.recObj.r_pid = rp_pid
275                    }
276                }
277            } catch (error) {
278                console.log(error);
279            }
280        },
281        checkAccessory:function(){
282            var _this = this;
283            /* 没有poa属性时在这里请求一次组合html,有poa时已经执行updatePoa方法请求接口 */
284            if(_this.shopStatus){
285                headerInfoAjax.then(function(data){
286                    _this.hasAccessory = data.data.has_acce;
287                    if(_this.hasAccessory && !_this.defaultPoa){
288                        _this.getAccessoryHtml(); 
289                    }
290                }) 
291                
292            }
293            
294        },
295        setShipCountry: function(){
296            var countryInfo = this.headerInfo.coutry_data;
297            var countryHtml = ''
298                countryHtml += '<em class="icon-flag icon-flag-'+ countryInfo.code +'" style="margin-right:5px"></em>' +
299                            '<span>'+countryInfo.name+' </span>'
300            $('.js-shipto-country').html(countryHtml); //弹框显示ship to国家
301            $('.js-shipping-country').html(countryInfo.name);
302        },
303        //获取选中仓库和poa的邮寄方式
304        checkShippingMethod: function() {
305            var _this = this;
306            var poa = _this.poaNum != ''? _this.poaNum : _this.defaultPoa != '' ? _this.defaultPoa : productSKU ;
307            var code = $('.js-detail-warehouse .js-warehouse-item .active').attr('war_code'); //默认选中的仓库
308            var len = $('.js-detail-warehouse .js-warehouse-item li').length;
309            if(len > 0) {
310                $.ajax({
311                    url: '/index.php?com=product&t=getProductShippingList',
312                    type: 'get',
313                    dataType: 'json',
314                    data: {
315                        'products_id': this.pid,
316                        'poa':poa,
317                        'code':code,
318                    },
319                    success: function (response) {
320                        var data = response.data,
321                            str = '',
322                            m_str = '',
323                           selIcon = _this.selIcon,
324                            $shipWrap = $('.ship_box_center');
325                        if(data.length){
326                            $shipWrap.show();
327                            //更新邮寄方式
328                            $.each(data, function (index, value) {
329                                var PriceText = value.us_price == 0 ? 'Free Shipping' : _this.transformCurrencyText(value.currency, value.price)
330                                if(index === 0) {
331                                    //更新详情页shipping地区文字显示,显示第一个邮寄方式
332                                    $shipWrap.find('.js-shipping-price').text(PriceText).attr('usprice',value.us_price);
333                                    $shipWrap.parent().find('.js-shipping-price').text(PriceText).attr('usprice',value.us_price);
334                                    $shipWrap.find('.js-shipping-method a, .js-mship-method a').text(value.name);
335                                    $shipWrap.find('.js-shipping-range').html(value.shipday);
336                                }
337                                var active = '';
338                                if(!this.shippingCode || this.shippingCode == ''){
339                                    active =  index == 0 ? 'active' : ''
340                                } else {
341                                    active = value.code == this.shippingCode ? 'active' : ''
342                                }
343                                var tracked = value.tracked ? 'Tracked' : 'Not Tracked'
344                                str += ' <li ship_days="'+ value.shipday +'" ship_name="'+ value.name +'" ship_price="'+ value.price +'" usprice="'+ value.us_price +'" class="ship_item '+ active +' ">' +
345                                    '<div class="list_cell list_name"><label></label>'+value.name+'</div>' +
346                                    '<div class="list_cell list_shipcost">'+PriceText+'</div>' +
347                                    '<div class="list_cell list_days"><u>'+value.shipday+'</u> business days</div>' +
348                                    '<div class="list_cell list_track">'+ tracked+'</div>' +
349                                '</li>'
350                                m_str += '<li ship_days="'+ value.shipday +'" ship_name="'+ value.name +'" ship_price="'+ value.price +'" usprice="'+ value.us_price +'" class="ship_m_item ship_item ' +active+'">' +
351                                        '<div class="ship_left"><label></label></div>' +
352                                        '<div><div class="ship_m_price">'+ PriceText +'</div>' +
353                                       '<div class="ship_m_method">'+value.name +', '+ value.shipday+' business days</div> <div>' +
354                                    '</li>'
355                            });
356                            if(_this.isPc){
357                                $('.js-shipping-poplist').html(str)
358                            } else {
359                                $('.js-shipping-poplist').html(m_str)
360                            }
361                        } else {
362                            $shipWrap.hide();
363                        }
364                    },
365                    error: function () {
366                        console.log('error');
367                    }
368                }) 
369            } else {
370                var shippingText = 'sold out',
371                $shipping = $('.js-product-info').find(".shipping_text");
372                $shipping.html(shippingText).addClass('warn');
373                this.$addBtn.addClass('gray');
374                this.$buyNowBtn.addClass('gray');
375                this.$paypalBtn.addClass('gray');
376                this.$startMyGroupBtn.addClass('gray');
377                this.isBtnDisabled = true;
378            }
379            
380        },
381        // 运费显示格式修正
382        transformCurrencyText:function(currency,price) {
383            var selIcon = this.selIcon;
384            var strText = ''
385            var newCurrency = currency == ''? selIcon : currency
386            if (newCurrency == 'руб.' || newCurrency == 'AED') {
387                strText = strText = price + ' ' + newCurrency
388            } else {
389                strText = newCurrency + price
390            }
391            return strText
392        },
393        productBindEvent: function () {
394            $('.js-product-info .js-apply-free').on('click', $.proxy(this.applyFreeProduct, this));//测评页申请
395            $(document).on('click', '.js-dianzan-pop .js-dianzan-close', $.proxy(this.dianZanHandler, this));//点赞 or 取消点赞
396        },
397        applyFreeProduct: function (e) {
398            var _this = this;
399            var applyUrl = $('.js-apply-free').attr('href');
400            e.preventDefault();
401            $.ajax({
402                url: '/index.php?com=superuser&t=getUserVerify&products_id=' + _this.productId,
403                type: 'post',
404                dataType: 'json',
405                beforeSend: function () {
406                    $('.m-makeup2-free').find('.loading_bg').show();
407                    $(e.target).parents().siblings('.loading_wrap').show();
408                },
409                success: function (data) {
410                    $('.m-makeup2-free').find('.loading_bg').hide();
411                    $(e.target).parents().siblings('.loading_wrap').hide();
412                    if (data.code == 200) {
413                        window.location.href = data.data.url;
414                    } else if (data.code == 401) {
415                        $(win).width() < 769 ? window.location.href = 'login.html' : _this.showPopLogin();   
416                    } else if (data.code == 403) {
417                        _this.dianzanPopTip.fadeIn().find('.ajax-tip').html(data.message);
418                        setTimeout(function () {
419                            window.location.href = applyUrl;
420                        }, 3000);
421                    } else {
422                        _this.dianzanPopTip.fadeIn().find('.ajax-tip').html(data.message);
423                    }
424                }
425            })
426        },
427        dianZanHandler: function (e) {
428            this.dianzanPopTip.hide().find('.ajax-tip').html('');
429        },
430        /* 检测设备宽度 */
431        checkEquipment: function () {
432            var winWidth = $(window).width();
433            if (winWidth >= 845) {
434                this.isPc = true;
435            } else {
436                this.isPc = false;
437            }
438        },
439        /*获取POA信息*/
440        getPoaData: function () {
441            var cacheData = this.poaCache[this.poaNum];
442            //是否有缓存数据
443            if (cacheData) {
444                this.isUseCacheData = true;
445                this.poaDataHanlder(cacheData);
446            } else {
447                this.isUseCacheData = false;
448                this.showBtnLoading();
449                var _this = this;
450                var data = new FormData();
451                data.append('sel_poa', this.poaNum);//poa
452                data.append('products_id', _this.pid);//产品id
453                data.append('cur_warehouse', _this.cur_warehouse);
454                /* 没有属性选 则不传products_attr_id */
455                if (_this.poaLength) {
456                    $.each(this.activeIndex, function (i, val) {
457                        data.append('products_attr_id[' + _this.activeIndex2[i] + ']', val);
458                    });
459                }
460
461                $.ajax({
462                    url: '/stockMessage.html',
463                    type: 'post',
464                    dataType: 'json',
465                    data: data,
466                    cache: false,
467                    processData: false,
468                    contentType: false,
469                    success: function (data) {
470                        _this.poaCache[_this.poaNum] = data;//缓存poa数据
471
472                        _this.poaDataHanlder(data);
473                        _this.setCouponInfo(data.productCoupons);
474
475                        if (!_this.isDefaultSelected) {
476                            _this.isDefaultSelected = true;
477                        }
478
479                        _this.hideBtnLoading();
480                    },
481                    error: function () {
482                        console.log('error');
483                    }
484                })
485                
486            }
487            if(!!this.isDefaultSelected){//默认选中时不触发,已经默认选中之后的poa切换才执行
488                this.checkShippingMethod();//获取最新的运费
489            }
490        },
491        /* 事件绑定 */
492        _buildEvent: function () {
493            var _this = this,
494                qtyInput = '',
495                addToCartBtn = '';
496
497            if (this.isPc) {
498                qtyInput = '.js-product-info .quantity-container .quantity_input';
499                addToCartBtn = '.js-product-info .addToCart';
500
501                /* 是否开启购物车 */
502                if (this.shopStatus) {
503                    this._giftEvent();
504                }
505
506                this.countryHandler();
507                $(doc).on('click', '.js-product-info .poaItem .attrimg:not(.gray)', $.proxy(this.previewPic, this));//预览图片
508                
509                $(doc).on('click', '.js-amazon-btn, js-mbuy-amazon', $.proxy(this.thirdChannelFbEvents, this));//amazon按钮转化率 
510                $('.js-product-info .wholesale_price_wrap').hover(function () {
511                    $(this).find('.wholesale_price_container').show();
512                }, function () {
513                    $(this).find('.wholesale_price_container').hide();
514                });
515
516                $(window).resize(this.shippingModalPositon);
517            } else {
518                qtyInput = '.qty_box_m .quantity_input';
519                addToCartBtn = '.addToCart_m';
520                this.poaHandler_m();
521                this.giftHandler_m();
522                this.wholeSaleHandler_m();
523                this.share_m();
524                this.countryHandler_m(); //第三方按钮国家选择
525                
526                $(doc).on('click', '.js-product-info .poaItem .attrimg', $.proxy(this.previewPic_m, this));//预览图片
527
528                this.buywayHandler_m();
529                this.discountHandler_m();//M端满减
530
531                if (this.shopStatus) {
532                    this.priceHandler_m();
533                }
534
535                this.$bottomBar.find('.wishlist_m').on('click', $.proxy(this.triggerWishlist, this));
536            }
537
538            if (this.shopStatus) {
539                $(doc).on('click', '.js-product-info .count.plus', $.proxy(this.plus, this));//数量+
540                $(doc).on('click', '.js-product-info .count.minus', $.proxy(this.minus, this));//数量-
541                $(doc).on('click', addToCartBtn, $.proxy(this.addToCart, this));//加购按钮事件
542                $(doc).on('click', '.js-product-info .js-start-group', $.proxy(this.startMyGroup, this));//点击开团事件
543                $(doc).on('click', '.js-product-info .js-buynow, .js-product-info .js-paypal', $.proxy(this.buyNow, this));//buynow事件
544                $(doc).on('change', qtyInput, $.proxy(this.changeQty, this));//修改数量事件
545                $(doc).on('keypress', qtyInput, $.proxy(this.checkQtyVaild, this));//检验键盘输入数量事件
546                $(doc).on('click', '.js-product-info .price_datalist li', $.proxy(this.changeCurrency, this));//切换币种
547                $(doc).on('click', '.js-product-info .viewcart_btn', function () {
548                    window.location.href = '/shopcart';
549                });
550                $(doc).on('click', '.shipping-modal .continue_btn,.shipping-modal .close_btn', function () {
551                    _this.modalRemove();
552                });
553                win.modal_remove = this.addModalRemove.bind(this);
554
555                this.couponHandler();
556            }
557
558            $(doc).on('click', '.js-product-info .poaItem .attr_item', $.proxy(this.updatePoa, this));
559            $(doc).on('click', '.js-product-info .add_wish_list', $.proxy(this.triggerWishlist, this));
560            $(doc).on('click', '.js-product-info .attrcolor, .js-product-info .attrimg', $.proxy(this.switchColorName, this)); //选中图片或色块显示属性值
561            $(doc).on('click', '.js-product-info .js-close-fixed', $.proxy(this.closeFixed, this));
562            $(window).resize($.proxy(this.shippingModalPositon, this));
563            $(doc).on('click', '.js-detail-warehouse .js-warehouse-item .war_item:not(.disabled)', $.proxy(this.changeWarehouse, this));//切换仓库时获取仓库运输方式
564            $(doc).on('click', '.js-detail-shipbox .js-shipping-method, .js-detail-module .js-shipping-close', $.proxy(this.changeShippingModal, this));//显示/隐藏物流弹框
565            $(doc).on('click', '.js-shipping-poplist li', $.proxy(this.changeShipping, this));//切换邮寄方式
566            
567        },
568        /* 提交购物车 */
569        addToCart: function (e) {
570            var _this = this,
571                $this = $(e.target);
572            if ($this.hasClass('gray')) return false;
573            if ($this.hasClass('forbidGray')) return false;//禁售地区
574            if ($this.hasClass('loading_bg')) return false;
575            
576            _this.judgeGaAddToCart();
577            /* 属性数量不为0 */
578            if (this.poaLength !== 0) {
579                if (!this.isPc) {
580                    /* M端 */
581                    var wrapIsShow = this.$poaWrapper.find('.poa_list_wrap').css('display') === 'none' ? false : true;//弹框显示状态
582                    if (wrapIsShow) {
583                        /* 点击弹框的加购按钮 */
584                        if (this.checkSelected(true)) {
585                            this.addRequire();
586                        }
587                    } else {
588                        /* 点击页面下方的加购按钮 */
589                        this.openModal();
590                        this.$giftWrapper.removeClass('show').find('.gift_list_wrap').hide();
591                        this.$poaWrapper.find('.poa_list_wrap').show().find('.submit_box .addToCart_m').show().removeClass('bgwhite').css({'margin-left': 0,'margin-right': 0}).siblings().hide();//poa窗口显示
592                        setTimeout(function () {
593                            _this.$poaWrapper.addClass('show');
594                        }, 0);
595                        //this.$poaWrapper.find('.poa_list_wrap').show().end().addClass('show');
596                    }
597
598                } else {
599                    /* PC端 */
600                    if (this.checkSelected(true)) {
601                        this.addRequire();
602                    }
603                }
604
605            } else {
606                this.addRequire();
607            }
608
609            // Bing增设埋点
610            _this.reportBingCustomEvent('click', 'product', 'middle_addToCart_button')
611
612        },
613        /* 开团按钮事件处理 */
614        startMyGroup: function (e) {
615            var _this = this,
616            $this = $(e.currentTarget);
617                
618            if ($this.hasClass('gray')) return false;
619            if ($this.hasClass('forbidGray')) return false;//禁售地区
620            if ($this.hasClass('loading_bg')) return false;
621            
622            _this.judgeGaAddToCart();
623            /* 属性数量不为0 */
624            if (this.poaLength !== 0) {
625                if (!this.isPc) {
626                    /* M端 */
627                    var wrapIsShow = this.$poaWrapper.find('.poa_list_wrap').css('display') === 'none' ? false : true;//弹框显示状态
628                    if (wrapIsShow) {
629                        /* 点击弹框的加购按钮 */
630                        if (this.checkSelected(true)) {
631                            this.startGroupRequire();
632                        }
633                    } else {
634                        /* 点击页面下方的加购按钮 */
635                        this.openModal();
636                        this.$giftWrapper.removeClass('show').find('.gift_list_wrap').hide();
637                        this.$poaWrapper.find('.poa_list_wrap').show().find('.submit_box .addToCart_m').show().removeClass('bgwhite').css({'margin-left': 0,'margin-right': 0}).siblings().hide();//poa窗口显示
638                        setTimeout(function () {
639                            _this.$poaWrapper.addClass('show');
640                        }, 0);
641                        //this.$poaWrapper.find('.poa_list_wrap').show().end().addClass('show');
642                    }
643
644                } else {
645                    /* PC端 */
646                    if (this.checkSelected(true)) {
647                        this.startGroupRequire();
648                    }
649                }
650
651            } else {
652                this.startGroupRequire();
653            }
654
655        },
656        /* 拼团start my group请求 */
657        startGroupRequire: function () {
658            this.showBtnLoading(4);
659
660            var _this = this,
661                data = this.packAddData(),
662                quantity = this.$qtyInput.val();
663            
664            $.ajax({
665                url: '/startGroupBuying.html',
666                type: 'post',
667                dataType: 'json',
668                data: data,
669                cache: false,
670                processData: false,
671                contentType: false,
672                success: function (res) {
673                    if (res.code == 200) {
674                        window.location.href = res.data.url;
675                    } else {
676                        _this.errorAlert(res.message);
677                    }
678                    _this.hideBtnLoading();
679
680                    //点击加购成功后追踪推荐位数据
681                    _this.recObj["ac"] = "cart"; 
682                    _this.recObj["products_id"] = _this.pid; 
683                    Record.rec(_this.recObj);
684                    var rmmds = _this.getQueryString("rmmds")
685                    if(rmmds === 'search'){
686                        nDC.RecordClick('startGroup', [_this.pid])
687                    }
688                    //FB事件监测
689                    _this.sendFbEvents('AddToCart')
690                },
691                error: function (data) {
692                    console.log(data);
693                    _this.hideBtnLoading();
694                }
695            })
696
697        },
698        /* 选择仓库交互 */
699        changeWarehouse: function(e) {
700            var _this = this,
701                url = win.location.href,
702                newUrl = "",
703                gmcWarehouse = _this.getQueryString('cur_warehouse'),
704                $this = $(e.target);
705            if($this.hasClass('active')){
706                return false;
707            }
708            if(!_this.isPc){
709                _this.setCookie('isChangedWarehouse', '1', 0.5)
710            }
711            var code = $this.attr('war_code');
712            if(gmcWarehouse == null || gmcWarehouse == ''){
713                newUrl = url.indexOf('?') > -1 ? url + '&cur_warehouse=' + code : url + '?cur_warehouse=' + code
714            } else {
715                newUrl = _this.replaceParamVal(url,'cur_warehouse',code); 
716            }
717           window.location.href = newUrl;
718        },
719        //替换指定传入参数的值,url为地址,paramName为参数,replaceWith为新值
720         replaceParamVal: function(url,paramName,replaceVal) {
721            var oUrl = url.toString();
722            var re=eval('/('+ paramName+'=)([^&]*)/gi');
723            var nUrl = oUrl.replace(re,paramName+'='+replaceVal);
724            return nUrl;
725        },
726        /* 运输方式弹框 */
727        changeShippingModal: function(e) {
728            if($('.js-detail-module').css('display') == 'none'){
729                $('.js-detail-module').fadeIn();
730            } else {
731                $('.js-detail-module').fadeOut();
732            }
733        },
734        /* 切换邮寄方式 */
735        changeShipping: function(e) {
736            var $target = $(e.target).hasClass('ship_item')? $(e.target) : $(e.target).parents('.ship_item');
737            $shipWrap = $('.js-detail-shipbox');
738            $target.addClass('active').siblings().removeClass('active')
739            this.shippingCode = $target.attr('ship_code')
740            var pcShippingPrice = $target.find('.list_shipcost').text()
741            var mShippingPrice = $target.find('.ship_m_price').text()
742            //更新详情页shipping地区文字显示,显示第一个邮寄方式
743            if(this.isPc){
744                $shipWrap.parent().find('.js-shipping-price').text(pcShippingPrice);
745            } else {
746                $shipWrap.find('.js-shipping-price').text(mShippingPrice);
747            }
748            $shipWrap.find('.js-shipping-method a, .js-mship-method a').text($target.attr('ship_name'));
749            $shipWrap.find('.js-shipping-range').html($target.attr('ship_days'));
750            $('.js-detail-module').fadeOut();
751        },
752        /**
753         * @desc 检测是否产品属性全选
754         * @author lijiahao
755         * @param   boolean  isClickAddBtn     是否通过点击add to cart按钮触发,用于显示提示语
756         * @return  boolean   status           产品属性是否全选
757         *  */
758        checkSelected: function (isClickAddBtn) {
759            var status = false,
760                length = 0,
761                _this = this;
762            if (this.poaAttr.length === 0) {
763                return true;
764            }
765            this.poaAttr.each(function () {
766                var isSelected = false,
767                    $this = $(this);
768
769                $this.find('a').each(function () {
770                    if ($(this).hasClass('active')) {
771                        isSelected = true;
772                        length++;
773                        return false;
774                    }
775                });
776                /* 未选择属性 && 通过点击按钮触发 */
777                if (!isSelected && isClickAddBtn) {
778                    $this.find('.select_prompt').show();
779                }
780            });
781            if (length == this.poaLength) {
782                status = true;
783            }
784            return status;
785        },
786        /*获取库存数量*/
787        // getInventory: function(){
788        //     var data = this.poaData;
789        //     for(var i = 0,j = this.activeIndex.length;i<j;i++){
790        //         data = data[this.activeIndex[i]];
791        //     }
792        //
793        //     return data;
794        // },
795        /* 选择产品属性触发 */
796        updatePoa: function (e) {
797            /* 判断点击的是否为空的<a>标签,如<a>里面有<img>,则选择<img>的父元素<a> */
798            if (!$(e.target).is('a')) {
799                e.target = $(e.target).parent();
800            }
801            var _this = this,
802                activeNameArr = [],
803                $target = $(e.target),
804                $poaItem = $target.parents('.poaItem'),
805                poaIndex = $poaItem.attr('data-poaIndex'),
806                $errorTips = $target.parent().siblings('.select_prompt');
807
808            //有无库存的情况
809            if (!$target.hasClass('gray')){
810                /* 有库存 */
811                if ($target.hasClass('active')) {
812                    $target.removeClass('active');
813                    this.activeIndex[poaIndex] = '';
814                    this.activeIndex2[poaIndex] = '';
815                } else {
816                    $target.addClass('active').siblings().removeClass('active');
817                    this.activeIndex[poaIndex] = $(e.target).attr('data-vid');
818                    this.activeIndex2[poaIndex] = $(e.target).attr('data-pid');
819
820
821                    /* M端选择属性后,显示所有已选属性名 */
822                    if(!_this.isPc){
823                        var $active = $('.box_wrap .poaItem a.active');//已选的属性
824                        $active.each(function () {
825                            var str = '"' + $(this).attr('title') + '"'
826                            activeNameArr.push(str); //每个属性名称
827                        });
828                        $('.js-selected-attr').html(activeNameArr.join(','))
829                    }
830                }
831                this.activeSortVid = $.extend(true,[],this.activeIndex); //深拷贝已选中的vid数组
832                this.activeSortVid.sort(function (value1, value2) {  //对其进行排序
833                    return parseInt(value1) - parseInt(value2);
834                });
835                var $activeLen = $target.closest('.poa_wrap').find('.attr_item.active').length;
836
837                this.$qtyInput.parents('.limitContent').find('.limitQty').slide
837Up();//隐藏only xxx left 提示语
838
839                /* 隐藏提示语 */
840                if ($errorTips.css('display') == 'none' ? false : true) {
841                    $errorTips.hide();
842                }
843
844                /* 已选属性数量 = 属性数量 */
845                if (this.poaLength == $activeLen) {
846                    if (this.shopStatus) {
847                        this.getPoaNum();
848                        this.getPoaData();
849                       // this.checkShippingMethod();//暂时移动到此处保持请求poa正确
850                        if (!this.isWsdataNull) {
851                            this.updateWsTable(false);
852                        }
853                    } else {
854                        this.updatePrice();
855                    }
856                    
857                    //有商品组合点击POA时才重新请求更新商品组合
858                    headerInfoAjax.then(function (data) {
859                        _this.hasAccessory = data.data.has_acce;
860                        if (_this.hasAccessory) {
861                            _this.getAccessoryHtml();
862                        }
863                    })   
864                } else {
865                    if (this.shopStatus) {
866                        /*若属性没有选中,加购按钮置灰,显示提示语*/
867                        this.$addBtn.addClass('gray');
868                        this.$buyNowBtn.addClass('gray');
869                        this.$paypalBtn.addClass('gray');
870                        this.$startMyGroupBtn.addClass('gray');
871                        this.checkSelected(true);
872                        /* 已经默认选中后,才触发 */
873                        if (this.isDefaultSelected) {
874                            /* 请求库存 */
875                            this.getOthersStock();
876                        }
877                    }
878                }
879                
880            }
881             
882
883        },
884        /* 获取属性组合对应的poa码 */
885        getPoaNum: function () {
886            var arr = [],
887                _this = this,
888                poaNum = null;
889
890            $.each(this.poaCodeList, function (i, val) {
891                arr = i.split(';');
892                var len = 0;
893                $.each(arr, function (j, val2) {
894                    if (_this.activeIndex.indexOf(val2) !== -1) {
895                        len++
896                    }
897                });
898                if (len == _this.activeIndex.length) {
899                    poaNum = val;
900                    return false;
901                }
902            });
903            this.poaNum = poaNum;
904        },
905        plus: function (e) {
906            var quantity = Number(this.$qtyInput.val());
907            if (this.checkSelected(false)) {
908                if (this.stockQty > quantity) {
909                    if (this.$plusBtn.hasClass('gray')) return false;
910                    this.$qtyInput.val(++quantity);
911                    //当实际库存且用户数量大于300时
912                    if (this.stockQty > 300 && quantity > 299) {
913                        this.$qtyInput.val(300);
914                        this.$qtyInput.parents('.limitContent').find('.limitQty').show().find('.moreStock').show().siblings().hide();
915                        this.$plusBtn.addClass('gray')
916                    }
917                    //当实际库存<300且小于用户加购数量时
918                    if (this.stockQty <= quantity && this.stockQty < 300) {
919                        this.$plusBtn.addClass('gray');
920                        var stockTip = this.stockData.isPreorder == 1 && this.stockData.preorderInfo.once_limit_amount > 0 ? 'maximum '+this.stockQty+' pcs at a time' : 'Only ' + this.stockQty + '  left';
921                        this.$qtyInput.parents('.limitContent').find('.limitQty').show().find('.onlyStock').html(stockTip).show().siblings().hide();
922                    }
923                    if (this.$minusBtn.hasClass('gray')) {
924                        this.$minusBtn.removeClass('gray');
925                    }
926                }
927            } else {
928                if (this.$plusBtn.hasClass('gray')) return false;
929                this.$qtyInput.val(++quantity);
930                //当实际库存且用户数量大于300时
931                if (this.stockQty > 300 && quantity > 299) {
932                    this.$qtyInput.val(300);
933                    this.$qtyInput.parents('.limitContent').find('.limitQty').show().find('.moreStock').show().siblings().hide();
934                    this.$plusBtn.addClass('gray')
935                }
936                //当实际库存<300且小于用户加购数量时
937                if (this.stockQty <= quantity && this.stockQty < 300) {
938                    this.$plusBtn.addClass('gray');
939                    var stockTip = this.stockData.isPreorder == 1 && this.stockData.preorderInfo.once_limit_amount > 0 ? 'maximum '+this.stockQty+' pcs at a time' : 'Only ' + this.stockQty + '  left';
940                    this.$qtyInput.parents('.limitContent').find('.limitQty').show().find('.onlyStock').html(stockTip).show().siblings().hide();
941                }
942
943
944                if (this.$minusBtn.hasClass('gray')) {
945                    this.$minusBtn.removeClass('gray');
946                }
947            }
948        },
949        minus: function (e) {
950            var quantity = this.$qtyInput.val();
951            if (this.$minusBtn.hasClass('gray')) return false;
952            this.$qtyInput.val(--quantity);
953            if (this.$plusBtn.hasClass('gray')) {
954                this.$plusBtn.removeClass('gray');
955                this.$qtyInput.parents('.limitContent').find('.limitQty').slideUp();
956            }
957
958            if (quantity == 1) {
959                this.$minusBtn.addClass('gray');
960            }
961        },
962        plusHandler: function () {
963            var inputValue = Number(this.$qtyInput.val());
964            if (inputValue >= this.stockQty) {
965                this.$plusBtn.addClass('gray');
966            } else {
967                this.$plusBtn.removeClass('gray');
968            }
969        },
970        setPreSaleHandle: function(data, obj) {
971            var _this = this;
972            $('.js-isPreSale').css('display', 'block');
973            var countDownTime = _this.getCountTimer(data.endTime);
974            if (_this.isPc) {
975              $('.js-pre-sale-activity').find('.js-pre-sale-name').text(data.name);
976              $('.js-pre-sale-activity').find('.js-counting-time').attr('data-time', countDownTime);
977              _this.pcCountDownTimer = new TimeFormat();
978              $('.js-pre-sale-activity').find('.js-counting-time').each(function () {
979                _this.pcCountDownTimer.PhoneCountdownTime(this);
980              });
981              $('.price_value_box').find('.js-pre-sale-price-box').show(0, $('.js-pre-sale-price-box').find('.js-discount').text(data.discount));
982              $('.js-pre-sale-price-box').find('.js-isPreSale').attr('href', data.url);
983            } else {
984              $('.js-m-pre-sale-activity-box').find('.js-counting-time').attr('data-time', countDownTime);
985              _this.mCountDownTimer = new TimeFormat();
986              $('.js-m-pre-sale-activity-box').find('.js-counting-time').each(function () {
987                _this.mCountDownTimer.PhoneCountdownTime(this);
988              });
989              $('.js-m-pre-sale-activity-box').find('.js-view-more').attr('href', data.url);
990              $('.js-m-pop-wrap').find('.js-pre-sale-shipping').html(obj.message);
991            }
992        },
993        getCountTimer: function(endTime) {
994            var timeStamp = (Date.parse(new Date())) / 1000;
995            var time = parseInt((endTime - timeStamp));
996            return time;
997        },
998        minusHandler: function () {
999            var inputValue = Number(this.$qtyInput.val());
1000            if (inputValue != 1) {
1001                this.$minusBtn.removeClass('gray');
1002            } else {
1003                this.$minusBtn.addClass('gray');
1004            }
1005        },
1006        /* 更改数量,如未全选属性,不做限制 */
1007        changeQty: function (e) {
1008            if (this.checkSelected(false)) {
1009                var num = this.stockQty;
1010                this.updateInput(num);
1011            }
1012            this.minusHandler();
1013        },
1014        /* 检测输入是否为数字 */
1015        checkQtyVaild: function (e) {
1016            var keyCode = e.which;
1017            if (keyCode >= 48 && keyCode <= 57) {
1018                return true;
1019            } else {
1020                return false;
1021            }
1022        },
1023        /**
1024         * @desc 根据库存数量对input框赋值
1025         * @author lijiahao
1026         * @param   Number    num       库存数量
1027         *
1028         **/
1029        updateInput: function (num) {
1030            var inputValue = this.$qtyInput.val();
1031            if (inputValue > num && num > 0) {
1032                this.$qtyInput.val(num);
1033            }
1034            if (inputValue == 0 || num <= 0) {
1035                this.$qtyInput.val(1);
1036            }
1037        },
1038        /* 显示库存信息 */
1039        updateStockInfo: function () {
1040            var stockQty = this.stockQty;
1041            var shippingText = this.stockData.message,
1042                $shipping = $('.js-product-info').find(".shipping_text"),
1043                warLen = $('.js-detail-warehouse .js-warehouse-item li').length, //仓库数量,无任何仓库则无任何通邮方式
1044                ware_code = $('.js-warehouse-item').find('.war_item.active');
1045            
1046            if (stockQty > 0 && warLen > 0) {
1047                $shipping.removeClass('warn').html(shippingText);
1048                this.$addBtn.removeClass('gray');
1049                this.$buyNowBtn.removeClass('gray');
1050                this.$paypalBtn.removeClass('gray');
1051                //拼团开团按钮只有中仓有效
1052                if(ware_code === "CN"){
1053                  this.$startMyGroupBtn.removeClass('gray'); 
1054                }
1055                this.isBtnDisabled = false;
1056            } else {
1057                $shipping.html('sold out').addClass('warn');
1058                this.$addBtn.addClass('gray');
1059                this.$buyNowBtn.addClass('gray');
1060                this.$paypalBtn.addClass('gray');
1061                this.$startMyGroupBtn.addClass('gray');
1062                this.isBtnDisabled = true;
1063            }
1064
1065        },
1066        //监听输入数量input库存加购处理(限制不超300)
1067        keyCodeStockLimit: function (e) {
1068            var _this = this;
1069            var inputChange = 0;
1070            var $limitTip = _this.$qtyInput.parents('.limitContent').find('.limitQty');
1071            _this.$qtyInput.on('input propertychange', function () {
1072                inputChange = $(this).val();
1073                if (_this.$plusBtn.hasClass('gray')) {
1074                    _this.$plusBtn.removeClass('gray');
1075                }
1076                $limitTip.slideUp();
1077            }).blur(function () {
1078                var stockQty = _this.stockQty;
1079                var isPreorder = _this.stockData.isPreorder;
1080                var preorderLimit = _this.stockData.preorderInfo.once_limit_amount;
1081                var inputValue = Number($(this).val());
1082                //当实际库存且用户数量大于300时
1083                if (stockQty > 300 && inputValue > 299) {
1084                    $limitTip.slideDown().find('.moreStock').show().siblings().hide();
1085                    _this.$plusBtn.addClass('gray');
1086                    $(this).val(300);
1087                }
1088                //当实际库存<300且小于用户加购数量时
1089                if (stockQty < 300 && stockQty <= inputValue) {
1090                    $(this).val(stockQty);
1091                    _this.$plusBtn.addClass('gray');
1092                    var stockTip = isPreorder == 1 && preorderLimit > 0 ? 'maximum '+ stockQty+' pcs at a time' : 'Only ' + stockQty + '  left';
1093                    $limitTip.slideDown().find('.onlyStock').html(stockTip).show().siblings().hide();
1094                }
1095            })
1096
1097        },
1098
1099        /* 加入购物车请求 */
1100        addRequire: function () {
1101            this.showBtnLoading(1);
1102
1103            var _this = this,
1104                data = this.packAddData(),
1105                quantity = this.$qtyInput.val();
1106                
1107            
1108            $.ajax({
1109                url: '/addProduct.html',
1110                type: 'post',
1111                dataType: 'json',
1112                data: data,
1113                cache: false,
1114                processData: false,
1115                contentType: false,
1116                success: function (data) {
1117                    if (data.message == 'success') {
1118                        
1119                        var selected_total = _this.shopCartNum = data.data.selected_total;
1120                        if(!_this.isPc){
1121                            $('.js-m-pop-wrap').removeClass('show') //关闭poa属性选择弹框
1122                            $('.js-m-pop-wrap').find('.poa_list_wrap').hide(300);
1123                            _this.closeModal() //恢复页面滚动
1124                        }
1125                        
1126                        
1127                        /* 飞入导航特效开始 */
1128                        window.scrollTo(0,0) //滚动到页面顶部
1129                        if(_this.isPc) {
1130                            var offset = $(".shopCart-box").offset();
1131                            var boxLeft = $('.js-addcart-flyer .addToCart').offset().left;
1132                            var boxTop = $('.js-addcart-flyer .addToCart').offset().top - $(window).scrollTop();
1133                            leftNum = 7
1134                        } else {
1135                            var offset = $(".shopcart_m").offset();
1136                            var boxLeft = $(window).width()/2;
1137                            var boxTop = 100;
1138                            leftNum  = 15
1139                        }
1140                        var img = $('#thumbs-banner>.swiper-wrapper').eq(0).find('img').attr('data-original');
1141                        var flyer = $('<img class="img-flyer" src="'+img+'">');
1142                        //飞入导航特效
1143                        flyer.fly({
1144                            start: {
1145                                left: boxLeft,
1146                                top: boxTop,
1147                            },
1148                            end: {
1149                                left: offset.left+ leftNum,
1150                                top: offset.top - $(window).scrollTop() + 10,
1151                                width: 20,
1152                                height: 20
1153                            },
1154                            speed: _this.isPc ? 0.9 : 0.8, //越大越快,默认1.2
1155                            onEnd: function(){
1156                                //修改导航处购物车数量
1157                                if(_this.isPc){
1158                                    $('.shopCart-box').find('.msg_sum').text(selected_total).show();
1159                                }else{
1160                                    if(_this.theme === 'makeup2'){
1161                                        $("#js-nav-container .m-nav-shopCart .msg_sum").text(selected_total).show();
1162                                    }
1163                                    _this.$bottomBar.find('.shopcart_m .num').text(selected_total).show();
1164                                    $('#js-nav-container .m-shopcart .num').text(selected_total).show();
1165                                }
1166                                this.destory();
1167                            }
1168                        });
1169
1170                        /* 飞入导航特效结束 */
1171
1172                        $('.shopcart-products-container').html(data.data.shopcart_list);
1173                        
1174                    } else {
1175                        _this.errorAlert(data.msg);
1176                    }
1177                    _this.hideBtnLoading();
1178
1179                    //点击加购成功后追踪推荐位数据
1180                    _this.recObj["ac"] = "cart"; 
1181                    _this.recObj["products_id"] = _this.pid; 
1182                    Record.rec(_this.recObj);
1183                    var rmmds = _this.getQueryString('rmmds');
1184                    if(rmmds === 'search'){
1185                        //搜索埋点
1186                        nDC.RecordClick('cart', [_this.pid])
1187                    }
1188                    
1189                    //FB事件监测
1190                    _this.sendFbEvents('AddToCart')
1191                },
1192                error: function (data) {
1193                    console.log(data);
1194                    _this.hideBtnLoading();
1195                }
1196            })
1197
1198        },
1199        //获取url中query参数
1200        getQueryString: function (name) {
1201            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
1202            var r = window.location.search.substr(1).match(reg);
1203            if (r != null) return unescape(r[2]);
1204            return null;
1205        },
1206        /*点击加购按钮及添加心愿单按钮发送FB事件 */
1207        sendFbEvents: function (eventName) {
1208            var sku = productSKU,//产品sku
1209                currency = this.sel !== null ? this.sel : this.defaultSel,//当前币种
1210                quantity = this.$qtyInput.val(),//数量
1211                type = '',//content_type类型
1212                price = this.fbsendPrice,//产品美元价格
1213                productData = pointData.pointData,
1214                gmcCountry = this.getQueryString('gmcCountry'),
1215                code = this.headerInfo.coutry_data.code,
1216                poaList = [], //poa数组
1217                id= '',
1218                obj = {};
1219            var country = gmcCountry && gmcCountry !== '' ? gmcCountry : code;
1220            if (poaKeys.length) {
1221                type = 'product_group'
1222            } else {
1223                type = 'product'
1224            }
1225            if(poaCodeList != null) {
1226                Object.keys(poaCodeList).forEach(function(key){
1227                    var poaId = productData.products_id + '-' + poaCodeList[key].replace('POA', '') + '-' + country + '-' + productData.warehouse; //产品ID-POA数字-国家编码-仓库
1228                    poaList.push(poaId)
1229                });
1230            }
1231            if (poaKeys.length) {
1232                this.getPoaNum();
1233            }
1234            if (this.poaLength > 0) {
1235                if(poaCodeList != null){
1236                    id = productData.products_id + '-' + poaCodeList[this.activeSortVid.join(";")].replace('POA', '') + '-' + country + '-' + productData.warehouse; //产品ID-POA数字-国家编码-仓库
1237                }   
1238            } else {
1239                id = productData.products_id + '-' + productData.sku.replace('SKU', '') + '-' + country + '-' + productData.warehouse; //产品ID-SKU数字-国家编码-仓库
1240                
1241            }
1242            if (eventName === 'AddToCart') {
1243                obj = {
1244                    value: (Number(quantity) * Number(price)).toFixed(2),
1245                    currency: currency,
1246                    content_ids: id,
1247                    content_type: 'product',
1248                    item_group_id: productData.products_id,
1249                    contents: [
1250                        {
1251                            id: id,
1252                            quantity: quantity,
1253                            item_price: price
1254                        }
1255                    ],
1256                }
1257                
1258            } else if (eventName === 'AddToWishlist') {
1259                if (!poaKeys.length) {
1260                    obj.content_ids = id
1261                } else {
1262                    obj.content_ids = poaList
1263                }
1264                obj.content_type = type
1265            }
1266            //fb id存在测发送事件
1267            if (fbNo && fbNo != '') {
1268                fbq('track', eventName, obj);
1269            }
1270
1271        },
1272        /* matcc站点Buy At Amazon 转化率埋点*/
1273        thirdChannelFbEvents: function(){
1274            var price = this.fbsendPrice,//产品美元价格
1275                host = win.location.host;
1276
1277            // audew站点SKU979938不上报
1278            if (host.indexOf('audew') > -1 && [100058].includes(+productID)) {
1279              return
1280            }
1281            try{
1282                //域名判断-域名是否包含matcc
1283                if(host.indexOf('matcc') > -1){
1284                    gtag('event', 'conversion', {
1285                        'send_to': 'AW-715655859/F73FCOPS-q0BELOVoNUC',
1286                        'value': Number(price*0.15).toFixed(2),//美元价格*0.15后的订单金额
1287                        'currency': 'USD',//固定不变
1288                    });
1289                } else {
1290                    awInfo.forEach(function(item){
1291                        gtag('event', 'conversion', {
1292                            'send_to': item.id + '/' + item.label
1293                        });
1294                    }) 
1295                }
1296                
1297            } catch (errors){
1298                console.log('Fb id 不存在')
1299            }
1300        },
1301        /* 隐藏模态框 */
1302        modalRemove: function () {
1303            $(".shipping-modal").hide();
1304        },
1305         /* 关闭加购成功提示模态框 */
1306        addModalRemove: function () {
1307            var _this = this,
1308                leftNum = 0,
1309                selected_total = this.shopCartNum;
1310            $(".shipping-modal").hide();
1311            if(_this.isPc) {
1312                var offset = $(".shopCart-box").offset();
1313                var boxLeft = $('.js-addcart-flyer .addToCart').offset().left;
1314                var boxTop = $('.js-addcart-flyer .addToCart').offset().top - $(window).scrollTop();
1315                leftNum = 7
1316            } else {
1317                var offset = $(".shopcart_m").offset();
1318                var boxLeft = $(window).width()/2;
1319                var boxTop = 100;
1320                leftNum  = 15
1321            }
1322            var img = $('#thumbs-banner>.swiper-wrapper').eq(0).find('img').attr('data-original');
1323            var flyer = $('<img class="img-flyer" src="'+img+'">');
1324            //飞入导航特效
1325            flyer.fly({
1326                start: {
1327                    left: boxLeft,
1328                    top: boxTop,
1329                },
1330                end: {
1331                    left: offset.left+ leftNum,
1332                    top: offset.top - $(window).scrollTop() + 10,
1333                    width: 20,
1334                    height: 20
1335                },
1336                speed: _this.isPc ? 0.9 : 0.8, //越大越快,默认1.2
1337                onEnd: function(){
1338                    //修改导航处购物车数量
1339                    if(_this.isPc){
1340                        $('.shopCart-box').find('.msg_sum').text(selected_total).show();
1341                    }else{
1342                        if(_this.theme === 'makeup2'){
1343                            $("#js-nav-container .m-nav-shopCart .msg_sum").text(selected_total).show();
1344                        }
1345                        _this.$bottomBar.find('.shopcart_m .num').text(selected_total).show();
1346                        $('#js-nav-container .m-shopcart .num').text(selected_total).show();
1347                    }
1348                    this.destory();
1349                }
1350            });
1351        },
1352        /* 更改邮寄方式 */
1353        selShipment: function (self) {
1354            var $this = $(self);
1355
1356            $this.prop('checked', true);
1357            $shipments = $("#item_shipments_box");
1358            $shipments.find('.shipping_type').html($this.attr('ship') + '<u><span class="arrow_a"><i><i></i></i></span></u>');
1359            $shipments.find('.changePrice').html($this.attr('fee'));
1360            $shipments.find('.shipping_time>em').html($this.attr('time'));
1361
1362        },
1363        /* 计算模态框位置 */
1364        shippingModalPositon: function () {
1365            var modal_container = $('.shipping-modal .modal_container');//模态框container
1366            var modal_content = modal_container.children().eq(0);//模态框content对象
1367            var modal_content_width = modal_content.outerWidth(true);//content宽度
1368            var modal_content_height = modal_content.outerHeight(true);//content高度
1369            var window_width = $(window).outerWidth(true);//屏幕宽度
1370            var window_height = $(window).outerHeight(true);//屏幕高度
1371            var sum = 50;//相对值
1372            modal_content.css({
1373                margin: '0 auto'
1374            });
1375            if (!this.isPc) {
1376                modal_container.css({
1377                    marginTop: '225px'
1378                });
1379                return;
1380            }
1381            if (modal_content_height >= window_height - sum) {
1382                modal_container.css({
1383                    marginTop: sum + 'px'
1384                });
1385            } else {
1386                if ((window_height - modal_content_height) / 2 <= sum) {
1387                    modal_container.css({
1388                        marginTop: sum + 'px'
1389                    });
1390                } else
1390 {
1391                    modal_container.css({
1392                        marginTop: (window_height - modal_content_height) / 2 + 'px'
1393                    });
1394                }
1395            }
1396
1397        },
1398        /* 询问是否进入购物车 */
1399        // asking: function (quantity) {
1400        //     var terminal = this.isPc ? '_pc' : '_m'
1401        //     if(templates['asking'][this.theme + terminal]){
1402        //         $(".shipping-modal").show(200).find('.modal_container').html(templates['asking'][this.theme + terminal].replace(templates['asking']['replaceKey'], quantity ));
1403        //     }else{
1404        //         $(".shipping-modal").show(200).find('.modal_container').html(templates['asking']['common'].replace(templates['asking']['replaceKey'], quantity ));
1405        //     }
1406        // },
1407        getObjKeys: function (obj) {
1408            if (obj !== Object(obj)) throw new TypeError('Invalid object');
1409            var keys = [];
1410            for (var key in obj)
1411                if (Object.prototype.hasOwnProperty.call(obj, key))
1412                    keys[keys.length] = key;
1413            return keys;
1414        },
1415        //把组合的key放入结果集SKUResult
1416        add2SKUResult: function (combArrItem, sku) {
1417            var key = combArrItem.join(";");
1418            if (this.SKUResult[key]) {//SKU信息key属性·
1419                this.SKUResult[key].count += sku.count;
1420                this.SKUResult[key].prices.push(sku.price);
1421                this.SKUResult[key].usPrice.push(sku.usPrice);
1422                this.SKUResult[key].usMarketPrice.push(sku.usMarketPrice);
1423            } else {
1424                this.SKUResult[key] = {
1425                    prices: [sku.price],
1426                    usPrice: [sku.usPrice],
1427                    usMarketPrice: [sku.usMarketPrice],
1428                };
1429            }
1430        },
1431        add2GiftResult: function (combArrItem, sku, num) {
1432            var key = combArrItem.join(";");
1433            if (!this.giftResult[num]) {
1434                this.giftResult[num] = {}
1435            }
1436            if (this.giftResult[num][key]) {//SKU信息key属性·
1437                //this.giftResult[key].count += sku.count;
1438                this.giftResult[num][key].prices.push(sku.price);
1439            } else {
1440                this.giftResult[num][key] = {
1441                    prices: [sku.price]
1442                };
1443            }
1444        },
1445        //初始化得到结果集
1446        initSKU: function () {
1447            var i, j, skuKeys = this.getObjKeys(poaData);
1448            for (i = 0; i < skuKeys.length; i++) {
1449                var skuKey = skuKeys[i];//一条poa信息key
1450                var sku = poaData[skuKey];    //一条poa信息value
1451                var skuKeyAttrs = skuKey.split(";"); //poa信息key属性值数组
1452                var len = skuKeyAttrs.length;
1453                //对每个SKU信息key属性值进行拆分组合
1454                var combArr = this.arrayCombine(skuKeyAttrs);
1455                for (j = 0; j < combArr.length; j++) {
1456                    this.add2SKUResult(combArr[j], sku);
1457                }
1458                //结果集接放入SKUResult
1459                this.SKUResult[skuKey] = {
1460                    prices: [sku.price],
1461                    usPrices: [sku.usPrice],
1462                    usMarketPrice: [sku.usMarketPrice]
1463                }
1464            }
1465        },
1466        initGift: function () {
1467            for (var item in this.giftInfo) {
1468                var i, j, skuKeys = this.getObjKeys(this.giftInfo[item]);
1469                if (!skuKeys.length) {
1470                    this.giftResult[item] = {};
1471                }
1472                for (i = 0; i < skuKeys.length; i++) {
1473                    var skuKey = skuKeys[i];//一条poa信息key
1474                    var sku = this.giftInfo[item][skuKey];    //一条poa信息value
1475                    var skuKeyAttrs = skuKey.split(";"); //poa信息key属性值数组
1476                    var len = skuKeyAttrs.length;
1477                    //对每个SKU信息key属性值进行拆分组合
1478                    var combArr = this.arrayCombine(skuKeyAttrs);
1479                    for (j = 0; j < combArr.length; j++) {
1480                        this.add2GiftResult(combArr[j], sku, item);
1481                    }
1482                    //结果集接放入SKUResult
1483                    this.giftResult[item][skuKey] = {
1484                        prices: [sku.price]
1485                    }
1486                }
1487            }
1488        },
1489        pad: function (num, len) {
1490            var num = num.toString(2).toString();
1491            var length = num.length
1492            for (var i = 0; i < (len - length); i++) {
1493                num = "0" + num;
1494            }
1495            return num.split('');
1496            ''
1497        },
1498        /**
1499         * 从数组中生成指定长度的组合
1500         */
1501        arrayCombine: function (targetArr) {
1502            if (!targetArr || !targetArr.length) {
1503                return [];
1504            }
1505            var len = targetArr.length;
1506            var resultArrs = [];
1507            // 所有组合
1508            var flagArrs = [];
1509            var combineTotal = Math.pow(2, 4) - 1;
1510            for (var n = 1; n <= combineTotal; n++) {
1511                flagArrs.push(this.pad(n, len));
1512            }
1513            for (var i = 0; i < flagArrs.length; i++) {
1514                var combArr = [];
1515                var flagArr = flagArrs[i];
1516                for (var j = 0; j < len; j++) {
1517                    (flagArr[j] > 0) && combArr.push(targetArr[j]);
1518                }
1519                resultArrs.push(combArr);
1520            }
1521            return resultArrs;
1522        },
1523        /**
1524         * @desc 未开启购物车时的价格切换
1525         * @author lijiahao
1526         */
1527        updatePrice: function () {
1528            var _this = this,
1529                $active = $('.poaItem a.active');//已选属性的数量
1530
1531            if ($active.length === this.poaLength) {
1532                var selectedIds = [];//存放data-vid;
1533                $active.each(function () {
1534                    selectedIds.push($(this).attr('data-vid'));
1535                });
1536                /* 属性值由小到大排序 */
1537                selectedIds.sort(function (value1, value2) {
1538                    return parseInt(value1) - parseInt(value2);
1539                });
1540
1541                var selIcon = $.trim($(".product_price .price_datalist").find('b').text());
1542                var usPrices = this.SKUResult[selectedIds.join(';')].usPrices;
1543                var usMarketPrice = this.SKUResult[selectedIds.join(';')].usMarketPrice;
1544                var maxPrice = Math.max.apply(Math, usPrices);
1545                var minPrice = Math.min.apply(Math, usPrices);
1546                var maxUsMarketPrice = Math.max.apply(Math, usMarketPrice);
1547
1548                // maxPrice = _this.transformPrice(maxPrice);
1549                // maxUsMarketPrice = _this.transformPrice(maxUsMarketPrice);
1550
1551                if (this.isPc) {
1552                    $(".product_price").find('.new_price>.price_value').text(toThousands(maxPrice));
1553                    if (selIcon != 'руб.' && selIcon != 'AED') {
1554                        $(".product_price").find('.old_price').text(selIcon + toThousands(maxUsMarketPrice));
1555                    } else {
1556                        $(".product_price").find('.old_price').text(toThousands(maxUsMarketPrice) + ' ' + selIcon);
1557                    }
1558                } else {
1559                    if (selIcon != 'руб.' && selIcon != 'AED') {
1560                        $(".product_price").find('.new_price>.price_value').text(selIcon + toThousands(maxPrice));
1561                        $(".product_price").find('.old_price').text(selIcon + toThousands(maxUsMarketPrice));
1562                    } else {
1563                        $(".product_price").find('.new_price>.price_value').text(toThousands(maxPrice) + ' ' + selIcon);
1564                        $(".product_price").find('.old_price').text(toThousands(maxUsMarketPrice) + ' ' + selIcon);
1565                    }
1566                }
1567            }
1568
1569        },
1570        /**
1571         * @desc 从stockMessage接口获取价格后更新价格
1572         * @author lijiahao
1573         */
1574        updatePrice2: function () {
1575            var _this = this,
1576                sel = this.sel !== null ? this.sel : this.defaultSel,//当前币种
1577                selIcon = $.trim($(".product_price .price_datalist").find('b').text()),//当前币种icon
1578                stockData = this.stockData,//库存信息
1579                final_price = this.transformPrice(stockData.final_price_usd),
1580                market_price = this.transformPrice(stockData.market_price_usd);
1581
1582            this.fbsendPrice = stockData.final_price_usd; //获取poa的us价格
1583
1584            if(this.isUseCacheData){
1585                if (_this.isPc) {
1586                    if(selIcon != 'руб.'){
1587                        $(".product_price").find('.new_price>.price_value').text(toThousands(final_price));
1588                    }else{
1589                        $(".product_price").find('.new_price>.price_value').text(toThousands2(final_price));
1590                    }
1591                } else {
1592                    if (selIcon == 'руб.' || selIcon == 'AED') {
1593                        $(".product_price").find('.new_price>.price_value').html(toThousands(final_price) + ' ' + selIcon);
1594                        $(".activity-phone .product-info .activity-price").html(toThousands(final_price) + ' ' + selIcon);//M端活动价
1595                    } else {
1596                        $(".product_price").find('.new_price>.price_value').html(selIcon + toThousands(final_price));
1597                        $(".activity-phone .product-info .activity-price").html(selIcon + toThousands(final_price));//M端活动价
1598                    }
1599                }
1600    
1601                if (selIcon == 'руб.' || selIcon == 'AED') {
1602                    if(selIcon != 'руб.'){
1603                        $(".product_price").find('.old_price').text(toThousands(market_price) + ' ' + selIcon);
1604                        $(".activity-phone .product-info .activity-del").text(toThousands(market_price) + ' ' + selIcon);//M端活动价
1605                    }else{
1606                        $(".product_price").find('.old_price').text(toThousands2(market_price) + ' ' + selIcon);
1607                        $(".activity-phone .product-info .activity-del").text(toThousands2(market_price) + ' ' + selIcon);//M端活动价
1608                    }
1609                } else {
1610                    $(".product_price").find('.old_price').text(selIcon + toThousands(market_price));
1611                    $(".activity-phone .product-info .activity-del").text(selIcon + toThousands(market_price));//M端活动价
1612                }
1613            }else{
1614                /* data-usprice用于右上角切换币种时用的数据 */
1615                if (this.isPc) {
1616                    $(".product_price").find('.new_price>.price_value').text(stockData.final_price).attr('data-usprice', stockData.final_price_usd);
1617                } else {
1618                    $(".product_price").find('.new_price>.price_value').text(stockData.format_final_price).attr('data-usprice', stockData.final_price_usd);
1619                    //处理活动区域价格显示
1620                    $(".activity-phone").find('.activity-price').text(stockData.format_final_price).attr('data-usprice', stockData.final_price_usd);
1621                }
1622
1623                if (sel === 'USD') {
1624                    $(".product_price").find('.old_price').text(stockData.format_market_price).attr('data-usprice', stockData.market_price_usd);
1625                    $(".activity-phone").find('.activity-del').text(stockData.format_market_price).attr('data-usprice', stockData.market_price_usd);
1626                } else {
1627                    if (selIcon != 'руб.' && selIcon != 'AED') {
1628                        $(".product_price").find('.old_price').text(selIcon + stockData.market_price).attr('data-usprice', stockData.market_price_usd);
1629                        $(".activity-phone").find('.activity-del').text(selIcon + stockData.market_price).attr('data-usprice', stockData.market_price_usd);
1630                    } else {
1631                        $(".product_price").find('.old_price').text(stockData.market_price + ' ' + selIcon).attr('data-usprice', stockData.market_price_usd);
1632                        $(".activity-phone").find('.activity-del').text(stockData.market_price + ' ' + selIcon).attr('data-usprice', stockData.market_price_usd);
1633                    }
1634                }
1635            }
1636            
1637        },
1638        showAmazonList: function (e) {
1639            $(e.target).siblings('.dropdown_list').toggle();
1640        },
1641        chooseGift: function (e) {
1642            var $gift_item = $(e.target).closest('.gift_item');
1643            if ($gift_item.hasClass('disabled')) return false;
1644            if ($gift_item.hasClass('isChecked')) {
1645                $gift_item.removeClass('isChecked');
1646                if (!this.isPc) {
1647                    $gift_item.find('.clickIcon:visible>i').removeClass('icon-M-selected').addClass('icon-M-Notselected');
1648                    this.changeGiftText_m();
1649                }
1650            } else {
1651                var isNull = false;
1652                var $attr_item = $gift_item.find('.gift_info_wrap').find('.info_attr');
1653                $attr_item.each(function () {
1654                    if ($(this).find('.gift_attr.active').length == 0) {
1655                        isNull = true;
1656                    }
1657                });
1658                if (isNull) return false;
1659                $gift_item.addClass('isChecked');
1660                if (!this.isPc) {
1661                    $gift_item.find('.clickIcon>i').addClass('icon-M-selected').removeClass('icon-M-Notselected');
1662                    this.changeGiftText_m();
1663                }
1664                e.stopPropagation();
1665            }
1666        },
1667        _giftEvent: function () {
1668            var _this = this;
1669            $(doc).on('click', '.js-product-info .gift .gift_attr:not(.gray)', $.proxy(this.updateGift, this));
1670            $(doc).on('click', '.js-product-info .gift_info_wrap', function (e) {
1671                e.stopPropagation();
1672            });
1673
1674            $(doc).on('click', '.js-product-info .gift_item>.clickIcon', $.proxy(this.chooseGift, this));
1675            $(doc).on('click', '.js-product-info .gift_item>a:not(.gray)', function (e) {
1676                if ($(this).siblings('.gift_info_wrap').find('.info_attr').length == 0) {
1677                    window.open($(this).attr('data-url'));
1678                    return false;
1679                }
1680                // if($(this).parent().hasClass('showInfo')){
1681                //     $(this).parent().removeClass('showInfo');
1682                //     return false;
1683                // }
1684                $('.gift_item').removeClass('showInfo');
1685                $(this).parent().addClass('showInfo');
1686
1687                /* 根据wrap高度,重新设置top值 */
1688                var $wrap = $(this).next('.gift_info_wrap');
1689                _this.giftModalPostion($wrap);
1690
1691                e.stopPropagation();
1692            });
1693            $(doc).on('click', '.js-product-info .gift_info_wrap .ok_btn', $.proxy(this.checkGift, this));
1694            $(doc).on('click', '.js-product-info .gift_info_wrap .cancel_btn', function () {
1695                var $wrap = $(this).closest('.gift_info_wrap');
1696                $(this).parents('.gift_item').removeClass('showInfo');
1697                if ($wrap.find('.info_attr').length !== $wrap.find('.gift_attr.active').length) {
1698                    $wrap.closest('.gift_item').removeClass('isChecked');
1699                }
1700            });
1701        },
1702        updateGift: function (e) {
1703            /* 判断点击的是否为空的<a>标签,如<a>里面有<img>,则选择<img>的父元素<a> */
1704
1705            if (!$(e.target).is('a')) {
1706                e.target = $(e.target).parent();
1707            }
1708
1709            var _this = this,
1710                $target = $(e.target),
1711                gift_id = $target.closest('.gift_item').attr('data-giftid');
1712
1713            if ($target.hasClass('active')) {
1714                $target.removeClass('active');
1715            } else {
1716                $target.addClass('active').siblings().removeClass('active');
1717                $target.closest('.info_attr').attr('data-activeIndex', $target.index());
1718            }
1719
1720            $target.closest('.gift_info').next('.gift_tips').hide();
1721            this.giftModalPostion($target.closest('.gift_info_wrap'));
1722
1723            if (!this.checkSelected(false)) return false;
1724            var selectedObjs = $target.closest('.gift_info').find('.gift_attr.active');
1725
1726            if (selectedObjs.length) {
1727                //获得组合key价格
1728                var selectedIds = [];
1729                selectedObjs.each(function () {
1730                    selectedIds.push($(this).attr('data-valueid'));
1731                });
1732                selectedIds.sort(function (value1, value2) {
1733                    return parseInt(value1) - parseInt(value2);
1734                });
1735                var len = selectedIds.length;
1736
1737
1738                //用已选中的节点验证待测试节点 underTestObjs
1739                $target.closest('.gift_info').find('.gift_attr').not(selectedObjs).each(function () {
1740                    var siblingsSelectedObj = $(this).siblings('.active');
1741                    var testAttrIds = [];//从选中节点中去掉选中的兄弟节点
1742                    if (siblingsSelectedObj.length) {
1743                        var siblingsSelectedObjId = siblingsSelectedObj.attr('data-valueid');
1744                        for (var i = 0; i < len; i++) {
1745                            (selectedIds[i] != siblingsSelectedObjId) && testAttrIds.push(selectedIds[i]);
1746                        }
1747                    } else {
1748                        testAttrIds = selectedIds.concat();
1749                    }
1750                    testAttrIds = testAttrIds.concat($(this).attr('data-valueid'));
1751                    testAttrIds.sort(function (value1, value2) {
1752                        return parseInt(value1) - parseInt(value2);
1753                    });
1754                    if (!_this.giftResult[gift_id][testAttrIds.join(';')]) {
1755                        $(this).addClass('gray').removeClass('active');
1756                    } else {
1757                        $(this).removeClass('gray');
1758                    }
1759                });
1760            }
1761
1762        },
1763        checkAmazonBtn: function () {
1764            if (this.isPc) {
1765                var $way_box = $('.way_btn_box');
1766                var $country_wrap = $way_box.find('.country-fa');
1767                var thirdChannel = $way_box.find('.way_btn_bg')
1768                if(thirdChannel.length < 2) { //第三方按钮只有一个时,取消高亮样式
1769                    thirdChannel.eq(0).removeClass('first_btn')
1770                }
1771                if ($way_box.height() == 0) {
1772                    $way_box.closest('.buy_way_wrap').hide();
1773                    return false;
1774                }
1775                $country_wrap.each(function () {
1776                    if ($(this).find('.attrCountry').find('li').length == 0) {
1777                        $(this).remove();
1778                        //$(this).addClass('gray');
1779                    }
1780                });
1781            } else {
1782                $('.buy_way_wrap').remove();
1783                var $buy_btn_list = $(".buybtn_list_wrap .btnlist"),
1784                    btnLen = $(".buybtn_list_wrap").find('a').length;
1785                if (!btnLen) {
1786                    this.$bottomBar.find('.abtest_buyway_btn,.countryBox').hide().end().find('.addToCart_m').css('width', '100%'); //M端无第三方按钮时,buy At 按钮隐藏
1787                }
1788            }
1789        },
1790        previewPic: function (e) {
1791            $('#bigImg-container .imgLoading').show();
1792            if (!$(e.target).is('img')) {
1793              e.target = $(e.target).find('img');
1794            }
1795            var pic_big_url = $(e.target).attr('pic_big');
1796            $('.single_pic').eq(0).find('img').attr('src', pic_big_url).closest('.single_pic').show().siblings('.product_img_list').hide();
1797            document.querySelector('.single_pic img').onload = function() {
1798              $('#bigImg-container .imgLoading').hide();
1799            }
1800        },
1801        previewPic_m: function (e) {
1802            if (!$(e.target).is('img')) {
1803                e.target = $(e.target).find('img');
1804            }
1805            var pic_big_url = $(e.target).attr('pic_big');
1806            $(".poa_wrap .base_img img").attr('src', pic_big_url);
1807        },
1808        checkGift: function (e) {
1809            var $attr_item = $(e.target).parent().siblings('.gift_info').find('.info_attr'),
1810                attr_name = '',
1811                status = true;
1812
1813            $attr_item.each(function () {
1814                if ($(this).find('.gift_attr.active').length === 0) {
1815                    status = false;
1816                    attr_name = $(this).attr('data-name');
1817                    return false;
1818                }
1819            });
1820
1821            if (!status) {
1822                $(e.target).parent().siblings('.gift_tips').show().children('span').text('please select a ' + attr_name);
1823            } else {
1824                $(e.target).closest('.gift_item').removeClass('showInfo').addClass('isChecked');
1825            }
1826
1827            this.giftModalPostion($(e.target).closest('.gift_info_wrap'));
1828        },
1829        /**
1830         * @desc 修改giftModal的位置
1831         * @author lijiahao
1832         * @param  $wrap modal容器
1833         *
1834         **/
1835        giftModalPostion: function ($wrap) {
1836            var wrapHeight = $wrap.outerHeight();
1837            $wrap.css('top', -wrapHeight - 10);
1838        },
1839        setGiftInfo: function () {
1840            var _this = this,
1841                $gift_item = $('.gift').find('.gift_item');
1842
1843            $gift_item.each(function () {
1844                $(this).addClass('isChecked').removeClass('disabled');
1845                $(this).find('.gift_attr').removeClass('active').addClass('gray');
1846            });
1847
1848            $gift_item.each(function () {
1849                var gift_id = $(this).attr('data-giftid');
1850                if (_this.giftResult.hasOwnProperty(gift_id)) {
1851                    var obj = _this.giftResult[gift_id];
1852                    for (var item in obj) {
1853                        if (!/;/.test(item)) {
1854                            $(this).find('.gift_attr[data-valueid=' + item + ']').removeClass('gray');
1855                        }
1856                    }
1857                    $(this).find('.attr_list').each(function () {
1858                        /* activeIndex:原先已选取的index值,切换poa时重新选取 */
1859                        var activeIndex = $(this).parent().attr('data-activeIndex');
1860                        if (activeIndex == undefined) {
1861                            $(this).find('.gift_attr:not(.gray)').eq(0).click();
1862                        } else {
1863                            if ($(this).find('.gift_attr').eq(activeIndex).hasClass('gray')) {
1864                                $(this).find('.gift_attr:not(.gray)').eq(0).click();
1865                            } else {
1866                                $(this).find('.gift_attr').eq(activeIndex).click();
1867                            }
1868                        }
1869
1870                    });
1871                } else {
1872                    $(this).removeClass('isChecked').addClass('disabled');
1873                    $(this).find('.gift_attr').removeClass('active').addClass('gray');
1874                }
1875            });
1876
1877        },
1878        /**
1879         * @desc 按钮loading
1880         * @param { number || undefined } type 按钮类型,1:add to cart; 2:buy now; 3:paypal 4:拼团start my group
1881         */
1882        showBtnLoading: function (type) {
1883            var $loading = '<div class="loading_bg" style="display:block;"><img src="/templates/common/src/shopCart/images/loading.gif" class="loading"></div>';
1884            if (type) {
1885                if (type === 1) {
1886                    this.$addBtn.addClass('gray').append($loading);
1887                } else if (type === 2) {
1888                    this.$buyNowBtn.addClass('gray').append($loading);
1889                } else if(type === 3){
1890                  this.$paypalBtn.addClass('gray').append($loading);
1891                }else if(type === 4){
1892                  this.$startMyGroupBtn.addClass('gray').append($loading);
1893                }
1894            } else {
1895                this.$addBtn.addClass('gray').append($loading);
1896                this.$buyNowBtn.addClass('gray').append($loading);
1897                this.$paypalBtn.addClass('gray').append($loading);
1898                this.$startMyGroupBtn.addClass('gray').append($loading);
1899            }
1900        },
1901        hideBtnLoading: function () {
1902            if (!this.isBtnDisabled) {
1903                this.$addBtn.removeClass('gray').find('.loading_bg').remove();
1904                this.$buyNowBtn.removeClass('gray').find('.loading_bg').remove();
1905                this.$paypalBtn.removeClass('gray').find('.loading_bg').remove();
1906                var ware_code = $('.js-warehouse-item').find('.war_item.active').attr('war_code');
1907                //拼团开团按钮只有中仓有效
1908                if(ware_code === "CN"){
1909                  this.$startMyGroupBtn.removeClass('gray') 
1910                }
1911                this.$startMyGroupBtn.find('.loading_bg').remove();
1912            } else {
1913                this.$addBtn.find('.loading_bg').remove();
1914                this.$buyNowBtn.find('.loading_bg').remove();
1915                this.$paypalBtn.find('.loading_bg').remove();
1916                this.$startMyGroupBtn.find('.loading_bg').remove();
1917            }
1918        },
1919        changeShippingCurrency: function(){
1920            var _this = this,
1921                sel = _this.sel,
1922                selIcon = _this.selIcon;
1923            $('.js-detail-module .js-shipping-poplist li').each(function(){
1924                var usPrice = Number($(this).attr('usprice'));
1925                if(usPrice != 0) { //价格为0,免运费,则无需切换价格
1926                    var newPrice = _this.transformPrice(usPrice);
1927                    $(this).attr('ship_price',newPrice)
1928                    if (selIcon == 'руб.' || selIcon == 'AED') {
1929                        if (selIcon != 'руб.') {
1930                            $(this).find('.list_shipcost, .ship_m_price').text(toThousands(newPrice) + ' ' + selIcon);
1931                            
1932                        } else {
1933                            $(this).find('.list_shipcost, .ship_m_price').text(toThousands2(newPrice) + ' ' + selIcon);
1934                        }
1935                    } else {
1936                        $(this).find('.list_shipcost, .ship_m_price').text(selIcon + toThousands(newPrice));
1937                    }
1938                }
1939            })
1940            var currentUsPrice = $('.js-detail-module .js-shipping-poplist li.active').attr('usprice')
1941            var currentShip = $('.js-detail-module .js-shipping-poplist li.active').attr('ship_price')
1942            var priceText = ''
1943            if(Number(currentUsPrice) == 0){
1944                return false
1945            }
1946            if (selIcon == 'руб.' || selIcon == 'AED') {
1947                if (selIcon != 'руб.') {
1948                    priceText = currentShip + ' ' + selIcon;   
1949                } else {
1950                    priceText = currentShip + ' ' + selIcon;
1951                }
1952            } else {
1953                priceText = selIcon + currentShip;
1954            }
1955            $('.js-detail-shipbox').find('.js-shipping-price').html(priceText)
1956        },
1957        changeCurrency: function (e) {
1958            var _this = this,
1959                $this = $(e.target).closest('li'),
1960                $activeLen = $('.poa_wrap').find('.attr_item.active').length;;
1961
1962            if (_this.CurrencyCfg) {
1963                var sel = $this.attr('sel'),
1964                    selHtml = $this.find('a').html(),
1965                    selIcon = $this.find('u').eq(0).text(),
1966                    $product_price = $(".product_price"),
1967                    wsStatus = null;
1968
1969                _this.sel = sel;
1970                _this.selIcon = selIcon;
1971
1972                _this.changeShippingCurrency();
1973
1974                /* 已选属性数量 != 属性数量 */
1975                if (this.poaLength != $activeLen || this.poaLength == 0) {
1976                    wsStatus = true;
1977
1978                    var new_new_price = _this.transformPrice(_this.usPrice),
1979                        new_old_price = _this.transformPrice(_this.oldUsPrice);
1980
1981                } else {
1982                    wsStatus = false;
1983                    var $active = $('.poaItem a.active');//已选属性的数量
1984                    var selectedIds = [];//存放data-vid;
1985                    $active.each(function () {
1986                        selectedIds.push($(this).attr('data-vid'));
1987                    });
1988                    /* 属性值由小到大排序 */
1989                    selectedIds.sort(function (value1, value2) {
1990                        return parseInt(value1) - parseInt(value2);
1991                    });
1992
1993
1994                    var usPrices = this.SKUResult[selectedIds.join(';')].usPrices;
1995                    var usMarketPrice = this.SKUResult[selectedIds.join(';')].usMarketPrice;
1996                    var maxPrice = Math.max.apply(Math, usPrices);
1997                    var maxUsMarketPrice = Math.max.apply(Math, usMarketPrice);
1998
1999                    var new_new_price = _this.transformPrice(maxPrice),
2000                        new_old_price = _this.transformPrice(maxUsMarketPrice);
2001                }
2002
2003                //$product_price.find('.price_datalist>b').html(_this.CurrencyCfg[sel][1]+'<i class="icon shopCart icon-arrows_down1"></i>');
2004                $product_price.find('.price_datalist>b').html(selIcon + ' ' + '<i class="icon shopCart icon-arrows_down1"></i>');
2005
2006                if (_this.isPc) {
2007                    if(selIcon != 'руб.'){
2008                        $product_price.find('.new_price>.price_value').text(toThousands(new_new_price));
2009                    }else{
2010                        $product_price.find('.new_price>.price_value').text(toThousands2(new_new_price));
2011                    }
2012                } else {
2013                    if (selIcon == 'руб.' || selIcon == 'AED') {
2014                        $product_price.find('.new_price>.price_value').html(toThousands(new_new_price) + ' ' + selIcon);
2015                        $(".activity-phone .product-info .activity-price").html(toThousands(new_new_price) + ' ' + selIcon);//M端活动价
2016                    } else {
2017                        $product_price.find('.new_price>.price_value').html(selIcon + toThousands(new_new_price));
2018                        $(".activity-phone .product-info .activity-price").html(selIcon + toThousands(new_new_price));//M端活动价
2019                    }
2020                }
2021
2022                if (selIcon == 'руб.' || selIcon == 'AED') {
2023                    if(selIcon != 'руб.'){
2024                        $product_price.find('.old_price').text(toThousands(new_old_price) + ' ' + selIcon);
2025                        $(".activity-phone .product-info .activity-del").text(toThousands(new_old_price) + ' ' + selIcon);//M端活动价
2026                    }else{
2027                        $product_price.find('.old_price').text(toThousands2(new_old_price) + ' ' + selIcon);
2028                        $(".activity-phone .product-info .activity-del").text(toThousands2(new_old_price) + ' ' + selIcon);//M端活动价
2029                    }
2030                } else {
2031                    $product_price.find('.old_price').text(selIcon + toThousands(new_old_price));
2032                    $(".activity-phone .product-info .activity-del").text(selIcon + toThousands(new_old_price));//M端活动价
2033                }
2034                var $topCountryBox = $(".top-country-box").eq(0);
2035                $topCountryBox.find('.currency').find('.active').find('span').html(selHtml);
2036                $topCountryBox.find('.currency_name').text(sel);
2037                $topCountryBox.find('.currency_box').find('li[sel=' + sel + ']').addClass('selected').siblings().removeClass('selected');
2038                _this.setCurRequire(sel);
2039                if (!_this.isWsdataNull) {
2040                    _this.updateWsTable(wsStatus);//修改批发价
2041                }
2042
2043                if (!_this.isPc) {
2044                    $('.price_datalist').fadeOut();
2045                }
2046
2047            }
2048            //详情页其他版块价格切换
2049            _this.detailPanelPrice(selIcon);
2050            ProductMixHandle.changeTotalPrice(); //更新组合商品价格js
2051        },
2052        setCookie: function(name,value, day) { 
2053            var exp = new Date(); 
2054            exp.setTime(exp.getTime() + day*24*60*60*1000); 
2055            document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
2056		},
2057		//获取cookie信息
2058		getCookie: function(name){
2059			var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
2060			if(arr=document.cookie.match(reg))
2061			return unescape(arr[2]);
2062			else
2063			return null;
2064		},
2065        triggerWishlist: function (e) {
2066            var _this = this;
2067            if (this.$wishlistWrap.hasClass('submiting')) return false;
2068            if(_this.theme === 'MultiPurpose'){
2069                this.$isMultiWishWrap.addClass('submiting')
2070            }else{
2071                _this.$wishlistWrap.addClass('submiting');
2072            }
2073            
2074
2075            this.userInfoRequire().then(function (data) {
2076                /* 检测数据,判断是否已登录 */
2077                if (_this.checkLogin(data)) {
2078                    if (_this.wishId != '0') {
2079                        _this.deleteWishlist();
2080                    } else {
2081                        _this.addToWishlist();
2082                    }
2083                } else {
2084                    //当用户未登录时cookie记录产品Id
2085					var obj = {'products_id': _this.pid,'entrance': 0}
2086					_this.setCookie('add_products_wish', JSON.stringify(obj), 7) //用户点击心愿单信息保存到cookie7天
2087                    _this.showPopLogin();
2088                    _this.$wishlistWrap.removeClass('submiting');
2089                    _this.$isMultiWishWrap.removeClass('submiting');
2090                }
2091            });
2092        },
2093        /* 添加商品到wishlist */
2094        addToWishlist: function () {
2095            if (this.pid == '') return false;
2096            var _this = this;
2097            $.get("index.php", { com: "account", t: "addUserWish", "products_id": this.pid, entrance:'0' },
2098                function (res) {
2099                    if(res.code === 200){
2100                        if (_this.isPc) {
2101                            var $wishlist_btn = $('.add_wish_list');
2102                        } else {
2103                            var $wishlist_btn = $('.wishlist_m');
2104                        }
2105    
2106                        _this.wishId = res.data.wish_id;
2107                        var rmmds = _this.getQueryString('rmmds');
2108                        var offsetLeft = $(".js-pc-wishlist-box").offset().left ;
2109                        var offsetTop = $(".js-pc-wishlist-box").offset().top - $(window).scrollTop();
2110                        var flyer = $('<i class="icon shopCart icon-collect wishlist-copy"></i>');
2111                        //飞入导航特效
2112                        flyer.fly({
2113                            start: {
2114                                left: $wishlist_btn.offset().left,
2115                                top: $wishlist_btn.offset().top - $(window).scrollTop(),
2116                            },
2117                            end: {
2118                                left: offsetLeft-6,
2119                                top: offsetTop + 5,
2120                                width: 0,
2121                                height: 0
2122                            },
2123                            onEnd: function(){
2124                                $wishlist_btn.attr('data-ga', 'products-right_removeWishlist_button_180718').find('i').removeClass('icon-collect').addClass('icon-collect1');
2125                                //修改导航心愿单数量
2126                                var wishListNum = $('.productWishNum em').html() || 0;
2127                                if (wishListNum === 0) {
2128                                    if(_this.theme === 'MultiPurpose'){
2129                                        if(!_this.shopStatus){
2130                                            var count = '<span class="productWishNum"><em>(0)</em></span>';
2131                                        }else{
2132                                            var count = '<span class="productWishNum"><em>0</em></span>';
2133                                        }
2134                                        
2135                                    }else{
2136                                        var count = '<span class="productWishNum">(<em>0</em>)</span>';
2137                                    }
2138                                    
2139                                    $('.add_wish_list').append(count);
2140                                }
2141                                wishListNum++;
2142                                $('.productWishNum em').html(wishListNum);
2143            
2144                                var myWishNum = $('.js-myWishNum').html() || 0;
2145                                myWishNum++;
2146                                this.destory(); 
2147                                $('.js-myWishNum').html(myWishNum);
2148                            }
2149                        });
2150                        
2151                        //点击收藏成功追踪推荐位数据
2152                        _this.recObj["ac"] = "wish";
2153                        _this.recObj["products_id"] = _this.pid;
2154                        Record.rec(_this.recObj);
2155                        if(rmmds === 'search'){
2156                            nDC.RecordClick('wish', [_this.pid])
2157                        }
2158                        //FB事件监测
2159                        try {
2160                            _this.sendFbEvents('AddToWishlist');
2161                        }
2162                        catch (err) {
2163                            console.log(err, 'err');
2164                        }
2165    
2166                        _this.$wishlistWrap.removeClass('submiting');
2167                        _this.$isMultiWishWrap.removeClass('submiting');
2168                    }
2169                }
2170            );
2171            
2172            //发送数据到魔方接口
2173            var bguser = _this.getCookie('__bguser'); //获取bguser cookie 参数
2174            var visit_page = window.location.href; //当前访问页面
2175            var referer = document.referrer; //访问来源的上一个地址
2176
2177            $.get("https://dc.banggood.com/index.php?com=sess&t=collectWish", 
2178            { 
2179                'bguser': bguser, 
2180                "products_id": this.pid, 
2181                'visit_page':visit_page,
2182                'referer':referer 
2183                
2184            },function (res) {
2185                    console.log(res)
2186                }
2187            );
2188            //新魔方采集接口 
2189            var portName = window.location.hostname.split('.')[0]
2190            var beeData={
2191                '__key':'wish',
2192                'domain': 124,
2193                'site_port': portName && portName.indexOf('m') > 0 ? 'm' : 'pc',
2194                'products_id': this.pid,
2195                'visit_page': visit_page,
2196                'referer': referer,
2197                'wish_method': 'details_page'
2198            }
2199            Record.rec(beeData);
2200        },
2201        /* 从wishlist删除商品 */
2202        deleteWishlist: function () {
2203            if (this.pid == '') return false;
2204            var _this = this;
2205            $.get("index.php", { com: "account", t: "delectUserWish", "wish_id": this.wishId },
2206                function (res) {
2207                    if(res.code === 200){
2208                        if (_this.isPc) {
2209                            var $wishlist_btn = $('.add_wish_list');
2210                        } else {
2211                            var $wishlist_btn = $('.wishlist_m');
2212                        }
2213                        $wishlist_btn.attr('data-ga', 'products-right_addWishlist_button_180718').find('i').removeClass('icon-collect1').addClass('icon-collect');
2214                        
2215                        _this.wishId = '0';
2216    
2217                        var wishListNum = $('.productWishNum em').html();
2218                        wishListNum--;
2219    
2220                        $('.productWishNum em').html(wishListNum);
2221                        if (!wishListNum) {
2222                            $('.productWishNum').remove();
2223                        }
2224    
2225                        var myWishNum = Number($('.js-myWishNum').html()) ;
2226                        myWishNum--;
2227                        if(myWishNum === 0) myWishNum = '';
2228                        $('.js-myWishNum').html(myWishNum);
2229                        _this.$wishlistWrap.removeClass('submiting');
2230                        _this.$isMultiWishWrap.removeClass('submiting')
2231                    }
2232                }
2233            );
2234        },
2235        /**
2236         * @desc 绘制批发价表格
2237         * @author lijiahao
2238         * @param  status 使用SKU还是POA的批发价数据 true:使用SKU数据  false: 使用POA数据
2239         * */
2240        updateWsTable: function (status) {
2241            var poaNum = this.poaNum,
2242                _this = this,
2243                data = status || this.poaNum == null ? this.wsData['ws'] : this.wsData['ws_' + poaNum],
2244                numArr = [],
2245                priceArr = [],
2246                headHTML = '',
2247                bodyHTML = '',
2248                selector = '',
2249                selIcon = $(".product_price .price_datalist").find('b').text();
2250
2251
2252            if (this.isPc) {
2253                selector = '.wholesale_price_container';
2254                data.forEach(function (obj) {
2255                    numArr.push(obj.num);
2256                    priceArr.push(obj.price);
2257                });
2258
2259                headHTML += '<tr><td>Quantity</td>';
2260                numArr.forEach(function (val) {
2261                    headHTML += '<td>' + val + '</td>';
2262                });
2263                headHTML += '</tr>';
2264
2265                if (this.sel) {
2266                    bodyHTML += '<tr><td class="js-changeSelIcon">Price ' + this.sel + ' ' + selIcon + '</td>';
2267                } else {
2268                    bodyHTML += '<tr><td class="js-changeSelIcon">Price ' + this.defaultSel + ' ' + selIcon + '</td>';
2269                }
2270
2271                priceArr.forEach(function (val) {
2272                    var original = val;
2273                    val = _this.transformPrice(val);
2274
2275                    bodyHTML += '<td class="js-changePrice" data-USPrice="' + original + '" data-unit="1">' + val + '</td>';
2276                });
2277                bodyHTML += '</tr>';
2278            } else {
2279                selector = '.wholesale_price_container_m';
2280                if (this.sel) {
2281                    headHTML = '<tr><td>Quantity</td><td>Price ' + this.sel + ' ' + selIcon + '</td></tr>'
2282                } else {
2283                    headHTML = '<tr><td>Quantity</td><td>Price ' + this.defaultSel + ' ' + selIcon + '</td></tr>'
2284                }
2285                data.forEach(function (obj) {
2286                    var price = _this.transformPrice(obj.price);
2287                    bodyHTML += '<tr><td>' + obj.num + '</td><td>' + price + '</td></tr>'
2288                });
2289            }
2290
2291            this.$wholesaleWrap.find(selector).find('thead').html(headHTML);
2292            this.$wholesaleWrap.find(selector).find('tbody').html(bodyHTML);
2293
2294        },
2295        transformPrice: function (price) {
2296            var _this = this;
2297            
2298            if(typeof price === 'string'){
2299                price = price.replace(/[,\s]/, '');//去除价格中的逗号和空格
2300            }
2301            
2302            if (_this.sel != null) {
2303                if (_this.sel != 'USD') {
2304                    if (_this.sel != 'EUR' && _this.sel != 'MXN') {
2305                        price = Number(price) * _this.CurrencyCfg[_this.sel][0] * _this.CurrencyBGLoss;
2306                    } else {
2307                        if (_this.sel == 'EUR') price = Number(price) * _this.CurrencyCfg[_this.sel][0] * _this.CurrencyBGEurLoss;
2308                        if (_this.sel == 'MXN') price = Number(price) * _this.CurrencyCfg[_this.sel][0] * _this.CurrencyBGMxnLoss;
2309                    }
2310                }
2311                price = _this.transformDecimals(price);
2312            } else {
2313                if (_this.defaultSel != 'USD') {
2314                    if (_this.defaultSel != 'EUR' && _this.defaultSel != 'MXN') {
2315                        price = Number(price) * _this.CurrencyCfg[_this.defaultSel][0] * _this.CurrencyBGLoss;
2316                    } else {
2317                        if (_this.defaultSel == 'EUR') price = Number(price) * _this.CurrencyCfg[_this.defaultSel][0] * _this.CurrencyBGEurLoss;
2318                        if (_this.defaultSel == 'MXN') price = Number(price) * _this.CurrencyCfg[_this.defaultSel][0] * _this.CurrencyBGMxnLoss;
2319                    }
2320                }
2321                price = _this.transformDecimals(price);
2322            }
2323            return price;
2324        },
2325        transformDecimals: function (price) {
2326            var _this = this;
2327            if (_this.sel != null) {
2328                if (_this.CurrencyCfg[_this.sel][3] == '2') {
2329                    price = Number(price).toFixed(2);
2330                } else {
2331                    price = Number(price).toFixed(0);
2332                }
2333            } else {
2334                if (_this.CurrencyCfg[_this.defaultSel][3] == '2') {
2335                    price = Number(price).toFixed(2);
2336                } else {
2337                    price = Number(price).toFixed(0);
2338                }
2339            }
2340            return price;
2341        },
2342        changePrice: function (obj,isMain) {
2343            var _this = this
2344            if(isMain == '1'){
2345                var oldMainPrice = $(obj).attr('data-original-usprice'), //主产品原始价
2346                    mainOriginalPrice = _this.transformPrice(oldMainPrice);
2347                    var oldPrice = $(obj).attr('data-USPrice'),//US参考价格
2348                    newPrice = _this.transformPrice(oldPrice);//通过转换之后的价格
2349
2350                    return {
2351                        newPrice:newPrice,
2352                        originalPrice:mainOriginalPrice,
2353                    }
2354
2355            } else{
2356                var oldPrice = $(obj).attr('data-USPrice'),//US参考价格
2357                    newPrice = _this.transformPrice(oldPrice);//通过转换之后的价格
2358                return newPrice;
2359            }
2360            
2361           
2362            
2363        },
2364        detailPanelPrice:function(selIcon){
2365            var _this = this;
2366            var selIcon = selIcon;
2367			$('.js-changePrice:not(.old_price,.price_value)').each(function () {
2368                //主产品价格变化
2369                var $this = $(this);
2370                var isMainPro = $this.parents('.mix-product-price').hasClass('main-pro-price') ? true :false;
2371                if(isMainPro){
2372                    var price = _this.changePrice(this,1);
2373                }else{
2374                    var currentPrice = _this.changePrice(this,0);
2375                }             
2376                //当内容不为空时写入新价格
2377                if($this.html().trim() != ''){
2378                    if (selIcon == 'руб.' || selIcon == 'AED') {
2379                        if(isMainPro){
2380                            $(this).attr('data-original-price',price.originalPrice);
2381                            $(this).html(toThousands(price.newPrice) + ' ' + selIcon).attr('data-price',price.newPrice);  
2382                        }else{
2383                            $(this).html(toThousands(currentPrice) + ' ' + selIcon).attr('data-price',currentPrice); 
2384                        }
2385                                    
2386                    } else {
2387                        if(isMainPro){
2388                            $(this).attr('data-original-price',price.originalPrice);
2389                            $(this).html(selIcon + toThousands(price.newPrice)).attr('data-price',price.newPrice);
2390                        }else{
2391                            $(this).html(selIcon + toThousands(currentPrice)).attr('data-price',currentPrice);
2392                        }
2393                        
2394                    }
2395                    if($(this).attr('data-maketprice')){
2396                        $(this).attr('data-maketprice',currentPrice)
2397                    }
2398                }
2399            });     
2400        },
2401        getAccessoryHtml:function(){
2402            var _this = this;
2403            var data = new FormData();
2404            data.append('sel_poa', _this.poaNum);//poa
2405            data.append('products_id', _this.pid);//产品id
2406            data.append('cur_warehouse', _this.cur_warehouse);
2407            $.ajax({
2408                url: '/getAccessory.html',
2409                type: 'post',
2410                data: data,
2411                dataType: 'json',
2412                cache: false,
2413                processData: false,
2414                contentType: false,
2415                success: function (data) {
2416                   if(data.code == 200){
2417                     $('.js-html-mixProduct').html(data.data);
2418                     $("img.lazy").lazyload({
2419                        effect: "fadeIn",
2420                        failure_limit:50,
2421                        check_appear_throttle_time: 300,
2422                        parentClass: 'loading-gif-bg',
2423                    });
2424                     ProductMixHandle.mixProductSlide();//组合商品交互处理
2425                     ProductMixHandle.totalCount = Number($('.mix-main-product').find('.current-price').attr('data-original-price')); //选中任何配件时取原价
2426                   }
2427                },
2428                error: function () {
2429                    console.log('error');
2430                }
2431            }) 
2432        },
2433        errorAlert: function (msg) {
2434            var text = msg || 'Item(s) added to your cart unsuccessfully.';
2435            $(".shipping-modal").show().find('.modal_container').html('<div class="modal_shipping">' +
2436                '<div class="modal_shipping_con">' +
2437                '<i class="delete_btn icon shopCart icon-pinpaizhangouwuche_guanbi" onclick="modal_remove();"></i>' +
2438                '<div class="img_wrap text-center"><img src="/templates/common/dist/shopCart/images/payError.png" alt="" style="width:50px;height:50px;margin-top: 10px;"></div>' +
2439                '<div class="text-center" style="font-size:16px;margin: 20px 0;">
2439' + text + '</div>' +
2440                '<div class="after_btn_wrap">' +
2441                '<div class="afterAddBtn text-center"><a href="javascript:void(0)" class="product_info_btn close_btn">close</a><div style="clear:both;"></div></div>' +
2442                '</div>' +
2443                '</div>' +
2444                '</div>');
2445        },
2446        poaHandler_m: function () {
2447            var _this = this;
2448            $('.js-product-info .poa_wrap_title').on('click', function (e) {
2449                var $this = $(this);
2450                window.scrollTo(0,0);//打开弹窗回到页面顶部 
2451                _this.openModal();
2452
2453                $this.siblings('.poa_list_wrap').show().find('.addToCart_m').addClass('bgwhite').end().find('.submit_box > a').show().eq(0).css('margin-right','5px');//poa窗口显示
2454                setTimeout(function () {
2455                    $this.closest('.poa_wrap').addClass('show');
2456                }, 0);
2457                //e.preventDefault();
2458            }).closest('.poa_wrap').find('.closeBtn').on('click', function (e) {
2459                var $this = $(this);
2460
2461                _this.closeModal();
2462
2463                $this.closest('.poa_wrap').removeClass('show');
2464                setTimeout(function () {
2465                    $this.closest('.poa_list_wrap').hide();
2466                }, 200);
2467                e.stopPropagation();
2468                e.preventDefault();
2469            });
2470        },
2471
2472        giftHandler_m: function () {
2473            var _this = this;
2474            $('.js-product-info .item_box.gift').find('.item_name').on('click', function (e) {
2475                var $this = $(this);
2476
2477                _this.openModal();
2478
2479                $this.siblings('.gift_list_wrap').show();//poa窗口显示
2480                setTimeout(function () {
2481                    $this.closest('.gift_wrap').addClass('show');
2482                }, 0);
2483                //e.preventDefault();
2484            }).closest('.gift_wrap').find('.closeBtn').on('click', function (e) {
2485                var $this = $(this);
2486
2487                _this.closeModal();
2488
2489                $this.closest('.gift_wrap').removeClass('show');
2490                setTimeout(function () {
2491                    $this.closest('.gift_list_wrap').hide();
2492                }, 200);
2493                e.stopPropagation();
2494                e.preventDefault();
2495            });
2496
2497            $(doc).on('click', '.js-product-info .gift_item>.clickIcon', $.proxy(this.chooseGift, this));
2498            $(doc).on('click', '.js-product-info .gift .gift_attr:not(.gray)', $.proxy(this.updateGift, this));
2499        },
2500        /* 移动端市场价事件 */
2501        wholeSaleHandler_m: function () {
2502            var _this = this;
2503            $(".js-product-info .wholesale_price_wrap").find('.wholesale_price_label').on('click', function (e) {
2504
2505                _this.openModal();
2506
2507                var $price_wrap = $(this).siblings('.price_wrap');
2508                $price_wrap.show();
2509                setTimeout(function () {
2510                    $price_wrap.addClass('show');
2511                }, 0);
2512            }).end().find('.back').on('click', function (e) {
2513
2514                _this.closeModal();
2515
2516                var $price_wrap = $(this).closest('.price_wrap');
2517                $price_wrap.removeClass('show');
2518                setTimeout(function () {
2519                    $price_wrap.hide();
2520                }, 200);
2521                e.stopPropagation();
2522            });
2523        },
2524        /* M端选择赠品后的提示语 */
2525        changeGiftText_m: function () {
2526            var activeLen = this.$giftList.find('.gift_item.isChecked').length,
2527                giftText = activeLen > 1 ? 'gifts' : 'gift';
2528            if (activeLen === 0) {
2529                this.$giftList.find('.selected_text').text('');
2530            } else {
2531                this.$giftList.find('.selected_text').text(activeLen + ' ' + giftText + ' have been selected');
2532            }
2533        },
2534        share_m: function () {
2535            var _this = this;
2536            this.$shareBtn.on('click', function () {
2537                _this.openModal();
2538                $('.share_container:last').show();
2539            });
2540            $(doc).on('click', '.share_container .closeBtn,.share_container .share_bg', function () {
2541                _this.closeModal();
2542                $('.share_container:last').hide();
2543            });
2544        },
2545        /* 请求是否登录接口 */
2546        userInfoRequire: function () {
2547            var _this = this;
2548            return $.ajax({
2549                url: '/userHeaderInfo.html',
2550                dataType: 'json',
2551                success: function (data) {
2552
2553                }
2554            });
2555
2556        },
2557        checkLogin: function (data) {
2558            if (data.data.customer_info.length !== 0 && data.data.customer_info.customers_id) {
2559                return true;
2560            }
2561            return false;
2562        },
2563        priceHandler_m: function () {
2564            var $priceList = $('.js-product-info .price_datalist'),
2565                _this = this;
2566                
2567            $(".js-product-info .poa_wrap").find('.new_price').on('click', function () {
2568                var has_activity = _this.$wrapper.hasClass('has_activity');
2569                if(has_activity){
2570                    $('.price_value_box').show();
2571                }
2572                $priceList.fadeIn();
2573            });
2574            $priceList.find('.back').on('click', function () {
2575                var has_activity = _this.$wrapper.hasClass('has_activity');
2576                $priceList.fadeOut(function(){
2577                    if(has_activity){
2578                        $(".price_value_box").hide();
2579                    }
2580                });
2581            });
2582        },
2583        scrollHandler_m: function () {
2584            $('.js-product-info .poa_wrap,.gift_wrap,.wholesale_price_wrap,.js-product-info .price_datalist,.share_container,.fixed_wrap').on('touchmove', function (e) {
2585                e.preventDefault();
2586            });
2587        },
2588        setCurRequire: function (currency_id) {
2589            var input = $('.top-country-box').children('.country-container'),
2590                country_id = input.find('[name=country_sel]').val();
2591
2592            $.ajax({
2593                url: '/setDefaltCountry.html?country=' + country_id + '&currency=' + currency_id,
2594                type: 'post',
2595                dataType: 'text',
2596                success: function (data) {
2597                    $.cookie('currency', currency_id);
2598                },
2599                error: function (error) {
2600                    console.log(error);
2601                }
2602            })
2603        },
2604        /*选中图片或色块显示属性值 by Li Xiaojun*/
2605        switchColorName: function (e) {
2606            var $isAttrTitle = $('.js-attr-title');
2607            /* 判断点击的是否为空的<a>标签,如<a>里面有<img>,则选择<img>的父元素<a> */
2608            if (!$(e.target).is('a')) {
2609                e.target = $(e.target).parent();
2610            }
2611            if ($isAttrTitle.length) {
2612                var colorTitle = $(e.target).attr('title');
2613                if(!$(e.target).hasClass('gray')){
2614                    $(e.target).parents('.poaItem').find('.js-attr-title').html(colorTitle);
2615                }
2616            }
2617        },
2618        /**
2619         * @desc 根据国家下拉选项切换按钮链接-amazon\ebay
2620         * @author lijiahao
2621         **/
2622        countryHandler: function () {
2623            var _this = this,
2624                $country = _this.$wrapper.find('.way_btn_country'),
2625                $btnWrap = $('.buy_way_wrap .way_btn_box');
2626
2627            $country.find('.country_icon').on('click', function (e) {
2628                $country.not($(this).closest('.way_btn_country')).removeClass('show');
2629                $(this).closest('.way_btn_country').toggleClass('show');
2630                e.stopPropagation();
2631            });
2632
2633            $(doc).on('click', function (e) {
2634                $country.removeClass('show');
2635            });
2636
2637            $country.find('.country_item').on('click', function () {
2638                var country_id = $(this).attr('data-country-id'),
2639                    flag = $(this).find('i').prop("outerHTML"),
2640                    url = $(this).attr('data-url'),
2641                    type = $(this).closest('.way_btn_country').attr('data-type');
2642
2643                $(this).addClass('act').siblings().removeClass('act');
2644                $(this).closest('.country_contain').find('.way_title').attr('data-url', url).end().find('.country_icon').html(flag);
2645                _this.setThirdDeliveryCountry(country_id, type);
2646            });
2647
2648            $country.find('.way_title').on('click', function () {
2649                var url = $(this).attr('data-url')
2650                if (url) {
2651                    window.open(url);
2652                }
2653            });
2654        },
2655        /**
2656         * @desc M 端悬浮栏国家点击事件
2657         * @author lijiahao
2658         **/
2659        countryHandler_m: function () {
2660            /* 悬浮栏国家点击事件 */
2661            this.$bottomBar.find('.countryBox').on('click', $.proxy(this.showCountry, this));
2662
2663            /* country关闭按钮事件 */
2664            $('.country_list_wrap .closeBtn').on('click', $.proxy(this.hideCountry, this));
2665            $('.country_list_wrap .wrap_bg').on('click', $.proxy(this.hideCountry, this));
2666
2667            $('.country_list_m .country_ul').find('li').on('click', $.proxy(this.updateCountry, this));
2668
2669            /* 解决拖动穿透 */
2670            $('.country_list_wrap').on('touchmove', function (e) { e.stopPropagation(); })
2671        },
2672        // M 端按钮显示初始化
2673        buyWayInit: function (isFirstTime) {
2674            var $selected = $(".country_list_m").find('.country_ul .selected');
2675            //amazon默认选中的国家有ebay的链接,显示ebay按钮
2676            if (isFirstTime && $selected.attr('data-ebay')) {
2677                $('.buybtn_list_wrap .buybtn_list .btnlist').find('.js-mbuy-ebay').removeClass('forbid').addClass('go');
2678            }
2679
2680            var wayWrap = $('.buybtn_list_wrap .btnlist'),
2681                wayList = wayWrap.find('a.go'),
2682                wayBtn = this.$bottomBar.find('.abtest_buyway_btn'),
2683                btnList = $('.js-mbtn-container').children('a');
2684
2685            if (btnList.length === 0) {
2686                if(this.theme !== 'outerdo'){
2687                    $('.js-mbtn-container').addClass('only_wishlist')
2688                }else{
2689                    this.$bottomBar.hide();
2690                    $(document).ready(function(){
2691                        $('.footer').css('padding-bottom', '0');
2692                    });
2693                }
2694            }
2695            if (wayList.length === 1) { /* 列表length为1时,外部按钮显示为列表的第一个 */
2696                var firstEle = wayList.eq(0),
2697                    firstText = firstEle.text(),
2698                    firstHref = firstEle.attr('href'),
2699                    firstId = firstEle.attr('data-id'),
2700                    firstGa = firstEle.attr('data-ga');
2701                    firstFb = firstEle.attr('data-fb');
2702
2703                wayBtn.off('click').text('Buy At ' + firstText).attr('href', firstHref).attr('data-ga', '').attr('data-ga', firstGa);
2704                if(typeof (firstFb) != 'undefined'){
2705                    wayBtn.attr('data-fb', '').attr('data-fb', firstFb)
2706                }
2707                if(firstEle.hasClass('js-mbuy-amazon')) { //判断该按钮是否为amazon按钮
2708                    wayBtn.addClass('js-mbuy-amazon') 
2709                }
2710
2711                //有data-id的标签需选国家后再跳转
2712                // if(firstId){
2713                //     wayBtn.attr('data-id',firstId).on('click',function(){
2714                //         $("#"+firstId).show().addClass('show');
2715                //     });
2716                // }
2717            } else if (wayList.length > 1 && !isFirstTime) {
2718                if (this.shopStatus) {
2719                    wayBtn.off('click').text('Other Channels');
2720                } else {
2721                    wayBtn.off('click').text('BUY NOW');
2722                }
2723                wayBtn.attr('href', 'javascript:void(0);').attr('data-ga', 'product-bottom_BuyNowButton_20181119').on('click', $.proxy(this.showBuyList, this));
2724            }
2725
2726            /* 产品没有属性可选,增加GA埋点 */
2727            if(this.poaLength === 0){
2728                this.$bottomBar.find('.addToCart_m').attr('data-ga', 'products-right_addToCart_button_180920');
2729            }
2730
2731        },
2732        buywayHandler_m: function () {
2733            this.$bottomBar.find('.abtest_buyway_btn').on('click', $.proxy(this.showBuyList, this));
2734
2735            $('.buybtn_list_wrap .closeBtn').on('click', $.proxy(this.hideBuyList, this));
2736            $('.buybtn_list_wrap .wrap_bg').on('click', $.proxy(this.hideBuyList, this));
2737
2738            this.$bottomBar.on('touchmove', function (e) { e.stopPropagation(); })
2739        },
2740        showCountry: function () {
2741            $('.country_list_wrap').show();
2742            this.openModal();
2743            setTimeout(function () {
2744                $('.country_list_wrap').addClass('show');
2745            }, 0);
2746        },
2747        closeFixed: function () {
2748            this.closeModal();
2749        },
2750        hideCountry: function () {
2751            $('.country_list_wrap').removeClass('show');
2752            setTimeout(function () {
2753                $('.country_list_wrap').hide();
2754            }, 300);
2755        },
2756        showBuyList: function () {
2757            $('.buybtn_list_wrap').show();
2758            this.openModal();
2759            setTimeout(function () {
2760                $('.buybtn_list_wrap').addClass('show');
2761            }, 0);
2762        },
2763        hideBuyList: function () {
2764            $('.buybtn_list_wrap').removeClass('show');
2765            this.closeModal();
2766            setTimeout(function () {
2767                $('.buybtn_list_wrap').hide();
2768            }, 300);
2769        },
2770        updateCountry: function (e) {
2771            var $ele = $(e.currentTarget),
2772                country_name = $ele.attr('name'),
2773                country_name2 = country_name;
2774            if ($ele.hasClass('selected')) return false;
2775
2776            if (country_name === 'uk') country_name = 'gb';
2777
2778            $ele.addClass('selected').siblings().removeClass('selected');
2779            this.$bottomBar.find('.countryBox').html('<i class="icon-flag icon-flag-' + country_name.toUpperCase() + '"></i><span>' + country_name2.toUpperCase() + '</span>')
2780            this.hideCountry();
2781
2782            /* 替换amazon按钮的href */
2783            var amazonLink = $ele.attr('data-href'),
2784                ebayLink = $ele.attr('data-ebay'),
2785                country_id = $ele.attr('data-country-id');
2786
2787            if (!this.shopStatus) {
2788                var currency = $ele.attr('currency'),
2789                    price = $ele.attr('data-price'),
2790                    $product_price = $(".product_price");
2791                if (price) {
2792
2793                    if (currency == 'руб.' || currency == 'AED') {
2794                        $product_price.find('.new_price').html('</span><span class="price_value">' + price + '</span>' + '<span class="currencys_m mobile">' + currency);
2795                    } else {
2796                        $product_price.find('.new_price').html('<span class="currencys_m mobile">' + currency + '</span><span class="price_value">' + price + '</span>');
2797                    }
2798
2799                }
2800            }
2801
2802            $('.buybtn_list .js-mbuy-amazon').attr('href', amazonLink);
2803            $('.buybtn_list .js-mbuy-ebay').attr('href', ebayLink);
2804            if (amazonLink != '') {
2805                $('.buybtn_list .js-mbuy-amazon').removeClass('forbid').addClass('go')
2806            } else {
2807                $('.buybtn_list .js-mbuy-amazon').removeClass('go').addClass('forbid')
2808            }
2809            if (ebayLink != '') {
2810                $('.buybtn_list .js-mbuy-ebay').removeClass('forbid').addClass('go')
2811            } else {
2812                $('.buybtn_list .js-mbuy-ebay').removeClass('go').addClass('forbid')
2813            }
2814
2815            /* 初始化按钮 */
2816            this.buyWayInit(false);
2817            this.setThirdDeliveryCountry(country_id, 'third_delivery_country');
2818            this.closeModal();
2819        },
2820        setThirdDeliveryCountry: function (country_id, type) {
2821
2822            $.ajax({
2823                url: 'setThirdDeliveryCountry.html',
2824                type: 'post',
2825                dataType: 'json',
2826                data: {
2827                    'country_id': country_id,
2828                    'type': type,
2829                },
2830                success: function (data) {
2831
2832                },
2833                error: function () {
2834
2835                }
2836            })
2837        },
2838        openModal: function () {
2839            this.bodyTop = document.scrollingElement.scrollTop;
2840            document.body.style.top = -this.bodyTop + 'px';
2841            $('body').addClass('overflow');//body添加position:fixed,防止拖动poa页面时,body也随着拖动。
2842        },
2843        closeModal: function () {
2844            $('body').removeClass('overflow');
2845            document.scrollingElement.scrollTop = this.bodyTop;
2846            document.body.style.top = '';
2847        },
2848        /**
2849         * 默认选中属性值
2850         * @param {Array} 属性值数组
2851         */
2852        onClickHandler: function (arr) {
2853            this.$poaWrapper.find('.box_wrap .attr_item').each(function () {
2854                var vid = $(this).attr('data-vid'),
2855                    $this = $(this);
2856                if (arr && arr.length && arr.indexOf(vid) > -1) {
2857                    setTimeout(function () {
2858                        $this.click();
2859                    }, 0);
2860                }
2861            });
2862        },
2863        attrPreviewInit: function () {
2864            var _this = this,
2865                isLoaded = false,
2866                $poaItem = this.$poaWrapper.find('.box_wrap .poaItem'),
2867                $previewWrap = $("#poa_preview");
2868
2869            $poaItem.each(function (index) {
2870                var $list = $(this).find('.attr_value_list'),
2871                    imgLen = $list.find('.attrimg').length,
2872                    itemLen = $list.find('.attr_item').length,
2873                    attr_name = $(this).attr('data-attr-name'),
2874                    plural = itemLen > 1 ? 's' : '';
2875
2876                /* poa有图片优先显示有图片的 */
2877                if (imgLen > 0) {
2878                    var $newDiv = $('<div></div>');
2879                    $newDiv.html($list.html());
2880                    $newDiv.append('<label class="num_tips" style="margin-top:5px;">' + itemLen + ' ' + attr_name + plural + ' to choose</label>');
2881                    $previewWrap.html($newDiv.html());
2882                    isLoaded = true;
2883                    $previewWrap.parent().addClass('show').parent().addClass('hasPoa');
2884                    _this.poaCheckInline();
2885                    return false;
2886                }
2887            });
2888
2889            //Poa属性有颜色块
2890            if (!isLoaded) {
2891                $poaItem.each(function (index) {
2892                    var $list = $(this).find('.attr_value_list'),
2893                        colorLen = $list.find('.attrcolor').length,
2894                        itemLen = $list.find('.attr_item').length,
2895                        attr_name = $(this).attr('data-attr-name'),
2896                        plural = itemLen > 1 ? 's' : '';
2897
2898                    /* poa有图片优先显示有图片的 */
2899                    if (colorLen > 0) {
2900                        var $newDiv = $('<div></div>');
2901                        $newDiv.html($list.html());
2902                        $newDiv.append('<label class="num_tips">' + itemLen + ' ' + attr_name + plural + ' to choose</label>');
2903                        $previewWrap.html($newDiv.html());
2904                        isLoaded = true;
2905                        $previewWrap.parent().addClass('show').parent().addClass('hasPoa');
2906                        _this.poaCheckInline();
2907                        return false;
2908                    }
2909                });
2910            }
2911
2912            //Poa属性没有图片
2913            if (!isLoaded) {
2914                $poaItem.each(function (index) {
2915                    var $list = $(this).find('.attr_value_list'),
2916                        itemLen = $list.find('.attr_item').length,
2917                        attr_name = $(this).attr('data-attr-name'),
2918                        plural = itemLen > 1 ? 's' : '';
2919
2920                    /* 文字属性只显示size,其余不显示 */
2921                    if (attr_name.toLowerCase() === 'size') {
2922                        var $newDiv = $('<div></div>');
2923                        $newDiv.html($list.html());
2924                        $newDiv.append('<label class="num_tips">' + itemLen + ' ' + attr_name + plural + ' to choose</label>');
2925                        $previewWrap.html($newDiv.html());
2926                        $previewWrap.parent().addClass('show').parent().addClass('hasPoa');
2927                        _this.poaCheckInline();
2928                    }
2929                });
2930            }
2931
2932        },
2933        /**
2934         * @desc poa入口显示的属性超出父元素,对元素进行移除;
2935         * @author lijiahao
2936         **/
2937        poaCheckInline: function () {
2938            var $previewWrap = $("#poa_preview"),
2939                $wrap = $previewWrap.parent();
2940
2941            if ($previewWrap.width() === $wrap.width()) {
2942                var $items = $previewWrap.find('.attr_item');
2943                $items.slice($items.length - 1).remove();
2944                this.poaCheckInline();
2945            } else {
2946                return false;
2947            }
2948        },
2949        poaDataHanlder: function (data) {
2950            var _this = this,
2951                attrVids = Object.keys(data.stockVids),
2952                attrLen = attrVids.length,
2953                $discount = $(".js-discount-update");
2954
2955            this.giftResult = {};
2956            this.stockData = data;
2957            this.stockQty = Number(data.stock);//库存
2958            if(data.isPreorder === 1 && Object.keys(data.preorderInfo).length > 0 && data.preorderInfo.once_limit_amount > 0 ){
2959                this.stockQty = Number(data.preorderInfo.once_limit_amount)
2960            }
2961            this.giftInfo = data.validGifts;//赠品信息
2962            this.cur_warehouse = data.warehouse;//该POA所在仓库,加购时使用
2963            this.updatePrice2();//更新价格
2964            this.updateStockInfo();//更新库存提示
2965            this.updateInput(this.stockQty);//数量修改
2966            this.plusHandler();//+号状态更新
2967            this.setCouponInfo(data.productCoupons);//切换poa时更新coupon展示
2968            if (data.isPreorder === 1 && Object.keys(data.preorderInfo).length > 0) {
2969              this.setPreSaleHandle(data.preorderInfo, data);
2970              if (!_this.isPc) {
2971                //m端的 在预售的时候 把普通价格隐藏
2972                $('.js-product-info').find('.m-js-product-price').hide();
2973              }
2974            } else {
2975              $('.js-isPreSale').hide();
2976              if (!_this.isPc) {
2977                //m端的 在预售的时候 把普通价格隐藏
2978                $('.js-product-info').find('.m-js-product-price').show();
2979              }
2980              if (_this.pcCountDownTimer !== null) {
2981                $('.js-pre-sale-activity').find('.js-counting-time').each(function () {
2982                  _this.pcCountDownTimer.destroyedTimer();
2983                });
2984              }
2985              if (_this.mCountDownTimer !== null) {
2986                $('.js-m-pre-sale-activity-box').find('.js-counting-time').each(function () {
2987                  _this.mCountDownTimer.destroyedTimer();
2988                });
2989              }
2990            }
2991
2992            if (attrLen === 1 && !_this.isFTLoaded) {
2993                var attr_ids = data.stockVids[attrVids[0]].split('.');
2994                $(".poaItem").find('.attr_item').addClass('gray').each(function () {
2995                    var vid = $(this).attr('data-vid');
2996                    if (attr_ids && attr_ids.length && attr_ids.indexOf(vid) > -1) {
2997                        $(this).removeClass('gray');
2998                    }
2999                });
3000            }
3001
3002            if (attrLen > 1) {
3003                var attr_ids = [];
3004                Object.keys(data.stockVids).forEach(function (key) {
3005                    attr_ids = data.stockVids[key].split('.').concat(attr_ids);
3006                });
3007
3008                $(".poaItem").find('.attr_item').addClass('gray').each(function () {
3009                    var vid = $(this).attr('data-vid');
3010                    if (attr_ids && attr_ids.length && attr_ids.indexOf(vid) > -1) {
3011                        $(this).removeClass('gray');
3012                    }
3013                });
3014            }
3015
3016            if (!this.isPc) {
3017                this.changeGiftText_m();
3018            }
3019
3020            if($discount.length){
3021                /* 切换poa更新活动产品的折扣 */
3022                var newDiscount = (((data.market_price_usd - data.final_price_usd) / data.market_price_usd * 100)).toFixed(0);
3023                if(newDiscount > 0){ //折扣大余0时显示
3024                    $discount.text(newDiscount + '%'); 
3025                } else {
3026                    $discount.parents('.m-discount').hide()
3027                }
3028            }
3029            
3030            /* 第一次调用 去除价格loading效果 */
3031            if (!this.isFTLoaded) {
3032                $('.product_price').removeClass('loading');
3033                this.isFTLoaded = true;
3034            }
3035        },
3036        /**
3037         * @description 根据已选择属性 来获取其他未选择属性是否有库存;
3038         */
3039        getOthersStock: function () {
3040            var _this = this,
3041                formData = new FormData;
3042
3043            formData.append('products_id', this.pid);//产品id
3044
3045            /* 没有属性选 则不传products_attr_id */
3046            if (this.poaLength) {
3047                $.each(this.activeIndex, function (i, val) {
3048                    if (val) {
3049                        formData.append('products_attr_id[' + _this.activeIndex2[i] + ']', val);
3050                    }
3051                });
3052            }
3053
3054            $.ajax({
3055                url: '/stockMessage.html',
3056                type: 'post',
3057                dataType: 'json',
3058                data: formData,
3059                cache: false,
3060                processData: false,
3061                contentType: false,
3062                success: function (data) {
3063                    var attr_ids = [];
3064                    Object.keys(data.stockVids).forEach(function (key) {
3065                        attr_ids = data.stockVids[key].split('.').concat(attr_ids);
3066                    });
3067
3068                    $(".poaItem").find('.attr_item').addClass('gray').each(function () {
3069                        var vid = $(this).attr('data-vid');
3070                        if (attr_ids && attr_ids.length && attr_ids.indexOf(vid) > -1) {
3071                            $(this).removeClass('gray');
3072                        }
3073                    });
3074                },
3075                error: function () {
3076                    console.log('error');
3077                }
3078            })
3079        },
3080        /* 根据信息接口初始化数据 */
3081        initHeaderInfo: function () {
3082            var _this = this;
3083            headerInfoAjax.then(function (data) {
3084                _this.headerInfo = data.data;
3085
3086                _this.setActivityStatus();
3087                _this.setPromotion();
3088                _this.setSuperUser();
3089                _this.setIsWishlist();
3090                _this.setHeaderWishlist();
3091                _this.setUnsaleArea();
3092
3093                if(!_this.isPc){
3094                    _this.setShopcart();
3095                }
3096                _this.setShipCountry();
3097
3098            });
3099        },
3100        /* 设置wishlist数量 */
3101        setHeaderWishlist: function () {
3102            var customerInfo = this.headerInfo.customer_info;
3103            
3104            if (customerInfo.productWishNum && customerInfo.productWishNum > 0) {
3105                if(this.theme === 'MultiPurpose'){
3106                    if(!this.shopStatus){
3107                        var count = '<span class="productWishNum"><em>(' + customerInfo.productWishNum + ')</em></span>';
3108                    }else{
3109                        var count = '<span class="productWishNum"><em>' + customerInfo.productWishNum + '</em></span>';
3110                    }
3111                    
3112                }else{
3113                    var count = '<span class="productWishNum">(<em>' + customerInfo.productWishNum + '</em>)</span>';
3114                }
3115                
3116                $('.add_wish_list').append(count);
3117            }
3118        },
3119        /* 根据产品的活动状态修改class,控制dom是否显示 */
3120        setActivityStatus: function(){
3121            var actInfo = this.headerInfo.products_items_list.activity_info;
3122            
3123            if(actInfo.has_activity){ 
3124                this.$wrapper.addClass('has_activity');
3125
3126                if(actInfo.is_started){
3127                    this.$wrapper.addClass('activity_started');
3128
3129                    /* M端活动批发价样式 */
3130                    if(!this.isPc){
3131                        this.$wholesaleWrap.addClass('activity-start');
3132                    }
3133                }
3134            }
3135        },
3136        setSuperUser: function(){
3137            var isSuperUser = this.headerInfo.products_items_list.is_superuser;
3138            /* 全部模板通用 apply for free */
3139            if(isSuperUser != '0' ){
3140                if(this.isPc){
3141                    $(".apply-forfree-box").show();
3142                    $('.forfreeShow').show();
3143                }else{
3144                    $(".m-makeup2-free").show();
3145                }  
3146            }
3147        },
3148        setIsWishlist: function(){
3149            var is_add_to_wishlist = this.headerInfo.products_items_list.is_add_to_wishlist;
3150            /* 没开购物车 && 可以收藏 */
3151            if(!this.shopStatus && is_add_to_wishlist){
3152                $('.wishlist_wrap tips').show();
3153            }
3154        },
3155        /* 是否禁售产品 */
3156        setUnsaleArea: function(){
3157            var isUnsalesArea = this.headerInfo.products_items_list.is_unsales_area,
3158                country = this.headerInfo.country_name_ip;
3159
3160            if(!isUnsalesArea){
3161                this.$addBtn.removeClass('forbidGray');
3162                this.$buyNowBtn.removeClass('forbidGray');
3163                this.$paypalBtn.removeClass('forbidGray');
3164                this.$startMyGroupBtn.removeClass('forbidGray');
3165            }else{
3166                
3167                $("#item_shipments_box").remove();
3168                $('.shipping_box').remove();//M端shipping提示语去除
3169                $(".js_forbidOrder_country").text(country);
3170
3171                if(this.isPc){
3172                    this.$addBtn.html('<span class="not_allow">Not Available</span>');
3173                    this.$buyNowBtn.hide();
3174                    this.$paypalBtn.hide();
3175                    this.$startMyGroupBtn.hide();
3176                    $('.forbidOrder').show();
3177                }else{
3178                    $('.forbidOrder-m').show();
3179                }
3180            }
3181        },
3182        setCouponInfo: function(html){
3183            $(".coupon-container").html(html);
3184            if(html){
3185                $(".coupon-container").find('.couponTime').each(function () {
3186                    var format_date = getTime($(this).attr('data-time'), 1);
3187                    $(this).text(format_date);
3188                });
3189            }
3190        },
3191        couponHandler: function(){
3192            var _this = this;
3193            $(doc).on('click', '.js-product-info .coupon_list .coupon_item:not(.successful),.js-product-info .coupon_alllist_modal .coupon_item .getCoupons,.js-getAll-coupon:not(.disabled)', $.proxy(this.getCouponRequire, this));//领取优惠券
3194            $(doc).on('click', '.js-product-info .item_coupon .more_btn,.phone-js-showCoupon', $.proxy(this.showCouponModal, this));
3195            $(doc).on('click', ".js-product-info .coupon_alllist_modal .modal_content>.close_btn", $.proxy(this.hideCouponModal,this));
3196            _this.hoverCouponList(); //pc端hover显示全部
3197        },
3198        getCouponRequire: function(e){
3199            e.stopPropagation();
3200            var $this = $(e.currentTarget),
3201                _this = this,
3202                isAllEle = $this.attr('data-isAll'),//是否是移动端一键获取
3203                isModalEvent = !$this.is('.outerCoupon');//是否在modal里面领取的
3204            var coupons = [];    
3205            var formData = new FormData();
3206            formData.append('products_id', _this.pid);
3207            if(isAllEle){
3208                //获取所有未领取的coupon_id
3209                coupons = $('.coupon_alllist_modal .coupon_list .getCoupons');  
3210                $.each(coupons,function(){
3211                    var coupon_id = $(this).attr('data-id');
3212                    formData.append('coupon_ids[]', coupon_id);
3213                })             
3214            } else{
3215                coupons = $this.attr('data-id');
3216                formData.append('coupon_ids[]', coupons);
3217            }
3218            
3219
3220            headerInfoAjax.then(function(res){
3221                if(_this.checkLogin(res)){
3222                    /* 已登录 */
3223                    if($this.hasClass('loading'))return false;
3224                    if(!isModalEvent){
3225                        $this.find('.item_control').addClass('loading').html('<img src="/templates/common/src/shopCart/images/loading.gif" alt="" class="loading_img">');
3226                    }else{
3227                        $this.addClass('loading');
3228                    }
3229                    
3230                    $.ajax({
3231                        url: '/getCoupon.html',
3232                        type: 'post',
3233                        dataType:'json',
3234                        contentType: false,
3235                        data: formData,
3236                        processData: false,
3237                        success: function(res){
3238                            if(res.code === 200){
3239                                /* 外面领取和modal内领取完都刷新页面 */
3240                                $('#coupon-container').html(res.productCoupons);
3241                                if(isModalEvent){ 
3242                                    _this.showCouponModal();
3243                                    if(!_this.isPc){
3244                                        if(isAllEle){
3245                                            $this.addClass('disabled');
3246                                        }
3247                                        _this.hideCouponModal();
3248                                        setTimeout(function(){
3249                                            _this.tipsModal('Success !');
3250                                        })
3251                                    }
3252                                }else{
3253                                    $this.find('.item_control').removeClass('loading').html('<i class="icon shopCart icon-pinpaizhangouwuche_gouxuan"></i>');
3254                                    _this.tipsModal('Success !');
3255                                }
3256                            }
3257                        }
3258                    })
3259                }else{
3260                    _this.showPopLogin();
3261                    $('.coupon_alllist_modal').addClass('zIndex')
3262
3263                }
3264            });
3265        },
3266        hoverCouponList:function(){
3267            var _this = this;
3268            if(_this.isPc){
3269                $(".coupon-container").delegate('.coupon_list','mouseenter',function(){
3270                    $(this).addClass('removeHeight')
3271                })
3272                $(".coupon-container").delegate('.coupon_list','mouseleave',function(){
3273                    $(this).removeClass('removeHeight')
3274                })
3275            }
3276        },
3277        showPopLogin: function(){
3278            var isMakeUp2 = $('#themeId'),themeFlag = false;
3279            if(isMakeUp2){
3280                themeFlag = isMakeUp2.val() == 'makeup2' ? true : false;
3281            }
3282            if (!this.isPc) {
3283                var $mPopLogin = $('.mPopLogin');
3284                $mPopLogin.show();
3285                setTimeout(function () {
3286                    $mPopLogin.addClass('show');//显示弹窗
3287                }, 100);
3288            } else {
3289                if(themeFlag){
3290                    $(".popLogin").find('.tab-list li').eq(1).addClass('active').siblings().removeClass('active');
3291                }else{
3292                    
3293                    $(".popLogin").find('.tab-list li').eq(0).addClass('active').siblings().removeClass('active');
3294                }
3295                $(".popLogin").show().find('.loginWrapper').addClass('show').show().siblings('.registerWrapper').removeClass('show').hide();
3296               
3297            }
3298        },
3299        showCouponModal: function(){
3300            var _this = this;
3301            // headerInfoAjax.then(function(res){
3302            //     if(_this.checkLogin(res)){
3303            //         /* 已登录 */
3304            //         if(_this.isPc){
3305            //             $('.coupon_alllist_modal').show();
3306            //         }else{
3307            //             _this.openModal();
3308
3309            //             $('.coupon_alllist_modal').show();//poa窗口显示
3310            //             setTimeout(function () {
3311            //                 $('.coupon_alllist_modal').addClass('show');
3312            //             }, 0);
3313            //         }
3314            //     }else{
3315            //         _this.showPopLogin();
3316            //     }
3317            // });
3318            
3319            //后面需求优化无需判断登录可显示优惠券,只有领取和使用优惠券需验证登录
3320            if (_this.isPc) {
3321                $('.coupon_alllist_modal').show();
3322            } else {
3323                _this.openModal();
3324                $('.coupon_alllist_modal').show();//poa窗口显示
3325                setTimeout(function () {
3326                    $('.coupon_alllist_modal').addClass('show');
3327                }, 0);
3328            }
3329        },
3330        hideCouponModal: function(){
3331            if(this.isPc){
3332                $('.coupon_alllist_modal').hide();
3333            }else{
3334                this.closeModal();
3335                $('.coupon_alllist_modal').removeClass('show');
3336                setTimeout(function(){
3337                    $('.coupon_alllist_modal').hide();
3338                },200);
3339            }
3340        },
3341        /* 提示层 */
3342        tipsModal: function(content){
3343            var $success = $('<div class="tipsModal">' +
3344                                '<div class="iconbox">' +
3345                                    '<i class="icon shopCart icon-pinpaizhangouwuche_gouxuan"></i>' +
3346                                '</div>'+ content +'</div>');
3347            
3348            $('body').append($success);
3349
3350            var $eleW = $success.innerWidth(),
3351                $eleH = $success.innerHeight(),
3352                winW = $(win).width(),
3353                winH = $(win).height(),
3354                offsetLeft = (winW - $eleW) / 2,
3355                offsetTop = (winH - $eleH) / 2;
3356                
3357            $success.css({
3358                top: offsetTop,
3359                left: offsetLeft,
3360            })
3361            
3362            $success.fadeIn();
3363            setTimeout(function(){
3364                $success.fadeOut();
3365            },3000);
3366            setTimeout(function(){
3367                $success.remove();
3368            },3500);
3369        },
3370        setShopcart: function(){
3371            var selected_total = this.headerInfo.selected_total;
3372
3373            if(selected_total > 0){
3374                this.$bottomBar.find('.shopcart_m .num').text(selected_total).show();
3375            }
3376            
3377        },
3378        /* 尺码表 */
3379        sizeChartDialog:function(){
3380            var _this = this;
3381            var $sizeChartWrap = $('.size_chart_dialog_wrapper');
3382            var $transitionWrap = $('.size_dialog-wrap');
3383            var $body = $('body');
3384            var win_w = $(window).width();
3385            // 交互处理
3386            $('.js-size_chart_anchor,.js-sizeChart-close,.size_dialog-backdrop').on('click', function (e) {
3387                var $this = $(this);
3388                if($this.hasClass('size_chart')){
3389                    if ($this.hasClass('js-isDetail')) {
3390                        try {
3391                            if(gaNo && gaNo != ''){
3392                                gtag('event', 'click', {
3393                                    'event_category': 'productDetails',
3394                                    'event_label': 'sizeChart',
3395                                    'value': 0,
3396                                });
3397                            }
3398                        } catch (err) {
3399                            console.log(err);
3400                        }
3401                        e.stopPropagation();
3402                    }
3403                    $sizeChartWrap.addClass('chartShow');
3404                    setTimeout(function(){
3405                        $transitionWrap.addClass('isShowSize');
3406                    },100)
3407                    $body.addClass('forbid-to-scroll');
3408                }else{
3409                    $sizeChartWrap.removeClass('chartShow');
3410                    $transitionWrap.removeClass('isShowSize');
3411                    $body.removeClass('forbid-to-scroll');
3412                }
3413            })
3414            // 国家下拉
3415            var $sizeCountryList = $('.size_list_box .list');
3416            if(win_w>768){
3417                $('.size_list_box').hover(function(){
3418                    $sizeCountryList.stop(true,true).slideDown();
3419                },function(){
3420                    $sizeCountryList.stop(true,true).slideUp();
3421                })
3422            }else{
3423                $('.size_list_box').click(function(){
3424                    $sizeCountryList.stop(true,true).slideDown();
3425                });
3426            }
3427            
3428            
3429            //hover一一对应
3430            $(doc).on('mouseenter', '.size_content-wrap .tab-chart-size-wrap td', function () {
3431                    var $tr = $(this).closest('tr');
3432                    $(this).addClass('active');
3433                    $('td:first', $tr).addClass('active');
3434                })
3435                .on('mouseleave', '.size_content-wrap .tab-chart-size-wrap td', function () {
3436                    var $tr = $(this).closest('tr');
3437                    $('td', $tr).removeClass('active');
3438                })
3439            
3440            //inch-cm切换
3441            $(doc).on('click','.pull-right .js-shop-radio',function(e){ 
3442                e.preventDefault();
3443                var $this = $(this);
3444                var index = Number($this.attr('data-size'));
3445                if($this.find('.shop-radio').hasClass('shop-radio-checked')){
3446                    return false;
3447                }
3448                $('.shop-radio').removeClass('shop-radio-checked');
3449                $this.find('.shop-radio').addClass('shop-radio-checked');
3450                $('.tab-chart-size-wrap .tab-pane').eq(index).show().siblings().hide();
3451            })
3452            
3453            //切换国家更换对应的size值
3454            $(".size_list_box .list li").click(function(e) {
3455                e.stopPropagation();
3456                _this.selConversion($(this));
3457            });
3458        },
3459        getSizeData: function () {
3460			return window.size;//获取size数据
3461		},
3462        selConversion: function (o) {
3463            var data = this.getSizeData();
3464			if (!data) {return;}
3465			var type = o.find('a').text(),
3466				objInches = {
3467					type: type,
3468					sizes: [o.find('a').text()]
3469                };
3470            var data  = JSON.parse(data)
3471            objInches.sizes =objInches.sizes.concat(data[type]);
3472               
3473			$('.table-inches').each(function () {
3474				if ($('th.local-inches', this).length) {
3475					$('tr', this).each(function (i) {
3476						$(this).children().eq(1).text(objInches.sizes[i] || '-');
3477					});
3478				} else {
3479					$('tr', this).each(function (i) {
3480						$(this).children().eq(0).after(i === 0 ? '<th class="local-inches">' + objInches.sizes[i] + '</th>' : '<td>' + (objInches.sizes[i] || '-') + '</td>');
3481					});
3482				}
3483            });
3484            $(".size_list_box .list").hide();
3485            var type = o.find('a').attr('size');
3486            $('.size_list_box .cy_title a').attr('size', type).html(o.find('a').html());
3487        },
3488        //衡量产品详情查看ga数据监测
3489        judgeGaProductDetail:function(){
3490            if(gaNo && gaNo != ''){
3491                var product_SKU = productSKU ? productSKU : productID,
3492                    product_name = '',
3493                    product_category = '';
3494                if(pointData != null){
3495                    product_name = pointData.pointData.products_name;
3496                    product_category = pointData.pointData.cate_path;
3497                }
3498                ga('ec:addProduct', {
3499                    'id': product_SKU,
3500                    'name': product_name,
3501                    'category':product_category,
3502                    'brand': pointData.pointData.brand,
3503                });
3504                ga('ec:setAction', 'detail');
3505                ga('set', 'nonInteraction', true); //非互动匹配标记
3506                ga('send', 'pageview');
3507            }
3508        },
3509        //衡量购物车添加商品ga数据监测
3510        judgeGaAddToCart:function () {
3511            if(gaNo && gaNo != ''){
3512                var product_SKU = productSKU ? productSKU : productID,
3513                    product_name = '',
3514                    product_category = '';
3515                if(pointData != null){
3516                    product_name = pointData.pointData.products_name;
3517                    product_category = pointData.pointData.cate_path;
3518                }
3519                
3520                ga('ec:addProduct', {
3521                    'id': product_SKU,
3522                    'name': product_name,
3523                    'category':product_category,
3524                    'brand': pointData.pointData.brand,
3525                });
3526                ga('ec:setAction', 'add');
3527                ga('send', 'event', 'UX', 'click', 'add to cart');
3528            }
3529
3530            
3531        },
3532        buyNow: function(e){
3533            var _this = this,
3534                $this = $(e.currentTarget),
3535                isPayPal = $this.hasClass('js-paypal');
3536                isBuyNow = $this.hasClass('js-buynow');
3537                
3538            if ($this.hasClass('gray')) return false;
3539            if ($this.hasClass('forbidGray')) return false;//禁售地区
3540            if ($this.hasClass('loading_bg')) return false;
3541            
3542            if (isPayPal) {
3543                this.recordPayVisit('1', '1', 'PayPal Express Checkout');
3544                this.reportBingCustomEvent('click', 'product', 'middle_payPal_button'); // Bing增设埋点
3545                this.sendGaProductData(); // 营销埋点
3546                this.sendGAEvents('product', 'middle_payPal_button'); // GA埋点
3547            } else {
3548                this.recordPayVisit('1', '0');
3549                this.reportBingCustomEvent('click', 'product', 'middle_buyNow_button'); // Bing增设埋点
3550                this.sendGaProductData(); // 营销埋点
3551                this.sendGAEvents('product', 'middle_buyNow_button'); // GA埋点
3552            }
3553            
3554            //_this.judgeGaAddToCart();
3555            /* 属性数量不为0 */
3556            if (this.poaLength !== 0) {
3557                /* PC端 */
3558                if (!this.isPc) {
3559                    /* M端 */
3560                    var wrapIsShow = this.$poaWrapper.find('.poa_list_wrap').css('display') === 'none' ? false : true;//弹框显示状态
3561                    if (wrapIsShow) {
3562                        /* 点击弹框的加购按钮 */
3563                        if (this.checkSelected(true)) {
3564                            this.buyNowRequire(isPayPal);
3565                        }
3566                    } else {
3567                        /* 点击页面下方的加购按钮 */
3568                        this.openModal();
3569                        this.$giftWrapper.removeClass('show').find('.gift_list_wrap').hide();
3570                        this.$poaWrapper.find('.poa_list_wrap').show().find('.submit_box .js-buynow').show().css({'margin-left': 0,'margin-right': 0}).siblings().hide();//poa窗口显示
3571                        setTimeout(function () {
3572                            _this.$poaWrapper.addClass('show');
3573                        }, 0);
3574                    }
3575
3576                } else {
3577                    /* PC端 */
3578                    if (this.checkSelected(true)) {
3579                        this.buyNowRequire(isPayPal);
3580                    }
3581                }
3582            } else {
3583                this.buyNowRequire(isPayPal);
3584            }
3585
3586        },
3587        buyNowRequire: function(isPayPal){
3588            this.showBtnLoading(isPayPal ? 3 : 2);
3589            
3590            var _this = this,
3591                data = this.packAddData(),
3592                quantity = this.$qtyInput.val();
3593                var checkoutData={currency:'USD', value: quantity * $('.js-product-info #usPrice').val()}
3594             if(isPayPal){
3595                typeof fbq == 'function' && fbq('track','AddPaymentInfo',checkoutData);
3596             }  
3597            $.ajax({
3598                url: '/addProductBuyNow.html',
3599                type: 'post',
3600                dataType: 'json',
3601                data: data,
3602                cache: false,
3603                processData: false,
3604                contentType: false,
3605                success: function (data) {
3606                    if (data.message == 'success') {
3607                      if(!isPayPal){
3608                        window.location.href = '/checkout';
3609                      }else{
3610                        window.location.href = "/index.php?com=shopcart&t=checkoutPayPalExpressSubmit&payCode=paypal&isExpress=Y";
3611                        //_this.paypalRequire();
3612                      }
3613                        
3614                    } else {
3615                        _this.errorAlert(data.msg);
3616                    }
3617                    _this.shippingModalPositon();
3618                    _this.hideBtnLoading();
3619
3620                    //点击buy now 或 pay pal按钮后追踪推荐位数据
3621                    var rmmds = _this.getQueryString('rmmds');
3622                    if (isPayPal){
3623                        var pidArr = [_this.pid];
3624                        var bidArr = [];
3625                        var pid = "";
3626                        var loadData = Record.loadOntime('exp_rec_bid_' + _this.pid);
3627                        bidArr.push( loadData ? loadData.bid : "");
3628                        bidArr = bidArr.filter(Boolean);//删除空元素
3629                        _this.recObj["ac"] = "checkout";
3630                        _this.recObj["products_id"] = pidArr.join(",");
3631                        _this.recObj["basket_id"] = bidArr.join(",");
3632                        Record.rec(_this.recObj);
3633                        //写入cookie值给后端读取,数据保存15天
3634                        _this.setCookie('rec_bid', bidArr.join(","), 15) 
3635                    }else{
3636                        _this.recObj["ac"] = "cart";
3637                        _this.recObj["products_id"] = _this.pid;
3638                        Record.rec(_this.recObj);
3639                    }
3640                    if(rmmds === 'search'){
3641                        //搜索埋点
3642                        nDC.RecordClick('buynow', [_this.pid])
3643                    }
3644                    //FB事件监测
3645                    _this.sendFbEvents('AddToCart')
3646                    //buyNow追加监测
3647                  if (!isPayPal) {
3648                    try {
3649                      fbq('track', 'InitiateCheckout');
3650                    } catch (error) {
3651                      console.log(error);
3652                    }
3653                  }
3654                    
3655                },
3656                error: function (data) {
3657                    _this.hideBtnLoading();
3658                }
3659            })
3660        },
3661        /* add to cart 和 buy now 和start group 提交的数据 */
3662        packAddData: function(){
3663            var _this = this,
3664                data = new FormData(),
3665                quantity = this.$qtyInput.val();
3666
3667            data.append('quantity', quantity);
3668            data.append('products_id', this.pid);
3669            data.append('warehouse', this.cur_warehouse);
3670
3671            this.$giftList.find('.gift_item.isChecked').each(function () {
3672                var gift_id = $(this).attr('data-giftid'),
3673                    $attrs = $(this).find('.gift_info_wrap').find('.info_attr'),
3674                    accesory_id = gift_id;
3675
3676                if ($attrs !== 0) {
3677                    $attrs.each(function () {
3678                        var $active = $(this).find('.gift_attr.active');
3679                        accesory_id += '{' + $active.attr('data-optionid') + '}' + $active.attr('data-valueid');
3680                    });
3681
3682                }
3683
3684                data.append('accesory_id[]', accesory_id);
3685            });
3686
3687            $.each(this.activeIndex, function (i, val) {
3688                data.append('id[' + _this.activeIndex2[i] + ']', val);
3689            });
3690
3691            return data;
3692        },
3693        paypalRequire: function(){
3694          var _this = this;
3695          $.ajax({
3696            url: '/index.php?com=shopcart&t=checkoutPayPalExpressSubmit&payCode=paypal&isExpress=Y',
3697            type: 'post',
3698            dataType: 'json',
3699            success: function (data) {
3700                // if (data.message == 'success') {
3701                //   if(!isPayPal){
3702                //     headerInfoAjax.then(function (res) {
3703                //       if (_this.checkLogin(res)) {
3704                //           window.location.href = '/checkout';
3705                //       } else {
3706                //           window.location.href = '/information';
3707                //       }
3708                //     });
3709                //   }else{
3710                //     _this.paypalRequire();
3711                //   }
3712                    
3713                // } else {
3714                //     _this.errorAlert(data.msg);
3715                // }
3716                // _this.shippingModalPositon();
3717                // _this.hideBtnLoading();
3718                // //FB事件监测
3719                // _this.sendFbEvents('AddToCart')
3720            },
3721            error: function (data) {
3722                console.log(data);
3723                _this.hideBtnLoading();
3724            }
3725          })
3726        },
3727        /*
3728        属性值尺码切换
3729        author: liuyinggui
3730        */
3731        sizeChange: function() {
3732            var win_w = $(window).width();
3733            var _this = this;
3734            // 国家下拉
3735            var $sizeCountryList = $('.js-size-slide .list');
3736            if(win_w>768){
3737                $('.js-size-slide').hover(function(){
3738                    $sizeCountryList.stop(true,true).slideDown();
3739                },function(){
3740                    $sizeCountryList.stop(true,true).slideUp();
3741                })
3742            }else{
3743                $('.js-size-slide .cy_title').click(function(){
3744                    $sizeCountryList.stop(true,true).slideDown();
3745                });
3746            }
3747            //点击后切换属性值
3748            $('.js-size-item').on('click', function(){
3749                var attrList = $(this).parents('.item_name').next('.attr_value_list'),
3750                    items = JSON.parse($(this).children().attr('data-val'));
3751                var size = $(this).children().attr('size');
3752                $.each(attrList.children(),function(){
3753                    var vid = $(this).attr('data-vid')
3754                    $(this).text(items[vid])
3755                })
3756                _this.setCookie('_sizeType', size, 30) //尺码数据保存cookie30天
3757                $sizeCountryList.stop(true,true).slideUp();//收起下拉框
3758                $('.js-size-slide').find('.default_size').text('Size('+size+')') 
3759            })
3760        },
3761        setPromotion: function(){
3762            var promotionFlagArr = this.headerInfo.products_items_list.promotion_flag,
3763                group_url = this.headerInfo.products_items_list.group_url,
3764                $wrap = $('<div class="promotion-reduction-wrap"></div>');
3765            
3766            if(promotionFlagArr !== null && promotionFlagArr.length){
3767
3768                if(this.isPc){
3769                    var listHtml = '';
3770                    $.each(promotionFlagArr,function(index, value){
3771                        if(index !== 0){
3772                            listHtml += '<div class="reduction-item">' + value + '</div>';
3773                        }else{
3774                            listHtml += '<div class="reduction-item"> <i class="shopCart icon-M-mycoupons"></i> ' + value + '</div>';
3775                        }
3776                    });
3777                    
3778                    $wrap.html('<div class="promotion-flex-box"><a href="'+ group_url +'" class="reduction-list"> ' + listHtml + ' </a></div>');
3779                    
3780                    if(promotionFlagArr.length > 1){
3781                        $wrap.find('.promotion-flex-box').append('<a href="javascript:void(0);" class="more">More Deals <i class="shopCart icon-pinpaizhangouwuche_down-copy"></i></a>');
3782                    }
3783                }else{
3784                    var text = promotionFlagArr.join(', ');
3785                    $wrap.addClass('js-show-promotion').html('<div class="reduction-label">Discount:</div><div class="reduction-content"><div class="promotion-flag">'+ text +'</div><i class="icon shopCart icon-M-in"></i><img class="m-discount-loading" src="/templates/common/src/shopCart/images/loading.gif" /></div>');
3786                    //M端
3787
3788                }
3789
3790                $("#promotion-flag").html($wrap);
3791            }
3792        },
3793        initDefaultClick: function(){
3794            var _this = this;
3795            $(doc).ready(function () {
3796                if (_this.shopStatus) {
3797                    if (_this.semData) {
3798                        var key = Object.keys(_this.semData);
3799                        if (key.length) {
3800                            var defaultPoaArr = key[0].split('.');
3801                            _this.onClickHandler(defaultPoaArr);
3802                        }
3803                    } else {
3804                        if (_this.poaLength) {
3805                            /* 默认属性获取库存 */
3806                            var defaultPoaArr = [];//属性id数组
3807                            Object.keys(_this.defaultPoaVid).forEach(function (key) {
3808                                defaultPoaArr.push(String(_this.defaultPoaVid[key]));
3809                            });
3810                            _this.onClickHandler(defaultPoaArr);
3811                        } else {
3812                            /* 默认POA获取库存 */
3813                            _this.getPoaData();
3814                        }
3815                    }
3816
3817                    /* 判断批发价是否为空 */
3818                    if (!_this.isWsdataNull) {
3819                        _this.updateWsTable(true);
3820                        _this.$wholesaleWrap.css('display', 'inline-block');
3821                    }
3822                }
3823            });
3824        },
3825        groupBuyRule_m:function(){
3826          var $rulePop = $('#m-group-rule-pop');
3827          $(doc).on('click','.js-show-rulePop',function(){
3828            $rulePop.fadeIn();
3829          });
3830          $(doc).on('click','.js-close-rule',function(e){
3831            e.stopPropagation();
3832            $rulePop.fadeOut();
3833          })
3834        },
3835        discountHandler_m: function () {
3836          var _this = this,
3837            hasPromotionModal = false;
3838          /* 弹出promotion modal */
3839          $('#promotion-flag').on('click', '.js-show-promotion', function () {
3840            _this.$promotionModal = $('#promotion-modal');
3841            if (hasPromotionModal) {
3842              _this.$promotionModal.show();
3843              $('body').css({
3844                "overflow": "hidden"
3845              });
3846              _this.openModal();
3847              setTimeout(function () {
3848                _this.$promotionModal.addClass('show');
3849              }, 0);
3850            } else {
3851              var $promotionFlag_m = $('#js-promotion-flag'),
3852                $discountBtn = $('#js-discount-btn'),
3853                promotionFlagArr = _this.headerInfo.products_items_list.promotion_flag,
3854                group_url = _this.headerInfo.products_items_list.group_url;
3855                _this.group_id = _this.headerInfo.products_items_list.group_id;
3856              $('.m-discount-loading').fadeIn();  
3857              _this.loadMoreProducts_m().then(function (data) {
3858                $('.m-discount-loading').hide();  
3859                $promotionFlag_m.html(promotionFlagArr.join(', '));
3860                $discountBtn.html('<a href="' + group_url + '" class="product_info_btn">View More</a>');
3861                _this.$promotionModal.show();
3862                $('body').css({
3863                  "overflow": "hidden"
3864                });
3865                _this.openModal();
3866                hasPromotionModal = true;
3867                setTimeout(function () {
3868                  _this.$promotionModal.addClass('show');
3869                }, 0);
3870              })
3871            }
3872
3873          });
3874
3875          $(doc).on('click', '#promotion-modal .closeBtn', function () {
3876            _this.$promotionModal.removeClass('show');
3877            setTimeout(function () {
3878              _this.$promotionModal.hide();
3879            }, 200);
3880            _this.closeModal();
3881            $('body').css({
3882              "overflow": ""
3883            });
3884          });
3885        },
3886        scrollBind_m: function () {
3887          var _this = this;
3888          var numTime = _this.isPc ? 300 : 50;//之所以这样处理,因为M端手速过快没法继续加载更多数据
3889          var throttleFn = throttle(function () {
3890            var flagLoadType =!_this.pro_loading && !_this.pro_isLoadOver; 
3891            if (flagLoadType) {
3892              var boxHeight = $(".box_wrap").height(),
3893                eleScrollHight = $('.discount-list')[0].scrollHeight;
3894                eleScrollTop = $('.discount-list')[0].scrollTop;
3895                outHeight = $('.discount-list').outerHeight();
3896              //监听滚动到底部请求数据  
3897              if (eleScrollTop + boxHeight >= eleScrollHight - outHeight - 100){
3898                _this.loadMoreProducts_m();
3899              }
3900            }
3901            
3902          }, numTime);  
3903          $('#js-discount-list').scroll(throttleFn);  
3904        },
3905        loadMoreProducts_m: function () {
3906          var _this = this,
3907            $pro_loading = $('#js-more-pro_loading');
3908          _this.pro_loading = true;
3909          var $discountListWrap = $('#js-discount-list');  
3910          return $.ajax({
3911            url: '/Promotion_groupProducts.html',
3912            data: {
3913              group_id:_this.group_id,
3914              page: _this.promos_pager,
3915              order: '',
3916            },
3917            type: 'post',
3918            dataType: 'json',
3919            beforeSend: function () {
3920              $pro_loading.show();
3921            },
3922            success: function (res) {
3923              $pro_loading.hide();
3924              var pages = res.pages;//评论总页数
3925              if(res.code == 200){
3926                _this.productItem = template("templatePromotionContent", res);
3927                $discountListWrap.append(_this.productItem);
3928              }
3929              if (_this.promos_pager === pages) {
3930                _this.pro_isLoadOver = true;
3931              } else {
3932                _this.promos_pager++;
3933                _this.pro_isLoadOver = false;
3934              }
3935              _this.pro_loading = false;
3936
3937            },
3938            complete: function () {
3939              $pro_loading.hide();
3940            }
3941          });
3942        },
3943        // 支付锚点
3944        recordPayVisit: function(step, isExpress, payCode) {
3945          var step = step || 1,
3946            isExpress = isExpress || '',
3947            payCode = payCode || '';
3948          $.ajax({
3949            url: '/index.php',
3950            type: 'get',
3951            data: {
3952              com: 'shopcart',
3953              t: 'ajaxRecordPayVisit',
3954              isExpress: isExpress,
3955              step: step,
3956              payCode: payCode
3957            }
3958          })
3959        },
3960        reportBingCustomEvent: function(action, category, label) {
3961            // Bing增设埋点
3962            try {
3963                window.uetq = window.uetq || [];
3964                window.uetq.push('event', action, { 
3965                    'event_category': category,
3966                    'event_label': label,
3967                });
3968            } catch (err) {
3969            }
3970        },
3971        // 衡量结帐选项流程记录
3972        sendGaProductData:function(){
3973            try{
3974                var products_info = pointData.pointData;
3975                console.log(pointData.pointData);
3976                ga('ec:addProduct', {
3977                    'id': products_info.sku,
3978                    'name': products_info.products_name,
3979                    'category': products_info.cate_path,
3980                    'brand': products_info.brand_name,
3981                    'price': products_info.final_price,
3982                    'quantity': products_info.quantity
3983                });  
3984
3985                ga('ec:setAction', 'checkout', {
3986                    'step': 1,
3987                });
3988                    
3989                ga('send', 'pageview');  
3990            } catch(error){
3991                console.log(error)
3992            }
3993        },
3994        // 发送ga埋点
3995        sendGAEvents:function(category, label) {
3996            //GA id存在则发送事件
3997            if (gaNo && gaNo != '') {
3998                gtag('event', 'click', {
3999                    'event_category': category,
4000                    'event_label': label,
4001                    'value': 0
4002                });
4003            }
4004        },
4005    }
4006
4007    var pid = $('#product_name').attr('data-id');
4008    var sel_poa = $('#selPoa').val();
4009
4010    win.PoaHandler = new PoaHandler({
4011        pid: pid,
4012        poaCodeList: poaCodeList,
4013        selPoa: sel_poa,//默认SKU
4014        wsData: wsData,//批发价信息
4015        defaultPoaVid: defaultPoaVid,//默认选中
4016        semData: semData,//sem信息
4017        cur_warehouse: cur_warehouse,//产品所在仓库
4018        defaultPoa:defaultPoa,//默认poa
4019    });
4020
4021})(document, window, jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.