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. weibo.checkClientEnvironment();
  6. compnt.showLoading();
  7. var message = localStorage.getItem('message');
  8. if (message != null && message != '') {
  9. compnt.showAlert(message);
  10. localStorage.removeItem('message');
  11. }
  12. $('#btn-cancel').unbind('click').on('click', function() {
  13. showCancelReasonPage().done(function(cancelReason) {
  14. var k = JSON.stringify(cancelReason)
  15. window.localStorage.setItem('kye', k)
  16. showCancelPage()
  17. })
  18. })
  19. $('#btn-draw').unbind('click').on('click', function() {
  20. if (!checkEquip('draw')) return;
  21. showDrawPage();
  22. })
  23. $('#btn-active').unbind('click').on('click', function() {
  24. if (!checkEquip('active')) return;
  25. showActivePage();
  26. })
  27. if (weibo.app.weibo) {
  28. function bridgeReady() {
  29. if (weibo.checkWeiboVersion()) {
  30. weibo.getUserInfo().then(function() {
  31. init();
  32. }).fail(function(data) {
  33. init();
  34. });
  35. } else {
  36. weibo.getUserInfo();
  37. init();
  38. }
  39. }
  40. if (window.WeiboJSBridge) {
  41. bridgeReady();
  42. } else {
  43. document.addEventListener('WeiboJSBridgeReady', function() {
  44. bridgeReady();
  45. });
  46. }
  47. } else {
  48. // 不的app中
  49. // 1、如果没有fes和sou参数
  50. // 2、code
  51. init();
  52. }
  53. function showCancelReasonPage() {
  54. var reasonUrl;
  55. var baseUrl;
  56. if (window.location.href.indexOf("https://800.wo.cn/orderchannel") >= 0) {
  57. reasonUrl = "https://800.wo.cn/orderchannel/public/libs/cancelreason/index.html";
  58. baseUrl = "https://800.wo.cn/";
  59. } else if (window.location.href.indexOf("https://800.wo.cn/festivalchannel") >= 0) {
  60. reasonUrl = "https://800.wo.cn/festivalchannel/public/libs/cancelreason/index.html";
  61. baseUrl = "https://800.wo.cn/";
  62. } else if (window.location.href.indexOf("http://localhost") >= 0) {
  63. reasonUrl = "http://localhost:8088/orderchannel/public/libs/cancelreason/index.html";
  64. baseUrl = "http://localhost:8088/";
  65. } else if (window.location.href.indexOf("http://127.0.0.1") >= 0) {
  66. reasonUrl = "http://127.0.0.1:8088/orderchannel/public/libs/cancelreason/index.html";
  67. baseUrl = "http://127.0.0.1:8088/";
  68. } else if (window.location.href.indexOf("http://100.0.4.69:3344") >= 0) {
  69. reasonUrl = "http://100.0.4.69:3344/orderchannel/public/libs/cancelreason/index.html";
  70. baseUrl = "http://100.0.4.69:3344/";
  71. } else if (window.location.href.indexOf("http://100.0.4.69:8282") >= 0) {
  72. reasonUrl = "http://100.0.4.69:8282/orderchannel/public/libs/cancelreason/index.html";
  73. baseUrl = "http://100.0.4.69:8282/";
  74. } else {
  75. reasonUrl = "https://800.wo.cn/orderchannel/public/libs/cancelreason/index.html";
  76. baseUrl = "https://800.wo.cn/";
  77. }
  78. window.$capoverlay = $('<div class="overlay" style="z-index: 0; background-color: rgba(0,0,0,0.4);"></div>');
  79. $capoverlay.appendTo($(document.body));
  80. $("body").css("overflow", "hidden");
  81. var $iframe;
  82. if ($('#reasonIframe').length >= 1) {
  83. $iframe = $('#reasonIframe').attr('src', reasonUrl);
  84. } else {
  85. $iframe = $('<iframe id="reasonIframe" src="' + reasonUrl + '"></iframe>');
  86. $('body').append($iframe);
  87. }
  88. $iframe.css({
  89. width: "100%",
  90. height: "100%",
  91. position: "fixed",
  92. top: 0,
  93. left: 0,
  94. margin: 0,
  95. padding: 0,
  96. "-webkit-overflow-scrolling": "touch",
  97. border: "0px",
  98. "z-index": 111,
  99. });
  100. var def = $.Deferred();
  101. function messageListener(event) {
  102. var data = JSON.parse(event.data);
  103. $iframe.remove();
  104. $capoverlay.remove();
  105. $("body").css("overflow", "auto");
  106. window.removeEventListener('message', messageListener);
  107. if (data.eventtype != 'close') {
  108. def.resolve(data)
  109. } else {
  110. def.reject(data)
  111. }
  112. }
  113. window.addEventListener('message', messageListener);
  114. return def;
  115. }
  116. function init() {
  117. unicom.init().then(function(response) {
  118. unicom.product = response.product[0];
  119. unicom.fesname = response.festival;
  120. loadUserInfo();
  121. // compnt.showAlert(JSON.stringify(unicom.user))
  122. // compnt.showAlert(weibo.uid)
  123. // weibo.uid = "2245755811"; // 未订购
  124. // weibo.uid = "5345323620"; // 已经订购
  125. if (location.href.indexOf("index.html") >= 0) {
  126. if (unicom.user.userid) {
  127. openPage("flow");
  128. } else if (weibo.uid) {
  129. unicom.queryMember(null, null, weibo.uid).then(function(response) {
  130. if (response.resultCode == "0000") {
  131. unicom.user.userid = response.userid;
  132. // 已经领取微博会员的手机号码
  133. unicom.user.usermob = response.usermob;
  134. unicom.user.usertime = new Date().getTime();
  135. showFlowPage(response);
  136. compnt.hideLoading();
  137. }
  138. }).fail(function() {
  139. // compnt.showAlert("asdasd");
  140. });
  141. }
  142. compnt.hideLoading();
  143. showOrderPage();
  144. } else {
  145. openPage(unicom.query.page);
  146. compnt.hideLoading();
  147. }
  148. /*unicom.user.userid = "18674842761";
  149. unicom.user.usermob = '17610768237'
  150. showFlowPage();*/
  151. if (location.href.indexOf('/cancel') >= 0) {
  152. unicom.burypointLogId('110002'); // 退订页面pv, pv去重得到uv
  153. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'cancel_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  154. } else if (location.href.indexOf('/draw') >= 0 ||
  155. location.href.indexOf('/weibo1') >= 0) {
  156. unicom.burypointLogId('110003'); // 领取页面pv, pv去重得到uv
  157. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'draw_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  158. } else if (location.href.indexOf('/flow') >= 0) {
  159. unicom.burypointLogId('110004'); // 流量查询pv, pv去重得到uv
  160. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'flow_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  161. } else if (location.href.indexOf('/active') >= 0) {
  162. unicom.burypointLogId('110005'); // 激活页面pv, pv去重得到uv
  163. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'active_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  164. } else if (location.href.indexOf('/refund') >= 0) {
  165. unicom.burypointLogId('110006'); // 退款
  166. } else {
  167. unicom.burypointLogId('110001'); // 订购页面pv, pv去重得到uv
  168. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'order_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  169. }
  170. }).fail(function() {
  171. compnt.hideLoading();
  172. })
  173. }
  174. function openPage(pageName) {
  175. switch (pageName) {
  176. case "active":
  177. showActivePage();
  178. break;
  179. case "cancel":
  180. showCancelPage();
  181. break;
  182. case "draw":
  183. weibo.getUserInfo().then(function() {
  184. document.getElementById('name').innerHTML = weibo.screen_name
  185. })
  186. showDrawPage();
  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. location.href.indexOf("weibo1.html") < 0) {
  423. window.location.href = "draw.html?fes=" + unicom.query.fes + "&sou=" +
  424. unicom.query.sou + "&F=" + unicom.query.F + '&page=draw';
  425. return;
  426. }
  427. var $container = $('#section-draw').find('.form-group');
  428. compnt.showLoading();
  429. unicom.queryMember(null, null, weibo.uid).then(function(response) {
  430. if (response.resultCode == "0000") {
  431. switch (response.sync_code) {
  432. case "0": // 订购关系退订同步成功
  433. case "2": // 订购关系订购同步成功
  434. localStorage.setItem("message", "当前微博账号已经领取了会员~");
  435. unicom.user.userid = response.userid;
  436. unicom.user.usermob = response.usermob;
  437. unicom.user.usertime = new Date().getTime();
  438. showFlowPage();
  439. break;
  440. }
  441. } else {
  442. unicom.can(weibo.uid).then(function(response) {
  443. compnt.hideLoading();
  444. var hasMonthVip = false;
  445. switch (response.resultCode) {
  446. case "0000":
  447. hasMonthVip = false;
  448. break;
  449. case "1003":
  450. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  451. hasMonthVip = true;
  452. break;
  453. default:
  454. compnt.showAlert(response.resultInfo);
  455. break;
  456. }
  457. $container.find('.sendcode').unbind('click').on('click', function() {
  458. if (!checkEquip()) return;
  459. if (hasMonthVip) {
  460. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  461. return;
  462. }
  463. unicom.sendSms($container, 'drawlogin');
  464. // unicom.sendSms($container, '210');
  465. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_click_send_sms_code_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  466. })
  467. $container.find('.login').unbind('click').on('click', function() {
  468. if (hasMonthVip) {
  469. compnt.showAlert('当前微博账号已开通了新浪微博包月会员,请切换领取会员的账号~');
  470. return;
  471. }
  472. unicom.checkCode($container).then(function() {
  473. draw()
  474. })
  475. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_click_confirm_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  476. })
  477. }).fail(function(error) {
  478. // alert(JSON.stringify(error))
  479. })
  480. }
  481. })
  482. }
  483. function draw() {
  484. var $dialog = showConfirmDialog();
  485. $dialog.find('.btn-no').on('click', function() {
  486. compnt.showAlert('请切换登录的微博账号后,再领取会员')
  487. })
  488. $dialog.find('.btn-ok').on('click', function(event) {
  489. if (!compnt.lockClick()) return;
  490. unicom.drawMember(weibo.uid, weibo.screen_name).then(function(response) {
  491. compnt.unlockClick();
  492. switch (response.resultCode) {
  493. case "0000":
  494. weibo.active(); // 领取成功,静默激活
  495. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_success' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  496. compnt.showAlert('微博会员领取成功!').then(function() {
  497. showFlowPage();
  498. });
  499. break;
  500. case "1020":
  501. // 已经领取,领取的账号与当前微博账号一致,静默激活
  502. unicom.queryMember().then(function(response) {
  503. if (response.resultCode == "0000") {
  504. if (response.uid == weibo.uid) {
  505. weibo.active();
  506. compnt.showAlert('已领取过会员~').then(function(message) {
  507. showFlowPage();
  508. });
  509. } else { // 领取到了其他微博账号
  510. compnt.showAlert('该手机号已将会员领取到其他微博账号~')
  511. }
  512. } else { // 查询失败
  513. compnt.showAlert('已领取过会员~');
  514. }
  515. }).fail(function() {
  516. // 查询失败
  517. compnt.showAlert('已领取过会员~');
  518. })
  519. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  520. break;
  521. default:
  522. compnt.showAlert('领取失败,' + response.errorInfo);
  523. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  524. break;
  525. }
  526. }).fail(function() {
  527. compnt.unlockClick();
  528. });
  529. })
  530. }
  531. /**
  532. * 打开激活免流的页面
  533. * 客户端中才能激活
  534. */
  535. function showActivePage() {
  536. if (location.href.indexOf("active.html") < 0) {
  537. window.location.href = "active.html?fes=" + unicom.query.fes + "&sou=" +
  538. unicom.query.sou + "&F=" + unicom.query.F + "&page=active";
  539. return;
  540. }
  541. var $container = $('#section-active').find('.form-group');
  542. $container.find('.sendcode').unbind('click').on('click', function() {
  543. if (!checkEquip('active')) return;
  544. unicom.sendSms($container, 'activelogin');
  545. //unicom.sendSms($container, '209');
  546. })
  547. $container.find('.login').unbind('click').on('click', function(event) {
  548. if (!checkEquip('active')) return;
  549. if (!compnt.lockClick()) {
  550. return;
  551. }
  552. unicom.checkCode($container).then(function() {
  553. compnt.unlockClick()
  554. active()
  555. }).fail(function() {
  556. compnt.unlockClick();
  557. });
  558. })
  559. window.scrollTo(0, 0)
  560. }
  561. function checkEquip(action) {
  562. if (action == 'active') {
  563. if (!weibo.app.weibo) {
  564. compnt.showAlert('请到新浪微博客户端中激活免流~')
  565. return false;
  566. }
  567. if (!weibo.checkWeiboVersion()) {
  568. compnt.showAlert('请到升级到最新版新浪微博客户端后激活免流~')
  569. return false;
  570. }
  571. } else {
  572. if (!weibo.app.weibo && !unicom.query.code) {
  573. compnt.showAlert('请到新浪微博客户端中领取会员激活免流~')
  574. return false;
  575. }
  576. if (!weibo.checkWeiboVersion() && !unicom.query.code) {
  577. compnt.showAlert('请到升级到最新版新浪微博客户端后领取会员激活免流~')
  578. return false;
  579. }
  580. }
  581. return true;
  582. }
  583. function active() {
  584. unicom.queryMember().then(function(response) {
  585. switch (response.resultCode) {
  586. case "0000":
  587. break;
  588. case "0002":
  589. compnt.showAlert('激活失败,未领取新浪微博会员~');
  590. return;
  591. default:
  592. compnt.showAlert('激活失败,未领取新浪微博会员~');
  593. return;
  594. }
  595. if (weibo.uid != response.uid) {
  596. compnt.showAlert('激活失败,激活免流的微博账号与领取会员的微博账号不一致~');
  597. return;
  598. }
  599. switch (response.sync_code) {
  600. case "0": // 订购关系退订同步成功
  601. case "2": // 订购关系订购同步成功
  602. weibo.active().then(function() {
  603. //checkActiveResult();
  604. compnt.showAlert('激活成功').then(function() {
  605. localStorage.setItem('user', JSON.stringify(unicom.user));
  606. localStorage.setItem('time', new Date().getTime());
  607. showFlowPage();
  608. });
  609. })
  610. break;
  611. case "1": // 订购关系退订同步失败
  612. case "3": // 订购关系订购同步失败
  613. compnt.showAlert("请领取会员以后再进行激活操作~");
  614. break;
  615. }
  616. });
  617. }
  618. /**
  619. * 打开订购页面
  620. */
  621. function showOrderPage() {
  622. $('.section-banner').removeClass('section-banner-small');
  623. $('#btn-order').unbind('click').on('click', function(event) {
  624. if (!compnt.lockClick()) {
  625. //alert(1)
  626. return;
  627. }
  628. unicom.showCapPage().then(function(data) {
  629. compnt.unlockClick();
  630. order(data.userid, data.token, data.usermob);
  631. }).fail(function(response) {
  632. compnt.unlockClick();
  633. })
  634. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_click_order_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  635. })
  636. }
  637. /**
  638. * 订购
  639. */
  640. function order(userid, token, usermob) {
  641. compnt.showLoading();
  642. unicom.order(userid, token, usermob).then(function(response) {
  643. // console.log(response)
  644. compnt.hideLoading();
  645. switch (response.resultCode) {
  646. case "0000": //订购成功!跳转到领取会员页面
  647. // compnt.showAlert('unicom.user.userid:' + unicom.user.userid)
  648. // var versionFulfil = weibo.checkWeiboVersion();
  649. // alert('checkWeiboVersion()' + versionFulfil);
  650. localStorage.setItem('user', JSON.stringify(unicom.user));
  651. localStorage.setItem('time', new Date().getTime());
  652. // 客户端中进入领取页面,非客户端中,提示用户到客户端中去领取
  653. if (weibo.app.weibo && weibo.checkWeiboVersion()) {
  654. // 如果有用户号码,直接打开领取会员二次确认的提示
  655. compnt.showAlert('订购成功~').then(function(message) {
  656. localStorage.setItem('action', 'draw');
  657. showFlowPage();
  658. });
  659. } else {
  660. compnt.showAlert('订购成功,请到新浪微博客户端中领取会员开启免流~').then(function() {
  661. showFlowPage();
  662. })
  663. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_success' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  664. return;
  665. }
  666. break;
  667. case "0013":
  668. showOrderDialog('该号码归属省分2/3G暂未开通此产品!');
  669. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  670. break;
  671. case "6611":
  672. showOrderDialog('错误代码(6611),' + '订购失败,请重试!');
  673. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  674. break;
  675. case "6615":
  676. showOrderDialog('订购失败,请确定用户套餐!');
  677. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  678. break;
  679. case "6622": // 用户已订购过此产品!跳转到流量查页面
  680. localStorage.setItem('message', '您已经订购了本产品~');
  681. localStorage.setItem('user', JSON.stringify(unicom.user));
  682. localStorage.setItem('time', new Date().getTime());
  683. showFlowPage();
  684. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  685. break;
  686. default:
  687. showOrderDialog(response.errorInfo + ',订购失败,请确定用户套餐!');
  688. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'order_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) });
  689. break;
  690. }
  691. }).fail(function(error) {});
  692. }
  693. function showOrderDialog(message) {
  694. var $overlay = $('<div class="overlay"></div>');
  695. var $dialog = $(
  696. '<div class="dialog dialog-order">' +
  697. ' <div class="face">' +
  698. ' <img src="images/face-sad.png">' +
  699. ' </div>' +
  700. ' <h2>对不起,订购失败!</h2>' +
  701. ' <p>' + message + '</p>' +
  702. ' <div class="btn">我知道了</div>' +
  703. '</div>');
  704. $overlay.appendTo($(document.body))
  705. $dialog.appendTo($(document.body))
  706. $dialog.find('.btn').unbind('click').on('click', function() {
  707. $dialog.close()
  708. })
  709. $dialog.close = function() {
  710. $overlay.remove();
  711. $dialog.remove();
  712. $dialog = null;
  713. }
  714. return $dialog;
  715. }
  716. function showConfirmDialog() {
  717. var message = '确认将新浪微博会员领取到您当前登录的账号中吗?';
  718. if (weibo.screen_name) {
  719. message = '请确认将新浪微博会员领取到账号:' + weibo.screen_name
  720. }
  721. var $overlay = $('<div class="overlay"></div>');
  722. var $dialog = $(
  723. '<div class="dialog dialog-confirm">' +
  724. ' <h2>领取会员</h2>' +
  725. ' <p>' + message + '</p>' +
  726. ' <div class="actions" style="display: flex;">' +
  727. ' <div class="btn btn-no">其他账号</div>' +
  728. ' <div class="btn btn-ok">确认</div>' +
  729. ' </div>' +
  730. '</div>');
  731. $overlay.appendTo($(document.body))
  732. $dialog.appendTo($(document.body))
  733. $dialog.find('.btn').on('click', function() {
  734. $dialog.close()
  735. })
  736. $dialog.close = function() {
  737. $overlay.remove();
  738. $dialog.remove();
  739. $dialog = null;
  740. }
  741. return $dialog;
  742. }