goods.js 21.9 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
/**
 * 已选规格
 * @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)
        {
            $('.theme-signin-left .sku-items li.selected').each(function(k, v)
            {
D
Devil 已提交
88
                spec.push({"type": $(this).data('type-value'), "value": $(this).data('value')});
89 90 91 92 93 94
            });
        }
    }
    return spec;
}

D
v1.2.0  
devil_gong 已提交
95
/**
D
devil 已提交
96
 * 购买/加入购物车校验
D
v1.2.0  
devil_gong 已提交
97 98 99 100 101 102 103
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-09-13
 * @desc    description
 * @param   {[object]}        e [当前标签对象]
 */
D
devil 已提交
104
function BuyCartCheck(e)
D
v1.2.0  
devil_gong 已提交
105 106
{
    // 参数
D
devil_gong 已提交
107 108 109 110 111 112
    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 已提交
113
    {
D
devil 已提交
114
        Prompt('最低起购数量'+min+unit);
D
devil_gong 已提交
115 116 117 118
        return false;
    }
    if(max > 0 && stock > max)
    {
D
devil 已提交
119
        Prompt('最大限购数量'+max+unit);
D
devil_gong 已提交
120 121 122 123
        return false;
    }
    if(stock > inventory)
    {
D
devil 已提交
124
        Prompt('库存数量'+inventory+unit);
D
v1.2.0  
devil_gong 已提交
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
        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 已提交
140
                    $(this).addClass('sku-not-active');
D
v1.2.0  
devil_gong 已提交
141 142
                }
            });
D
devil 已提交
143
            Prompt('请选择规格');
D
v1.2.0  
devil_gong 已提交
144 145
            return false;
        }
146 147 148

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

/**
 * 购买/加入购物车处理
 * @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 已提交
176 177

    // 操作类型
D
devil 已提交
178
    switch(params.type)
D
v1.2.0  
devil_gong 已提交
179 180 181
    {
        // 立即购买
        case 'buy' :
D
devil 已提交
182 183 184 185
            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 已提交
186 187 188 189
            break;

        // 加入购物车
        case 'cart' :
D
devil 已提交
190 191 192 193
            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 已提交
194
            PoptitClose();
D
v1.2.0  
devil_gong 已提交
195 196 197 198
            break;

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

204 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
/**
 * 商品规格详情返回数据处理
 * @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 已提交
242
                $(extends_element[i]['element']).prop('outerHTML', extends_element[i]['content']);
243 244 245 246 247
            }
        }
    }
}

D
v1.2.0  
devil_gong 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
/**
 * 获取规格详情
 * @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;
    }

    // 获取规格值
D
Devil 已提交
267
    var spec = GoodsSelectedSpec();
D
v1.2.0  
devil_gong 已提交
268

269 270 271
    // 已填写数量
    var stock = parseInt($('#text_box').val()) || 1;

D
v1.2.0  
devil_gong 已提交
272 273 274 275 276 277 278 279 280
    // 开启进度条
    $.AMUI.progress.start();

    // ajax请求
    $.ajax({
        url: $('.goods-detail').data('spec-detail-ajax-url'),
        type: 'post',
        dataType: "json",
        timeout: 10000,
281 282 283 284 285 286
        data: {
            "id": $('.goods-detail').data('id'),
            "stock": stock,
            "spec": spec
        },
        success: function(res)
D
v1.2.0  
devil_gong 已提交
287 288
        {
            $.AMUI.progress.done();
289
            if(res.code == 0)
D
v1.2.0  
devil_gong 已提交
290
            {
291
                GoodsSpecDetailBackHandle(res.data);
D
v1.2.0  
devil_gong 已提交
292
            } else {
293
                Prompt(res.msg);
D
v1.2.0  
devil_gong 已提交
294 295 296 297 298
            }
        },
        error: function(xhr, type)
        {
            $.AMUI.progress.done();
D
Devil 已提交
299
            Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
D
v1.2.0  
devil_gong 已提交
300 301 302 303 304 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
        }
    });
}

/**
 * 获取规格类型
 * @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},
339
        success: function(res)
D
v1.2.0  
devil_gong 已提交
340 341
        {
            $.AMUI.progress.done();
342
            if(res.code == 0)
D
v1.2.0  
devil_gong 已提交
343 344 345 346 347 348 349 350
            {
                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');
351
                        var value = $(this).data('value').toString();
352
                        if(res.data.spec_type.indexOf(value) == -1)
D
v1.2.0  
devil_gong 已提交
353 354 355 356 357 358 359
                        {
                            $(this).addClass('sku-items-disabled');
                        } else {
                            $(this).removeClass('sku-items-disabled');
                        }
                    });
                }
D
devil_gong 已提交
360 361

                // 扩展数据处理
362
                var extends_element = res.data.extends_element || [];
D
devil_gong 已提交
363 364 365 366 367 368 369 370 371 372
                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 已提交
373
            } else {
374
                Prompt(res.msg);
D
v1.2.0  
devil_gong 已提交
375 376 377 378 379
            }
        },
        error: function(xhr, type)
        {
            $.AMUI.progress.done();
D
Devil 已提交
380
            Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
D
v1.2.0  
devil_gong 已提交
381 382 383 384 385 386 387 388 389 390 391 392 393 394
        }
    });
}

/**
 * 商品基础数据恢复
 * @author   Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2018-12-25
 * @desc    description
 */
function GoodsBaseRestore()
{
D
devil 已提交
395
    $('.text-info .price-now').text(__currency_symbol__+$('.text-info .price-now').data('original-price'));
D
devil_gong 已提交
396
    $('.goods-price').text($('.goods-price').data('original-price'));
D
v1.2.0  
devil_gong 已提交
397 398
    $('.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 已提交
399 400 401 402 403 404 405 406 407

    // 价格处理
    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 已提交
408
                $(this).text(__currency_symbol__+price);
D
devil_gong 已提交
409 410 411
            }
        });
    }
D
v1.2.0  
devil_gong 已提交
412 413
}

414 415 416 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
/**
 * 数量值改变
 * @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 已提交
472 473 474 475 476 477 478 479
/**
 * 规格选择显示
 * @author  Devil
 * @blog    http://gong.gg/
 * @version 1.0.0
 * @date    2020-08-16
 * @desc    description
 */
D
devil 已提交
480
function SpecPopupShow(e)
D
devil 已提交
481
{
D
devil 已提交
482
    $(document.body).css({"position":"fixed", "width":"100%"});
D
devil 已提交
483 484
    $('.theme-popover-mask').show();
    $('.theme-popover').slideDown(200);
D
devil 已提交
485
    $('.theme-popover .confirm').attr('data-type', e.data('type') || 'buy');    
D
devil 已提交
486 487
}

D
v1.2.0  
devil_gong 已提交
488
$(function() {
D
devil 已提交
489 490 491
    // 购物车表单初始化
    FromInit('form.cart-form');

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

                // 去掉元素之后的禁止
505
                $('.theme-signin-left .sku-container .sku-items').each(function(k, v)
D
v1.2.0  
devil_gong 已提交
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521
                {
                    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 已提交
522
                $(this).parents('.sku-items').removeClass('sku-not-active');
D
v1.2.0  
devil_gong 已提交
523 524 525 526

                // 去掉元素之后的禁止
                if(index < length)
                {
527
                    $('.theme-signin-left .sku-container .sku-items').each(function(k, v)
D
v1.2.0  
devil_gong 已提交
528 529 530 531 532 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
                    {
                        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 已提交
562 563 564
    $('.jqzoom').imagezoom({
        yzoom: 398
    });
D
v1.2.0  
devil_gong 已提交
565 566 567 568 569 570
    $('#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 已提交
571 572 573
    // 规格选择显示事件
    $('.mini-spec-event').on('click', function()
    {
D
devil 已提交
574
        SpecPopupShow($(this));
D
devil 已提交
575 576
    });

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

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

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

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

639
                    if(res.code == 0)
D
v1.2.0  
devil_gong 已提交
640
                    {
641 642 643
                        $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 已提交
644 645 646 647 648
                        {
                            $this.addClass('text-active');
                        } else {
                            $this.removeClass('text-active');
                        }
649
                        Prompt(res.msg, 'success');
D
v1.2.0  
devil_gong 已提交
650
                    } else {
651
                        Prompt(res.msg);
D
v1.2.0  
devil_gong 已提交
652 653 654 655 656
                    }
                },
                error: function(xhr, type)
                {
                    $.AMUI.progress.done();
657
                    PoptitClose();
D
Devil 已提交
658
                    Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
D
v1.2.0  
devil_gong 已提交
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678
                }
            });
        }
    });

    // 视频
    $('.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');
    });

    //获得文本框对象
679 680 681 682 683
    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 已提交
684

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

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

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

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

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

G
gongfuxiang 已提交
750 751 752 753 754 755 756 757 758 759 760
    // 评论
    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 已提交
761
            $(window).smoothScroll({position: $('.introduce-main').offset().top});
G
gongfuxiang 已提交
762 763 764 765 766 767
        }
    });

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

D
devil_gong 已提交
772 773 774
    // tab事件
    $('.introduce-main .am-tabs li').on('click', function()
    {
D
devil_gong 已提交
775
        $(window).smoothScroll({position: $('.introduce-main').offset().top});
D
devil_gong 已提交
776 777
    });

D
devil_gong 已提交
778
});
D
v1.2.0  
devil_gong 已提交
779

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