main.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. import * as compnt from "../../../../public/js/compnt";
  2. import * as unicom from "../../../../public/js/unicom.js";
  3. import * as weibo from "./weibo.js";
  4. import "../scss/main.scss";
  5. unicom.exo()
  6. weibo.checkClientEnvironment();
  7. compnt.showLoading();
  8. var message = localStorage.getItem('message');
  9. if (message != null && message != '') {
  10. compnt.showAlert(message);
  11. localStorage.removeItem('message');
  12. }
  13. $('#btn-cancel').unbind('click').on('click', function() {
  14. showCancelReasonPage().done(function(cancelReason) {
  15. var k = JSON.stringify(cancelReason)
  16. window.localStorage.setItem('kye', k)
  17. showCancelPage()
  18. })
  19. })
  20. $('#btn-draw').unbind('click').on('click', function() {
  21. if (!checkEquip('draw')) return;
  22. showDrawPage();
  23. })
  24. $('#btn-active').unbind('click').on('click', function() {
  25. if (!checkEquip('active')) return;
  26. showActivePage();
  27. })
  28. if (weibo.app.weibo) {
  29. function bridgeReady() {
  30. if (weibo.checkWeiboVersion()) {
  31. weibo.getUserInfo().then(function() {
  32. init();
  33. }).fail(function(data) {
  34. init();
  35. });
  36. } else {
  37. weibo.getUserInfo();
  38. init();
  39. }
  40. }
  41. if (window.WeiboJSBridge) {
  42. bridgeReady();
  43. } else {
  44. document.addEventListener('WeiboJSBridgeReady', function() {
  45. bridgeReady();
  46. });
  47. }
  48. } else {
  49. init();
  50. }
  51. function showCancelReasonPage() {
  52. var reasonUrl;
  53. var baseUrl;
  54. if (window.location.href.indexOf("https://800.wo.cn/orderchannel") >= 0) {
  55. reasonUrl = "https://800.wo.cn/orderchannel/public/libs/cancelreason/index.html";
  56. baseUrl = "https://800.wo.cn/";
  57. } else if (window.location.href.indexOf("https://800.wo.cn/festivalchannel") >= 0) {
  58. reasonUrl = "https://800.wo.cn/festivalchannel/public/libs/cancelreason/index.html";
  59. baseUrl = "https://800.wo.cn/";
  60. } else if (window.location.href.indexOf("http://localhost") >= 0) {
  61. reasonUrl = "http://localhost:8088/orderchannel/public/libs/cancelreason/index.html";
  62. baseUrl = "http://localhost:8088/";
  63. } else if (window.location.href.indexOf("http://127.0.0.1") >= 0) {
  64. reasonUrl = "http://127.0.0.1:8088/orderchannel/public/libs/cancelreason/index.html";
  65. baseUrl = "http://127.0.0.1:8088/";
  66. } else if (window.location.href.indexOf("http://100.0.4.69:3344") >= 0) {
  67. reasonUrl = "http://100.0.4.69:3344/orderchannel/public/libs/cancelreason/index.html";
  68. baseUrl = "http://100.0.4.69:3344/";
  69. } else if (window.location.href.indexOf("http://100.0.4.69:8282") >= 0) {
  70. reasonUrl = "http://100.0.4.69:8282/orderchannel/public/libs/cancelreason/index.html";
  71. baseUrl = "http://100.0.4.69:8282/";
  72. } else {
  73. reasonUrl = "https://800.wo.cn/orderchannel/public/libs/cancelreason/index.html";
  74. baseUrl = "https://800.wo.cn/";
  75. }
  76. window.$capoverlay = $('<div class="overlay" style="z-index: 0; background-color: rgba(0,0,0,0.4);"></div>');
  77. $capoverlay.appendTo($(document.body));
  78. $("body").css("overflow", "hidden");
  79. var $iframe;
  80. if ($('#reasonIframe').length >= 1) {
  81. $iframe = $('#reasonIframe').attr('src', reasonUrl);
  82. } else {
  83. $iframe = $('<iframe id="reasonIframe" src="' + reasonUrl + '"></iframe>');
  84. $('body').append($iframe);
  85. }
  86. $iframe.css({
  87. width: "100%",
  88. height: "100%",
  89. position: "fixed",
  90. top: 0,
  91. left: 0,
  92. margin: 0,
  93. padding: 0,
  94. "-webkit-overflow-scrolling": "touch",
  95. border: "0px",
  96. "z-index": 111,
  97. });
  98. var def = $.Deferred();
  99. function messageListener(event) {
  100. var data = JSON.parse(event.data);
  101. $iframe.remove();
  102. $capoverlay.remove();
  103. $("body").css("overflow", "auto");
  104. window.removeEventListener('message', messageListener);
  105. if (data.eventtype != 'close') {
  106. def.resolve(data)
  107. } else {
  108. def.reject(data)
  109. }
  110. }
  111. window.addEventListener('message', messageListener);
  112. return def;
  113. }
  114. function init() {
  115. unicom.init().then(function(response) {
  116. unicom.product = response.product[0];
  117. unicom.fesname = response.festival;
  118. loadUserInfo();
  119. // compnt.showAlert(JSON.stringify(unicom.user))
  120. // compnt.showAlert(weibo.uid)
  121. // weibo.uid = "2245755811"; // 未订购
  122. // weibo.uid = "5345323620"; // 已经订购
  123. if (location.href.indexOf("index.html") >= 0) {
  124. if (unicom.user.userid) {
  125. openPage("flow");
  126. } else if (weibo.uid) {
  127. unicom.queryMember(null, null, weibo.uid).then(function(response) {
  128. if (response.resultCode == "0000") {
  129. unicom.user.userid = response.userid;
  130. // 已经领取微博会员的手机号码
  131. unicom.user.usermob = response.usermob;
  132. unicom.user.usertime = new Date().getTime();
  133. showFlowPage(response);
  134. compnt.hideLoading();
  135. }
  136. }).fail(function() {
  137. // compnt.showAlert("asdasd");
  138. });
  139. }
  140. compnt.hideLoading();
  141. showOrderPage();
  142. } else {
  143. openPage(unicom.query.page);
  144. compnt.hideLoading();
  145. }
  146. /*unicom.user.userid = "18674842761";
  147. unicom.user.usermob = '17610768237'
  148. showFlowPage();*/
  149. if (location.href.indexOf('/cancel') >= 0) {
  150. unicom.burypointLogId('110002'); // 退订页面pv, pv去重得到uv
  151. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'cancel_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  152. } else if (location.href.indexOf('/draw') >= 0) {
  153. unicom.burypointLogId('110003'); // 领取页面pv, pv去重得到uv
  154. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'draw_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  155. } else if (location.href.indexOf('/flow') >= 0) {
  156. unicom.burypointLogId('110004'); // 流量查询pv, pv去重得到uv
  157. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'flow_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  158. } else if (location.href.indexOf('/active') >= 0) {
  159. unicom.burypointLogId('110005'); // 激活页面pv, pv去重得到uv
  160. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'active_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  161. } else if (location.href.indexOf('/refund') >= 0) {
  162. unicom.burypointLogId('110006'); // 退款
  163. } else {
  164. unicom.burypointLogId('110001'); // 订购页面pv, pv去重得到uv
  165. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'order_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  166. }
  167. }).fail(function() {
  168. compnt.hideLoading();
  169. })
  170. }
  171. function openPage(pageName) {
  172. switch (pageName) {
  173. case "active":
  174. showActivePage();
  175. break;
  176. case "cancel":
  177. showCancelPage();
  178. break;
  179. case "draw":
  180. if (weibo.uid == null || weibo.uid == '') {
  181. weibo.getUserInfo().then(function(response) {
  182. showDrawPage();
  183. })
  184. } else {
  185. showDrawPage();
  186. }
  187. break;
  188. case "flow":
  189. showFlowPage();
  190. break;
  191. default:
  192. showOrderPage();
  193. break;
  194. }
  195. }
  196. function loadUserInfo() {
  197. if (unicom.query.userid) {
  198. unicom.user.userid = unicom.query.userid;
  199. unicom.user.usermob = unicom.query.usermob;
  200. return;
  201. }
  202. try {
  203. var time = localStorage.getItem('time');
  204. if (time) {
  205. var curr = new Date().getTime();
  206. if (curr <= parseFloat(time) + (1000 * 60 * 60)) {
  207. var userString = localStorage.getItem("user");
  208. var user = JSON.parse(userString);
  209. unicom.user.userid = user.userid;
  210. unicom.user.usermob = user.usermob;
  211. if (unicom.user.usermob == "18674842761") {
  212. setTimeout(function() {
  213. alert(time + (1000 * 60 * 60))
  214. }, 100);
  215. }
  216. } else {
  217. localStorage.removeItem("time")
  218. localStorage.removeItem("user")
  219. }
  220. }
  221. } catch (e) {
  222. }
  223. }
  224. /**
  225. * 显示流量查询页面
  226. */
  227. function showFlowPage() {
  228. if (location.href.indexOf("flow.html") < 0) {
  229. window.location.href = "flow.html?fes=" +
  230. unicom.query.fes + "&sou=" + unicom.query.sou + "&F=" + unicom.query.F +
  231. "&userid=" + unicom.user.userid + "&usermob=" + unicom.user.usermob +
  232. "&usertime=" + (unicom.user.usertime || (new Date().getTime())) + "&page=flow";
  233. return;
  234. }
  235. if (localStorage.getItem('action') == 'draw') {
  236. if (!checkEquip('draw')) return;
  237. unicom.can(weibo.uid).then(function(response) {
  238. if (response.resultCode == "0000") {
  239. draw();
  240. }
  241. });
  242. localStorage.removeItem('action');
  243. }
  244. var $container = $('#section-flow');
  245. $container.find('.phone').html('免流号码:' + unicom.user.usermob);
  246. queryFlow();
  247. $container.find('.btn').unbind('click').on('click', function(event) {
  248. if (!compnt.lockClick()) {
  249. return;
  250. }
  251. queryFlow().then(function(message) {
  252. compnt.unlockClick()
  253. if (message != null && message != "") {
  254. compnt.showAlert(message);
  255. }
  256. });
  257. })
  258. $container.find('.member a').unbind('click').on('click', function() {
  259. if (!checkEquip('draw')) return;
  260. // alert(weibo.screen_name)
  261. // 如果有用户号码,直接打开领取会员二次确认的提示
  262. unicom.can(weibo.uid).then(function(response) {
  263. switch (response.resultCode) {
  264. case "0000":
  265. if (unicom.user.userid) {
  266. draw();
  267. } else {
  268. showDrawPage();
  269. }
  270. break;
  271. case "1003":
  272. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  273. break;
  274. default:
  275. compnt.showAlert(response.resultInfo);
  276. break;
  277. }
  278. });
  279. })
  280. if (weibo.app.weibo && weibo.checkWeiboVersion() && (weibo.uid == null || weibo.uid == '')) {
  281. weibo.getUserInfo().then(function() {
  282. unicom.queryMember().then(function(response) {
  283. showMemberInfo(response)
  284. });
  285. })
  286. } else {
  287. unicom.queryMember().then(function(response) {
  288. showMemberInfo(response)
  289. });
  290. }
  291. function showMemberInfo(response) {
  292. switch (response.resultCode) {
  293. case "0000":
  294. switch (response.sync_code) {
  295. case "0": // 订购关系退订同步成功
  296. case "2": // 订购关系订购同步成功
  297. if (response.screen_name) {
  298. $container.find('.member').html('微博账号:' + decodeURIComponent(response.screen_name));
  299. } else {
  300. $container.find('.member').html('微博会员:已领取');
  301. }
  302. $container.find('.vflag').css({ "display": "block" });
  303. $container.find('.member a').unbind('click');
  304. weibo.active(); // 静默激活
  305. break;
  306. default:
  307. $container.find('.member a').html('请点此领取微博会员');
  308. // 隐藏微博会员图标
  309. $container.find('.vflag').css({ "display": "none" })
  310. break;
  311. }
  312. break;
  313. case "1015": //{"resultCode":"1015","errorInfo":"用户未订购此产品!"}
  314. compnt.showAlert("未订购此产品!").then(function(message) {
  315. localStorage.removeItem('time');
  316. localStorage.removeItem('user')
  317. showOrderPage();
  318. $container.find('.phone').html('用户未订购此产品!');
  319. });
  320. break;
  321. default:
  322. break;
  323. }
  324. }
  325. }
  326. /**
  327. * 查询用户剩余流量
  328. */
  329. function queryFlow() {
  330. var $container = $('#section-flow');
  331. var def = $.Deferred();
  332. unicom.queryFlow().then(function(response) {
  333. switch (response.resultCode) {
  334. case "0000":
  335. var surplus = compnt.returnFloat(JSON.parse(response.data).surplusFlow / 1024 / 1024);
  336. $container.find('.suplus').html('本月剩余<br>' + surplus + 'GB');
  337. var usedFlowKb = parseInt(JSON.parse(response.data).usedFlow);
  338. if (usedFlowKb > 0 && usedFlowKb < 1024) {
  339. def.resolve("剩余流量更新成功,为您免流了" + usedFlowKb + "KB~");
  340. } else if (usedFlowKb > 1024) {
  341. var useedFlow = compnt.returnFloat(usedFlowKb / 1024);
  342. def.resolve("剩余流量更新成功,为您免流了" + useedFlow + "MB~");
  343. } else {
  344. def.resolve("剩余流量更新成功~");
  345. }
  346. break;
  347. case "9201": //{"resultCode":"9201","errorInfo":"查询失败,请检查是否有订购关系!"}
  348. def.resolve("您未订购新浪微博畅想会员畅想包~")
  349. $container.find('.phone').html('用户未订购此产品!');
  350. break;
  351. case "9203": //{"resultCode":"9203","errorInfo":"流量查询失败,没有获取到用户所使用流量信息!"}
  352. //compnt.showAlert("没有获取到用户所使用流量信息!");
  353. def.resolve("剩余流量更新成功~")
  354. $container.find('.suplus').html('本月剩余<br>10.00GB');
  355. break;
  356. default:
  357. break;
  358. }
  359. })
  360. return def;
  361. }
  362. /**
  363. * 打开退订页面
  364. */
  365. function showCancelPage() {
  366. var cancelReason = JSON.parse(window.localStorage.getItem('kye'))
  367. if (location.href.indexOf("cancel.html") < 0) {
  368. window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" +
  369. unicom.query.sou + "&F=" + unicom.query.F + '&page=cancel';
  370. return;
  371. }
  372. var $container = $('#section-cancel').find('.form-group');
  373. $container.find('.sendcode').unbind('click').on('click', function() {
  374. unicom.sendSms($container, 'cancellogin');
  375. //unicom.sendSms($container, '212');
  376. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_click_send_sms_code_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  377. })
  378. $container.find('.login').unbind('click').on('click', function() {
  379. compnt.showLoading();
  380. unicom.checkCode($container).then(function() {
  381. unicom.cancel(null, null, cancelReason.canceltype, cancelReason.cancelmsg).then(function(response) {
  382. compnt.hideLoading();
  383. switch (response.resultCode) {
  384. case "0000":
  385. compnt.showAlert('退订成功').then(function(message) {
  386. window.localStorage.clear()
  387. showFlowPage();
  388. });
  389. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_success' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  390. break;
  391. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  392. compnt.showAlert(response.errorInfo).then(function(message) {
  393. showFlowPage();
  394. });
  395. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  396. break;
  397. default:
  398. var prefix = '';
  399. if (response.errorInfo.indexOf('退订失败') < 0) {
  400. prefix = '退订失败,';
  401. }
  402. compnt.showAlert(prefix + response.errorInfo);
  403. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  404. break;
  405. }
  406. }).fail(function(data) {
  407. compnt.hideLoading();
  408. })
  409. }).fail(function(data) {
  410. compnt.hideLoading();
  411. })
  412. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_click_confirm_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  413. })
  414. window.scrollTo(0, 0)
  415. }
  416. /**
  417. * 打开领取会员的页面
  418. * 在客户端中才能领取会员
  419. */
  420. function showDrawPage() {
  421. if (location.href.indexOf("draw.html") < 0) {
  422. window.location.href = "draw.html?fes=" + unicom.query.fes + "&sou=" +
  423. unicom.query.sou + "&F=" + unicom.query.F + '&page=draw';
  424. return;
  425. }
  426. var $container = $('#section-draw').find('.form-group');
  427. compnt.showLoading();
  428. unicom.queryMember(null, null, weibo.uid).then(function(response) {
  429. if (response.resultCode == "0000") {
  430. switch (response.sync_code) {
  431. case "0": // 订购关系退订同步成功
  432. case "2": // 订购关系订购同步成功
  433. localStorage.setItem("message", "当前微博账号已经领取了会员~");
  434. unicom.user.userid = response.userid;
  435. unicom.user.usermob = response.usermob;
  436. unicom.user.usertime = new Date().getTime();
  437. showFlowPage();
  438. break;
  439. }
  440. } else {
  441. unicom.can(weibo.uid).then(function(response) {
  442. compnt.hideLoading();
  443. var hasMonthVip = false;
  444. switch (response.resultCode) {
  445. case "0000":
  446. hasMonthVip = false;
  447. break;
  448. case "1003":
  449. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  450. hasMonthVip = true;
  451. break;
  452. default:
  453. compnt.showAlert(response.resultInfo);
  454. break;
  455. }
  456. $container.find('.sendcode').unbind('click').on('click', function() {
  457. if (!checkEquip()) return;
  458. if (hasMonthVip) {
  459. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  460. return;
  461. }
  462. unicom.sendSms($container, 'drawlogin');
  463. // unicom.sendSms($container, '210');
  464. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_click_send_sms_code_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  465. })
  466. $container.find('.login').unbind('click').on('click', function() {
  467. if (hasMonthVip) {
  468. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  469. return;
  470. }
  471. unicom.checkCode($container).then(function() {
  472. draw()
  473. })
  474. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_click_confirm_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  475. })
  476. }).fail(function(error) {
  477. // alert(JSON.stringify(error))
  478. })
  479. }
  480. })
  481. }
  482. function draw() {
  483. var $dialog = showConfirmDialog();
  484. $dialog.find('.btn-no').on('click', function() {
  485. compnt.showAlert('请切换登录的微博账号后,再领取会员')
  486. })
  487. $dialog.find('.btn-ok').on('click', function(event) {
  488. if (!compnt.lockClick()) return;
  489. unicom.drawMember(weibo.uid, weibo.screen_name).then(function(response) {
  490. compnt.unlockClick();
  491. switch (response.resultCode) {
  492. case "0000":
  493. weibo.active(); // 领取成功,静默激活
  494. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_success' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  495. compnt.showAlert('微博会员领取成功!').then(function() {
  496. showFlowPage();
  497. });
  498. break;
  499. case "1020":
  500. // 已经领取,领取的账号与当前微博账号一致,静默激活
  501. unicom.queryMember().then(function(response) {
  502. if (response.resultCode == "0000") {
  503. if (response.uid == weibo.uid) {
  504. weibo.active();
  505. compnt.showAlert('已领取过会员~').then(function(message) {
  506. showFlowPage();
  507. });
  508. } else { // 领取到了其他微博账号
  509. compnt.showAlert('该手机号已将会员领取到其他微博账号~')
  510. }
  511. } else { // 查询失败
  512. compnt.showAlert('已领取过会员~');
  513. }
  514. }).fail(function() {
  515. // 查询失败
  516. compnt.showAlert('已领取过会员~');
  517. })
  518. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  519. break;
  520. default:
  521. compnt.showAlert('领取失败,' + response.errorInfo);
  522. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  523. break;
  524. }
  525. }).fail(function() {
  526. compnt.unlockClick();
  527. });
  528. })
  529. }
  530. /**
  531. * 打开激活免流的页面
  532. * 客户端中才能激活
  533. */
  534. function showActivePage() {
  535. if (location.href.indexOf("active.html") < 0) {
  536. window.location.href = "active.html?fes=" + unicom.query.fes + "&sou=" +
  537. unicom.query.sou + "&F=" + unicom.query.F + "&page=active";
  538. return;
  539. }
  540. var $container = $('#section-active').find('.form-group');
  541. $container.find('.sendcode').unbind('click').on('click', function() {
  542. if (!checkEquip('active')) return;
  543. unicom.sendSms($container, 'activelogin');
  544. //unicom.sendSms($container, '209');
  545. })
  546. $container.find('.login').unbind('click').on('click', function(event) {
  547. if (!checkEquip('active')) return;
  548. if (!compnt.lockClick()) {
  549. return;
  550. }
  551. unicom.checkCode($container).then(function() {
  552. compnt.unlockClick()
  553. active()
  554. }).fail(function() {
  555. compnt.unlockClick();
  556. });
  557. })
  558. window.scrollTo(0, 0)
  559. }
  560. function checkEquip(action) {
  561. if (action == 'active') {
  562. if (!weibo.app.weibo) {
  563. compnt.showAlert('请到新浪微博客户端中激活免流~')
  564. return false;
  565. }
  566. if (!weibo.checkWeiboVersion()) {
  567. compnt.showAlert('请到升级到最新版新浪微博客户端后激活免流~')
  568. return false;
  569. }
  570. } else {
  571. if (!weibo.app.weibo) {
  572. compnt.showAlert('请到新浪微博客户端中领取会员激活免流~')
  573. return false;
  574. }
  575. if (!weibo.checkWeiboVersion()) {
  576. compnt.showAlert('请到升级到最新版新浪微博客户端后领取会员激活免流~')
  577. return false;
  578. }
  579. }
  580. return true;
  581. }
  582. function active() {
  583. unicom.queryMember().then(function(response) {
  584. switch (response.resultCode) {
  585. case "0000":
  586. break;
  587. case "0002":
  588. compnt.showAlert('激活失败,未领取新浪微博会员~');
  589. return;
  590. default:
  591. compnt.showAlert('激活失败,未领取新浪微博会员~');
  592. return;
  593. }
  594. if (weibo.uid != response.uid) {
  595. compnt.showAlert('激活失败,激活免流的微博账号与领取会员的微博账号不一致~');
  596. return;
  597. }
  598. switch (response.sync_code) {
  599. case "0": // 订购关系退订同步成功
  600. case "2": // 订购关系订购同步成功
  601. weibo.active().then(function() {
  602. //checkActiveResult();
  603. compnt.showAlert('激活成功').then(function() {
  604. localStorage.setItem('user', JSON.stringify(unicom.user));
  605. localStorage.setItem('time', new Date().getTime());
  606. showFlowPage();
  607. });
  608. })
  609. break;
  610. case "1": // 订购关系退订同步失败
  611. case "3": // 订购关系订购同步失败
  612. compnt.showAlert("请领取会员以后再进行激活操作~");
  613. break;
  614. }
  615. });
  616. }
  617. /**
  618. * 打开订购页面
  619. */
  620. function showOrderPage() {
  621. $('.section-banner').removeClass('section-banner-small');
  622. $('#btn-order').unbind('click').on('click', function(event) {
  623. if (!compnt.lockClick()) {
  624. //alert(1)
  625. return;
  626. }
  627. unicom.showCapPage().then(function(data) {
  628. compnt.unlockClick();
  629. order(data.userid, data.token, data.usermob);
  630. }).fail(function(response) {
  631. compnt.unlockClick();
  632. })
  633. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_click_order_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  634. })
  635. }
  636. /**
  637. * 订购
  638. */
  639. function order(userid, token, usermob) {
  640. unicom.order(userid, token, usermob).then(function(response) {
  641. // console.log(response)
  642. switch (response.resultCode) {
  643. case "0000": //订购成功!跳转到领取会员页面
  644. // compnt.showAlert('unicom.user.userid:' + unicom.user.userid)
  645. // var versionFulfil = weibo.checkWeiboVersion();
  646. // alert('checkWeiboVersion()' + versionFulfil);
  647. localStorage.setItem('user', JSON.stringify(unicom.user));
  648. localStorage.setItem('time', new Date().getTime());
  649. // 客户端中进入领取页面,非客户端中,提示用户到客户端中去领取
  650. if (weibo.app.weibo && weibo.checkWeiboVersion()) {
  651. // 如果有用户号码,直接打开领取会员二次确认的提示
  652. compnt.showAlert('订购成功~').then(function(message) {
  653. localStorage.setItem('action', 'draw');
  654. showFlowPage();
  655. });
  656. } else {
  657. compnt.showAlert('订购成功,请到新浪微博客户端中领取会员开启免流~').then(function() {
  658. showFlowPage();
  659. })
  660. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_success' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  661. return;
  662. }
  663. break;
  664. case "0013":
  665. showOrderDialog('该号码归属省分2/3G暂未开通此产品!');
  666. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  667. break;
  668. case "6611":
  669. showOrderDialog('错误代码(6611),' + '订购失败,请重试!');
  670. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  671. break;
  672. case "6615":
  673. showOrderDialog('订购失败,请确定用户套餐!');
  674. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  675. break;
  676. case "6622": // 用户已订购过此产品!跳转到流量查页面
  677. localStorage.setItem('message', '您已经订购了本产品~');
  678. localStorage.setItem('user', JSON.stringify(unicom.user));
  679. localStorage.setItem('time', new Date().getTime());
  680. showFlowPage();
  681. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  682. break;
  683. default:
  684. showOrderDialog(response.errorInfo + ',订购失败,请确定用户套餐!');
  685. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  686. break;
  687. }
  688. }).fail(function(error) {
  689. console.log(error);
  690. });
  691. }
  692. function showOrderDialog(message) {
  693. var $overlay = $('<div class="overlay"></div>');
  694. var $dialog = $(
  695. '<div class="dialog dialog-order">' +
  696. ' <div class="face">' +
  697. ' <img src="images/face-sad.png">' +
  698. ' </div>' +
  699. ' <h2>对不起,订购失败!</h2>' +
  700. ' <p>' + message + '</p>' +
  701. ' <div class="btn">我知道了</div>' +
  702. '</div>');
  703. $overlay.appendTo($(document.body))
  704. $dialog.appendTo($(document.body))
  705. $dialog.find('.btn').unbind('click').on('click', function() {
  706. $dialog.close()
  707. })
  708. $dialog.close = function() {
  709. $overlay.remove();
  710. $dialog.remove();
  711. $dialog = null;
  712. }
  713. return $dialog;
  714. }
  715. function showConfirmDialog() {
  716. var message = '确认将新浪微博会员领取到您当前登录的账号中吗?';
  717. if (weibo.screen_name) {
  718. message = '请确认将新浪微博会员领取到账号:' + weibo.screen_name
  719. }
  720. var $overlay = $('<div class="overlay"></div>');
  721. var $dialog = $(
  722. '<div class="dialog dialog-confirm">' +
  723. ' <h2>领取会员</h2>' +
  724. ' <p>' + message + '</p>' +
  725. ' <div class="actions" style="display: flex;">' +
  726. ' <div class="btn btn-no">其他账号</div>' +
  727. ' <div class="btn btn-ok">确认</div>' +
  728. ' </div>' +
  729. '</div>');
  730. $overlay.appendTo($(document.body))
  731. $dialog.appendTo($(document.body))
  732. $dialog.find('.btn').on('click', function() {
  733. $dialog.close()
  734. })
  735. $dialog.close = function() {
  736. $overlay.remove();
  737. $dialog.remove();
  738. $dialog = null;
  739. }
  740. return $dialog;
  741. }