iswxapp = false; $(function () { show_confirm('.btn-confirm'); $('.control-label.must').each(function () { $(this).append('*'); }); $('#showmenu, .backdrop').click(function () { if($('.navbar-nav').is(':visible')){ $('.navbar-nav').fadeOut(); $('.backdrop').fadeOut(); }else{ $('.navbar-nav').fadeIn(); $('.backdrop').fadeIn(); } }); }); //腾讯地图开始 var qqmap_mylocation = ''; /*使用location打开地图*/ function openMap(){ if(iswxapp == true){ openWxappMap(); return; }else{ //window.location.href = "http://api.map.baidu.com/marker?location=" + qqmap_location + "&title=" + qqmap_name + "&content=" + qqmap_address + "&zoom=13&output=html" } var options = {timeout: 2000}; if(isweixin){ geolocation.getLocation(showPosition, showErr, options); //geolocation.getIpLocation(showPosition, showErr); }else{ geolocation.getLocation(showPosition, showErr, options); } } //调用小程序地图 function openWxappMap(){ path = '/pages/maps/index?name='+ qqmap_name +'&address='+ qqmap_address +'&location='+ qqmap_location; //path = '/pages/index/index?name='+ qqmap_name +'&address='+ qqmap_address +'&location='+ qqmap_location; window.wx.miniProgram.navigateTo({ url: path }) } //window.location.href = $url; function showPosition(position) { qqmap_mylocation = position.lat +','+ position.lng; if(qqmap_mylocation != ''){ $url = '//apis.map.qq.com/uri/v1/routeplan?type=drice&fromcoord='+ qqmap_mylocation +'&to=' + qqmap_name + '&tocoord=' + qqmap_location + '&policy=1&referer='+ qqmap_appkey; window.location.href = $url; } }; function showErr(e) { alert('获取位置失败!'); }; //腾讯地图结束 /*预览指定链接图片*/ function imageView(that){ if(ismobile == false){ $.getJSON($(that).attr('data-thumbs'), function(json){ if(json.data.length == 0) return false; layer.photos({ photos: json //格式见API文档手册页 ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机 }); }); }else{ window.location.href = $(that).attr('data-thumbs'); } } /*当前图片预览*/ function imageBig(that) { let data = {"status":1,"msg":"","start":0,"data":[{"src":$(that).attr('src'),"thumb":"","pid":0,"alt":""}]}; layer.photos({ photos: data ,anim: 5 }); } /* ajax_iframe */ function ajax_iframe(title, url, width, height, isfull) { width = width || 700; height = height || 450; isfull = isfull || 0; if($(window).width() <= width || $(window).height() <= height) isfull = 1; if($(window).width() < 500) isfull = 1; width = width > 1 ? width +'px' : width * 100 +'%'; height = height > 1 ? height +'px' : height * 100 +'%'; anim = 0; //打开动画,移动端不需要时 = -1 isOutAnim = true; //关闭动画,移动端不需要是 = false url = url_with_param(url, 'iframe=1'); var index = layer.open({ type: 2, shade: 0.5, fixed: false, maxmin: true, resizing: true, title: title, area: [width, height], anim: anim, isOutAnim: isOutAnim, content: url, scrollbar: false, cancel: function () { //if(isreload == 1) window.location.reload(); } }); if(isfull == 1) layer.full(index); return false; } /* * ajax-get*/ function ajax_get(that){ //是否显示加载中 isloading = $(that).attr('data-loading') !== undefined && $(that).attr('data-loading') != 1 ? 0 : 1; //是否转到页面,如果为空,表示刷新本页 isreload = $(that).attr('data-reload') !== undefined ? $(that).attr('data-reload') : 0; var loadindex; if(isloading == 1){ loadindex = layer.load(2, { shade: [0.5, '#000'] }); } $.ajax({ type: "get", url: $(that).attr('data-url'), dataType: "json", async: false, jsonp: "callback", jsonpCallback: "success_jsonpCallback", success:function(data){ layer.msg(data.msg, {icon: 1}); if(isloading == 1) layer.close(loadindex); if(isreload == 1){ if($(that).attr('data-reload') != ''){ window.location.href = $(that).attr('data-reload'); }else{ window.location.reload(); } } }, error:function(){ layer.msg('操作失败', {icon: 5}); if(isloading == 1) layer.close(loadindex); } }); return false; } /*首页模块,带子栏目+内容切换*/ function block_switch(blockid, tabid){ tabid = tabid || $(blockid +' .btn:first-child').attr('data-tabid'); $(blockid +' .btn').removeClass('btn-main').addClass('btn-default'); $(blockid +' .btn[data-tabid="'+ tabid +'"]').addClass('btn-main').removeClass('btn-default'); $(blockid +' .block-group').hide(); $(blockid +' .block-group[data-tabid="'+ tabid +'"]').fadeIn(); } /*给url附加参数*/ function url_with_param(url, pram){ if( url.indexOf('?')>0 ){ url += '&' + pram; }else{ url += '?' + pram; } return url; } /* 去掉字符串中所有空格(包括中间空格,需要设置第2个参数为:g) */ function trim(str,is_global){ var result; result = str.replace(/(^\s+)|(\s+$)/g,""); if(is_global.toLowerCase()=="g") { result = result.replace(/\s/g,""); } return result; } /* * 错误消息*/ function show_error(text) { layer.msg(text, {anim: 6}); } /* * 成功消息*/ function show_success(text) { layer.msg(text); } /* * confirm*/ function show_confirm(that) { that = that || '.btn-confirm'; $(that).click(function () { that = this; layer.confirm($(that).attr('confirm-tip'), {icon: 3, title: $(that).attr('confirm-text')}, function(index){ //layer.close(index); $.ajax({ type : 'GET', dataType: 'json', url: $(that).attr('data-url'), success: function (res) { console.log(res); if(res.code == 1){ show_success(res.msg); setTimeout(function () { window.location.href = res.url; }, 1500); }else{ show_error(res.msg); } } }); }); return false; }); } wxapp_ready(); function wxapp_ready(){ var title = document.title; var linkurl = window.location.href; var linkurl = encodeURIComponent(window.location.href); wx.miniProgram.getEnv(function (res) { if (res.miniprogram) { var data = { title: title, linkurl: linkurl, userid: 0, }; wx.miniProgram.postMessage({ data: JSON.stringify(data) }); //这种跳转方式是跳转到小程序指定页面 并携带此参数 // wx.miniProgram.reLaunch({ url: '../../pages/pay/pay?json=' + json }); } }); }