;!function(win){ "use strict"; var ytui_cachedScript= new Array(); var ytui= function(){ this.v = '2.5.62'; //版本号 this.shop_info={}; } ytui.prototype.loadShop=function(callback) { var sid=this.getUrlParam('sid'); var ucode=this.getUrlParam('code'); if(!sid){sid=layui.router().search.sid;} var uid=this.getUrlParam('uid'); $.get('../api/shop.php?cmd=shop_info_get&uid='+uid+'&sid='+sid+'&code='+ucode , function(res){ if(res.js_ver){$.ytui_js_ver=res.js_ver;}//加载模块JS 版本号 $.ytui_js_ver='20032811';//1765382942; if(res.layui_ver){layui.config({version:res.layui_ver});}//加载 LAYUI版本号 var shop_info={}; shop_info.tel=res.客服电话; shop_info.shop_code=res.shop_id; shop_info.shop_name=res.商家名称; shop_info.shop_class=res.商品分类; shop_info.qigoujine=res.起购金额; shop_info.ad1=res.横幅广告1; shop_info.ad2=res.横幅广告2; shop_info.ad3=res.横幅广告3; if(shop_info.ad1){shop_info.ad1=shop_info.ad1;} if(shop_info.ad2){shop_info.ad2=shop_info.ad2;} if(shop_info.ad3){shop_info.ad3=shop_info.ad3;} shop_info['ini']=res['ini'] || {}; if(callback){callback( shop_info);} },'json'); } //高亮当前页按钮 var active=function(){ var btn=$('.tab-item'); $('.tab-item').removeClass('active'); $.each(btn, function(index, item){ var tmp=$(item).attr('href'); if(tmp=='#'){$(item).addClass('active');} }); } ytui.prototype.touchstart=function(id,ins) { if(ins.elemItem.length>1)//大于1幅图片的才开启手势 { //横幅广告 手势滑动 $(id).on("touchstart", function (e) { var startX = e.originalEvent.targetTouches[0].pageX;//开始坐标X $(this).on('touchmove', function (e) { arguments[0].preventDefault();//阻止手机浏览器默认事件 }); $(this).on('touchend', function (e) { var endX = e.originalEvent.changedTouches[0].pageX;//结束坐标X e.stopPropagation();//停止DOM事件逐层往上传播 //alert("开始滑动" + startX + "到" + endX); if (endX - startX > 30) { ins.slide("sub"); // alert("向右滑动"); } else if (startX - endX > 30) { ins.slide("add"); // alert("向左滑动"); } $(this).off('touchmove touchend'); }); }); } } ytui.prototype.load_js=function(doc)//自动载入JS模块文件 { $(document).attr("title",this.shop_info.shop_name); active();//高亮当前页按钮 var url=doc.attr('js-url'); var cache=doc.attr('cache') ; if(!url){return;} var r=0; if(cache==true){ for (var s in ytui_cachedScript) { //如果某个数组已经下载到了本地 if (ytui_cachedScript[s]==url) {r=1;} } } //console.log(footer.attr('url')); if( r==0) { var options = $.extend(options || {}, { dataType: "script", url:url+"?_="+$.ytui_js_ver, cache:true, success:function(res){ }, error: function() { } }); if(cache==true){ytui_cachedScript.push(url); }//将url地址放入script标记数组中 $.ajax(options); } } //数字格式化,保留2位小数 ytui.prototype.Float_to_str=function(value) { var $tint= parseFloat(value ); $tint=$tint.toFixed(2); if (isNaN($tint)) {return '';} else{ return $tint} } //获取地址栏参数值 ytui.prototype.getUrlParam=function(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg); //匹配目标参数 if (r != null) return unescape(r[2]); return ''; //返回参数值 } //Ajax请求 ytui.prototype.req = function(options){ var that = this ,success = options.success ,error = options.error ,debug = function(){ return setter.debug ? '
URL:' + options.url : ''; }; options.data = options.data || {}; options.headers = options.headers || {}; delete options.success; delete options.error; return $.ajax($.extend({ type: 'get' ,dataType: 'json' ,success: function(res){ typeof success === 'function' && success(res); //只有 response 的 code 一切正常才执行 done if(res['code'] ==1) { typeof options.done === 'function' && options.done(res); } //其它异常 else { layer.msg('
'+(res['msg'] || '返回状态码异常')+'
',{anim: 6,offset: 't'}); if(res['code']==-999) { $.router.loadPage({ url: "login.html", noAnimation: false }); } } //只要 http 状态码正常,无论 response 的 code 是否正常都执行 success } ,error: function(e, code){ typeof error === 'function' && error(res); } }, options)); }; //延迟1秒显示加载条 var show_tip=0 $(window).on("pageLoadStart", function() { show_tip=1; setTimeout(function () { if(show_tip==1){ $.showIndicator() ; setTimeout(function () { show_tip=0; $.hideIndicator(); }, 10000); } }, 1000); }); $(window).on("pageLoadComplete", function() { show_tip=0; $.hideIndicator(); }); //延迟1秒显示加载条 END $(window).on("pageLoadError", function() { layer.msg("加载失败,请检查网络!",{offset: 't'}); }); $.ajax({ url:'user.html', dataType:'text', data:{}, beforeSend :function(xmlHttp){ xmlHttp.setRequestHeader("Cache-Control","no-cache"); }, success:function(response){ //操作 } }); win.ytui = new ytui(); }(window); /* $(document).off('click','.title').on('click','.title',function(){//点击标题刷新页面 window.location.reload() }); */ //初始化页面 $(document).on("pageInit", function(e, pageId, $page) { if(!ytui.shop_info.shop_code || ytui.getUrlParam('sid')!='' ) { ytui.loadShop(function(e){ ytui.shop_info=e; //图片为空时自动载入默认图片 if(ytui.shop_info.shop_code==102801){ document.addEventListener("error", function (e) { var elem = e.target; if (elem.tagName.toLowerCase() == 'img') { elem.src = "https://cbu01.alicdn.com/img/ibank/2020/543/655/13302556345_2142669554.jpg"; } }, true); } ytui.load_js($page); }); }else{ ytui.load_js($page); } });