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