main.js 15 KB

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