tuil.js 14 KB

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