main.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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. //
  167. // window.location.href = backPage + "?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  168. // return;
  169. // }
  170. $('#major').unbind('click').on('click', function (event) {
  171. if (!compnt.lockClick()) {
  172. return;
  173. }
  174. // unicom.showCapPage(null, null, false, false, true).then(function (data) {
  175. unicom.showCapPage().then(function(data) {
  176. compnt.unlockClick();
  177. order(data.userid, data.token, data.usermob);
  178. }).fail(function(response) {
  179. compnt.unlockClick();
  180. })
  181. })
  182. }
  183. function showFlowPage() {
  184. if (location.href.indexOf("flow.html") < 0) {
  185. window.location.href = "flow.html?fes="
  186. + unicom.query.fes + "&sou=" + unicom.query.sou
  187. + "&userid=" + unicom.user.userid + "&usermob=" + unicom.user.usermob
  188. + "&usertime=" + (unicom.user.usertime||(new Date().getTime()));
  189. return;
  190. }
  191. var $container = $('.section-flow');
  192. var usermob = unicom.user.usermob;
  193. $container.find('.phone').html(usermob.substring(0,3) + 'xxxx' + usermob.substring(7,11));
  194. $container.find('.btn').unbind('click').on('click', function() {
  195. queryFlow().then(function(message) {
  196. compnt.unlockClick()
  197. if (message != null && message != "") {
  198. compnt.showAlert(message);
  199. }
  200. }).fail(function() {
  201. compnt.unlockClick();
  202. });
  203. })
  204. queryFlow();
  205. }
  206. function showActivePage() {
  207. if (location.href.indexOf("active.html") < 0) {
  208. window.location.href = "active.html?fes=" + unicom.query.fes + "&sou="
  209. + unicom.query.sou;
  210. return;
  211. }
  212. var $container = $('.section-login').find('.form-group');
  213. $container.find('.sendcode').unbind('click').on('click', function () {
  214. if (!checkEquip()) return;
  215. unicom.sendSms($container, 'activelogin');
  216. })
  217. $container.find('.login').unbind('click').on('click', function (event) {
  218. if (!checkEquip()) return;
  219. if (!compnt.lockClick()) {
  220. return;
  221. }
  222. unicom.checkCode($container).then(function() {
  223. compnt.unlockClick()
  224. active()
  225. }).fail(function() {
  226. compnt.unlockClick();
  227. });
  228. })
  229. window.scrollTo(0, 0)
  230. }
  231. function showCancelPage() {
  232. if (location.href.indexOf("cancel.html") < 0) {
  233. window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  234. return;
  235. }
  236. var $container = $('.section-login').find('.form-group');
  237. $container.find('.sendcode').unbind('click').on('click', function () {
  238. unicom.sendSms($container, 'cancellogin');
  239. })
  240. $container.find('.login').unbind('click').on('click', function () {
  241. compnt.showLoading();
  242. unicom.checkCode($container).done(function() {
  243. unicom.cancel().done(function(response) {
  244. compnt.hideLoading();
  245. switch (response.resultCode) {
  246. case "0000":
  247. compnt.showAlert('退订成功');
  248. break;
  249. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  250. compnt.showAlert(response.errorInfo);
  251. break;
  252. default:
  253. var prefix = '';
  254. if (response.errorInfo.indexOf('退订失败') < 0) {
  255. prefix = '退订失败,';
  256. }
  257. compnt.showAlert(prefix + response.errorInfo);
  258. break;
  259. }
  260. }).fail(function(data) {
  261. compnt.hideLoading();
  262. })
  263. }).fail(function(data) {
  264. compnt.hideLoading();
  265. })
  266. })
  267. window.scrollTo(0, 0)
  268. }
  269. function checkEquip() {
  270. /*if (!baidu.app.baidu) {
  271. compnt.showAlert('请到百度产品客户端中激活免流~')
  272. return false;
  273. }
  274. if (!baidu.checkWeiboVersion()) {
  275. compnt.showAlert('请到升级到最新版百度产品客户端后激活免流~')
  276. return false;
  277. }*/
  278. return true;
  279. }
  280. /**
  281. * 订购
  282. */
  283. function order(userid, token, usermob) {
  284. compnt.showLoading('处理中,请稍后...');
  285. unicom.order(userid, token, usermob).done(function(response) {
  286. compnt.hideLoading();
  287. switch (response.resultCode) {
  288. case "0000": //订购成功!跳转到领取会员页面
  289. unicom.saveUserInfo();
  290. compnt.showAlert('订购成功');
  291. return;
  292. case "0013":
  293. compnt.showAlert('该号码归属省分2/3G暂未开通此产品!');
  294. break;
  295. case "6611":
  296. compnt.showAlert('错误代码(6611),订购失败,请重试!');
  297. break;
  298. case "6615":
  299. compnt.showAlert('订购失败,请确定用户套餐!');
  300. break;
  301. case "6622": // 用户已订购过此产品!跳转到流量查页面
  302. compnt.showAlert('您已经订购了本产品~')
  303. unicom.saveUserInfo();
  304. break;
  305. default:
  306. compnt.showAlert(response.errorInfo + ',订购失败,请确定用户套餐!');
  307. break;
  308. }
  309. }).fail(function (error) {
  310. compnt.hideLoading();
  311. console.log(error);
  312. });
  313. }
  314. function showAlertDialog(action, message) {
  315. var className = '';
  316. switch (action) {
  317. case 'orderSuccess':
  318. className = 'dialog-message-order-success';
  319. break;
  320. case 'orderFailure':
  321. className = 'dialog-message-order-failure';
  322. break;
  323. case 'activeSuccess':
  324. className = 'dialog-message-active-success';
  325. break;
  326. case 'activeFailure':
  327. className = 'dialog-message-active-failure';
  328. break;
  329. case 'cancelSuccess':
  330. className = 'dialog-message-cancel-success';
  331. break;
  332. case 'cancelFailure':
  333. className = 'dialog-message-cancel-failure';
  334. break;
  335. default:
  336. break;
  337. }
  338. var $overlay = $('<div class="overlay"></div>');
  339. var $dialog = $(
  340. '<div class="dialog dialog-message ' + className + '">' +
  341. ' <div class="title"></div>' +
  342. ' <div class="content">' + message + '</div>' +
  343. ' <div class="actions">' +
  344. ' <div class="btn">确定</div>' +
  345. ' </div>' +
  346. '</div>');
  347. $overlay.appendTo($(document.body))
  348. $dialog.appendTo($(document.body))
  349. $dialog.find('.btn').unbind('click').on('click', function () {
  350. $dialog.close()
  351. })
  352. $dialog.close = function () {
  353. $overlay.remove();
  354. $dialog.remove();
  355. $dialog = null;
  356. }
  357. return $dialog;
  358. }
  359. /**
  360. * 查询用户剩余流量
  361. */
  362. function queryFlow() {
  363. var $container = $('.section-flow');
  364. //return new Promise(function(resolve, reject) {
  365. var def = $.Deferred();
  366. unicom.queryFlow().then(function(response) {
  367. // var response = JSON.parse(responseText);
  368. // console.log("流量剩余情况:" + response.data)
  369. switch (response.resultCode) {
  370. case "0000":
  371. //compnt.showAlert(JSON.stringify(response.data));
  372. //console.log(response.data)
  373. //console.log(JSON.parse(response.data).surplusFlow)
  374. var surplus = compnt.returnFloat(JSON.parse(response.data).surplusFlow/1024/1024);
  375. $container.find('.surplus').html(surplus + 'GB');
  376. var usedFlowKb = parseInt(JSON.parse(response.data).usedFlow);
  377. if (usedFlowKb > 0 && usedFlowKb < 1024) {
  378. def.resolve("剩余流量更新成功,为您免流了" + usedFlowKb + "KB~");
  379. } else if (usedFlowKb > 1024) {
  380. var useedFlow = compnt.returnFloat(usedFlowKb/1024);
  381. def.resolve("剩余流量更新成功,为您免流了" + useedFlow + "MB~");
  382. } else {
  383. def.resolve("剩余流量更新成功~");
  384. }
  385. break;
  386. case "9201": //{"resultCode":"9201","errorInfo":"查询失败,请检查是否有订购关系!"}
  387. def.resolve("您未订购百度定向流量包~")
  388. $container.find('.phone').html('用户未订购此产品!');
  389. break;
  390. case "9203": //{"resultCode":"9203","errorInfo":"流量查询失败,没有获取到用户所使用流量信息!"}
  391. //compnt.showAlert("没有获取到用户所使用流量信息!");
  392. def.resolve("剩余流量更新成功~")
  393. $container.find('.suplus').html('本月剩余<br>8.00GB');
  394. break;
  395. default:
  396. def.resolve("剩余流量更新成功~")
  397. break;
  398. }
  399. })
  400. return def;
  401. //})
  402. }
  403. function active() {
  404. baidu.active().then(function() {
  405. //checkActiveResult();
  406. compnt.showAlert('激活成功').then(function() {
  407. unicom.saveUserInfo()
  408. // showFlowPage();
  409. });
  410. })
  411. }
  412. $('.section-agr').find('.footer').on('click',function() {
  413. if ($($('.section-agr .scope').find('li')[2]).hasClass('hidden')) {
  414. $('.section-agr .scope').find('li').each(function(i, ele) {
  415. $(ele).removeClass('hidden');
  416. })
  417. $('.section-agr').find('.footer').html('隐藏<span class="arrow">&gt;');
  418. } else {
  419. $('.section-agr .scope').find('li').each(function(i, ele) {
  420. if (i >= 1) {
  421. $(ele).addClass('hidden');
  422. }
  423. })
  424. $('.section-agr').find('.footer').html('查看更多专属流量适用范围<span class="arrow">&gt;');
  425. }
  426. });
  427. function showConfirmDialog(account) {
  428. var $overlay = $('<div class="overlay"></div>')
  429. var $dialog = $(
  430. '<div class="dialog dialog-confirm">' +
  431. ' <div class="content">请确认是否领取抖音币到' + account + '账号?</div>' +
  432. ' <div class="actions">' +
  433. ' <div class="btn cancel">取消</div>' +
  434. ' <div class="btn okay">确认</div>' +
  435. ' </div>' +
  436. '</div>');
  437. $overlay.appendTo($(document.body))
  438. $dialog.appendTo($(document.body))
  439. $dialog.find('.btn').on('click', function () {
  440. $overlay.remove();
  441. $dialog.remove();
  442. $dialog = null;
  443. })
  444. $dialog.close = function () {
  445. $overlay.remove();
  446. $dialog.remove();
  447. $dialog = null;
  448. }
  449. return $dialog;
  450. }