Skip to content

Instantly share code, notes, and snippets.

@htom78
Created February 16, 2016 11:34
Show Gist options
  • Save htom78/51710886e1dbd5475b76 to your computer and use it in GitHub Desktop.
Save htom78/51710886e1dbd5475b76 to your computer and use it in GitHub Desktop.
define("logic.wx.trafficH5", function(require, exports) {
function i() {
var e = [];
if (!code && !openId) {
o(0);
return
}
report.setTimePoint(20), a(), mobileData.adShow = "none", h(wxHistory.load(appId, code, cacheOnly).map(function(e) {
return {
mobile: e.mobileNum,
addr: e.localInfo
}
})), f(), report.reportSpeed("1621-1-1"), u(), wxHistory.on("patch-success", function(e, t) {
cookieReady = !0, t && h(e.map(function(e) {
return {
mobile: e.mobileNum,
addr: e.localInfo
}
}))
}), wxHistory.on("ajax-loaded", function(e) {
openId = cookie.get(appId + "_openId")
}), wxHistory.on("ajax-error", function(e) {
mdebug && console.log("ajax error"), o()
}), wxHistory.on("ajax-nologin", function(e) {
mdebug && console.log("no login"), o()
}), cacheOnly && (cookieReady = !0), s(+(new Date))
}
function s(e) {
var t = +(new Date);
if (cookieReady) return;
if (t - e > TIMEOUT) {
o();
return
}
mdebug && console.log("timeout checking."), setTimeout(function() {
s(e)
}, 100)
}
function o(e) {
e = e === undefined ? 1 : 0, e && cookie.del(appId + "_openId", !1, ".chong.qq.com"), window.location.href = "//open.weixin.qq.com/connect/oauth2/authorize?appid=wx47031447c8352579&redirect_uri=" + encodeURIComponent(window.location.protocol + "//" + window.location.host + window.location.pathname + "?cacheOnly=" + e + "&phone=" + num) + "&response_type=code&scope=snsapi_base&state=qqchongzhi#wechat_redirect"
}
function u() {
dlgConfirm = new Dialog({
title: "温馨提示",
content: "您即将充值的流量将于本月底23:59失效,您要继续充值吗?",
btnConfirm: "继续充",
btnCancel: "不充了"
})
}
function a() {
trafficRule = [], fastTrafficRule = [], trafficPrix = jdata.trafficPrix, (jdata.trafficPriceRules || []).forEach(function(e) {
var t = e.prix,
n, r, i, s, o, u = {
prix: {},
amountList: []
};
for (key in e) u[key] = e[key];
if (t)
for (n in t)
if (t[n] && t[n][2]) {
if (t[n][2].indexOf("8") == -1) continue;
r = n / 100, i = r / 1024 >= 1 ? r / 1024 + "G" : r + "M", hide = t[n][5], s = t[n][3] || "", o = t[n][6] || "", u.amountList.push({
amount: r,
amountVal: parseFloat(t[n][0]).toFixed(2),
amountText: i,
adText: s,
productType: o
}), u.prix[r] = t[n][0]
}
trafficRule.push(u)
}), (jdata.specialTrafficPriceRules || []).forEach(function(e) {
var t = e.prix,
n, r, i, s, o, u = {
prix: {},
amountList: []
};
for (key in e) u[key] = e[key];
if (t)
for (n in t)
if (t[n] && t[n][2]) {
if (t[n][2].indexOf("8") == -1) continue;
r = n / 100, i = r / 1024 >= 1 ? r / 1024 + "G" : r + "M", hide = t[n][5], s = t[n][3] || "", o = t[n][6] || "", u.amountList.push({
amount: r,
amountVal: parseFloat(t[n][0]).toFixed(2),
amountText: i,
adText: s,
productType: o
}), u.prix[r] = t[n][0]
}
fastTrafficRule.push(u)
}), amountList = [], jdata.amountList.forEach(function(e) {
var t = e,
n = e / 1024 >= 1 ? e / 1024 + "G" : e + "M";
amountList.push({
amountVal: e,
amountText: n
})
}), mobileData.nationAmountList = defaultPrix, e(".flowlist_item").addClass("flowlist_item__disable")
}
function f() {
num = num || (historyList[0] ? historyList[0].mobile : "");
if (!S(num)) return;
mobileData.mn = T(num), mobileData.mobileAddr = "", b(), E()
}
function l(t, n, r) {
var i = e(r).text().replace(/\D/g, "").slice(-11);
if (!S(i)) return;
mobileData.nationAmountList = [], mobileData.amount = 0, e("#amountList").attr("disabled", "true"), mobileData.historyShow = "none", mobileData.mn = T(i), mobileData.mobileAddr = "", b(), E()
}
function c(t, n, i) {
mobileData.mn = mobileData.mn.replace(/\D+/g, "");
var s = T(mobileData.mn);
e("#mn").val(""), e("#mn").val(s);
var o = mobileData.mn.replace(/\s/g, ""),
u, a, f, l, c, h, p = [];
if (n.type === "focusin") {
mobileData.clearBtnShow = "block";
return
}
r.hide(), mobileData.mobileAddr = "", mobileData.price = "0.0å…ƒ", mobileData.tipsBody = "", mobileData.tipsTitle = "", e(".flowlist_item").addClass("flowlist_item__disable"), S(o) ? (mobileData.historyShow = "none", mobileData.clearBtnShow = "none", n.type === "input" && E(), b()) : (mobileData.clearBtnShow = "", mobileData.historyShow = "")
}
function h(e) {
historyList = e, mobileData.historyList = e
}
function p(e, t, n) {
mobileData.historyShow = "none", mobileData.clearBtnShow = "none"
}
function d(t, n, i) {
r.hide(), mobileData.mn = "", mobileData.historyShow = "", mobileData.historyList = historyList, mobileData.mobileAddr = "", mobileData.price = "0.0å…ƒ", mobileData.tipsBody = "", mobileData.tipsTitle = "", e(".flowlist_item").addClass("flowlist_item__disable")
}
function v(e, t, n) {
mobileData.historyList = historyList, mobileData.historyList.length && (mobileData.historyShow = ""), c(e, t, n)
}
function m(t, n, r) {
if (e(r).parents(".flowlist_item").hasClass("flowlist_item__disable")) return;
!ignored && N() ? dlgConfirm.open(function() {
g(t, n, r)
}) : g(t, n, r)
}
function g(t, n, r) {
var i = S(mobileData.mn.replace(/\s/g, ""));
if (!i || i == "未知") {
mobileData.tipsBody = "è¯·è¾“å…¥æ­£ç¡®çš„æ‰‹æœºå·ç ";
return
}
if (typeof WeixinJSBridge == "undefined") return;
if (cacheOnly && paying) return;
cookieReady || setTimeout(function() {
g(t, n, r)
}, 100), mobileData.amount = e(r).attr("data-amount"), mobileData.productType = e(r).attr("data-productType") || 4;
var s = {
mobile: mobileData.mn.replace(/\s/g, ""),
amount: mobileData.amount,
vb2ctag: vb2ctag,
producttype: mobileData.productType,
source: source
};
e(r).addClass("active"), paying = !0, wx.submitMobileDeal(s, function(t) {
e(r).removeClass("active");
if (t.errCode == 1205) return cacheOnly && o(), alert("系统繁忙,请稍后再试。");
if (t.errCode == 1215) return cacheOnly && o(), alert("该商品暂时缺货,请选择其它面额。");
if (t.errCode != 0) return cacheOnly && o(), alert("系统繁忙,请稍后再试。");
jumpUrl = "//chong.qq.com/mobile/wx_traffic_success.shtml?phone=" + mobileData.mn.replace(/\s/g, ""), paySuccUrl && (jumpUrl = decodeURIComponent(paySuccUrl)), wx.pay(t.data, function(e) {
if (e.errCode == 0) return wxHistory.add(currentMobile), location.href = jumpUrl;
e.msg !== "get_brand_wcpay_request:cancel" ? (alert("æ”¯ä»˜å¼‚å¸¸è¯·æ ¸å¯¹é“¶è¡Œæ‰£æ¬¾:" + JSON.stringify(e)), cacheOnly && o()) : cacheOnly && o()
})
}, openId, appId, code)
}
function y(e, t) {
var i = 0,
s = null,
o = new Date,
u, a, f;
if (typeof adConfig == "undefined") return;
u = adConfig.filter(function(n) {
return n.conf_area === e && n.conf_isp === t && o < new Date(n.conf_end_time) && o > new Date(n.conf_start_time)
}), a = u.filter(function(e) {
return e.conf_href && e.conf_img
}), a = a.length > 0 ? a[0] : null, f = u.filter(function(e) {
return !!e.conf_text
}), f = f.length > 0 ? f[0] : null, a && n.show(a.conf_href, a.conf_img), f && r.show(f.conf_text)
}
function b() {
var n = mobileData.mn && mobileData.mn.replace(/\s/g, "") || num.replace(/\s/g, "");
if (!S(n) || S(n) == "未知") return mobileData.tipsBody = "è¯·è¾“å…¥æ­£ç¡®çš„æ‰‹æœºå·ç ";
mobileData.tipsBody = "", mobileData.price = "0.0å…ƒ", mobileData.clearBtnShow = "none", e(".flowlist_item").addClass("flowlist_item__disable"), currentIsp = null, mm.queryInfo(n, function(i) {
function l(e) {
var t = a[e.amount],
n = t.saleFlag != 1;
return e.disabledClass = n ? " flowlist_item__disable" : "", !isNaN(t.price) && t.price > 0 && (e.amountVal = t.price), n && (e.adText = "该面值缺货,请选其他面值"), f = n && f, e
}
var s = i.isp.replace("中国", "") || "";
currentMobile = {
mobileNum: n,
localInfo: i.province + s
}, ignored = ignoreInterceptList.indexOf(i.province + s) >= 0;
if (i.retCode) {
mobileData.mobileAddr = "...";
return
}
i.province && i.isp && (mobileData.mobileAddr = i.province + s), mobileData.amountTabShow = "none", e("#flowlistNation").removeClass("hide").addClass("show").siblings(".flowlist").addClass("hide").removeClass("show"), e(e("#navBar").children()[0]).addClass("active"), e(e("#navBar").children()[1]).removeClass("active");
for (var o = 0; o < window._tips.length; o++) {
var u = window._tips[o];
if (u.isp === mobileData.mobileAddr) {
mobileData.mobileAddr = "<span>" + mobileData.mobileAddr + "</span><span>" + u.area + "</span><span>" + u.startTime + "</span><span>" + u.endTime + "</span>";
break
}
}
y(i.province, s);
var a = {},
f = !0;
for (var c = 0; c < trafficRule.length; c++) {
var h = trafficRule[c],
p = [];
h.amountList = h.amountList.map(function(e) {
return e.disabledClass = "", e
});
if (i.isp.indexOf(h.isp) >= 0 && (h.area == "*" || i.province == h.area)) {
currentIsp = h, mobileData.nationAmountList = h.amountList, mobileData.amount = mobileData.nationAmountList[0].amount, e(h.hint).show().siblings().hide();
var d = h.amountList.map(function(e) {
return e.amount
});
w(4, 0, d.join("|"), function(e) {
a = {}, e.AmountData.forEach(function(e) {
a[e.amount] = {
saleFlag: e.saleFlag,
price: parseFloat(e.maxPrice / 100).toFixed(2)
}
}), f = !0, mobileData.nationAmountList = mobileData.nationAmountList.map(l), f && (r.show("当地运营商维护中,请稍后再试!"), mobileData.nationAmountList = mobileData.nationAmountList.map(function(e) {
return e.adText = "", e
}))
});
break
}
}
for (var c = 0; c < fastTrafficRule.length; c++) {
var h = fastTrafficRule[c],
p = [];
h.amountList = h.amountList.map(function(e) {
return e.disabledClass = "", e
});
if (i.isp.indexOf(h.isp) >= 0 && (h.area == "*" || i.province == h.area)) {
currentIsp = h, mobileData.provinceAmountList = h.amountList;
if (mobileData.provinceAmountList.length > 0) {
mobileData.amountTabShow = "";
if (url.getUrlParam("tab") == "2") {
e('[tab-flag="flowlistProvince"]').addClass("active").siblings().removeClass("active");
var v = mobileData.mobileAddr.replace(/((<span>[^<]*<\/span>){3})(<span>[^<]*<\/span>)$/, "$1");
t = mobileData.mobileAddr, mobileData.mobileAddr = v.replace("全国", "省内"), e("#flowlistProvince").removeClass("hide").addClass("show").siblings(".flowlist").addClass("hide").removeClass("show")
}
} else mobileData.amountTabShow = "none";
mobileData.amount = mobileData.provinceAmountList[0].amount, e(h.hint).show().siblings().hide();
var d = h.amountList.map(function(e) {
return e.amount
});
w(35, 0, d.join("|"), function(e) {
a = {}, e.AmountData.forEach(function(e) {
a[e.amount] = {
saleFlag: e.saleFlag,
price: parseFloat(e.maxPrice / 100).toFixed(2)
}
}), f = !0, mobileData.provinceAmountList = mobileData.provinceAmountList.map(l), f && (r.show("当地运营商维护中,请稍后再试!"), mobileData.provinceAmountList = mobileData.provinceAmountList.map(function(e) {
return e.adText = "", e
}))
});
break
}
}
currentIsp || (mobileData.tipsBody = "该地区暂不支持流量充值", e(".flowlist_item").addClass("flowlist_item__disable"))
})
}
function w(t, n, r, i) {
var s = mobileData.mn.replace(/\s/g, "");
if (s.length === 0) return;
n = n || 0, mm.multiPreInquiry4wx(s, r, n, 2079, function(t) {
var n = {
1: "è¯¥å·ç ä¸å¯å……å€¼ï¼Œè¯·è‡´ç”µè¿è¥å•†å’¨è¯¢",
2: "非3Gæ‰‹æœºå·ç ä¸èƒ½å……æµé‡ï¼Œè¯·è‡´ç”µè¿è¥å•†å’¨è¯¢",
3: "è¯¥æ‰‹æœºå·å·²æ¬ è´¹ä¸èƒ½å……æµé‡ï¼Œè¯·è‡´ç”µè¿è¥å•†å’¨è¯¢",
4: "与其他套餐互斥不能充流量,请致电运营商咨询",
5: "运营商繁忙,请致电运营商咨询",
6: "超过充值次数,请致电运营商咨询",
7: "该地区暂不支持流量充值,请致电运营商咨询",
8: "请选择其它流量面值",
other: "请稍候重试"
};
t.retCode == 0 ? i(t) : t.retCode == 10 ? o(0) : n[t.retCode] ? (mobileData.tipsBody = n[t.retCode], e(".flowlist_item").addClass("flowlist_item__disable")) : mobileData.tipsBody = n.other
}, appId, code, t)
}
function E() {
var t = e("input");
t.attr("readonly", "readonly"), t.attr("disabled", "true"), setTimeout(function() {
t.blur(), t.removeAttr("readonly"), t.removeAttr("disabled")
}, 50)
}
function S(e) {
var t = "134,135,136,137,138,139,150,151,152,157,158,159,187,188,147,182,183,184",
n = "130,131,132,155,156,185,186,145,176",
r = "133,153,180,181,189,177",
e = e || "",
i = e.substring(0, 3),
s = e.substring(0, 4),
e = /\d{11}$/.test(e) ? !0 : !1;
return e
}
function x() {
window.location = "//chong.qq.com/mobile/wx_traffic.shtml?phone=" + (num.replace(/\s/g, "") || mobileData.mn.replace(/\s/g, ""))
}
function T(e) {
var t = "";
for (var n = 0; n < e.length; ++n) n == 3 || n == 7 ? t += " " + e[n] : t += e[n];
return t
}
function N(e) {
var t = e || new Date,
n = new Date(new Date(t.getFullYear(), t.getMonth() + 1, 1) - 18e6);
return t - n >= 0 && t - n < 18e6
}
function C(n, r, i) {
e("#" + e(i).attr("tab-flag")).removeClass("hide").addClass("show").siblings(".flowlist").addClass("hide").removeClass("show");
var s = e(i).attr("tab-flag");
if (s === "flowlistProvince") {
t = mobileData.mobileAddr;
var o = mobileData.mobileAddr.replace(/((<span>[^<]*<\/span>){3})(<span>[^<]*<\/span>)$/, "$1");
mobileData.mobileAddr = o.replace("全国", "省内")
} else mobileData.mobileAddr = t;
e(i).addClass("active").siblings().removeClass("active")
}
var e = require("{jquery}"),
t = "...";
dlgConfirm = null, mobileData = require("ctrl.wx.m.trafficH5").viewData, wx = require("m.wx"), mm = require("m.mobile"), url = require("url"), cookie = require("cookie"), ajax = require("m.ajax"), report = require("m.report"), session = require("m.session"), wxHistory = require("util.wx.m.history").wxHistory, Dialog = require("util.wx.m.dialog").Dialog, vb2ctag = "4_2079_1_2728_67", appId = jdata.aid || "wx47031447c8352579", code = url.getUrlParam("code"), num = url.getUrlParam("num") || url.getUrlParam("phone"), mdebug = !!url.getUrlParam("mdebug"), currentMobile = {}, cacheOnly = !!url.getUrlParam("cacheOnly"), openId = cookie.get(appId + "_openId") || "", historyList = [], trafficRule = [], fastTrafficRule = [], trafficPrix = {}, amountList = [], currentIsp = null, ignoreInterceptList = ["北京移动"], ignored = !1, cookieReady = !1, paying = !1, TIMEOUT = 1e3, defaultPrix = [{
amount: "70",
amountVal: "10.00",
amountText: "70M",
adText: "",
disabledClass: ""
}, {
amount: "150",
amountVal: "20.00",
amountText: "150M",
adText: "",
disabledClass: ""
}, {
amount: "500",
amountVal: "30.00",
amountText: "500M",
adText: "",
disabledClass: ""
}, {
amount: "1024",
amountVal: "50.00",
amountText: "1G",
adText: "",
disabledClass: ""
}];
var n = {
show: function(t, r) {
n.href = t;
if (session.get(t)) return;
if (t && r) {
var i = new Image;
e("#ad").find("a").attr("href", t), i.src = r, i.onload = function() {
e("#ad").find("img").attr("src", r), e("#ad").addClass("past").show().removeClass("past")
}
} else e("#ad").addClass("past").show().removeClass("past")
},
hide: function() {
session.set(n.href, 1, 432e5), e("#ad").addClass("past"), setTimeout(function() {
e("#ad").hide()
}, 500)
}
},
r = {
show: function(e) {
mobileData.notice = e
},
hide: function() {
mobileData.notice = ""
}
};
vb2ctag = window.jdata && window.jdata.vb2ctag || vb2ctag, vb2ctag = url.getUrlParam("vb2ctag") || url.getHashParam("vb2ctag") || vb2ctag, vb2ctag = vb2ctag.replace(/(\d+_\d+_\d+_\d+)(_\d+)?/, "$1_67"), paySuccUrl = url.getUrlParam("pay_succ_url") || url.getHashParam("pay_succ_url") || "", source = url.getUrlParam("source") || url.getHashParam("source") || "", exports.init = i, exports.input = c, exports.blur = p, exports.focus = v, exports.submit = m, exports.goIndex = x, exports.selectNum = l, exports.clearNum = d, exports.hideAd = n.hide, exports.toggleTab = C
});; /* |xGv00|e39efa36ac0ac7902bba8223517deeaa */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment