goods.js 22.2 KB
Newer Older
D
v1.2.0  
devil_gong 已提交
1
// 规格弹窗PC显示
D
Devil 已提交
2
function PoptitPcShow()
D
v1.2.0  
devil_gong 已提交
3 4 5 6 7 8 9
{
    $(document.body).css('position', 'static');
    $('.theme-signin-left').scrollTop(0);
    $('.theme-popover-mask').hide();
    $('.theme-popover').slideDown(0);
}
// 规格弹窗关闭
D
Devil 已提交
10
function PoptitClose()
D
v1.2.0  
devil_gong 已提交
11 12 13 14 15 16 17 18 19 20
{
    if($(window).width() < 1025)
    {
        $(document.body).css('position', 'static');
        $('.theme-signin-left').scrollTop(0);
        $('.theme-popover-mask').hide();
        $('.theme-popover').slideUp(100);
    }
}

G
gongfuxiang 已提交
21 22 23 24 25 26 27 28 29 30
/**
 * 评论记录ajax请求
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  1.0.0
 * @datetime 2019-05-13T21:39:55+0800
 * @param    {[int]}                 page [分页值]
 */
function GoodsCommentsHtml(page)
{
D
devil_gong 已提交
31 32 33 34 35 36 37
    if((page || 1) <= 1)
    {
        $('.goods-page-no-data').removeClass('none');
        $('.goods-page-no-data span').text('加载中...');
    } else {
        $('.goods-page-no-data').addClass('none');
    }
G
gongfuxiang 已提交
38 39 40

    $.ajax({
        url: $('.goods-comment').data('url'),
41 42 43
        type: 'POST',
        data: {"goods_id": $('.goods-comment').data('goods-id'), "page": page || 1},
        dataType: 'json',
44
        success: function(res)
G
gongfuxiang 已提交
45
        {
D
devil_gong 已提交
46
            $('.goods-page-no-data').addClass('none');
47
            if(res.code == 0)
G
gongfuxiang 已提交
48
            {
49 50
                $('.goods-comment-content').html(res.data.data);
                $('.goods-page-container').html(PageLibrary(res.data.total, res.data.number, page, 2));
G
gongfuxiang 已提交
51 52 53 54 55 56
            }

            // 没有数据
            if($('.goods-comment-content article').length <= 0)
            {
                $('.goods-page-no-data').removeClass('none');
D
devil_gong 已提交
57
                $('.goods-page-no-data span').text('没有评论数据');
G
gongfuxiang 已提交
58
            }
D
devil_gong 已提交
59
        },
60
        error: function(xhr, type)
D
devil_gong 已提交
61 62
        {
            $('.goods-page-no-data').removeClass('none');
63
            $('.goods-page-no-data span').text(xhr.responseText || '请求出现错误,请稍后再试!');
G
gongfuxiang 已提交
64 65 66 67
        }
    });
}

68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
/**
 * 已选规格
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2021-10-05
 * @desc    description
 */
function GoodsSelectedSpec()
{
    // 规格
    var spec = [];
    var sku_count = $('.sku-items').length;
    if(sku_count > 0)
    {
        var spec_count = $('.sku-line.selected').length;
        if(spec_count >= sku_count)
        {
            $('.iteminfo_parameter .sku-items').removeClass('sku-not-active');
            $('.theme-signin-left .sku-items li.selected').each(function(k, v)
            {
                spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
            });
        }
    }
    return spec;
}

D
v1.2.0  
devil_gong 已提交
96
/**
D
devil 已提交
97
 * 购买/加入购物车校验
D
v1.2.0  
devil_gong 已提交
98 99 100 101 102 103 104
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-09-13
 * @desc    description
 * @param   {[object]}        e [当前标签对象]
 */
D
devil 已提交
105
function BuyCartCheck(e)
D
v1.2.0  
devil_gong 已提交
106 107
{
    // 参数
D
devil_gong 已提交
108 109 110 111 112 113
    var stock = parseInt($('#text_box').val()) || 1;
    var inventory = parseInt($('.stock-tips .stock').text());
    var min = $('.stock-tips .stock').data('min-limit') || 1;
    var max = $('.stock-tips .stock').data('max-limit') || 0;
    var unit = $('.stock-tips .stock').data('unit') || '';
    if(stock < min)
D
v1.2.0  
devil_gong 已提交
114
    {
D
devil 已提交
115
        Prompt('最低起购数量'+min+unit);
D
devil_gong 已提交
116 117 118 119
        return false;
    }
    if(max > 0 && stock > max)
    {
D
devil 已提交
120
        Prompt('最大限购数量'+max+unit);
D
devil_gong 已提交
121 122 123 124
        return false;
    }
    if(stock > inventory)
    {
D
devil 已提交
125
        Prompt('库存数量'+inventory+unit);
D
v1.2.0  
devil_gong 已提交
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
        return false;
    }

    // 规格
    var spec = [];
    var sku_count = $('.sku-items').length;
    if(sku_count > 0)
    {
        var spec_count = $('.sku-line.selected').length;
        if(spec_count < sku_count)
        {
            $('.sku-items').each(function(k, v)
            {
                if($(this).find('.sku-line.selected').length == 0)
                {
D
devil 已提交
141
                    $(this).addClass('sku-not-active');
D
v1.2.0  
devil_gong 已提交
142 143
                }
            });
D
devil 已提交
144
            Prompt('请选择规格');
D
v1.2.0  
devil_gong 已提交
145 146
            return false;
        }
147 148 149

        // 已选规格
        spec = GoodsSelectedSpec();
D
v1.2.0  
devil_gong 已提交
150
    }
151
    var type =( typeof(e) == 'object') ? e.attr('data-type') : null;
D
devil 已提交
152
    return {
153
        "id": $('.goods-detail').data('id'),
D
devil 已提交
154 155
        "stock": stock,
        "spec": spec,
156
        "type": type
D
devil 已提交
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
    };
}

/**
 * 购买/加入购物车处理
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-09-13
 * @desc    description
 * @param   {[object]}        e [当前标签对象]
 */
function BuyCartHandle(e)
{
    // 参数
    var params = BuyCartCheck(e);
    if(params === false)
    {
        return false;
    }
D
v1.2.0  
devil_gong 已提交
177 178

    // 操作类型
D
devil 已提交
179
    switch(params.type)
D
v1.2.0  
devil_gong 已提交
180 181 182
    {
        // 立即购买
        case 'buy' :
D
devil 已提交
183 184 185 186
            var $form = $('form.buy-form');
            $form.find('input[name="spec"]').val(JSON.stringify(params.spec));
            $form.find('input[name="stock"]').val(params.stock);
            $form.find('button[type="submit"]').trigger('click');
D
v1.2.0  
devil_gong 已提交
187 188 189 190
            break;

        // 加入购物车
        case 'cart' :
D
devil 已提交
191 192 193 194
            var $form = $('form.cart-form');
            $form.find('input[name="spec"]').val(JSON.stringify(params.spec));
            $form.find('input[name="stock"]').val(params.stock);
            $form.find('button[type="submit"]').trigger('click');
D
Devil 已提交
195
            PoptitClose();
D
v1.2.0  
devil_gong 已提交
196 197 198 199
            break;

        // 默认
        default :
D
devil 已提交
200
            Prompt('操作参数配置有误');
D
v1.2.0  
devil_gong 已提交
201 202 203 204
    }
    return true;
}

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
/**
 * 商品规格详情返回数据处理
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2021-10-05
 * @desc    description
 * @param   {[object]}        data [后端返回数据]
 */
function GoodsSpecDetailBackHandle(data)
{
    $('.text-info .price-now').text(__currency_symbol__+data.spec_base.price);
    $('.goods-price').text(data.spec_base.price);
    $('.number-tag input[type="number"]').attr('max', data.spec_base.inventory);
    $('.stock-tips .stock').text(data.spec_base.inventory);
    if(data.spec_base.original_price > 0)
    {
        $('.goods-original-price').text(__currency_symbol__+data.spec_base.original_price);
        $('.goods-original-price').parents('.items').show();
    } else {
        $('.goods-original-price').parents('.items').hide();
    }

    // 已选数量校验、超出规格数量则以规格数量为准
    var stock = parseInt($('#text_box').val());
    if(stock > data.spec_base.inventory)
    {
        $('#text_box').val(data.spec_base.inventory);
    }

    // 扩展数据处理
    var extends_element = data.extends_element || [];
    if(extends_element.length > 0)
    {
        for(var i in extends_element)
        {
            if((extends_element[i]['element'] || null) != null && extends_element[i]['content'] !== null)
            {
D
Devil 已提交
243
                $(extends_element[i]['element']).prop('outerHTML', extends_element[i]['content']);
244 245 246 247 248
            }
        }
    }
}

D
v1.2.0  
devil_gong 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
/**
 * 获取规格详情
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-12-14
 * @desc    description
 */
function GoodsSpecDetail()
{
    // 是否全部选中
    var sku_count = $('.theme-signin-left .sku-items').length;
    var active_count = $('.theme-signin-left .sku-items li.selected').length;
    if(active_count < sku_count)
    {
        return false;
    }

    // 获取规格值
    var spec = [];
    $('.theme-signin-left .sku-items li.selected').each(function(k, v)
    {
        spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
    });

274 275 276
    // 已填写数量
    var stock = parseInt($('#text_box').val()) || 1;

D
v1.2.0  
devil_gong 已提交
277 278 279 280 281 282 283 284 285
    // 开启进度条
    $.AMUI.progress.start();

    // ajax请求
    $.ajax({
        url: $('.goods-detail').data('spec-detail-ajax-url'),
        type: 'post',
        dataType: "json",
        timeout: 10000,
286 287 288 289 290 291
        data: {
            "id": $('.goods-detail').data('id'),
            "stock": stock,
            "spec": spec
        },
        success: function(res)
D
v1.2.0  
devil_gong 已提交
292 293
        {
            $.AMUI.progress.done();
294
            if(res.code == 0)
D
v1.2.0  
devil_gong 已提交
295
            {
296
                GoodsSpecDetailBackHandle(res.data);
D
v1.2.0  
devil_gong 已提交
297
            } else {
298
                Prompt(res.msg);
D
v1.2.0  
devil_gong 已提交
299 300 301 302 303
            }
        },
        error: function(xhr, type)
        {
            $.AMUI.progress.done();
D
Devil 已提交
304
            Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
D
v1.2.0  
devil_gong 已提交
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
        }
    });
}

/**
 * 获取规格类型
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-12-14
 * @desc    description
 */
function GoodsSpecType()
{
    // 是否全部选中
    var sku_count = $('.theme-signin-left .sku-items').length;
    var active_count = $('.theme-signin-left .sku-items li.selected').length;
    if(active_count <= 0 || active_count >= sku_count)
    {
        return false;
    }

    // 获取规格值
    var spec = [];
    $('.theme-signin-left .sku-items li.selected').each(function(k, v)
    {
        spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')})
    });

    // 开启进度条
    $.AMUI.progress.start();

    // ajax请求
    $.ajax({
        url: $('.goods-detail').data('spec-type-ajax-url'),
        type: 'post',
        dataType: "json",
        timeout: 10000,
        data: {"id": $('.goods-detail').data('id'), "spec": spec},
344
        success: function(res)
D
v1.2.0  
devil_gong 已提交
345 346
        {
            $.AMUI.progress.done();
347
            if(res.code == 0)
D
v1.2.0  
devil_gong 已提交
348 349 350 351 352 353 354 355
            {
                var spec_count = spec.length;
                var index = (spec_count > 0) ? spec_count : 0;
                if(index < sku_count)
                {
                    $('.theme-signin-left .sku-items').eq(index).find('li').each(function(k, v)
                    {
                        $(this).removeClass('sku-dont-choose');
356
                        var value = $(this).data('value').toString();
357
                        if(res.data.spec_type.indexOf(value) == -1)
D
v1.2.0  
devil_gong 已提交
358 359 360 361 362 363 364
                        {
                            $(this).addClass('sku-items-disabled');
                        } else {
                            $(this).removeClass('sku-items-disabled');
                        }
                    });
                }
D
devil_gong 已提交
365 366

                // 扩展数据处理
367
                var extends_element = res.data.extends_element || [];
D
devil_gong 已提交
368 369 370 371 372 373 374 375 376 377
                if(extends_element.length > 0)
                {
                    for(var i in extends_element)
                    {
                        if((extends_element[i]['element'] || null) != null && extends_element[i]['content'] !== null)
                        {
                            $(extends_element[i]['element']).html(extends_element[i]['content']);
                        }
                    }
                }
D
v1.2.0  
devil_gong 已提交
378
            } else {
379
                Prompt(res.msg);
D
v1.2.0  
devil_gong 已提交
380 381 382 383 384
            }
        },
        error: function(xhr, type)
        {
            $.AMUI.progress.done();
D
Devil 已提交
385
            Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
D
v1.2.0  
devil_gong 已提交
386 387 388 389 390 391 392 393 394 395 396 397 398 399
        }
    });
}

/**
 * 商品基础数据恢复
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-12-25
 * @desc    description
 */
function GoodsBaseRestore()
{
D
devil 已提交
400
    $('.text-info .price-now').text(__currency_symbol__+$('.text-info .price-now').data('original-price'));
D
devil_gong 已提交
401
    $('.goods-price').text($('.goods-price').data('original-price'));
D
v1.2.0  
devil_gong 已提交
402 403
    $('.number-tag input[type="number"]').attr('max', $('.number-tag input[type="number"]').data('original-max'));
    $('.stock-tips .stock').text($('.stock-tips .stock').data('original-stock'));
D
devil_gong 已提交
404 405 406 407 408 409 410 411 412

    // 价格处理
    if($('.tb-detail-price .original-price-value').length > 0)
    {
        $('.tb-detail-price .original-price-value').each(function(k, v)
        {
            var price = $(this).data('original-price');
            if(price !== undefined)
            {
D
devil 已提交
413
                $(this).text(__currency_symbol__+price);
D
devil_gong 已提交
414 415 416
            }
        });
    }
D
v1.2.0  
devil_gong 已提交
417 418
}

419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476
/**
 * 数量值改变
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2021-10-05
 * @desc    description
 */
function GoodsNumberChange()
{
    var stock = parseInt($('#text_box').val()) || 1;
    var spec = [];
    var sku_count = $('.sku-items').length;
    if(sku_count > 0)
    {
        // 未完全选择规格则返回
        var spec_count = $('.sku-line.selected').length;
        if(spec_count < sku_count)
        {
            return false;
        }

        // 已选规格
        spec = GoodsSelectedSpec();
    }

    // 开启进度条
    $.AMUI.progress.start();

    // ajax请求
    $.ajax({
        url: $('#text_box').data('ajax-url'),
        type: 'post',
        dataType: "json",
        timeout: 10000,
        data: {
            "id": $('.goods-detail').data('id'),
            "stock": stock,
            "spec": spec
        },
        success: function(res)
        {
            $.AMUI.progress.done();
            if(res.code == 0)
            {
                GoodsSpecDetailBackHandle(res.data);
            } else {
                Prompt(res.msg);
            }
        },
        error: function(xhr, type)
        {
            $.AMUI.progress.done();
            Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
        }
    });
}

D
devil 已提交
477 478 479 480 481 482 483 484
/**
 * 规格选择显示
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2020-08-16
 * @desc    description
 */
D
devil 已提交
485
function SpecPopupShow(e)
D
devil 已提交
486
{
D
devil 已提交
487
    $(document.body).css({"position":"fixed", "width":"100%"});
D
devil 已提交
488 489
    $('.theme-popover-mask').show();
    $('.theme-popover').slideDown(200);
D
devil 已提交
490
    $('.theme-popover .confirm').attr('data-type', e.data('type') || 'buy');    
D
devil 已提交
491 492
}

D
v1.2.0  
devil_gong 已提交
493
$(function() {
D
devil 已提交
494 495 496
    // 购物车表单初始化
    FromInit('form.cart-form');

D
v1.2.0  
devil_gong 已提交
497 498 499 500 501
    // 商品规格选择
    $('.theme-options').each(function()
    {
        $(this).find('ul>li').on('click', function()
        {
502
            // 规格处理
503
            var length = $('.theme-signin-left .sku-container .sku-items').length;
D
v1.2.0  
devil_gong 已提交
504 505 506 507 508 509
            var index = $(this).parents('.sku-items').index();
            if($(this).hasClass('selected'))
            {
                $(this).removeClass('selected');

                // 去掉元素之后的禁止
510
                $('.theme-signin-left .sku-container .sku-items').each(function(k, v)
D
v1.2.0  
devil_gong 已提交
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526
                {
                    if(k > index)
                    {
                        $(this).find('li').removeClass('sku-items-disabled').removeClass('selected').addClass('sku-dont-choose');
                    }
                });

                // 数据还原
                GoodsBaseRestore();

            } else {
                if($(this).hasClass('sku-items-disabled') || $(this).hasClass('sku-dont-choose'))
                {
                    return false;
                }
                $(this).addClass('selected').siblings('li').removeClass('selected');
D
devil 已提交
527
                $(this).parents('.sku-items').removeClass('sku-not-active');
D
v1.2.0  
devil_gong 已提交
528 529 530 531

                // 去掉元素之后的禁止
                if(index < length)
                {
532
                    $('.theme-signin-left .sku-container .sku-items').each(function(k, v)
D
v1.2.0  
devil_gong 已提交
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
                    {
                        if(k > index)
                        {
                            $(this).find('li').removeClass('sku-items-disabled').removeClass('selected').addClass('sku-dont-choose');
                        }
                    });
                }

                // 是否存在规格图片
                var spec_images = $(this).data('type-images') || null;
                if(spec_images != null)
                {
                    $('.jqzoom').attr('src', spec_images);
                    $('.jqzoom').attr('rel', spec_images);
                    $('.img-info img').attr('src', spec_images);
                }

                // 后面是否还有未选择的规格
                if(index < length-1)
                {
                    // 数据还原
                    GoodsBaseRestore();
                }

                // 获取下一个规格类型
                GoodsSpecType();

                // 获取规格详情
                GoodsSpecDetail();
            }
        });
    });

    // 放大镜初始化
G
gongfuxiang 已提交
567 568 569
    $('.jqzoom').imagezoom({
        yzoom: 398
    });
D
v1.2.0  
devil_gong 已提交
570 571 572 573 574 575
    $('#thumblist li a').on('mouseover', function() {
        $(this).parents('li').addClass('tb-selected').siblings().removeClass('tb-selected');
        $('.jqzoom').attr('src', $(this).find('img').attr('mid'));
        $('.jqzoom').attr('rel', $(this).find('img').attr('big'));
    });

D
devil 已提交
576 577 578
    // 规格选择显示事件
    $('.mini-spec-event').on('click', function()
    {
D
devil 已提交
579
        SpecPopupShow($(this));
D
devil 已提交
580 581
    });

D
v1.2.0  
devil_gong 已提交
582 583 584 585 586 587
    //弹出规格选择
    $('.buy-event').on('click', function() {
        if($(window).width() < 1025) {
            // 是否登录
            if(__user_id__ != 0)
            {
D
devil 已提交
588
                SpecPopupShow($(this));
D
v1.2.0  
devil_gong 已提交
589 590
            }
        } else {
D
Devil 已提交
591
            PoptitPcShow();
D
v1.2.0  
devil_gong 已提交
592 593 594
        }
    });
    $('.theme-poptit .close, .btn-op .close').on('click', function() {
D
Devil 已提交
595
        PoptitClose();
D
v1.2.0  
devil_gong 已提交
596 597 598 599 600 601 602 603 604 605
    });

    // 购买
    $('.buy-submit, .cart-submit').on('click', function()
    {
        // 是否登录
        if(__user_id__ != 0)
        {
            if($(window).width() >= 1025)
            {
D
devil 已提交
606
                BuyCartHandle($(this));
D
v1.2.0  
devil_gong 已提交
607 608 609
            }
        }
    });
D
Devil 已提交
610
    // 确认
D
v1.2.0  
devil_gong 已提交
611 612 613 614 615 616 617
    $('.theme-popover .confirm').on('click', function()
    {
        // 是否登录
        if(__user_id__ != 0)
        {
            if($(window).width() < 1025)
            {
D
devil 已提交
618
                BuyCartHandle($(this));
D
v1.2.0  
devil_gong 已提交
619 620 621 622 623 624 625 626 627 628 629 630 631
            }
        }
    });

    // 收藏
    $('.favor-submit').on('click', function()
    {
        // 是否登录
        if(__user_id__ != 0)
        {
            var $this = $(this);

            // ajax请求
632
            $.AMUI.progress.start();
D
v1.2.0  
devil_gong 已提交
633 634 635 636 637 638
            $.ajax({
                url: $(this).data('ajax-url'),
                type: 'post',
                dataType: "json",
                timeout: 10000,
                data: {"id": $('.goods-detail').data('id')},
639
                success: function(res)
D
v1.2.0  
devil_gong 已提交
640 641
                {
                    $.AMUI.progress.done();
642
                    PoptitClose();
D
v1.2.0  
devil_gong 已提交
643

644
                    if(res.code == 0)
D
v1.2.0  
devil_gong 已提交
645
                    {
646 647 648
                        $this.find('.goods-favor-text').text(res.data.text);
                        $this.find('.goods-favor-count').text('('+res.data.count+')');
                        if(res.data.status == 1)
D
v1.2.0  
devil_gong 已提交
649 650 651 652 653
                        {
                            $this.addClass('text-active');
                        } else {
                            $this.removeClass('text-active');
                        }
654
                        Prompt(res.msg, 'success');
D
v1.2.0  
devil_gong 已提交
655
                    } else {
656
                        Prompt(res.msg);
D
v1.2.0  
devil_gong 已提交
657 658 659 660 661
                    }
                },
                error: function(xhr, type)
                {
                    $.AMUI.progress.done();
662
                    PoptitClose();
D
Devil 已提交
663
                    Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
D
v1.2.0  
devil_gong 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
                }
            });
        }
    });

    // 视频
    $('.goods-video-submit-start').on('click', function()
    {
        $('.goods-video-container').removeClass('none').trigger('play');
        $('.goods-video-submit-close').removeClass('none');
        $('.goods-video-submit-start').addClass('none');
    });
    $('.goods-video-submit-close').on('click', function()
    {
        $('.goods-video-container').addClass('none').trigger('pause');
        $('.goods-video-submit-close').addClass('none');
        $('.goods-video-submit-start').removeClass('none');
    });

    //获得文本框对象
684 685 686 687 688
    var $input = $('#text_box');
    var $stock_tips = $('.stock-tips .stock');
    var min = parseInt($stock_tips.data('min-limit')) || 1;
    var max = parseInt($stock_tips.data('max-limit')) || 0;
    var unit = $stock_tips.data('unit') || '';
D
v1.2.0  
devil_gong 已提交
689

G
gongfuxiang 已提交
690
    // 手动输入
691
    $input.on('blur', function()
G
gongfuxiang 已提交
692
    {
693 694 695
        var stock = parseInt($(this).val());
        var inventory = parseInt($stock_tips.text());
        if(isNaN(stock))
G
gongfuxiang 已提交
696
        {
697
            stock = min;
G
gongfuxiang 已提交
698
        }
699
        if(max > 0 && stock > max)
G
gongfuxiang 已提交
700
        {
701
            stock = max;
G
gongfuxiang 已提交
702
        }
703 704 705 706 707 708 709 710 711 712 713 714
        if(stock < min)
        {
            stock = min;
        }
        if(stock > inventory)
        {
            stock = inventory;
        }
        $input.val(stock);

        // 数量更新事件
        GoodsNumberChange();
G
gongfuxiang 已提交
715 716
    });

D
v1.2.0  
devil_gong 已提交
717
    //数量增加操作
D
devil_gong 已提交
718 719
    $('#add').on('click', function()
    {
720 721 722
        var inventory = parseInt($stock_tips.text());
        var stock = parseInt($input.val())+1;
        if(max > 0 && stock > max)
D
v1.2.0  
devil_gong 已提交
723
        {
724
            $input.val(max);
D
devil_gong 已提交
725 726 727
            Prompt('最大限购数量'+max+unit);
            return false;
        }
728
        if(stock > inventory)
D
devil_gong 已提交
729
        {
730
            $input.val(min);
D
devil_gong 已提交
731 732
            Prompt('库存数量'+inventory+unit);
            return false;
D
v1.2.0  
devil_gong 已提交
733
        }
734 735 736 737
        $input.val(stock);

        // 数量更新事件
        GoodsNumberChange();
D
v1.2.0  
devil_gong 已提交
738 739
    });
    //数量减少操作
D
devil_gong 已提交
740 741
    $('#min').on('click', function()
    {
742
        var value = parseInt($input.val())-1;
D
devil_gong 已提交
743 744
        if(value < min)
        {
745
            $input.val(min);
D
devil_gong 已提交
746 747 748
            Prompt('最低起购数量'+min+unit);
            return false;
        }
749 750 751 752
        $input.val(value);

        // 数量更新事件
        GoodsNumberChange();
D
devil_gong 已提交
753 754
    });

G
gongfuxiang 已提交
755 756 757 758 759 760 761 762 763 764 765
    // 评论
    GoodsCommentsHtml(1);
    $(document).on('click', '.goods-page-container .pagelibrary a', function()
    {
        var page = $(this).data('page') || null;
        if(page != null)
        {
            // 获取数据
            GoodsCommentsHtml(page);

            // 回到评论顶部位置
D
devil_gong 已提交
766
            $(window).smoothScroll({position: $('.introduce-main').offset().top});
G
gongfuxiang 已提交
767 768 769 770 771 772
        }
    });

    // 累计评价点击事件
    $('.tm-ind-panel .ind-panel-comment').on('click', function()
    {
D
devil_gong 已提交
773
        $(window).smoothScroll({position: $('.introduce-main').offset().top});
G
gongfuxiang 已提交
774 775 776
        $('.introduce-main .am-tabs').tabs('open', 1);
    });

D
devil_gong 已提交
777 778 779
    // tab事件
    $('.introduce-main .am-tabs li').on('click', function()
    {
D
devil_gong 已提交
780
        $(window).smoothScroll({position: $('.introduce-main').offset().top});
D
devil_gong 已提交
781 782
    });

D
devil_gong 已提交
783
});
D
v1.2.0  
devil_gong 已提交
784

D
devil_gong 已提交
785 786 787
// 浏览器窗口实时事件
$(window).resize(function()
{
D
Devil 已提交
788 789 790
    var name = document.activeElement.tagName;
    var arr = ['INPUT', 'SELECT', 'TEXTAREA', 'BUTTON'];
    if(arr.indexOf(name) == -1)
D
devil_gong 已提交
791
    {
792 793 794 795 796 797 798
        // 规格显示/隐藏处理
        if($(window).width() < 1025)
        {
            PoptitClose();
        } else {
            PoptitPcShow();
        }
D
devil_gong 已提交
799
    }
D
v1.2.0  
devil_gong 已提交
800
});