$.ready(function(){
    //防止点击穿透
    function preventTapThrough(msec) { //msec 毫秒
        if(msec == null) {
            msec = 1000;
        }
        
        clearTimeout(window.preventThroughTimeoutId);
        document.querySelector('body').style.pointerEvents = 'none';
        window.preventThroughTimeoutId = setTimeout(function() {
            document.querySelector('body').style.pointerEvents = 'auto';
        }, msec);
    }

    // 图片后加载  
    function lazyLoad() {
        var images = document.querySelectorAll('img:not([src])');
        images.forEach(function (image) {
            var h = document.documentElement.clientHeight, 
            bounds = image.getBoundingClientRect();
            if (bounds.bottom > 0 && bounds.top < h) {
                image.lazyLoad();
            }
        });
        if (!lazyLoad.bind && document.querySelector('img:not([src])')) {
            lazyLoad.bind = 1;
            window.addEventListener('scroll', lazyLoad.onScroll);
        }
    }

    lazyLoad.onScroll = function () {
        if (lazyLoad.timer) clearTimeout(lazyLoad.timer);
        lazyLoad.timer = setTimeout(lazyLoad, 200);
    };

    lazyLoad.bind = 0;
    lazyLoad();
    window.addEventListener('load',function(){
        document.querySelector('img:not([src])') && (lazyLoad.bind = 1, window.addEventListener('scroll', lazyLoad.onScroll), lazyLoad());
    });

    //吸顶 
    function fixedTitleBar(){
        var titleBar = document.querySelector('.fixed-title-bar'),
            a,
            _a;
        if(titleBar){
            var back    = titleBar.firstElementChild;
//                state   = titleBar.lastElementChild;
            a = (window.scrollY / 300).toFixed(2);
//            _a = 0.4 - (window.scrollY / 750).toFixed(2);
            titleBar.style.backgroundColor = 'rgba(237,237,237,'+ a +')';
            back.style.backgroundColor = 'rgba(0,0,0,'+ _a +')';
//            state.style.backgroundColor = 'rgba(0,0,0,'+ _a +')';  
            titleBar.classList[_a <= 0 ? 'add' : 'remove']('visible');
        }
    };
    
    //给window对象绑定滑动事件
    window.addEventListener('scroll',fixedTitleBar);
    
    //菜单栏的显示和隐藏
    if(document.querySelector('.menu')){
        preventTapThrough(500);
        
       document.querySelector('.menu').addEventListener("tap", function () {
            if(this.classList.contains("active")){
                clearTimeout(this.jumpUrl );
                this.classList.remove('active');
                document.querySelector('.menu-list').style.display  = "none";
            }else{
                clearTimeout(this.jumpUrl );
                this.classList.add('active');
                document.querySelector('.menu-list').style.display  = "block";
                this.jumpUrl   =  setTimeout(function(){
                    document.querySelector('.menu').classList.remove('active');
                    document.querySelector('.menu-list').style.display  = "none";
               },5000); 
                
            }
        });
 
    }
    
    // 扩展一个日期对比函数，用于计算两个日期的时间差，并设置一些专有属性
    Date.prototype.dateDiff = function(lastTime){
        var pattern = /^\d{1,2}\/\d{1,2}\/\d{4}\s\d{1,2}:\d{1,2}:\d{1,2}$/;
        if(pattern.test(lastTime)){
            lastTime = Date.parse(lastTime);
            this.diffTime = lastTime - this;
            if(this.diffTime <= 0) return;
            this.days = parseInt(this.diffTime / 864E5);
            this.subtract  = this.diffTime - 864E5*this.days;
            this.hours = parseInt(this.subtract/36E5);
            this.subtract = this.subtract - 36E5*this.hours;
            this.minutes = parseInt(this.subtract/6E4);
            this.subtract = this.subtract - this.minutes*6E4;
            this.seconds = parseInt(this.subtract/1E3);
        }
    };
    
    // 倒计时
    var countdown = document.querySelector('#count_down');
    if(countdown){
        countdown.item = countdown.children;
        countdown.last = countdown.getAttribute('data-date');
        countdown.supplement = function(n){
            return ( n < 10 ? '0'+ n : n);
        };
        countdown.timeout = function(){
            countdown.timer && clearTimeout(countdown.timer);
            var now = new Date();
            now.dateDiff(countdown.last);
            if(now.diffTime <= 0){
                clearTimeout(countdown.timer);
                location.reload();
                return;
            }
            
            if(now.days && now.days >= 1){
                this.innerHTML = '仅剩<span class="days">'+now.days+'天</span>';
            }else{
                countdown.item.forEach(function(item){
                    item.innerHTML = countdown.supplement(now[item.className]);
                });
            }

            countdown.timer = setTimeout(countdown.timeout,1e3);
        };
        countdown.timeout();
    }
    
    //弹层的构造函数
    function Slide(id,formId){
        this.id     = id;
        this.form   = document.forms[formId];
        this.init();
    }
    
    // 收集
    if(document.querySelector('#goods_form')){
        var fieldNames = [];
            [].forEach.call(document.querySelector('#goods_form').elements,function(item){ 
                if((item.type === 'radio' || item.type=== 'checkbox') && fieldNames.indexOf(item.name) < 0) 
                fieldNames.push(item.name)
            });
    }

    //提交函数
    Slide.submit = function(e){
        e.preventDefault(fieldNames);

        if(fieldNames.length > 0){
            var data = this.data,goControl = [],flag=true;
            fieldNames.forEach(function(name){
                
                if(goods_form.elements[name].length > 1){
                    goods_form.elements[name].forEach(function(element){
                        if(element.type === 'radio' && element.checked){
                            data.name = element.value;  
                        }
                    });
                }else{
                    if(goods_form.elements[name].checked){
                        data.name = 1;
                    }
                    
                }
                if(!data[name]){
                    if(goControl.indexOf(0) === -1) { 
                        if(name == 'productSuitId') {
                            alert('请选择版本');
                        } else if(name == 'colorSuitId') {
                            alert('请选择颜色');
                        } else if(name == 'saleSuitId') {
                            alert('请选择类型');
                        } else if(name == 'suitSetId') {
                            alert('请选择套装');
                        } else {
                            alert('请选择套装信息');
                        }
                        goControl.push(0);
                    }
                }else{
                    goControl.push(1);   
                }
            });
            if(goControl.indexOf(0) >=0)
            return;
        };
        
        if(window.isAddToCart) { //添加到购物车
            addToCart.call(this);
        } else { //确认订单
            this.submit();
            getUserTrack('wap_shop_buy'); 
        }
        
    };
    
    //弹层的原型模式
    Slide.prototype = {
        init : function(){
           
            //初始化弹层id、遮罩id和关闭按钮id 
            this.wrap          = (typeof this.id === 'string') ? document.querySelector('#select_category') : this.id;
            this.cover         = document.querySelector('#cover');
            this.close          = document.querySelector('.close');
            var self            = this;
            this.addToCart      = document.querySelector('#add-to-cart');
            this.goOrder        = document.querySelector('#go-order');
            //添加遮罩和关闭按钮的监听事件
            if(this.cover){
                this.cover.addEventListener('tap',function(){
                    preventTapThrough(500);
                    self.down();
                });
            }
            
            
            this.close.addEventListener('tap',function(){
                preventTapThrough(500);
                self.down();
            });
            
            if(this.form && Function.isFunction(Slide.submit)){
                //表单提交
                this.form.addEventListener('submit',function(e){
                    Slide.submit.call(this,e);       
                });
                
                //添加购物车
                if(this.addToCart){
                    this.addToCart.addEventListener('tap',function(e){
                        window.isAddToCart = true;
                        Slide.submit.call(document.forms['goods_form'],e);       
                    });
                }
                
                if(this.goOrder){
                    this.goOrder.addEventListener('tap', function(e) { 
                        window.isAddToCart = false;
                        Slide.submit.call(document.forms['goods_form'],e);     
                    })
                }
                
                
            }
            
        },
        up : function(){
             //隐藏倒计时
             if(document.querySelector('#count_down')){
                 document.querySelector('#count_down').style.display = "none";
             }
            
            //弹层的显示
            this.wrap.classList.add('visible');
            this.wrap.style.display = "block";
            this.cover.classList.add('visible');
            this.cover.style.display = "block";
            
            //阻止冒泡
            document.addEventListener(Event.Touch.move,Event.preventDefault);
            
            //初始化滑动插件
            this.scroll = new IScroll('#scrollView', {momentum: false, useTransition: false, click: true});
        },
        down : function(){
            //弹层关闭
            this.wrap.classList.remove('visible');
            this.wrap.style.display = "none";
            this.cover.classList.remove('visible');
            this.cover.style.display = "none";
            
            //阻止冒泡
            document.removeEventListener(Event.Touch.move,Event.preventDefault);
            
            //销毁滑动模块插件
            if(this.scroll){
               this.scroll.destroy();
            }
            
            if(document.querySelector('#count_down')){
                 document.querySelector('#count_down').style.display = "block";
             }
            
        },
        
    }

    //购物车弹层
    function cartShield(type) { //type 1:显示  2:隐藏
        var coverMask       = document.querySelector('#cover-mask'), //遮罩层
            cartLayerBox    = document.querySelector('#cart-layer-box'); //弹出框
            
        if(type == null) {
            type = 1;
        }
        preventTapThrough();
        if(type == 1) { //显示
            if(document.querySelector('#count_down')){
                document.querySelector('#count_down').style.display = "none";
            }
            
            coverMask.style.display = 'block';
            cartLayerBox.style.display = 'block';
        } else if(type == 2) { //隐藏
            if(document.querySelector('#count_down')){
                document.querySelector('#count_down').style.display = "block";
            }
            
            coverMask.style.display = 'none';
            cartLayerBox.style.display = 'none';
        }
    }
    
    //添加商品到购物车
    function addToCart() {
        var addData = this.data;
        
        //添加购物车代码
        getUserTrack('wap_shop_add');
        delete addData.c;//删除c
        delete addData.a;//删除a
        
        if(this.data.goodsNumber <= 0){
            this.data.goodsNumber = 1;
        }
        
        $.ajax({
            type:'get',
            url:'/index.php?c=Shop_Ajax_ShopCart&a=AddCartInfo&t=' + (new Date()).getTime(),
            dataType:'json',
            data: addData,
            success:function(data){
                var shopCartEm  = document.querySelector('.number');
                
                if(parseInt(data.flag)) { //添加购物车成功         
                    popSlide.down();
                    cartShield(1); //打开添加成功提示层
                    if(shopCartEm){
                        shopCartEm.innerHTML = data.cartNumber; //显示购物车商品总数
                    }
                    
                } else { //添加失败
                    alert(data.msg);
                }
            },
            error: function() {
                alert('网络故障，请刷新重试:(');
            }
        });
    }
    
    //弹层的选择
    var select_category = document.querySelector('#select_category'),
        goods_form      = document.querySelector('#goods_form');
        
    if(select_category){
 
       //实例化Slide构造函数
        var popSlide = new Slide(select_category,'goods_form'),
            onlineBuy = document.querySelectorAll('#toolbar > span.online'),
            chooseCategory = document.querySelector('.choose-category');
            
            //点击显示弹层
            if(chooseCategory){
                chooseCategory.addEventListener('tap',function(){
                    Slide.timer && clearTimeout(Slide.timer);
                    document.body.style.pointerEvents = 'none';
                    Slide.timer = setTimeout(function(){
                        document.body.style.pointerEvents = 'all';
                    },400);
                    
                    if(!this.classList.contains('online') && document.querySelector('#submitShow') ){
                       document.querySelector('#submitShow').style.display = 'none';
                       document.querySelector('#toolbar-1').style.display = 'block';
                   } 
                    popSlide.up(); 
                });
            }
            
            //在线购买
            if(onlineBuy){
                onlineBuy.addEventListener('click',function(){
                   if(this.classList.contains('disabled')){
                       return ; 
                   }
                   if(this.classList.contains('online') && document.querySelector('#submitShow')){
                       document.querySelector('#submitShow').style.display = 'block';
                       document.querySelector('#toolbar-1').style.display = 'none';
                   } 
                   //判断是否是加入购物车
                    if(this.classList.contains('add-to-cart')) { //加入购物车
                        window.isAddToCart = true;
                    } else { //确认订单
                        window.isAddToCart = false;
                    }
                    
                     if(this.classList.contains('goOrder')) {
                        if(window.isAddToCart) { //添加到购物车
                            if(this.classList.contains('disabledForApp')) {
                                return;
                            }
                            this.data = goods_form.data;
                            addToCart.call(this);
                            return;
                        } else { //确认订单
                            if(this.classList.contains('disabledForApp')) {
                                return;
                            }
                            getUserTrack('wap_shop_buy'); 
                            goods_form.submit();
                            return;
                        }
                    }
                    
                    Slide.timer && clearTimeout(Slide.timer);
                    document.body.style.pointerEvents = 'none';
                    Slide.timer = setTimeout(function(){
                        document.body.style.pointerEvents = 'all';
                    },400);
                    
                    popSlide.up(); 
                });
            }
    }
    
     // 锁定按钮
    function disabledButton(button){
        if(button){
            button.disabled = true;
            button.classList.add('disabled');   
        }
        
    };

    // 激活按钮
    function enabledButton(button){
        button.disabled = false;
        button.classList.remove('disabled');   
    };

    //商品数量的选择
    var amount = document.querySelector('#amount'),
        amountAdd = document.querySelector('#add'),
        amountSubtract = document.querySelector('#subtract');
        
        if(amount && amountAdd && amountSubtract){
            
            amount.init = function(n){
                if(typeof n != 'undefined'){
                    var Max         = document.querySelector('.max');
                    amount.max      = n;  
                    Max.innerHTML   = ' \u9650\u8d2d'+ n + '\u4ef6'; //限购n件 
                }
                amount.value = 1; 
                enabledButton(amountAdd);
                disabledButton(amountSubtract);
                amount.validate();
            };
            
            amount.onchange = function(button,n){
                if(button.disabled)
                return;
            var temp = +amount.value + n;//转换成int类型的特殊用法 +amount 
                amount.value = temp;
                amount.validate();    
            };

            amount.validate = function(){
                _value = +amount.value;//_区分value函数方法
                _max   = +amount.max;//_区分max函数方法
                Max   = document.querySelector('.max');

                if(_value > _max){
                    amount.value = _max;
                    disabledButton(amount.add); 
//                    alert('\u8d85\u51fa\u9650\u5b9a\u6570\u91cf') // 超出限定数量
                    return;
                };

                switch(_value){
                    case 1: 
                        disabledButton(amountSubtract);
                         _max === 1 ? disabledButton(amountAdd) : enabledButton(amountAdd);     
                         Max.classList.add('hidden');
                        break;
                    case _max:
                        disabledButton(amountAdd);
                        if(amountSubtract.disabled){
                            enabledButton(amountSubtract);
                        }
                        Max.classList.remove('hidden');
                        break;
                    default:
                        if(amountAdd.disabled){
                            enabledButton(amountAdd);
                        }
                        
                        if(amountSubtract.disabled){
                            enabledButton(amountSubtract);
                        }
                        
                        Max.classList.add('hidden');
                };
            };
            
            //相加
            amountAdd.addEventListener('click',function(){ 
                
                amount.onchange(this,1);
            });
            
            //相减
            amountSubtract.addEventListener('click',function(){
                amount.onchange(this,-1);
            });
            
//            amount.addEventListener('input',amount.validate);
//            amount.addEventListener('change',amount.validate);
//            amount.addEventListener('blur',amount.validate);
            if(amount){
                 amount.init();
            }
           
        }
    
    //套装的选择
    var     choosePlaceholder   = document.querySelector('.choose-category'),
            optionDesc          = document.querySelector('.option-description'),
            chooseProduct   = '', chooseColor = '', chooseSuit = '', chooseSale = '';
    Slide.echo = function(){
        if(choosePlaceholder){
            choosePlaceholder.innerHTML = '\u5df2\u9009\u62e9  <em style="color:red;">'+ chooseColor + chooseProduct + ' '+chooseSale + ' ' + chooseSuit + '</em>';    
        }
        
        optionDesc.innerHTML        = chooseColor + chooseProduct + ' ' + chooseSuit + ' '+chooseSale;
    }
            
    //配置套装参数
    zsSuit.config({'suitRuleInfo':suitRuleInfo});
    
    //设置回调函数
    zsSuit.callBack = function(data, suitId){
        //可选与不可选
        for(var i in data){
            var suitArea    = document.querySelector("#scrollView");
            suitArea.querySelectorAll("input").forEach(function(that){
                var curNum      = that.getAttribute("num");
                if(curNum == i){
                    var curVal  = that.value;
                    if(zsSuit.inArr(curVal, data[i]) >= 0){
                        that.disabled = true;
                    }else{
                        that.disabled = false;
                    }
                }
            });
        }
        //信息的获取
        var suitIdNode      = document.querySelector("#order-suit-id");
        suitIdNode.value    = suitId;
        if(suitId){
            zsSuit.getSuitInfo(suitId);
        }

    };
        
    //获取套装信息
    zsSuit.getSuitInfo = function(suitId){
        //主要节点
        var price        = document.querySelector('.price'),
            choosePrice  = document.querySelector('.choose-price'),
            description  = document.querySelector('.option-description');

        //获取套装信息
        $.ajax({
            type:'get',
            url:'/index.php?c=Shop_Ajax_Detail&a=GetSuitInfo&callback=?',
            dataType:'jsonp',
            data: {
               'suitId': suitId,
               'goodsId': window.goodsId
            },
            success:function(res){
                if(res.flag){
                    if(!res && !res.data){ return;}
                    var data = res.data;
                    var desc = description.innerHTML;
                    if(instalment){
                        getInstalmentList(data['suitPrice']);
                    }
                    
                    if(price){
                        price.innerHTML = data['suitPrice'];
                    }
                    if(choosePrice){
                        choosePrice.innerHTML = '&yen;'+ data['suitPrice']
                    }
                    if(description){
                        description.innerHTML = desc + data['suitDesc'];
                    }
                    if(amount){
                        amount.init(data['suitNumber']);//重设数量
                    }
                        
                }
            },
            error: function() {
                alert('网络故障，请刷新重试:(');
            }
        });
    }
        
    if(goods_form){
        goods_form.elements.forEach(function(radio){
            if(radio.type === 'radio'){
                //初始化默认套装
                var statusDefault      = parseInt(radio.getAttribute('data-is-checked'));
                var positionDefault    = parseInt(radio.getAttribute('num'));
                var curValDefault      = radio.value ;

                //设置套装
                if(statusDefault == 1 ){
                    zsSuit.set(positionDefault, curValDefault);
                    
                    switch(positionDefault){
                            case 0:
                                chooseProduct   = radio.checked ? radio.nextElementSibling.innerHTML : '';
                                break;
                            case 1:
                                chooseColor     = radio.checked ? radio.nextElementSibling.innerHTML : '';
                                break;
                            case 2:
                                chooseSale      = radio.checked ? radio.nextElementSibling.innerHTML : '';
                                break;
                            case 3:
                                chooseSuit      = radio.checked ? radio.nextElementSibling.innerHTML : '';
                                break;
                        }
                }
                
                //添加监听事件
                radio.addEventListener('click',function(){
                    //是否可选
                    var curDisabled     = this.getAttribute('disabled');
                   
                    if(curDisabled){
                        return false;
                    }
                    
                    //设置选择
                    var status      = parseInt(this.getAttribute('data-is-checked'));
                    var position    = parseInt(this.getAttribute('num'));
                    var curVal      = this.value;

                    //判断是设置还是取消
                    if(status == 0){
                        this.checked    = true;
                        //模拟单选框，把同层的其他值设置为0
                        document.querySelector("#scrollView").querySelectorAll("input").forEach(function(inputObj){
                            var curNum  = parseInt(inputObj.getAttribute("num"));
                            if(curNum == position){
                                inputObj.setAttribute("data-is-checked", "0");
                            }
                        });
                        //将当前设置为1
                        this.setAttribute("data-is-checked", 1);
                    }else{
                        
                        this.checked    = false;
                        this.setAttribute('data-is-checked', 0);
                    }
                    
                    switch(position){
                            case 0:
                                chooseProduct   = this.checked ? this.nextElementSibling.innerHTML : '';
                                break;
                            case 1:
                                chooseColor     = this.checked ? this.nextElementSibling.innerHTML : '';
                                break;
                            case 2:
                                chooseSale      = this.checked ? this.nextElementSibling.innerHTML : '';
                                break;
                            case 3:
                                chooseSuit      = this.checked ? this.nextElementSibling.innerHTML : '';
                                break;
                        }
                    //回显
                    Slide.echo();

                    //设置数据
                    if(this.checked){
                        zsSuit.set(position, curVal);
                    }else{
                        zsSuit.unset(position);
                    }

                });
            }
        });    
    };
     
    //关闭添加购物车弹出
    document.querySelector('#cover-mask').addEventListener('tap', function(e) { 
        preventTapThrough();
        cartShield(2);
        //统计点击行为
        if(this.id == 'hide-cart-a') {
            
            $.ajax({
                type:'get',
                url:'/index.php?c=Shop_Ajax_ShopCart&a=RecordCartLayerClick&t=' + (new Date()).getTime(),
                dataType:'json',
                data: {
                    'clickType': 1
                },
                success:function(){
                },
                error: function() {
                }
            });
        }
    })

    //再逛逛
    document.querySelector('#hide-cart-a').addEventListener('tap', function(e) { 
        preventTapThrough();
        cartShield(2);
        //统计点击行为
        if(this.id == 'hide-cart-a') {
            
            $.ajax({
                type:'get',
                url:'/index.php?c=Shop_Ajax_ShopCart&a=RecordCartLayerClick&t=' + (new Date()).getTime(),
                dataType:'json',
                data: {
                    'clickType': 1
                },
                success:function(){
                },
                error: function() {
                }
            });
        }
    })
    
    //去购物车
    document.querySelector('#layer-box-go-cart-a').addEventListener('click', function(e) { 
            //统计点击行为
            if(this.id == 'layer-box-go-cart-a') {
                
                $.ajax({
                    type:'get',
                    url:'/index.php?c=Shop_Ajax_ShopCart&a=RecordCartLayerClick&t=' + (new Date()).getTime(),
                    dataType:'json',
                    data: {
                        'clickType': 2
                    },
                    success:function(){
                    },
                    error: function() {
                    }
                });
            }
            
            window.location = '/index.php?c=Shop_ShopCart';
    })
    
    //促销活动的显示和隐藏
    if(document.querySelector('.sale-activity')){
        document.querySelector('.sale-activity').addEventListener('click',function(e){
            if(this.classList.contains('sale-activity-click')){
                this.classList.remove('sale-activity-click');
            }else{
                this.classList.add('sale-activity-click');
            }
        });
    }
    
    //咨询商家的弹层
    document.querySelector('.consult') && document.querySelector('.consult').addEventListener('tap', function(e) { //添加监听事件
        var target      = e.target || e.srcElement; //兼容浏览器
        
        //切换显示隐藏状态
        if(document.querySelector('.contact-type').classList.contains('visible')){
            document.querySelector('.contact-type').classList.remove('visible');
        }else{
            document.querySelector('.contact-type').classList.add('visible');
        }
    });
    
    if(document.querySelector('#consult')){
        document.querySelector('#consult').addEventListener('tap', function(e) { //添加监听事件
            var target      = e.target || e.srcElement; //兼容浏览器

            //切换显示隐藏状态
            if(document.querySelector('#contact-type').classList.contains('visible')){
                document.querySelector('#contact-type').classList.remove('visible');
            }else{
                document.querySelector('#contact-type').classList.add('visible');
            }
        });
    }

    // 显示隐藏二维码
    if(document.querySelector('.view-qrcode')){
        document.querySelector('.view-qrcode').addEventListener('tap',function(){
            if(document.querySelector('.qrcode').classList.contains('expand')){
                document.querySelector('.qrcode').classList.remove("expand");
                document.querySelector('.qrcode').style.display = "none";
            }else{
                document.querySelector('.qrcode').classList.add("expand");
                document.querySelector('.qrcode').style.display = "block";
            }
            
        });
    }
    
    // 线下门店展开收起
    var offlineStoreHeader  = document.querySelector('.btns-group > span'),
        offlineStoreInfo    = document.querySelector('.offline-store');
    
    offlineStoreHeader && offlineStoreHeader.addEventListener('tap',function(){
        offlineStoreInfo.classList.toggle('expand');
        document.querySelector('.qrcode').classList.remove("expand");
        document.querySelector('.qrcode').style.display = "none";
    });

    //分期付款显示和隐藏//弹层的构造函数
    function InstalmentSlide(){
        this.init();
    }
    
    //弹层的原型模式
    InstalmentSlide.prototype = {
        init : function(){
            //初始化弹层id、遮罩id和关闭按钮id 
            this.instalmentBack         = document.querySelector('.w-stages-back');
            this.instalmentLayer        = document.querySelector('.w-stages-layer');
            var self            = this;

            //添加遮罩和关闭按钮的监听事件
            if(this.instalmentBack){
                this.instalmentBack.addEventListener('tap',function(){
                    preventTapThrough(500);
                    self.down();
                });
            }
            
        },
        up : function(){
            //弹层的显示
            this.instalmentBack.style.display   = "block";
            this.instalmentLayer.style.display  = "block";
            
            //阻止冒泡
            document.addEventListener(Event.Touch.move,Event.preventDefault);
            
            //初始化滑动插件
            this.scroll = new IScroll('#scrollInstalment', {momentum: false, useTransition: false, click: true});

        },
        down : function(){
            //弹层关闭
            this.instalmentBack.style.display   = "none";
            this.instalmentLayer.style.display  = "none";
            
            //阻止冒泡
            document.removeEventListener(Event.Touch.move,Event.preventDefault);
            
            //销毁滑动模块插件
            if(this.scroll){
               this.scroll.destroy();
            }
            
        },
        
    }
    
    var instalment             = document.querySelector('.w-stages');
    
    if(instalment){
        instalment.addEventListener('tap',function(){
            var popInstalmentSlide  = new InstalmentSlide();
            popInstalmentSlide.up();
        })
    }
    
    //获取分期信息列表
    function getInstalmentList(instalmentTotalPrice){
        var instalmentToatalPrice       = parseInt(instalmentTotalPrice);
        var html                        = '';
        if(!instalmentToatalPrice){
            return false;
        }
//        numberRateInfo.forEach(function(key,value){
            for(var key in numberRateInfo){
            html += '<div class="neirong">';
            html += '<h5>'+numberRateInfo[key].jsonName+'</h5>';
            html += '<ul class="w-stagesList">';
            var instalments = numberRateInfo[key].numberRateInfo; 
            for(var i in instalments){
                var everyNumber             = instalments[i].number,
                    everyRate               = instalments[i].rate,
                    everyPrice              = instalmentTotalPrice/everyNumber + everyRate*instalmentTotalPrice/100,
                    everyDatePrice          = everyPrice.toFixed(2),
                    erveryRatePrice         = (everyRate*instalmentTotalPrice)/100,
                    erveryDateRatePrice     = erveryRatePrice.toFixed(2);
                html += '<li>';
                html += '<p class="type">￥'+everyDatePrice+'×'+everyNumber+'期</p>';
                if(everyRate == 0){
                    html += '<p class="msg">免手续费</p>';
                }else{
                    html += '<p class="msg">含手续费：费率'+everyRate+'%，￥'+erveryDateRatePrice+'×'+everyNumber+'期</p>';
               }
               html += '</li>';
            };
            html += '</ul>';
            html += '</div>'
        };
        document.querySelector('#instalmentTotalPrice').innerHTML   = '￥'+instalmentTotalPrice;
        document.querySelector('.rongqi').innerHTML         = html;
    }

})