main.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. import * as compnt from "../../../../public/js/compnt.js";
  2. import * as unicom from "../../../../public/js/unicom.js";
  3. import "../scss/main.scss";
  4. $(function () {
  5. var isPageHide = false;
  6. window.addEventListener('pageshow', function () {
  7. if (isPageHide) {
  8. window.location.reload();
  9. }
  10. });
  11. window.addEventListener('pagehide', function () {
  12. isPageHide = true;
  13. });
  14. if (window.location.href.indexOf('draw.html') >=0) {
  15. var user = JSON.parse(localStorage.getItem('user'));
  16. if (user != null) {
  17. $('.usermob').val(user.usermob);
  18. }
  19. }
  20. })
  21. init();
  22. function init() {
  23. var message = localStorage.getItem('message');
  24. if (message != null && message != '') {
  25. compnt.showAlert(message);
  26. localStorage.removeItem('message');
  27. }
  28. compnt.showLoading();
  29. unicom.init().then(function(response) {
  30. compnt.hideLoading();
  31. unicom.product = response.product[0];
  32. unicom.fesname = response.festival;
  33. // 孔明灯
  34. unicom.query.ringid = '';
  35. unicom.loadUserInfo();
  36. if (location.href.indexOf("/index") >= 0) {
  37. showOrderPage();
  38. } else {
  39. openPage();
  40. }
  41. if (location.href.indexOf('/cancel') >= 0) {
  42. unicom.burypointLogId('110002');// 退订页面pv, pv去重得到uv
  43. } else if (location.href.indexOf('/draw') >= 0) {
  44. unicom.burypointLogId('110003');// 领取页面pv, pv去重得到uv
  45. } else if (location.href.indexOf('/flow') >= 0) {
  46. unicom.burypointLogId('110004');// 流量查询pv, pv去重得到uv
  47. } else if (location.href.indexOf('/active') >= 0) {
  48. unicom.burypointLogId('110005');// 激活页面pv, pv去重得到uv
  49. } else if (location.href.indexOf('/refund') >= 0) {
  50. unicom.burypointLogId('110006');// 退款
  51. } else {
  52. // location.href.indexOf('/index') >= 0
  53. // location.href.indexOf('/order') >= 0
  54. unicom.burypointLogId('110001');// 订购页面pv, pv去重得到uv
  55. }
  56. })
  57. }
  58. function showAlertDialog(message) {
  59. var $overlay = $('<div class="overlay"></div>');
  60. var $dialog = $(
  61. '<div class="dialog dialog-message">' +
  62. ' <div class="status"></div>' +
  63. ' <div class="title"></div>' +
  64. ' <div class="content">' +
  65. ' <img src="./v1/images/order-success.jpg">' +
  66. ' </div>' +
  67. ' <div class="actions">' +
  68. ' <div class="btn">确定</div>' +
  69. ' </div>' +
  70. '</div>');
  71. $overlay.appendTo($(document.body))
  72. $dialog.appendTo($(document.body))
  73. $dialog.find('.btn').unbind('click').on('click', function () {
  74. $dialog.close()
  75. })
  76. $dialog.close = function () {
  77. $overlay.remove();
  78. $dialog.remove();
  79. $dialog = null;
  80. $('body').css('overflow', 'auto')
  81. }
  82. $('body').css('overflow', 'hidden')
  83. return $dialog;
  84. }
  85. function showPlayerDialog(src, poster) {
  86. var $dialog = $(
  87. '<div class="dialog-player">' +
  88. ' <div class="content">' +
  89. ' <div class="close"></div>' +
  90. ' <video id="video1" src="' + src + '" poster="' + poster + '"' +
  91. ' controls ' +
  92. ' playsinline="true"' +
  93. ' webkit-playsinline="true"' +
  94. ' x-webkit-airplay="true"' +
  95. ' x5-video-player-type="h5"' +
  96. ' x5-video-player-fullscreen="true"' +
  97. ' x5-video-ignore-metadata="true">' +
  98. ' </video>' +
  99. ' </div>' +
  100. '</div>');
  101. $dialog.appendTo($(document.body))
  102. $dialog.find('.close').unbind('click').on('click', function () {
  103. $dialog.close()
  104. })
  105. $dialog.close = function () {
  106. $dialog.remove();
  107. $dialog = null;
  108. $('body').css('overflow', 'auto')
  109. }
  110. $('body').css('overflow', 'hidden')
  111. var video = document.getElementById("video1");
  112. video.play();
  113. return $dialog;
  114. }
  115. function openPage(pageName) {
  116. if (pageName == null) {
  117. if (location.href.indexOf("index.html") >= 0) pageName = "order";
  118. if (location.href.indexOf("cancel.html") >= 0) pageName = "cancel";
  119. if (location.href.indexOf("draw.html") >= 0) pageName = "draw";
  120. if (location.href.indexOf("active.html") >= 0) pageName = "active";
  121. if (location.href.indexOf("flow.html") >= 0) pageName = "flow";
  122. }
  123. switch (pageName) {
  124. case "active":
  125. showActivePage();
  126. break;
  127. case "cancel":
  128. showCancelPage();
  129. break;
  130. case "draw":
  131. showDrawPage();
  132. break;
  133. case "flow":
  134. showFlowPage();
  135. break;
  136. default:
  137. showOrderPage();
  138. break;
  139. }
  140. }
  141. $('#btn-cancel').unbind('click').on('click', function () {
  142. showCancelPage();
  143. })
  144. function showOrderPage(backPage) {
  145. if (location.href.indexOf('/index') < 0) {
  146. if (backPage == null || backPage == '') {
  147. backPage = 'index.html';
  148. }
  149. window.location.href = backPage + "?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  150. return;
  151. }
  152. $('#btn-order').unbind('click').on('click', function (event) {
  153. if (!compnt.lockClick()) {
  154. return;
  155. }
  156. unicom.showCapOrder().then(function (data) {
  157. compnt.unlockClick();
  158. // order(data.userid, data.token, data.usermob, unicom.query.ringid);
  159. }).fail(function(response) {
  160. compnt.unlockClick();
  161. })
  162. })
  163. $('.rbt-item').find('.status').on('click', function(obj) {
  164. if (unicom.query.ringid == $(obj.currentTarget).attr('ringid')) {
  165. return;
  166. }
  167. $('.rbt-item').find('.status').each(function(i, item) {
  168. if ($(item).hasClass('status-checked')) {
  169. $(item).removeClass('status-checked').addClass('status-unchecked')
  170. } else {
  171. $(item).removeClass('status-unchecked').addClass('status-checked')
  172. unicom.query.ringid = $(item).attr('ringid')
  173. }
  174. });
  175. })
  176. $('.rbt-item').find('.rbt-cover').each(function(i, item) {
  177. $(item).on('click', function(obj) {
  178. var src = $(obj.currentTarget).attr('src');
  179. var poster = $(obj.currentTarget).attr('poster');
  180. showPlayerDialog(src, poster);
  181. })
  182. })
  183. $('#myPlay').on('click', function(obj) {
  184. var src = $(obj.currentTarget).attr('src');
  185. var poster = $(obj.currentTarget).attr('poster');
  186. showPlayerDialog(src, poster);
  187. })
  188. }
  189. function showCancelPage() {
  190. if (location.href.indexOf("cancel.html") < 0) {
  191. window.location.href = "cancel.html?fes=" + unicom.query.fes + "&sou=" + unicom.query.sou;
  192. return;
  193. }
  194. var $container = $('.sms-form');
  195. $container.find('.sendcode').unbind('click').on('click', function () {
  196. unicom.sendSms($container, 'cancellogin');
  197. })
  198. $container.find('.login').unbind('click').on('click', function () {
  199. compnt.showLoading();
  200. unicom.checkCode($container).done(function() {
  201. unicom.cancel().done(function(response) {
  202. compnt.hideLoading();
  203. switch (response.resultCode) {
  204. case "0000":
  205. compnt.showAlert('退订成功');//.then(function(message) {
  206. //showFlowPage();
  207. //});
  208. break;
  209. case "7605": //应该是已经退订了吧,因此不需要在重复退订啦
  210. compnt.showAlert(response.errorInfo);//.then(function(message) {
  211. //showFlowPage();
  212. //});
  213. break;
  214. default:
  215. var prefix = '';
  216. if (response.errorInfo.indexOf('退订失败') < 0) {
  217. prefix = '退订失败,';
  218. }
  219. compnt.showAlert(prefix + response.errorInfo);
  220. break;
  221. }
  222. }).fail(function(data) {
  223. compnt.hideLoading();
  224. })
  225. }).fail(function(data) {
  226. compnt.hideLoading();
  227. })
  228. })
  229. window.scrollTo(0, 0)
  230. }
  231. /**
  232. * 订购
  233. */
  234. function order(userid, token, usermob, ringid) {
  235. compnt.showLoading('处理中,请稍后...');
  236. unicom.order(userid, token, usermob).done(function(response) {
  237. compnt.hideLoading();
  238. switch (response.resultCode) {
  239. case "0000": //订购成功!跳转到领取会员页面
  240. unicom.saveUserInfo();
  241. compnt.showAlert('订购成功!');
  242. return;
  243. case "0013":
  244. compnt.showAlert('该号码归属省分2/3G暂未开通此产品!');
  245. break;
  246. case "6611":
  247. compnt.showAlert('错误代码(6611),订购失败,请重试!');
  248. break;
  249. case "6615":
  250. compnt.showAlert('订购失败,请确定用户套餐!');
  251. break;
  252. case "6622": // 用户已订购过此产品!跳转到流量查页面
  253. // localStorage.setItem('message', '您已经订购了本产品~');
  254. compnt.showAlert('您已经订购了本产品~')
  255. unicom.saveUserInfo();
  256. break;
  257. default:
  258. compnt.showAlert(response.errorInfo + ',订购失败,请确定用户套餐!');
  259. break;
  260. }
  261. }).fail(function (error) {
  262. compnt.hideLoading();
  263. console.log(error);
  264. });
  265. }