main.js 20 KB

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