main.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. import * as compnt from "../../../../public/js/compnt.js";
  2. import * as unicom from "../../../../public/js/unicom.js";
  3. import "../scss/main.scss";
  4. var flowproductid = "2018072301"
  5. var rightsproductid = "2020010201"
  6. // 返回时强制手机刷新
  7. $(function() {
  8. var isPageHide = false;
  9. window.addEventListener('pageshow', function() {
  10. if (isPageHide) {
  11. window.location.reload();
  12. }
  13. });
  14. window.addEventListener('pagehide', function() {
  15. isPageHide = true;
  16. });
  17. if (window.location.href.indexOf('draw.html') >= 0) {
  18. var user = JSON.parse(localStorage.getItem('user'));
  19. if (user != null) {
  20. $('.usermob').val(user.usermob);
  21. }
  22. }
  23. })
  24. init();
  25. function init() {
  26. var message = localStorage.getItem('message');
  27. if (message != null && message != '') {
  28. compnt.showAlert(message);
  29. localStorage.removeItem('message');
  30. }
  31. compnt.showLoading();
  32. unicom.init().then(function(response) {
  33. compnt.hideLoading();
  34. unicom.loadUserInfo();
  35. if (location.href.indexOf("/index") >= 0) {
  36. var pid = localStorage.getItem('pid');
  37. var pidtime = localStorage.getItem('pidtime')
  38. var currproduct = flowproductid;
  39. // 设置选择的产品
  40. if (pidtime != null && new Date().getTime() - pidtime < 1000 * 60 * 2 &&
  41. unicom.products[pid] != null) {
  42. currproduct = pid;
  43. }
  44. orderPageProductChange(currproduct)
  45. showOrderPage();
  46. } else {
  47. openPage();
  48. }
  49. if (location.href.indexOf('/cancel') >= 0) {
  50. unicom.burypointLogId('110002'); // 退订页面pv, pv去重得到uv
  51. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'cancel_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  52. } else if (location.href.indexOf('/draw') >= 0) {
  53. unicom.burypointLogId('110003'); // 领取页面pv, pv去重得到uv
  54. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'draw_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  55. } else if (location.href.indexOf('/flow') >= 0) {
  56. unicom.burypointLogId('110004'); // 流量查询pv, pv去重得到uv
  57. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'flow_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  58. } else if (location.href.indexOf('/active') >= 0) {
  59. unicom.burypointLogId('110005'); // 激活页面pv, pv去重得到uv
  60. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'active_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  61. } else if (location.href.indexOf('/refund') >= 0) {
  62. unicom.burypointLogId('110006'); // 退款
  63. } else {
  64. // location.href.indexOf('/index') >= 0
  65. // location.href.indexOf('/order') >= 0
  66. unicom.burypointLogId('110001'); // 订购页面pv, pv去重得到uv
  67. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'open', ea: 'order_open' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  68. }
  69. })
  70. }
  71. function openPage(pageName) {
  72. if (pageName == null) {
  73. if (location.href.indexOf("/index") >= 0) pageName = "order";
  74. if (location.href.indexOf("cancel.html") >= 0) pageName = "cancel";
  75. if (location.href.indexOf("draw.html") >= 0) pageName = "draw";
  76. if (location.href.indexOf("active.html") >= 0) pageName = "active";
  77. if (location.href.indexOf("flow.html") >= 0) pageName = "flow";
  78. }
  79. switch (pageName) {
  80. case "cancel":
  81. showCancelPage();
  82. break;
  83. case "draw":
  84. showDrawPage();
  85. break;
  86. default:
  87. showOrderPage();
  88. break;
  89. }
  90. orderPageProductChange(unicom.query.pid)
  91. }
  92. // 意外惊喜, 用标签+name 属性,在iphone6,7中会报错
  93. //$('a[name="gotoCancelPage"').each(function(i, item) {
  94. $('.gotoCancelPage').each(function(i, item) {
  95. $(item).unbind('click').on('click', function() {
  96. showCancelPage()
  97. })
  98. })
  99. $('#gotoDrawPage').unbind('click').on('click', function() {
  100. showDrawPage(window.location.href.substring(window.location.href.lastIndexOf('/') + 1, window.location.href.lastIndexOf('.')))
  101. })
  102. function showOrderPage(backPage) {
  103. if (location.href.indexOf('/index') < 0) {
  104. if (backPage == null || backPage == '') {
  105. backPage = 'index.html';
  106. }
  107. window.location.href = backPage + "?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  108. return;
  109. }
  110. $('#btn-order').unbind('click').on('click', function(event) {
  111. if (!compnt.lockClick()) {
  112. return;
  113. }
  114. unicom.showCapPage(null, null, false, false, true).then(function(data) {
  115. compnt.unlockClick();
  116. order(data.userid, data.token, data.usermob);
  117. }).fail(function(response) {
  118. compnt.unlockClick();
  119. })
  120. })
  121. }
  122. function showDrawPage(back) {
  123. if (location.href.indexOf("draw.html") < 0) {
  124. window.location.href = "draw.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou + '&back=' + (back == null ? '' : back) + '&pid=' + unicom.product.productid;
  125. return;
  126. }
  127. unicom.product = unicom.products[rightsproductid];
  128. var $container = $('.section-login').find('.form-group');
  129. $container.find('.sendcode').unbind('click').on('click', function() {
  130. unicom.sendSms($container, 'drawlogin', unicom.products[rightsproductid]);
  131. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_click_send_sms_code_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  132. })
  133. $container.find('.login').unbind('click').on('click', function() {
  134. var usermob = $container.find('.usermob').val();
  135. var account = $container.find('.account').val();
  136. var smscode = $container.find('.smscode').val();
  137. if (usermob == null || usermob == "") {
  138. compnt.showAlert('请输入联通手机号');
  139. return;
  140. }
  141. if (account == null || account == "") {
  142. compnt.showAlert('请输入抖音短视频账号');
  143. return;
  144. }
  145. if (smscode == null || smscode == "") {
  146. compnt.showAlert('请输入验证码');
  147. return;
  148. }
  149. var $comfirm = showConfirmDialog(account);
  150. $comfirm.find('.cancel').on('click', function() {
  151. compnt.hideLoading();
  152. });
  153. $comfirm.find('.okay').on('click', function() {
  154. unicom.checkCode($container, true).done(function() {
  155. drawCoin(account);
  156. }).fail(function(data) {
  157. compnt.hideLoading();
  158. })
  159. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_click_confirm_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  160. });
  161. })
  162. }
  163. function drawCoin(account) {
  164. compnt.showLoading();
  165. unicom.drawCoin(account, '').done(function(response) {
  166. compnt.hideLoading();
  167. switch (response.resultCode) {
  168. case "0000":
  169. var $container = $('.section-login').find('.form-group');
  170. $container.find('.usermob').val('');
  171. $container.find('.smscode').val('');
  172. $container.find('.account').val('');
  173. showAlertDialog('抖币充值中,详情结果以短信形式告知').then(function() {
  174. if (unicom.query.back != null && unicom.query.back != '') {
  175. showOrderPage(unicom.query.back + ".html");
  176. }
  177. });
  178. break;
  179. case "7605":
  180. showAlertDialog(response.errorInfo);
  181. break;
  182. default:
  183. var prefix = '';
  184. if (response.errorInfo.indexOf('领取失败') < 0) {
  185. prefix = '领取失败,';
  186. }
  187. showAlertDialog(prefix + response.errorInfo);
  188. break;
  189. }
  190. }).fail(function(data) {
  191. compnt.hideLoading();
  192. })
  193. }
  194. function showCancelPage() {
  195. if (location.href.indexOf("cancel.html") < 0) {
  196. window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou + '&pid=' + unicom.product.productid;
  197. return;
  198. }
  199. var $container = $('.section-login').find('.form-group');
  200. $container.find('.sendcode').unbind('click').on('click', function() {
  201. unicom.sendSms($container, 'cancellogin');
  202. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'draw_click_send_sms_code_btn' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  203. })
  204. $container.find('.login').unbind('click').on('click', function() {
  205. compnt.showLoading();
  206. unicom.checkCode($container).done(function() {
  207. unicom.cancel().done(function(response) {
  208. compnt.hideLoading();
  209. switch (response.resultCode) {
  210. case "0000":
  211. showAlertDialog('退订成功!');
  212. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_success' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  213. break;
  214. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  215. showAlertDialog(response.errorInfo); //.then(function(message) {
  216. //showFlowPage();
  217. //});
  218. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  219. break;
  220. default:
  221. var prefix = '';
  222. if (response.errorInfo.indexOf('退订失败') < 0) {
  223. prefix = '退订失败,';
  224. }
  225. showAlertDialog(prefix + response.errorInfo);
  226. WoAnalytics.addPoint({ ad: $('#nanyanad').val(), ett: 'click', ea: 'cancel_failure' + $('#nanyanlabel').val(), ct: 'web', pm: parseInt(unicom.query.sou, 32) })
  227. break;
  228. }
  229. }).fail(function(data) {
  230. compnt.hideLoading();
  231. })
  232. }).fail(function(data) {
  233. compnt.hideLoading();
  234. })
  235. })
  236. window.scrollTo(0, 0)
  237. }
  238. $(".product-slider").delegate(".item-9", "click", function() {
  239. orderPageProductChange(flowproductid)
  240. });
  241. $(".product-slider").delegate(".item-15", "click", function() {
  242. orderPageProductChange(rightsproductid)
  243. });
  244. function orderPageProductChange(productid) {
  245. if (unicom.products[productid] == null) {
  246. return;
  247. }
  248. unicom.product = unicom.products[productid];
  249. if (productid == flowproductid) {
  250. $('body').addClass('body-9')
  251. $('.banner-text').addClass('banner-text-9')
  252. } else {
  253. $('body').removeClass('body-9')
  254. $('.banner-text').removeClass('banner-text-9')
  255. }
  256. if (window.location.href.indexOf('/index') >= 0) {
  257. // 记录当前选择的是哪个产品,等从退订页面返回到订购页面的时候,还能选择同样的产品
  258. localStorage.setItem('pid', productid);
  259. localStorage.setItem('pidtime', new Date().getTime())
  260. if (productid == flowproductid) {
  261. $('body').addClass('body-9');
  262. $('.banner-text').addClass('banner-text-9');
  263. $('.item-15').addClass('item-15-inactive');
  264. $('.item-9').removeClass('item-9-inactive');
  265. $('.agr-15').css({ 'display': 'none' });
  266. $('.agr-9').css({ 'display': 'block' });
  267. } else {
  268. $('body').removeClass('body-9');
  269. $('.banner-text').removeClass('banner-text-9');
  270. $('.item-15').removeClass('item-15-inactive');
  271. $('.item-9').addClass('item-9-inactive');
  272. $('.agr-15').css({ 'display': 'block' });
  273. $('.agr-9').css({ 'display': 'none' });
  274. }
  275. } else if (window.location.href.indexOf('cancel.html') >= 0) {
  276. if (productid == flowproductid) {
  277. $('.agr-15').css({ 'display': 'none' });
  278. $('.agr-9').css({ 'display': 'block' });
  279. } else {
  280. $('.agr-15').css({ 'display': 'block' });
  281. $('.agr-9').css({ 'display': 'none' });
  282. }
  283. }
  284. }
  285. function showConfirmDialog(account) {
  286. var $overlay = $('<div class="overlay"></div>')
  287. var $dialog = $(
  288. '<div class="dialog dialog-confirm">' +
  289. ' <div class="content">请确认是否领取抖音币到' + account + '账号?</div>' +
  290. ' <div class="actions">' +
  291. ' <div class="btn cancel">取消</div>' +
  292. ' <div class="btn okay">确认</div>' +
  293. ' </div>' +
  294. '</div>');
  295. $overlay.appendTo($(document.body))
  296. $dialog.appendTo($(document.body))
  297. $dialog.find('.btn').on('click', function() {
  298. $overlay.remove();
  299. $dialog.remove();
  300. $dialog = null;
  301. })
  302. $dialog.close = function() {
  303. $overlay.remove();
  304. $dialog.remove();
  305. $dialog = null;
  306. }
  307. return $dialog;
  308. }
  309. /**
  310. * 订购
  311. */
  312. function order(userid, token, usermob) {
  313. compnt.showLoading('处理中,请稍后...');
  314. unicom.order(userid, token, usermob).done(function(response) {
  315. compnt.hideLoading();
  316. switch (response.resultCode) {
  317. case "0000": //订购成功!跳转到领取会员页面
  318. unicom.saveUserInfo();
  319. showAlertDialog('订购成功!');
  320. return;
  321. case "0013":
  322. showAlertDialog('该号码归属省分2/3G暂未开通此产品!');
  323. break;
  324. case "6611":
  325. showAlertDialog('错误代码(6611),订购失败,请重试!');
  326. break;
  327. case "6615":
  328. showAlertDialog('订购失败,请确定用户套餐!');
  329. break;
  330. case "6622": // 用户已订购过此产品!跳转到流量查页面
  331. showAlertDialog('您已经订购了本产品~')
  332. unicom.saveUserInfo();
  333. break;
  334. default:
  335. showAlertDialog(response.errorInfo + ',订购失败,请确定用户套餐!');
  336. break;
  337. }
  338. }).fail(function(error) {
  339. compnt.hideLoading();
  340. console.log(error);
  341. });
  342. }
  343. function showAlertDialog(message) {
  344. var $overlay = $('<div class="overlay"></div>');
  345. var $dialog = $(
  346. '<div class="dialog dialog-message">' +
  347. ' <div class="content">' + message + '</div>' +
  348. ' <div class="actions">' +
  349. ' <div class="btn"></div>' +
  350. ' </div>' +
  351. '</div>');
  352. $overlay.appendTo($(document.body))
  353. $dialog.appendTo($(document.body))
  354. $("body").css("overflow", "hidden");
  355. $dialog.find('.btn').unbind('click').on('click', function() {
  356. $dialog.close()
  357. })
  358. var def = $.Deferred();
  359. $dialog.close = function() {
  360. $overlay.remove();
  361. $dialog.remove();
  362. $dialog = null;
  363. $("body").css("overflow", "auto");
  364. def.resolve($dialog);
  365. }
  366. return def;
  367. }
  368. /*$("body").on("touchstart", function(e) {
  369. // 判断默认行为是否可以被禁用
  370. // iphone 6, 7中不能滑动,判断 touchstart 未失效
  371. if (e.cancelable) {
  372. // 判断默认行为是否已经被禁用
  373. if (!e.defaultPrevented) {
  374. e.preventDefault();
  375. }
  376. }
  377. });*/
  378. var startX = 0;
  379. var startY = 0;
  380. var endX = 0;
  381. var endY = 0;
  382. $('.slider').unbind('touchstart').on('touchstart', function(event) {
  383. var touch = event.targetTouches[0];
  384. startX = touch.pageX;
  385. startY = touch.pageY;
  386. })
  387. $('.slider').unbind('touchmove').on('touchmove', function(event) {
  388. var touch = event.targetTouches[0];
  389. endX = touch.pageX;
  390. endY = touch.pageY;
  391. })
  392. $('.slider').unbind('touchend').on('touchend', function(event) {
  393. if (endX - startX >= 100) {
  394. orderPageProductChange(rightsproductid)
  395. } else if (startX - endX >= 100) {
  396. orderPageProductChange(flowproductid)
  397. }
  398. })