tuil.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  1. /**
  2. * 初始化加载
  3. */
  4. $(function() {
  5. postini();
  6. ncode = false;
  7. fes = getUrlParam("fes"),
  8. sou = getUrlParam("sou")
  9. });
  10. /*
  11. $(".gx input").click(function() {
  12. if ($(this).hasClass("chose_yes")) {
  13. $(this).removeClass("chose_yes").addClass("chose_no");
  14. } else {
  15. $(this).addClass("chose_yes").removeClass("chose_no");
  16. }
  17. })*/
  18. /**
  19. * 跳转至404页面
  20. */
  21. function goto404() {
  22. var url = getRootPath() + "/404.html";
  23. $(location).attr('href', url);
  24. }
  25. //选中
  26. $('.circular').click(function() {
  27. $('.circular').toggleClass("active")
  28. });
  29. //边框
  30. $('.iphone').focus(function() {
  31. $(this).css('border', '1px solid #FF14CB');
  32. $(this).css('opacity', '1');
  33. })
  34. $('.iphone').blur(function() {
  35. $(this).css('border', '1px solid #fff');
  36. if ($(this).val() == '') {
  37. $(this).css('opacity', '0.49');
  38. } else {
  39. $(this).css('opacity', '1');
  40. }
  41. })
  42. $('.yanzhenma').focus(function() {
  43. $(this).css('border', '1px solid #FF14CB');
  44. $(this).css('opacity', '1');
  45. })
  46. $('.yanzhenma').blur(function() {
  47. $(this).css('border', '1px solid #fff')
  48. if ($(this).val() == '') {
  49. $(this).css('opacity', '0.49');
  50. } else {
  51. $(this).css('opacity', '1');
  52. }
  53. })
  54. //
  55. $('.btn').mousedown(function() {
  56. $(this).css('opacity', '0.8')
  57. });
  58. $('.btn').mouseup(function() {
  59. console.log(1);
  60. $(this).css('opacity', '1')
  61. })
  62. //弹窗
  63. $('.yuyue').click(function() {
  64. $('.maskArea').show();
  65. $('.tc').show();
  66. $('.close').show();
  67. })
  68. $('.close').click(function() {
  69. $('.maskArea').hide();
  70. $('.tc').hide();
  71. $('.close').hide();
  72. })
  73. /**
  74. * 百度统计组件
  75. */
  76. // var _hmt = _hmt || [];
  77. // (function() {
  78. // var hm = document.createElement("script");
  79. // hm.src = "https://hm.baidu.com/hm.js?0ece85510b3306c074204023de4e49dc";
  80. // var s = document.getElementsByTagName("script")[0];
  81. // s.parentNode.insertBefore(hm, s);
  82. // })();
  83. /*点击文字勾选checkbox框*/
  84. $(".gx").click(function() {
  85. if ($(this).children("input").prop("checked")) {
  86. $(this).children("input").prop("checked", false);
  87. } else {
  88. $(this).children("input").prop("checked", "checked");
  89. }
  90. })
  91. /**
  92. * 页面统一工具
  93. */
  94. var derice = "";
  95. var pattern = /^1[345678]\d{9}$/; //判断联通号码正则表达式
  96. var ncode = false; //用于页面判断验证码超时
  97. //验证码倒计时
  98. var countdown = 60;
  99. function settime(mode) {
  100. if (countdown == 0) {
  101. $("#yzm").attr("onclick", "sendSms('tt','" + mode + "')");
  102. $(".yanzhenma_btn").attr("disabled", false);
  103. $(".yanzhenma_btn").text("获取验证码");
  104. countdown = 60;
  105. } else {
  106. $(".yanzhenma_btn").attr("disabled", true);
  107. $(".yanzhenma_btn").text(countdown + "s后可重发");
  108. countdown--;
  109. setTimeout(function() {
  110. settime(mode)
  111. }, 1000)
  112. }
  113. }
  114. /**
  115. * 页面弹框提示
  116. */
  117. function pro_bounced(headmg, textmg, buttonmg, state) {
  118. if (state) {
  119. $('.maskArea').show();
  120. $('.tc').show();
  121. $('.close').show();
  122. $("#ts").attr('src', 'img/wancheng.png');
  123. $("#co").text(textmg);
  124. } else {
  125. $('.maskArea').show();
  126. $('.tc').show();
  127. $('.close').show();
  128. $("#ts").attr('src', 'img/wan.png');
  129. $("#co").text(textmg);
  130. }
  131. }
  132. function closeSe() {
  133. $(".maskArea").attr("style", "display:none;"); //关闭提示框
  134. }
  135. function emptyM() {
  136. $(".coupon").empty();
  137. }
  138. /**
  139. * 获取对应标签中value
  140. * @param memoid
  141. * @param type
  142. * @returns
  143. */
  144. function getMemoValbyId(product, type) {
  145. var val = "";
  146. switch (type) {
  147. case "phone":
  148. val = $("#input_100_" + product).val();
  149. break;
  150. case "code":
  151. val = $("#input_50_" + product).val();
  152. break;
  153. case "fog":
  154. val = $("#fog_" + product).val();
  155. break;
  156. case "useraccount":
  157. val = $("#useraccount_" + product).val();
  158. break;
  159. case "sendsmsorder":
  160. val = $("#sendsms_order_" + product).val();
  161. break;
  162. case "sendsmscancel":
  163. // val = $("#sendsms_cancel_"+product).val();
  164. val = "cancellogin";
  165. break;
  166. case "sendsmsyuyue":
  167. val = $("#sendsms_yuyue_" + product).val();
  168. break;
  169. case "sendsmsacti":
  170. // val = $("#sendsms_acti_"+product).val();
  171. val = "activelogin";
  172. break;
  173. }
  174. if (val == null) {
  175. return "";
  176. } else {
  177. return val;
  178. }
  179. }
  180. /**
  181. * 获取项目根目录
  182. * @returns
  183. */
  184. function getRootPath() {
  185. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  186. var curWwwPath = window.document.location.href;
  187. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  188. var pathName = window.document.location.pathname;
  189. var pos = curWwwPath.indexOf(pathName);
  190. //获取主机地址,如: http://localhost:8080
  191. var localhostPath = curWwwPath.substring(0, pos);
  192. //获取带"/"的项目名,如:/ems
  193. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  194. return (localhostPath + projectName);
  195. }
  196. /**
  197. * 获取项目页面前
  198. * @returns
  199. */
  200. function getHref() {
  201. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  202. var curWwwPath = window.document.location.href;
  203. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  204. var pathName = window.document.location.pathname;
  205. var pos = curWwwPath.indexOf(pathName);
  206. //获取主机地址,如: http://localhost:8080
  207. var localhostPath = curWwwPath.substring(0, pos);
  208. //获取带"/"的项目名,如:/ems
  209. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
  210. return (localhostPath + pathName);
  211. }
  212. /**
  213. * 短信发送信息包装.
  214. */
  215. function sendSmsDate(product, mode) {
  216. var data = {
  217. "fog": getMemoValbyId(product, "fog"),
  218. "usermob": getMemoValbyId(product, "phone"),
  219. "smstype": getMemoValbyId(product, "sendsms" + mode),
  220. "sou": getUrlParam("sou"),
  221. };
  222. return data;
  223. }
  224. /**
  225. * 获取当前url中参数信息
  226. * @param urlprm url中参数名称
  227. * @returns
  228. */
  229. function getUrlParam(urlprm) {
  230. var reg = new RegExp("(^|&)" + urlprm + "=([^&]*)(&|$)");
  231. var r = window.location.search.substr(1).match(reg);
  232. if (r != null) {
  233. return r[2];
  234. } else { //当获取链接中必须要参数未获取到时标示链接错误直接跳转至统一404页面
  235. if (urlprm == "con") {
  236. return "1";
  237. //获取强制页面跳转标示,不跳转至404.
  238. } else if (urlprm == "use") {
  239. return "";
  240. } else {
  241. var url = getRootPath() + "/404.html";
  242. $(location).attr('href', url);
  243. }
  244. }
  245. }
  246. /**
  247. * 根据页面加载函数初始化页面图标,页面主题
  248. * 页面中必须有对应标签ID
  249. * @param iniJson 后台获取到的页面加载函数
  250. */
  251. function theme(title, icon) {
  252. //加载页面主题文字
  253. $("title").text(title);
  254. //加载页面图标
  255. //$("#icon").attr("href", icon+".ico");
  256. }
  257. /**
  258. * 消息发送获取Josn数据
  259. * @param method 方法名称
  260. * @param data 发送数据
  261. * @returns 返回的json数据
  262. * 此方法需加载页面头信息与页面显示图标:
  263. * 页面必须有 title 标签
  264. * id = "icon" 链接地址
  265. * <link id="icon" rel="shortcut icon" type="image/x-icon" href=""/>
  266. * 加载页面基本信息:
  267. * XX 为活动对应产品表中配置标示
  268. * <input type="hidden" id="fog_XX"/>
  269. */
  270. function postini() {
  271. $.ajax({
  272. url: getRootPath() + "-s1api" + '/ini/getstyle',
  273. type: "POST", // 用POST方式传输
  274. contentType: "application/json; charset=utf-8",
  275. dataType: "Json",
  276. data: JSON.stringify(postiniDate()),
  277. success: function(msg) {
  278. var resCode = msg["resultCode"];
  279. if (resCode == "0000") {
  280. var festival = msg["festival"];
  281. theme(festival["title"], festival["icon"]); //加载页面信息头,图标
  282. var productlist = msg["product"];
  283. for (var i = 0, l = productlist.length; i < l; i++) {
  284. $("#fog_" + productlist[i].url).attr("value", productlist[i].fog);
  285. var smslist = productlist[i].icon.split(",");
  286. for (var int = 0; int < smslist.length; int++) {
  287. if (int == 0) {
  288. $("#sendsms_order_" + productlist[i].url).attr("value", smslist[int]);
  289. }
  290. if (int == 1) {
  291. $("#sendsms_cancel_" + productlist[i].url).attr("value", smslist[int]);
  292. }
  293. if (int == 2) {
  294. $("#sendsms_yuyue_" + productlist[i].url).attr("value", smslist[int]);
  295. }
  296. }
  297. }
  298. } else { //未取出对应渠道与活动组数据
  299. goto404();
  300. }
  301. if (location.href.indexOf('/cancel') >= 0) {
  302. burypointLogId('110002'); // 退订页面pv, pv去重得到uv
  303. } else if (location.href.indexOf('/draw') >= 0) {
  304. burypointLogId('110003'); // 领取页面pv, pv去重得到uv
  305. } else if (location.href.indexOf('/flow') >= 0) {
  306. burypointLogId('110004'); // 流量查询pv, pv去重得到uv
  307. } else if (location.href.indexOf('/active') >= 0) {
  308. burypointLogId('110005'); // 激活页面pv, pv去重得到uv
  309. } else {
  310. // location.href.indexOf('/index') >= 0
  311. // location.href.indexOf('/order') >= 0
  312. burypointLogId('110001'); // 订购页面pv, pv去重得到uv
  313. }
  314. },
  315. error: function(XMLHttpRequest, textStatus, errorThrown) { //加载请求失败
  316. goto404();
  317. },
  318. });
  319. }
  320. function gotorder() {
  321. var url = getRootPath() + "/Tou/Dy/order.html" +
  322. "?fes=" + getUrlParam("fes") + "&sou=" + getUrlParam("sou") +
  323. "&con=0";
  324. $(location).attr('href', url);
  325. }
  326. /**
  327. * 去往成功页面
  328. */
  329. function gotosucc() {
  330. var url = getRootPath() + "/Tou/Dy/orderSucc.html" +
  331. "?fes=" + getUrlParam("fes") + "&sou=" + getUrlParam("sou") +
  332. "&phone=" + getMemoValbyId('tt', 'phone') + "&fog=" + getMemoValbyId('tt', 'fog') + "&fog=" + getMemoValbyId('tt', 'fog') + "&use=" + getMemoValbyId('tt', 'useraccount');
  333. $(location).attr('href', url);
  334. }
  335. /**
  336. * 验证码发送
  337. * @param product
  338. */
  339. function sendSms(product, mode) {
  340. $("#yzm").removeAttr("onclick");
  341. if (getMemoValbyId(product, "phone") != "") { //判断号码是否输入
  342. if (pattern.test(getMemoValbyId(product, "phone"))) { //判断号码格式
  343. $.ajax({
  344. type: "POST",
  345. contentType: "application/json; charset=utf-8",
  346. dataType: "Json",
  347. url: getRootPath() + "-s1api" + '/sms/send',
  348. data: JSON.stringify(sendSmsDate(product, mode)),
  349. success: function(msg) {
  350. var resCode = eval(msg["resultCode"]);
  351. if (resCode == "0000") {
  352. ncode = true;
  353. settime(mode);
  354. } else {
  355. sleep(mode);
  356. pro_bounced("温馨提示", msg["errorInfo"], "", false);
  357. }
  358. },
  359. error: function(XMLHttpRequest, textStatus, errorThrown) {
  360. sleep(mode);
  361. pro_bounced("温馨提示", "短信验证码发送失败", "", false);
  362. },
  363. });
  364. } else {
  365. $("#yzm").attr("onclick", "sendSms('" + product + "','" + mode + "')");
  366. pro_bounced("温馨提示", "请输入正确的中国联通手机号码", "", false);
  367. }
  368. } else {
  369. $("#yzm").attr("onclick", "sendSms('" + product + "','" + mode + "')");
  370. pro_bounced("温馨提示", "手机号码未输入", "", false);
  371. }
  372. try {
  373. window.HtmlPageVisitor && window.HtmlPageVisitor.setMp(getMemoValbyId(product, "phone"));
  374. } catch (e) {}
  375. }
  376. function sleep(mode) {
  377. var start = new Date().getTime();
  378. // console.log('休眠前:' + start);
  379. while (true) {
  380. if (new Date().getTime() - start > 10000) {
  381. $("#yzm").attr("onclick", "sendSms('tt','" + mode + "')");
  382. break;
  383. }
  384. }
  385. }
  386. /**
  387. * 跳转至对应页面
  388. */
  389. function gotoUrl(html) {
  390. var timestamp = (new Date()).getTime();
  391. var url = getRootPath() + "/" + html + ".html?fes=" + getUrlParam("fes") + "&sou=" + getUrlParam("sou") + "&use=" + getUrlParam("use") + "&tl=" + timestamp;
  392. // var url = "http://800.wo.cn/orderchannel" + "/" + html + ".html?fes=" + getUrlParam("fes") + "&sou=" + getUrlParam("sou") + "&use=" + getUrlParam("use") + "&tl=" + timestamp;
  393. $(location).attr('href', url);
  394. }
  395. /**
  396. * 数据加载发送信息包装.
  397. */
  398. function postiniDate() {
  399. var data = {
  400. fes: getUrlParam("fes"),
  401. sou: getUrlParam("sou"),
  402. };
  403. return data;
  404. }
  405. /**
  406. * 获取流量
  407. */
  408. function GetFlowJsonData(product) {
  409. var data = {
  410. "fog": fog,
  411. "usermob": phone,
  412. };
  413. return data;
  414. }
  415. /**
  416. * 订购发送信息包装
  417. * @param product
  418. * @returns {___anonymous5356_5582}
  419. */
  420. function GetMasData(product, canceltype, cancelmsg) {
  421. var data = {
  422. "code": getMemoValbyId(product, "code"),
  423. "fog": getMemoValbyId(product, "fog"),
  424. "usermob": getMemoValbyId(product, "phone"),
  425. "useraccount": getMemoValbyId(product, "useraccount"),
  426. "canceltype": canceltype,
  427. "cancelmsg": cancelmsg,
  428. "fes": getUrlParam("fes"),
  429. "sou": getUrlParam("sou"),
  430. };
  431. try {
  432. window.WoAnalytics && window.WoAnalytics.setMp($(getMemoValbyId(product, "phone")));
  433. } catch (e) {}
  434. return data;
  435. }
  436. var se = 0;
  437. function seuid() {
  438. se = se + 1;
  439. if (se == 5) {
  440. se = 0;
  441. alert("sou:" + sou);
  442. }
  443. }
  444. (function() {
  445. Date.prototype.from = function(dateString) {
  446. var pattern2 = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/
  447. var str = dateString.replace(/-/g, '/');
  448. str = str.replace(pattern2, '$1/$2/$3 $4:$5:$6')
  449. return new Date(str)
  450. }
  451. // 对Date的扩展,将 Date 转化为指定格式的String
  452. // 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
  453. // 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
  454. // 例子:
  455. // (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
  456. // (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
  457. Date.prototype.format = function(fmt) { //author: meizz
  458. var o = {
  459. "M+": this.getMonth() + 1, //月份
  460. "d+": this.getDate(), //日
  461. "h+": this.getHours(), //小时
  462. "m+": this.getMinutes(), //分
  463. "s+": this.getSeconds(), //秒
  464. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  465. "S": this.getMilliseconds() //毫秒
  466. };
  467. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  468. for (var k in o)
  469. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  470. return fmt;
  471. }
  472. })();
  473. function getTodaySurplusMillis() {
  474. var time1 = new Date();
  475. var time2 = time1.from(time1.getFullYear() + '-' + (time1.getMonth() + 1) + '-' + time1.getDate() + ' 23:59:59');
  476. console.log(time2.getTime() - time1.getTime())
  477. return time2.getTime() - time1.getTime();
  478. }
  479. function burypointLogId(operid, remark, url) {
  480. var uuid = getCookie('uuid'); // uv
  481. var vvid = getCookie('vvid'); // vv
  482. if (uuid == null || uuid.trim() == '') {
  483. uuid = guid();
  484. setCookie('uuid', uuid, getTodaySurplusMillis());
  485. }
  486. if (vvid == null || vvid.trim() == '') {
  487. vvid = guid();
  488. setCookie('vvid', vvid, -1);
  489. }
  490. if (operid == null || operid == '') {
  491. // 页面的埋点不通过/burypoint/logid接口实现,通过文件日志入库方式
  492. return;
  493. }
  494. var param = {
  495. operid: operid,
  496. uuid: uuid,
  497. vvid: vvid,
  498. fog: getMemoValbyId('wy', 'fog'),
  499. userid: '',
  500. fes: getUrlParam("fes"),
  501. sou: getUrlParam("sou"),
  502. url: encodeURIComponent(url || window.location.href),
  503. remark: encodeURIComponent(remark || '')
  504. }
  505. $.ajax({
  506. type: "POST",
  507. contentType: "application/json; charset=utf-8",
  508. dataType: "Json",
  509. url: getRootPath() + "-s1api" + '/burypoint/logid', //目标地址
  510. data: JSON.stringify(param),
  511. success: function() {},
  512. error: function() {},
  513. });
  514. }
  515. function getCookie(name) {
  516. var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
  517. if (arr = document.cookie.match(reg))
  518. return unescape(arr[2]);
  519. else
  520. return null;
  521. }
  522. /**
  523. * 如果没有设置时间, 默认5分钟
  524. */
  525. function setCookie(name, value, millis) {
  526. millis = (millis == undefined ? 0 : millis);
  527. var exp = new Date();
  528. if (millis < 0) {
  529. document.cookie = name + "=" + escape(value);
  530. } else {
  531. exp.setTime(exp.getTime() + millis);
  532. document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
  533. }
  534. }
  535. function guid() {
  536. return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  537. var r = Math.random() * 16 | 0,
  538. v = c == 'x' ? r : (r & 0x3 | 0x8);
  539. return v.toString(16);
  540. });
  541. }