main.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. import * as compnt from "../../../../public/js/compnt.js";
  2. import * as unicom from "../../../../public/js/unicom.js";
  3. import "../scss/main.scss";
  4. $(function () {
  5. var isPageHide = false;
  6. window.addEventListener('pageshow', function () {
  7. if (isPageHide) {
  8. window.location.reload();
  9. }
  10. });
  11. window.addEventListener('pagehide', function () {
  12. isPageHide = true;
  13. });
  14. if (window.location.href.indexOf('draw.html') >=0) {
  15. var user = JSON.parse(localStorage.getItem('user'));
  16. if (user != null) {
  17. $('.usermob').val(user.usermob);
  18. }
  19. }
  20. })
  21. init();
  22. function init() {
  23. var message = localStorage.getItem('message');
  24. if (message != null && message != '') {
  25. compnt.showAlert(message);
  26. localStorage.removeItem('message');
  27. }
  28. compnt.showLoading();
  29. unicom.init().then(function(response) {
  30. compnt.hideLoading();
  31. unicom.product = response.product[0];
  32. unicom.fesname = response.festival;
  33. unicom.loadUserInfo();
  34. if (location.href.indexOf("/index") >= 0) {
  35. showOrderPage();
  36. } else {
  37. openPage();
  38. }
  39. if (location.href.indexOf('/cancel') >= 0) {
  40. unicom.burypointLogId('110002');// 退订页面pv, pv去重得到uv
  41. } else if (location.href.indexOf('/draw') >= 0) {
  42. unicom.burypointLogId('110003');// 领取页面pv, pv去重得到uv
  43. } else if (location.href.indexOf('/flow') >= 0) {
  44. unicom.burypointLogId('110004');// 流量查询pv, pv去重得到uv
  45. } else if (location.href.indexOf('/active') >= 0) {
  46. unicom.burypointLogId('110005');// 激活页面pv, pv去重得到uv
  47. } else if (location.href.indexOf('/refund') >= 0) {
  48. unicom.burypointLogId('110006');// 退款
  49. } else {
  50. // location.href.indexOf('/index') >= 0
  51. // location.href.indexOf('/order') >= 0
  52. unicom.burypointLogId('110001');// 订购页面pv, pv去重得到uv
  53. }
  54. })
  55. }
  56. function openPage(pageName) {
  57. switch (pageName) {
  58. case "active":
  59. showActivePage();
  60. break;
  61. case "cancel":
  62. showCancelPage();
  63. break;
  64. case "draw":
  65. showDrawPage();
  66. break;
  67. case "flow":
  68. showFlowPage();
  69. break;
  70. default:
  71. showOrderPage();
  72. break;
  73. }
  74. }
  75. $('#btn-cancel').unbind('click').on('click', function () {
  76. showCancelPage();
  77. })
  78. $('#btn-active').unbind('click').on('click', function () {
  79. showActivePage();
  80. })
  81. $('#gotoDrawPage').unbind('click').on('click', function () {
  82. showDrawPage(window.location.href.substring(window.location.href.lastIndexOf('/')+1,window.location.href.lastIndexOf('.')))
  83. })
  84. function showDrawPage(back) {
  85. if (location.href.indexOf("draw.html") < 0) {
  86. window.location.href = "draw.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou + '&back=' + (back == null ? '' : back);
  87. return;
  88. }
  89. var $container = $('.section-login').find('.form-group');
  90. $container.find('.sendcode').unbind('click').on('click', function () {
  91. unicom.sendSms($container, 'drawlogin');
  92. })
  93. $container.find('.login').unbind('click').on('click', function() {
  94. var usermob = $container.find('.usermob').val();
  95. var account = $container.find('.account').val();
  96. var smscode = $container.find('.smscode').val();
  97. if (usermob == null || usermob == "") {
  98. compnt.showAlert('请输入联通手机号');
  99. return;
  100. }
  101. if (account == null || account == "") {
  102. compnt.showAlert('请输入抖音短视频账号');
  103. return;
  104. }
  105. if (smscode == null || smscode == "") {
  106. compnt.showAlert('请输入验证码');
  107. return;
  108. }
  109. var $comfirm = showConfirmDialog(account);
  110. $comfirm.find('.cancel').on('click', function() {
  111. compnt.hideLoading();
  112. });
  113. $comfirm.find('.okay').on('click', function() {
  114. unicom.checkCode($container, true).done(function() {
  115. /*unicom.canDrawCoin(account).then(function (response) {
  116. if (response.resultCode != "0000") {
  117. compnt.hideLoading();
  118. compnt.showAlert(response.errorInfo);
  119. return;
  120. }
  121. drawCoin(account)
  122. })*/
  123. drawCoin(account);
  124. }).fail(function(data) {
  125. compnt.hideLoading();
  126. })
  127. });
  128. })
  129. }
  130. function drawCoin(account) {
  131. compnt.showLoading();
  132. unicom.drawCoin(account, '').done(function(response) {
  133. compnt.hideLoading();
  134. switch (response.resultCode) {
  135. case "0000":
  136. var $container = $('.section-login').find('.form-group');
  137. $container.find('.usermob').val('');
  138. $container.find('.smscode').val('');
  139. $container.find('.account').val('');
  140. compnt.showAlert('抖币充值中,详情结果以短信形式告知').then(function() {
  141. if (unicom.query.back != null && unicom.query.back != '') {
  142. showOrderPage(unicom.query.back + ".html");
  143. }
  144. });
  145. break;
  146. case "7605":
  147. compnt.showAlert(response.errorInfo);
  148. break;
  149. default:
  150. var prefix = '';
  151. if (response.errorInfo.indexOf('领取失败') < 0) {
  152. prefix = '领取失败,';
  153. }
  154. compnt.showAlert(prefix + response.errorInfo);
  155. break;
  156. }
  157. }).fail(function(data) {
  158. compnt.hideLoading();
  159. })
  160. }
  161. function showOrderPage(backPage) {
  162. if (location.href.indexOf('/index') < 0) {
  163. if (backPage == null || backPage == '') {
  164. backPage = 'order.html';
  165. }
  166. window.location.href = backPage + "?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  167. return;
  168. }
  169. $('#btn-order').unbind('click').on('click', function (event) {
  170. if (!compnt.lockClick()) {
  171. return;
  172. }
  173. unicom.showCapPage(null, null, false, false, true).then(function (data) {
  174. compnt.unlockClick();
  175. order(data.userid, data.token, data.usermob);
  176. }).fail(function(response) {
  177. compnt.unlockClick();
  178. })
  179. })
  180. }
  181. function showFlowPage() {
  182. if (location.href.indexOf("flow.html") < 0) {
  183. window.location.href = "flow.html?fes="
  184. + unicom.query.fes + "&sou=" + unicom.query.sou
  185. + "&userid=" + unicom.user.userid + "&usermob=" + unicom.user.usermob
  186. + "&usertime=" + (unicom.user.usertime||(new Date().getTime()));
  187. return;
  188. }
  189. var $container = $('.section-flow');
  190. var usermob = unicom.user.usermob;
  191. $container.find('.phone').html(usermob.substring(0,3) + 'xxxx' + usermob.substring(7,11));
  192. $container.find('.btn').unbind('click').on('click', function() {
  193. queryFlow().then(function(message) {
  194. compnt.unlockClick()
  195. if (message != null && message != "") {
  196. compnt.showAlert(message);
  197. }
  198. }).fail(function() {
  199. compnt.unlockClick();
  200. });
  201. })
  202. queryFlow();
  203. }
  204. function showActivePage() {
  205. if (location.href.indexOf("active.html") < 0) {
  206. window.location.href = "active.html?fes=" + unicom.query.fes + "&sou="
  207. + unicom.query.sou;
  208. return;
  209. }
  210. var $container = $('.section-login').find('.form-group');
  211. $container.find('.sendcode').unbind('click').on('click', function () {
  212. if (!checkEquip()) return;
  213. unicom.sendSms($container, 'activelogin');
  214. })
  215. $container.find('.login').unbind('click').on('click', function (event) {
  216. if (!checkEquip()) return;
  217. if (!compnt.lockClick()) {
  218. return;
  219. }
  220. unicom.checkCode($container).then(function() {
  221. compnt.unlockClick()
  222. active()
  223. }).fail(function() {
  224. compnt.unlockClick();
  225. });
  226. })
  227. window.scrollTo(0, 0)
  228. }
  229. function showCancelPage() {
  230. if (location.href.indexOf("cancel.html") < 0) {
  231. window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  232. return;
  233. }
  234. var $container = $('.section-login').find('.form-group');
  235. $container.find('.sendcode').unbind('click').on('click', function () {
  236. unicom.sendSms($container, 'cancellogin');
  237. })
  238. $container.find('.login').unbind('click').on('click', function () {
  239. compnt.showLoading();
  240. unicom.checkCode($container).done(function() {
  241. unicom.cancel().done(function(response) {
  242. compnt.hideLoading();
  243. switch (response.resultCode) {
  244. case "0000":
  245. compnt.showAlert('退订成功');
  246. break;
  247. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  248. compnt.showAlert(response.errorInfo);
  249. break;
  250. default:
  251. var prefix = '';
  252. if (response.errorInfo.indexOf('退订失败') < 0) {
  253. prefix = '退订失败,';
  254. }
  255. compnt.showAlert(prefix + response.errorInfo);
  256. break;
  257. }
  258. }).fail(function(data) {
  259. compnt.hideLoading();
  260. })
  261. }).fail(function(data) {
  262. compnt.hideLoading();
  263. })
  264. })
  265. window.scrollTo(0, 0)
  266. }
  267. function checkEquip() {
  268. /*if (!baidu.app.baidu) {
  269. compnt.showAlert('请到百度产品客户端中激活免流~')
  270. return false;
  271. }
  272. if (!baidu.checkWeiboVersion()) {
  273. compnt.showAlert('请到升级到最新版百度产品客户端后激活免流~')
  274. return false;
  275. }*/
  276. return true;
  277. }
  278. /**
  279. * 订购
  280. */
  281. function order(userid, token, usermob) {
  282. compnt.showLoading('处理中,请稍后...');
  283. unicom.order(userid, token, usermob).done(function(response) {
  284. compnt.hideLoading();
  285. switch (response.resultCode) {
  286. case "0000": //订购成功!跳转到领取会员页面
  287. unicom.saveUserInfo();
  288. compnt.showAlert('订购成功');
  289. return;
  290. case "0013":
  291. compnt.showAlert('该号码归属省分2/3G暂未开通此产品!');
  292. break;
  293. case "6611":
  294. compnt.showAlert('错误代码(6611),订购失败,请重试!');
  295. break;
  296. case "6615":
  297. compnt.showAlert('订购失败,请确定用户套餐!');
  298. break;
  299. case "6622": // 用户已订购过此产品!跳转到流量查页面
  300. compnt.showAlert('您已经订购了本产品~')
  301. unicom.saveUserInfo();
  302. break;
  303. default:
  304. compnt.showAlert(response.errorInfo + ',订购失败,请确定用户套餐!');
  305. break;
  306. }
  307. }).fail(function (error) {
  308. compnt.hideLoading();
  309. console.log(error);
  310. });
  311. }
  312. function showAlertDialog(action, message) {
  313. var className = '';
  314. switch (action) {
  315. case 'orderSuccess':
  316. className = 'dialog-message-order-success';
  317. break;
  318. case 'orderFailure':
  319. className = 'dialog-message-order-failure';
  320. break;
  321. case 'activeSuccess':
  322. className = 'dialog-message-active-success';
  323. break;
  324. case 'activeFailure':
  325. className = 'dialog-message-active-failure';
  326. break;
  327. case 'cancelSuccess':
  328. className = 'dialog-message-cancel-success';
  329. break;
  330. case 'cancelFailure':
  331. className = 'dialog-message-cancel-failure';
  332. break;
  333. default:
  334. break;
  335. }
  336. var $overlay = $('<div class="overlay"></div>');
  337. var $dialog = $(
  338. '<div class="dialog dialog-message ' + className + '">' +
  339. ' <div class="title"></div>' +
  340. ' <div class="content">' + message + '</div>' +
  341. ' <div class="actions">' +
  342. ' <div class="btn">确定</div>' +
  343. ' </div>' +
  344. '</div>');
  345. $overlay.appendTo($(document.body))
  346. $dialog.appendTo($(document.body))
  347. $dialog.find('.btn').unbind('click').on('click', function () {
  348. $dialog.close()
  349. })
  350. $dialog.close = function () {
  351. $overlay.remove();
  352. $dialog.remove();
  353. $dialog = null;
  354. }
  355. return $dialog;
  356. }
  357. /**
  358. * 查询用户剩余流量
  359. */
  360. function queryFlow() {
  361. var $container = $('.section-flow');
  362. //return new Promise(function(resolve, reject) {
  363. var def = $.Deferred();
  364. unicom.queryFlow().then(function(response) {
  365. // var response = JSON.parse(responseText);
  366. // console.log("流量剩余情况:" + response.data)
  367. switch (response.resultCode) {
  368. case "0000":
  369. //compnt.showAlert(JSON.stringify(response.data));
  370. //console.log(response.data)
  371. //console.log(JSON.parse(response.data).surplusFlow)
  372. var surplus = compnt.returnFloat(JSON.parse(response.data).surplusFlow/1024/1024);
  373. $container.find('.surplus').html(surplus + 'GB');
  374. var usedFlowKb = parseInt(JSON.parse(response.data).usedFlow);
  375. if (usedFlowKb > 0 && usedFlowKb < 1024) {
  376. def.resolve("剩余流量更新成功,为您免流了" + usedFlowKb + "KB~");
  377. } else if (usedFlowKb > 1024) {
  378. var useedFlow = compnt.returnFloat(usedFlowKb/1024);
  379. def.resolve("剩余流量更新成功,为您免流了" + useedFlow + "MB~");
  380. } else {
  381. def.resolve("剩余流量更新成功~");
  382. }
  383. break;
  384. case "9201": //{"resultCode":"9201","errorInfo":"查询失败,请检查是否有订购关系!"}
  385. def.resolve("您未订购百度定向流量包~")
  386. $container.find('.phone').html('用户未订购此产品!');
  387. break;
  388. case "9203": //{"resultCode":"9203","errorInfo":"流量查询失败,没有获取到用户所使用流量信息!"}
  389. //compnt.showAlert("没有获取到用户所使用流量信息!");
  390. def.resolve("剩余流量更新成功~")
  391. $container.find('.suplus').html('本月剩余<br>8.00GB');
  392. break;
  393. default:
  394. def.resolve("剩余流量更新成功~")
  395. break;
  396. }
  397. })
  398. return def;
  399. //})
  400. }
  401. function active() {
  402. baidu.active().then(function() {
  403. //checkActiveResult();
  404. compnt.showAlert('激活成功').then(function() {
  405. unicom.saveUserInfo()
  406. // showFlowPage();
  407. });
  408. })
  409. }
  410. $('.section-agr').find('.footer').on('click',function() {
  411. if ($($('.section-agr .scope').find('li')[2]).hasClass('hidden')) {
  412. $('.section-agr .scope').find('li').each(function(i, ele) {
  413. $(ele).removeClass('hidden');
  414. })
  415. $('.section-agr').find('.footer').html('隐藏<span class="arrow">&gt;');
  416. } else {
  417. $('.section-agr .scope').find('li').each(function(i, ele) {
  418. if (i >= 1) {
  419. $(ele).addClass('hidden');
  420. }
  421. })
  422. $('.section-agr').find('.footer').html('查看更多专属流量适用范围<span class="arrow">&gt;');
  423. }
  424. });
  425. function showConfirmDialog(account) {
  426. var $overlay = $('<div class="overlay"></div>')
  427. var $dialog = $(
  428. '<div class="dialog dialog-confirm">' +
  429. ' <div class="content">请确认是否领取抖音币到' + account + '账号?</div>' +
  430. ' <div class="actions">' +
  431. ' <div class="btn cancel">取消</div>' +
  432. ' <div class="btn okay">确认</div>' +
  433. ' </div>' +
  434. '</div>');
  435. $overlay.appendTo($(document.body))
  436. $dialog.appendTo($(document.body))
  437. $dialog.find('.btn').on('click', function () {
  438. $overlay.remove();
  439. $dialog.remove();
  440. $dialog = null;
  441. })
  442. $dialog.close = function () {
  443. $overlay.remove();
  444. $dialog.remove();
  445. $dialog = null;
  446. }
  447. return $dialog;
  448. }