tuil.js 17 KB

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