function PageInit(url,session_id,bridge) { this.url = url; this.goodsItems = $('.goods-list .goods-item'); this.refreshBtn = $('.refresh-btn'); this.detailPopup = $('.detail-popup'); this.eggsBtn = $('.eggs-btn'); this.close = $('.close'); this.goodsList = []; this.session_id = session_id; this.bridge = bridge; var self = this; this.goodsItems.on('click', function () { self.result($(this)); }); this.refreshBtn.on('click', function () { self.hidePopup(); self.refresh(); }); this.detailPopup.on('touchmove', function (e) { e.preventDefault(); }); this.eggsBtn.on('click', function () { $('.mysterious-popup, .mysterious').fadeIn(); }); this.close.on('click', function () { $('.mysterious-popup, .mysterious').fadeOut(); }); $('.mysterious-popup, .mysterious').on('touchmove', function (e) { e.preventDefault(); }); } PageInit.prototype = { init: function () { this.getDatas(); }, getDatas: function () { var self = this; $.ajax({ type: "get", url: self.url, data: { act: "festval", op: "ajax_freeCollection", client_type: "ajax" }, success: function (res) { var res = JSON.parse(res) if (res.code == 200) { self.goodsList = res.datas.goods_list self.render(); } else { alert(res.message); } }, error: function () { alert('网络错误!'); } }); $.ajax({ type: "get", url: self.url, data: { act: "member_bonus", op: "mine_bonus", client_type: "ajax" }, success: function (res) { var res = JSON.parse(res); if (res.code == 200) { var usable_bonus = res.datas.usable_bonus; $('.bonus-price').html('¥ ' + usable_bonus); } } }); }, render: function() { if (!this.goodsList.length)return; var self = this; this.goodsItems.each(function(index, item) { var goods = self.goodsList[index]; $(item).find('.bonus').html(goods.need_bonus); $(item).find('.goods-storage').html(goods.storage); $(item).attr('data-id', goods.goods); $(item).attr('data-state', goods.state); if (goods.state == 1) { $(item).addClass('over'); } else if (goods.state == 2) { $(item).addClass('receive'); } else if (goods.state == 3) { $(item).addClass('invite'); } else if (goods.state == 4) { $(item).addClass('isReceived'); } }); }, result: function (target) { if (!this.goodsList.length)return; var self = this; var state = target.attr('data-state'); if (state == 2) { var id = target.attr('data-id'); window.location.href = 'xmmz://p.lrlz.com/goods/goods?goodsId=' + id; setTimeout(function() { self.showPopup(); }, 10); return; } else if (state == 3) { window.location.href = 'xmmz://p.lrlz.com/invite/invite'; return; } }, showPopup: function () { $('.detail-popup, .refresh-btn').fadeIn(); }, hidePopup: function () { $('.detail-popup, .refresh-btn').fadeOut('fast'); }, refresh: function() { this.init(); } }