
var mLayer = function (ev) {
    $('.m_layer').removeClass('show');
    $('.m_layer').children().removeClass('show');
    $('input').blur();
    $('html,body').css({
        'height': 'auto',
        'overflow': 'visible'
    })
    ev.preventDefault();
}
var common = {
    init: function () {
        this.mLayer();
    },

    isTrue: function (bl, fn) {
        bl && fn && fn(this);
    },

    // swiper
    swiper: function () {
        var swiper = new Swiper('#swiper_1', {
            pagination: '.swiper-pagination',
            paginationClickable: true,
            loop: true,
            autoplay: 3000,
            speed: 500,
            eventTarget: 'container',
            autoplayDisableOnInteraction: false
        });
    },

    guessList: function () {
        // 猜你喜欢
        var swiper = new Swiper('#guess_list', {
            slidesPerView: 3,
            slidesPerGroup: 3,
            speed: 500
        });
    },

    // 判断是否有效点击
    isMove: function (obg, fn) {
        bOk = true;

        $(obg).on('touchstart', function () {
            bOk = true;
        });

        $(document).on('touchmove', function () {
            bOk = false;
        });

        $(obg).on('touchend', function (ev) {
            if (!bOk) return;
            fn(this, ev);
            return false;
        });
    },

    mLayer: function () {
        this.isTrue($('.m_layer')[0], function () {
            $('.m_layer').on('touchmove', function (ev) {
                ev.preventDefault();
            });
        })



        this.isMove($('.m_layer'), function (_this, ev) {
            mLayer(ev);
        });

        this.isMove($('.close'), function (_this, ev) {
            mLayer(ev);
        });
    },

    sucLayer: function (str) {
        var str = str || '加入清单成功';
        var oS = str;
        $('body').append('<div class="suc_state on">' + str + '</div>');
        setTimeout(function () {
            $('.suc_state').remove();
        }, 1000);
    }
};

common.init();

var ComMonPopup = new Object();
ComMonPopup.PopupText = function (StringText, Switch) {
    var PopupHTML = "<div class=\"common_popup transform_popup\">" +
        "<div class=\"common_popup_text\"><p>" + StringText + "</p></div>" +
        "<div class=\"common_popup_bj\"></div>" +
        "</div>";

    $("body").prepend(PopupHTML);

    $(".common_popup_bj").on("touchstart touchend touchmove", function () {
        return false;
    });
    $(".common_popup_text").on("touchstart touchmove", function () {
        return false;
    });

    if (Switch) {
        setTimeout(function () {
            $(".common_popup").detach();
        }, 2000);
    }
};
ComMonPopup.no_list = function (url, f1, f2, f3,fn) {
    var f1 = f1 ? f1 : '亲~请完成相应的快速任务再来做此<br>任务吧！';
    var f2 = f2 ? f2 : '我知道了';
    var f3 = f3 ? f3 : '快速任务';
    var MultipleHTML = '<div class="list_popup_box list_popup1 transform_popup">' +
                       '<div class="list_popup_box_text">' +
                        '<div class="list_popup_box_text_top">' +
                          '<p class="p_img"><img src="../images/prompt_01.png"></p>' +
                          '<p class="p_text">' + f1 + '</p>' +
                        '</div>' +
                        '<div class="one_popup_butt">' +
                          '<p class="active close">' + f2 + '</p>' +
                          '<p class="red_de">' + f3 + '</p>' +
                        '</div>' +
                      '</div>' +
                      '<div class="list_popup_box_bj"></div>' +
                    '</div>';

    $('body').prepend(MultipleHTML);

    $('.one_popup_butt .active').on('touchstart', function () {
        $(this).addClass('ons');
    });
    $('.one_popup_butt .red_de').on('touchstart', function () {
        $(this).addClass('ons');
    });

    $('.one_popup_butt .close').on('touchend', function () {
        $(this).removeClass('ons');
        $('.list_popup1').detach();
    });
    $('.one_popup_butt .red_de').on('touchend', function () {
        $(this).removeClass('ons');
        if (url.length > 0) {
            window.location.href = url;
        } else {
            fn && fn();
        }
        $('.list_popup1').detach();
    });
    this.FalseFn(); //阻止默认事件
}
