main.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 douyinProductId = "2018072301";
  5. var douyinPreProductId = "2020031101";
  6. var baiduProductId = "2020021201";
  7. var baiduPreProductId = "2020071301";
  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. showDialogMessage(message);
  30. localStorage.removeItem('message');
  31. }
  32. compnt.showLoading();
  33. unicom.init().then(function(response) {
  34. compnt.hideLoading();
  35. unicom.product = unicom.products[douyinProductId];
  36. unicom.fesname = response.festival;
  37. unicom.loadUserInfo();
  38. if (location.href.indexOf("index.html") >= 0) {
  39. showOrderPage();
  40. } else {
  41. openPage();
  42. }
  43. if (location.href.indexOf('/cancel') >= 0) {
  44. unicom.burypointLogId('110002');// 退订页面pv, pv去重得到uv
  45. } else if (location.href.indexOf('/draw') >= 0) {
  46. unicom.burypointLogId('110003');// 领取页面pv, pv去重得到uv
  47. } else if (location.href.indexOf('/flow') >= 0) {
  48. unicom.burypointLogId('110004');// 流量查询pv, pv去重得到uv
  49. } else if (location.href.indexOf('/active') >= 0) {
  50. unicom.burypointLogId('110005');// 激活页面pv, pv去重得到uv
  51. } else if (location.href.indexOf('/refund') >= 0) {
  52. unicom.burypointLogId('110006');// 退款
  53. } else {
  54. // location.href.indexOf('/index') >= 0
  55. // location.href.indexOf('/order') >= 0
  56. unicom.burypointLogId('110001');// 订购页面pv, pv去重得到uv
  57. }
  58. })
  59. }
  60. function openPage(pageName) {
  61. if (pageName == null) {
  62. if (location.href.indexOf("index.html") >= 0) pageName = "order";
  63. if (location.href.indexOf("cancel.html") >= 0) pageName = "cancel";
  64. }
  65. switch (pageName) {
  66. case "cancel":
  67. showCancelPage();
  68. break;
  69. default:
  70. showOrderPage();
  71. break;
  72. }
  73. }
  74. $('#gotoCancel').unbind('click').on('click', function () {
  75. if ($douyinItem.hasClass('active')) {
  76. unicom.product = unicom.products[douyinProductId];
  77. } else {
  78. unicom.product = unicom.products[baiduProductId];
  79. }
  80. showCancelPage(unicom.product.productid);
  81. })
  82. $('.more .text').unbind('click').on('click', function() {
  83. showDialogAgr()
  84. })
  85. var $douyinItem = $($('.products').find('.item')[0]);
  86. var $baiduItem = $($('.products').find('.item')[1]);
  87. $douyinItem.unbind('click').on('click', function(e) {
  88. $douyinItem.addClass('active');
  89. $baiduItem.removeClass('active');
  90. unicom.product = unicom.products[douyinProductId];
  91. // console.log(unicom.product);
  92. })
  93. $baiduItem.unbind('click').on('click', function() {
  94. $douyinItem.removeClass('active');
  95. $baiduItem.addClass('active');
  96. unicom.product = unicom.products[baiduProductId];
  97. // console.log(unicom.product);
  98. })
  99. function showOrderPage(backPage) {
  100. if (location.href.indexOf('index.html') < 0 && location.href.indexOf('15/20200') < 0) {
  101. if (backPage == null || backPage == '') {
  102. backPage = 'index.html';
  103. }
  104. window.location.href = backPage + "?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  105. return;
  106. }
  107. $('#btn-order').unbind('click').on('click', function (event) {
  108. if (!compnt.lockClick()) {
  109. return;
  110. }
  111. if ($douyinItem.hasClass('active')) {
  112. unicom.product = unicom.products[douyinProductId];
  113. } else {
  114. unicom.product = unicom.products[baiduProductId];
  115. }
  116. unicom.showCapPage(null, null, false, false, true, null).then(function (data) {
  117. compnt.unlockClick();
  118. order(data.userid, data.token, data.usermob);
  119. }).fail(function(response) {
  120. compnt.unlockClick();
  121. })
  122. })
  123. $('.modify').unbind('click').on('click', function (event) {
  124. if (!compnt.lockClick()) {
  125. return;
  126. }
  127. if ($douyinItem.hasClass('active')) {
  128. unicom.product = unicom.products[douyinPreProductId];
  129. } else {
  130. unicom.product = unicom.products[baiduPreProductId];
  131. }
  132. unicom.showCapPage(null, null, false, false, true, null).then(function (data) {
  133. compnt.unlockClick();
  134. order(data.userid, data.token, data.usermob);
  135. }).fail(function(response) {
  136. compnt.unlockClick();
  137. })
  138. })
  139. }
  140. function showCancelPage(productid) {
  141. if (location.href.indexOf("cancel.html") < 0) {
  142. window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou + "&productid=" + productid;
  143. return;
  144. }
  145. unicom.product = unicom.products[unicom.query.productid]
  146. var $container = $('.sms-form').find('.form-group');
  147. $container.find('.sendcode').unbind('click').on('click', function () {
  148. unicom.sendSms($container, 'cancellogin');
  149. })
  150. $container.find('.login').unbind('click').on('click', function () {
  151. compnt.showLoading();
  152. unicom.checkCode($container).done(function() {
  153. unicom.choiceCancel().done(function(response) {
  154. compnt.hideLoading();
  155. switch (response.resultCode) {
  156. case "0000":
  157. showDialogMessage('退订成功');
  158. break;
  159. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  160. showDialogMessage(response.errorInfo);
  161. break;
  162. default:
  163. var prefix = '';
  164. if (response.errorInfo.indexOf('退订失败') < 0) {
  165. prefix = '退订失败,';
  166. }
  167. showDialogMessage(prefix + response.errorInfo);
  168. break;
  169. }
  170. }).fail(function(data) {
  171. compnt.hideLoading();
  172. })
  173. }).fail(function(data) {
  174. compnt.hideLoading();
  175. })
  176. })
  177. window.scrollTo(0, 0)
  178. }
  179. /**
  180. * 订购
  181. */
  182. function order(userid, token, usermob) {
  183. compnt.showLoading('处理中,请稍后...');
  184. unicom.choiceOrder(userid, token, usermob).done(function(response) {
  185. compnt.hideLoading();
  186. switch (response.resultCode) {
  187. case "0000": //订购成功!跳转到领取会员页面
  188. unicom.saveUserInfo();
  189. showDialogMessage('订购成功');
  190. return;
  191. case "0013":
  192. showDialogMessage('该号码归属省分2/3G暂未开通此产品!');
  193. break;
  194. case "6611":
  195. showDialogMessage('错误代码(6611),订购失败,请重试!');
  196. break;
  197. case "6615":
  198. showDialogMessage('订购失败,请确定用户套餐!');
  199. break;
  200. case "6622": // 用户已订购过此产品!跳转到流量查页面
  201. unicom.saveUserInfo();
  202. break;
  203. //case "1078": //{"resultCode":"1078","errorInfo":"预约失败,请直接订购此产品!"}
  204. // showDialogMessage('预约变更失败,请先订购本产品!');
  205. // showDialogMessage('预约变更失败,请先订购本产品!');
  206. // break;
  207. //case "1077": //{"resultCode":"1077","errorInfo":"订购失败,您已订购过二选一产品,请预约订购!"}
  208. // showDialogMessage('订购失败,您已订购过二选一产品,请预约变更!');
  209. // break;
  210. //case "1079": // {"resultCode":"1079","errorInfo":"预约失败,请先订购百度产品!"}
  211. // showDialogMessage('预约变更失败,与当前生效的专属流量流量相同!');
  212. // break;
  213. default:
  214. showDialogMessage(response.errorInfo);
  215. break;
  216. }
  217. }).fail(function (error) {
  218. compnt.hideLoading();
  219. console.log(error);
  220. });
  221. }
  222. function showDialogMessage(message) {
  223. var replaceString = '';
  224. if (unicom.product.productid == baiduPreProductId
  225. || unicom.product.productid == douyinPreProductId) {
  226. message = message.replace('订购失败', '预约变更失败')
  227. .replace('订购成功', '预约变更成功');
  228. }
  229. var $overlay = $('<div class="overlay"></div>')
  230. var $dialog = $(
  231. '<div class="dialog-meesage">' +
  232. ' <div class="content">' + message + '</div>' +
  233. ' <div class="actions">' +
  234. ' <div class="btn"></div>' +
  235. ' </div>' +
  236. '</div>');
  237. $overlay.appendTo($(document.body))
  238. $dialog.appendTo($(document.body))
  239. $dialog.find('.btn').on('click', function () {
  240. $overlay.remove();
  241. $dialog.remove();
  242. $dialog = null;
  243. })
  244. $dialog.close = function () {
  245. $overlay.remove();
  246. $dialog.remove();
  247. $dialog = null;
  248. }
  249. return $dialog;
  250. }
  251. function showDialogAgr() {
  252. var $overlay = $('<div class="overlay"></div>')
  253. var $dialog = $(
  254. '<div class="dialog-agr">' +
  255. ' <div class="head">' +
  256. ' <div class="title"></div>' +
  257. ' <div class="close"></div>' +
  258. ' </div>' +
  259. ' <ul>' +
  260. ' <li>1)此产品包含9元10G今日头条定向流量包、9元8GB百度定向流量包两款服务,任选一款产品订购、使用业务以本机实际使用号码为准。资费9元/月,按自然月收费,下月自动续订;退订次月生效,当月仍享受免流权益,次月不再享受免流服务;</li>' +
  261. ' <li>2)本产品立即预约,次月生效,预约成功后将退订当前订购的产品;例如:如果用户当月订购的是今日头条定向流量包,点击预约变更,预约成功后,退订当前的头条包,次月生效百度包,且头条包免流可使用到月底,反之一样;</li>' +
  262. ' <li>3)预约成功后,当月不能再次预约变更产品,且不支持取消已预约的产品;</li>' +
  263. ' <li>4)本产品支持3G/4G用户使用,但4G套餐中的共享类套餐不共享该月包,需单独预约订购,给您带来的不便敬请谅解;</li>' +
  264. ' <li>5)建议使用最新版本今日头条、百度系列手机客户端,如果您更换其他系统手机或使用较低版本客户端,请谨慎使用您的流量;</li>' +
  265. ' <li>6)今日头条定向流量包的免流范围包括:抖音APP、今日头条、西瓜视频、火山小视频、多闪、懂车帝、图虫、皮皮虾APP;</li>' +
  266. ' <li>百度定向流量包产品的免流范围包括:百度后视镜、百度 APP 、好看视频、 全民小视频、 百度贴吧、 百度地图、百度网盘(会员);</li>' +
  267. ' <li>7)订购今日头条包的用户,如您为头条相关免流卡用户,如蚂蚁宝卡、阿里宝卡、钉钉宝卡或工商银行e卡等其他免头条系产品卡类,将优先使用免流卡产品的流量,免流卡流量用罄后将消耗今日头条定向流量包的流量;</li>' +
  268. ' <li>8)订购成功后,请在对应视频客户端内登录使用,联通3G/4G网络下观看,免流内容不包含第三方提供的广告、视频、图片及直播类视频上传/下载/缓存第三方视频所产生的流量;</li>' +
  269. ' <li>9)请务必使用3GNET接入点访问本产品,使用其他接入点观看视频会照常收取流量费用。请不要安装和使用任何流量监控、上网代理及VPN类软件和插件,可能会引起免流量策略失效而产生高额流量费用;</li>' +
  270. ' <li>10)以下地区暂不支持产品订购及免流业务:港、澳、台及国际漫游;</li>' +
  271. ' <li>11)如果遇到困难,请拨打10010联系联通客服解决。</li>' +
  272. ' </ul>' +
  273. '</div>');
  274. $overlay.appendTo($(document.body))
  275. $dialog.appendTo($(document.body))
  276. $dialog.find('.btn').on('click', function () {
  277. $overlay.remove();
  278. $dialog.remove();
  279. $dialog = null;
  280. })
  281. $dialog.find('.close').on('click', function () {
  282. $overlay.remove();
  283. $dialog.remove();
  284. $dialog = null;
  285. })
  286. $dialog.close = function () {
  287. $overlay.remove();
  288. $dialog.remove();
  289. $dialog = null;
  290. }
  291. return $dialog;
  292. }