main.js 18 KB

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