common.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. function lenthString(str){
  2. var len = str.length;
  3. var tt=0;
  4. for(var i=0;i<len;i++){
  5. var txt = str.charCodeAt(i);
  6. if(txt>128){
  7. tt= tt+2;
  8. } else{
  9. tt= tt+1;
  10. }
  11. }
  12. return tt;
  13. }
  14. function chkEmail(str){
  15. var reg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  16. if(reg.test(str)){
  17. return true;
  18. }else{
  19. alert('请输入正确的电子邮箱地址!');
  20. return false;
  21. }
  22. }
  23. function chkMobile(mobile)
  24. {
  25. var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
  26. if(mobile.length!=11) {
  27. alert('请输入有效的手机号码!');
  28. return false;
  29. }
  30. if(!myreg.test(mobile)) {
  31. alert('请输入有效的手机号码!');
  32. return false;
  33. }else{
  34. return true;
  35. }
  36. }
  37. function is_wxclient(){
  38. var ua = navigator.userAgent.toLowerCase();
  39. if(ua.match(/MicroMessenger/i)=="micromessenger") {
  40. return true;
  41. } else {
  42. return false;
  43. }
  44. }
  45. function showNewPage(tit,html,callback){
  46. var windowIframe = $('#windowIframe'),windowIframeTitle = $('#windowIframeTitle'),windowIframeBody = $('#windowIframeBody');
  47. function showBox(){
  48. windowIframe.show();
  49. //$('body').css({'height':$(window).height()+'px','overflow':'hidden'});
  50. $('.wrapper').hide();
  51. $('.footer').hide();
  52. }
  53. function hideBox(){
  54. windowIframe.hide();
  55. //$('body').css({'height':'auto','overflow':'visible'});
  56. $('.wrapper').show();
  57. $('.footer').show();
  58. }
  59. var addEditAddressInit = function(){
  60. var w_h = $(window).height();
  61. windowIframeTitle.html(tit);
  62. windowIframeBody.html(html);
  63. windowIframe.css({'min-height':w_h+'px'});
  64. showBox();
  65. callback&&callback.call(this);
  66. };
  67. setTimeout(function(){addEditAddressInit();},10);
  68. windowIframe.on('click','.close',function(e){
  69. e.preventDefault();
  70. hideBox();
  71. });
  72. }
  73. function windowToShow(action_name,to_url,ok_url){//从微信客户端中跳出//微信客户端中的支付宝问题
  74. var html = '<s class="s s1"></s><s class="s s2"></s>'+
  75. '<div class="txt">请在菜单中选择在浏览器中打开,<br>以完成'+action_name+'。</div>'+
  76. '<a href="'+ok_url+'" class="btn">已完成'+action_name+'</a> <a href="'+ok_url+'" class="btn">取消并返回</a>';
  77. var divs = document.createElement('div');
  78. divs.id = 'alipayForSafari';
  79. divs.className = 'alipay_for_safari';
  80. divs.innerHTML = html;
  81. $('body').append(divs);
  82. $('#alipayForSafari').show();
  83. history.pushState(null, '', to_url);
  84. alert('to_url:'+to_url);
  85. }
  86. function MympsWindowMsg_JSON(data){
  87. if(data.action === "pay" && data.classid === "2" ){
  88. payAppsubmitGo(data);
  89. }else{
  90. if(data.islogin === '1'){
  91. $('#isrep').val('');
  92. $('#parentid').val('');
  93. $('#chrcontent').html('');
  94. $('#chrcontent2').val('');
  95. $('#maskTB').trigger('click');
  96. if(data.isopen === '0'){
  97. MympsWindowMsg('revert','0','恭喜你,回复成功!请耐心等待系统审核!','','');
  98. }else{
  99. successPostRevert(data);
  100. }
  101. }else{
  102. MympsWindowMsg('revert','0',data.error,'','');
  103. }
  104. }
  105. }
  106. function payAppsubmitGo(MSGkeyval){
  107. if(isapp ==="1"){
  108. var YDB = new YDBOBJ();
  109. if(MSGkeyval.Payid === "7" ){//拉起微信app支付
  110. YDB.SetWxpayInfo(MSGkeyval.ProductName, MSGkeyval.Desicript, MSGkeyval.Price, MSGkeyval.OuttradeNo,MSGkeyval.attach);
  111. }
  112. else if(MSGkeyval.Payid === "1" ){//拉起阿里app支付
  113. YDB.SetAlipayInfo(MSGkeyval.ProductName, MSGkeyval.Desicript, MSGkeyval.Price, MSGkeyval.OuttradeNo);
  114. }
  115. }
  116. }
  117. function windowlocationhref(url,nodecode){
  118. if(nodecode) {}else{url = decodeURIComponent(url);}
  119. if(url.length > 5){window.location.href=url;}
  120. }
  121. function MympsWindowMsg(action,showid,str,url,formcode){
  122. var sys_tips = '<div class="sys_tips" id="sys_tips" style="display:none;"><div class="hd" id="sys_tips_title"></div><div class="bd"><p id="sys_tips_info"></p><div class="btn"><a href="javascript:void(0);" class="btn2" id="sys_tips_submit">确定</a></div></div></div>';
  123. if(!$('#sys_tips')[0]){
  124. $('body').prepend(sys_tips);
  125. }
  126. var sys_tips = $('#sys_tips'),sys_tips_title = $('#sys_tips_title'),sys_tips_info = $('#sys_tips_info'),sys_tips_submit = $('#sys_tips_submit');
  127. if(showid=="0"){ //只提示不跳转
  128. showConsole('提示',false);
  129. }else if(showid=="1"){ //提示加跳转
  130. showConsole('提示',true,formcode);
  131. }else if(showid=="2"){ //直接跳转
  132. windowlocationhref(url,formcode);
  133. }else if(showid=="3"){ //错误信息加跳转
  134. showConsole('出错了',true,formcode);
  135. }else if(showid=="4"){ //错误信息加只提示不跳转
  136. showConsole('出错了',false);
  137. }else{
  138. return false;
  139. }
  140. function showConsole(tit,isredirect,formcode){
  141. sys_tips_info.html(str);
  142. sys_tips_title.html(tit);
  143. sys_tips_submit.bind('click',function(e){
  144. e.preventDefault();
  145. sys_tips.hide();
  146. isredirect&&windowlocationhref(url,formcode);
  147. });
  148. sys_tips.show();
  149. var w_h = $(window).height(),d_h = sys_tips.height(),s_h = $(document).scrollTop(),top_val = (w_h-d_h)/2;
  150. sys_tips.css({'top':top_val+'px'});
  151. }
  152. }
  153. //地图测距
  154. function reloadLocation(){//切换地址 恢复当前位置
  155. if(navigator.geolocation){
  156. navigator.geolocation.getCurrentPosition(showMapGPSre, handleError, {enableHighAccuracy:true, maximumAge:1000,timeout:6000});
  157. window['location_timeout'] = setTimeout("geolocFail()", 10000);
  158. }else{
  159. MympsWindowMsg('location','0','抱歉,您的浏览器不支持使用HTML 5来获取地理位置服务','','');
  160. }
  161. }
  162. function getLocation(){
  163. if(navigator.geolocation){
  164. navigator.geolocation.getCurrentPosition(showMapGPS, handleError, {enableHighAccuracy:true, maximumAge:1000,timeout:6000});
  165. window['location_timeout'] = setTimeout("geolocFail()", 10000);
  166. }else{
  167. MympsWindowMsg('location','0','抱歉,您的浏览器不支持使用HTML 5来获取地理位置服务','','');
  168. }
  169. }
  170. window['location_timeout'] = null;
  171. function geolocFail(){
  172. if(typeof keyvalues !== 'undefined'){
  173. getPagingGlobal();
  174. }
  175. MympsWindowMsg('location','0','抱歉,我们没有获取到您的位置信息','','');
  176. }
  177. function handleError(value){
  178. clearTimeout(window['location_timeout']);
  179. geolocFail();
  180. switch(value.code){
  181. case value.PERMISSION_DENIED:
  182. MympsWindowMsg('location','0','抱歉,位置服务被拒绝','','');
  183. break;
  184. case value.POSITION_UNAVAILABLE:
  185. MympsWindowMsg('location','0','抱歉,暂时获取不到位置信息','','');
  186. break;
  187. case value.TIMEOUT:
  188. MympsWindowMsg('location','0','抱歉,获取信息超时','','');
  189. break;
  190. case value.UNKNOWN_ERROR:
  191. MympsWindowMsg('location','0','抱歉,位置服务未知错误','','');
  192. break;
  193. }
  194. }
  195. function showMapGPSre(value){
  196. clearTimeout(window['location_timeout']);
  197. var longitude = value.coords.longitude;
  198. var latitude = value.coords.latitude;
  199. var map = new BMap.Map();
  200. var gpsPoint = new BMap.Point(longitude, latitude); //GPS坐标
  201. BMap.Convertor.translate(gpsPoint, 0, function(point){
  202. var geoc = new BMap.Geocoder();
  203. geoc.getLocation(point, function(rs){
  204. var addComp = rs.addressComponents;
  205. $('#curLocation2').html(addComp.district + addComp.street + addComp.streetNumber);
  206. });
  207. });
  208. }
  209. function showMapGPS(value){
  210. clearTimeout(window['location_timeout']);
  211. var longitude = value.coords.longitude;
  212. var latitude = value.coords.latitude;
  213. var map = new BMap.Map();
  214. var gpsPoint = new BMap.Point(longitude, latitude); //GPS坐标
  215. BMap.Convertor.translate(gpsPoint, 0, function(point){
  216. setMap(map,point);
  217. if(typeof keyvalues !== 'undefined'){
  218. getPagingGlobal({'x':point.lng,'y':point.lat},true);
  219. }
  220. });
  221. }
  222. function showMapBD(longitude, latitude){
  223. if(longitude===''){return;}
  224. var map = new BMap.Map();
  225. var myPoint = new BMap.Point(longitude, latitude); //GPS坐标
  226. setMap(map,myPoint);
  227. }
  228. function setMap(map,point){
  229. var mapPointList = $('#mapPoint').find('.item');
  230. //逆向地址解析
  231. var geoc = new BMap.Geocoder();
  232. geoc.getLocation(point, function(rs){
  233. var addComp = rs.addressComponents;
  234. $('#curLocation').html(addComp.district + addComp.street + addComp.streetNumber);
  235. });
  236. //列表距离
  237. mapPointList.each(function(){
  238. var mapPoint = $(this);
  239. var dataX = mapPoint.attr('data-x'),dataY = mapPoint.attr('data-y');
  240. if(dataX === '' || dataX ==='0'){return;}
  241. var pointB = new BMap.Point(dataX,dataY); // 商家坐标
  242. var txt = (map.getDistance(point,pointB)/1000).toFixed(2)+'公里';
  243. $(this).find('.juli').html(txt);
  244. });
  245. }
  246. function showFilter(option){
  247. var node = $('#'+option.ibox),
  248. fullbg = $('#'+option.fullbg),
  249. ct1 = $('#'+option.content1),
  250. ct2 = $('#'+option.content2),
  251. ctp1 = ct1.find('.innercontent'),
  252. ctp2 = ct2.find('.innercontent'),
  253. currentClass = 'current';
  254. var tabs = node.find('.tab .item'),
  255. conts = node.find('.inner');
  256. fullbg.css({'height':$(document).height()+'px'});
  257. var timelist = node.find('.inner > ul > li').filter(function(index) {
  258. return $('ul', this).length > 0;
  259. }),
  260. childUL = null;
  261. timelist.each(function(){
  262. var that = $(this);
  263. that.addClass('hasUL');
  264. that.children('a').addClass('hasUlLink');
  265. });
  266. ct1.on("click",".hasUlLink",function(e){
  267. e.preventDefault();
  268. var that = $(this).parent();
  269. if(!window['myScroll_inner']){
  270. window['myScroll_inner'] = new IScroll('#'+option.content2, {
  271. click: true,
  272. scrollX: false,
  273. scrollY: true,
  274. scrollbars: true,
  275. interactiveScrollbars: true,
  276. shrinkScrollbars: 'scale',
  277. fadeScrollbars: true
  278. });
  279. }
  280. setTimeout(function(){
  281. ctp1.find('.hasUL_current').removeClass('hasUL_current');
  282. that.addClass('hasUL_current');
  283. ctp2.html('<ul>'+that.find('ul').html()+'</ul>').show();
  284. ct1.css({'width':'50%'});
  285. ct2.show();
  286. window['myScroll_inner'].refresh();
  287. },100);
  288. });
  289. tabs.each(function(i){
  290. $(this).bind("click",function(e){
  291. e.preventDefault();
  292. if(!window['myScroll_parent']){
  293. window['myScroll_parent'] = new IScroll('#'+option.content1, {
  294. click: true,
  295. scrollX: false,
  296. scrollY: true,
  297. scrollbars: true,
  298. interactiveScrollbars: true,
  299. shrinkScrollbars: 'scale',
  300. fadeScrollbars: true
  301. });
  302. }
  303. setTimeout(function(){
  304. node.addClass('filter-fixed');
  305. ct2.hide();
  306. ctp1[0].innerHTML = conts.eq(i).html();
  307. ct1.css('width','100%').show();
  308. fullbg.fadeIn('fast');
  309. tabs.removeClass(currentClass);
  310. tabs.eq(i).addClass(currentClass);
  311. window['myScroll_parent'].refresh();
  312. },100);
  313. });
  314. });
  315. fullbg.bind('click',function(e){
  316. e.preventDefault();
  317. hide_nav();
  318. });
  319. function hide_nav(){
  320. node.removeClass('filter-fixed');
  321. fullbg.fadeOut('fast');
  322. timelist.removeClass('hasUL_current');
  323. tabs.removeClass(currentClass);
  324. ct1.css('width','100%').hide();
  325. ct2.hide();
  326. }
  327. }
  328. function nearby(distance,la,ln){
  329. var lat = la;
  330. var lng = ln;
  331. document.getElementById('distanceInput').value = distance;
  332. if(lat=='' && lng==''){
  333. if (navigator.geolocation)
  334. {
  335. navigator.geolocation.getCurrentPosition(showPosition);
  336. }
  337. }else{
  338. var obj = new Object();
  339. obj.lat = lat;
  340. obj.lng = lng;
  341. showPosition(obj,1);
  342. }
  343. }
  344. function showPosition(position)
  345. {
  346. var url = location.search; //获取url中"?"符后的字串
  347. var theRequest = '';
  348. var ic = 0;
  349. var idistance = 0;
  350. var lat = 0;
  351. var lng = 0;
  352. if(arguments[1]==1){
  353. lat = position.lat;
  354. lng = position.lng;
  355. }else{
  356. lat = position.coords.latitude;
  357. lng = position.coords.longitude;
  358. }
  359. var distance = document.getElementById('distanceInput').value==''?0.5:document.getElementById('distanceInput').value;
  360. if (url.indexOf("?") != -1) {
  361. var str = url.substr(1);
  362. strs = str.split("&");
  363. for(var i = 0; i < strs.length; i ++) {
  364. var k = strs[i].split("=")[0];
  365. var v = strs[i].split("=")[1];
  366. if(k!=''){
  367. if(k=='lat'){
  368. ic++;
  369. v = lat;
  370. }
  371. if(k=='lng'){
  372. ic++;
  373. v = lng;
  374. }
  375. if(k=='distance'){
  376. idistance++;
  377. v = distance;
  378. }
  379. theRequest+=k+'='+v+'&';
  380. }
  381. }
  382. }
  383. if(ic<2){
  384. theRequest+='lat='+lat+'&lng='+lng;
  385. }
  386. if(idistance==0){
  387. theRequest+='&distance='+distance;
  388. }
  389. var stringArray = theRequest.split('')
  390. if(stringArray[theRequest.length-1]=='&'){
  391. stringArray[theRequest.length-1] = '';
  392. theRequest = stringArray.join('');
  393. }
  394. location.href = 'index.php?'+theRequest;
  395. }
  396. function LoginHide(){
  397. $('#inner_iframe').hide();
  398. $('#mask').hide();
  399. }