/** ishop base javascript trb 2015-11-01 **/ +function (B, $){ B.DEBUG = false; B.dialog = function(option){ var doption = { title:'正在提交...', btntext:'取消', btnclick:B.cancel, showloading:true } console.log(doption.title); }; B.doing = function(option){ B.dialog(option) }; B.query = function(msg, cb){ var r = confirm(msg); if(cb){ cb(r); } }; B.msg = function(til, msg, ico, fnc){ var title = null, message = null; var icos = ["error", "info", "question", "warning"]; for (var i = 0; i < arguments.length; ++i) { var arg = arguments[i]; if(icos.indexOf(arg)>=0) ico = arg; else if(typeof (arg) == "function") fnc = arg; else if(title==null) title = arg; else message = arg; }; if(message == null){ message = title; title = "提示"; } if(!ico) ico = 'info'; B.dialog({ title:message, btntext:"确定", showloading:false, btnclick:function(){ B.done(); if(fnc) fnc(); } }) }; B.done = function(){ console.log("done..."); }; B.cancel = function(){ B.done(); }; B.toast = function(msg){ B.doing({ title:msg, btntext:"", showloading:false }); window.top.setTimeout(function() { B.done(); }, 800); } B.progress = function(title,per){ B.doing(title + per); } B.callapi = function(m, p, succ, fail){ if(!p) p = {}; $.ajax({ url:'/api/'+m, type:B.DEBUG?'GET':'POST', dataType:'JSON', data:p, success:function(res){ if(res.code == 0){ if(succ) succ(res); } else{ if(res.code == 1000){ window.location.href = "/shopadmin/logout?next=/login/"; } else{ B.done(); if(fail){ if(!fail(res)) B.msg("错误", res.msg,"error"); } else{ if(!succ || !succ(null)) B.msg("错误", res.msg,"error"); } } } }, error:function(e){ B.done(); if(fail) fail(e); else if(succ){ console.log(e); B.msg("错误", "操作失败,请检查网络!"); succ(null); } } }); }; B.close = function(){ if(typeof(WeixinJSBridge)!="undefined"){ WeixinJSBridge.call('closeWindow'); } else if(typeof(IRWebView)!="undefined"){ IRWebView.close(); } else{ // alert("关闭功能仅支持微信浏览器"); } } B.back = function() { if(B.getQueryString("_back")){ history.go(B.getQueryString("_back")); } else{ history.go(-1); } }; B.open = function(url){ // window.open(url); window.location.href = url; } // 初始化列表选择器 B.initChildSel = function(thiz, genselecte){ var m = thiz.attr('v-model'); if(!genselecte){ genselecte = function(items){ var arr = ['']; for (var i =0; i < items.length; ++i) { arr.push(Base.renderstr('', items[i])) }; return ""; } } thiz.find('select').live('change', function(event) { var sel = $(this); sel.nextAll('select').remove(); var v = sel.val(); thiz.find('input').val(v); thiz.find('input').change(); if(v){ Base.callapi("getModelObject",{modelname:m,modelid:v}, function(r){ if(r){ var o = r.data; if(o.children && o.children.length>0){ var h = genselecte(o.children); var hs = $(h); hs.val(o.selected); hs.appendTo(thiz); } } }); } }); var initParents = function(){ var v = thiz.find('input').val(); Base.callapi("getModelParents",{modelname:m,modelid:v}, function(r){ if(r){ thiz.find('select').remove(); for (var i = 0; i < r.data.length; i++) { var o = r.data[i] if(o.children && o.children.length>0){ var h = genselecte(o.children); var hs = $(h); hs.val(o.selected); hs.appendTo(thiz); } }; } }); } initParents(); }; B.payorder = function(orderid, cbk){ B.doing("获取订单信息..."); if(!cbk){ cbk = function(d){ if(d.paid){ B.msg("支付成功!",function(){ window.location.reload(); }); } else{ B.msg("支付不成功!"); } }; } B.callapi('queryPayResult', {orderid:orderid}, function(res){ if(res && res.data && res.data.paid){ cbk(res.data); } else{ B.callapi('getPayUrl', {orderid:orderid}, function(res){ B.done(); var iswx = typeof(WeixinJSBridge)!="undefined"; if(res && res.data && res.data.payurl){ window.top.location.href = res.data.payurl; // if(iswx){ // B.doing("正在打开支付..."); // // WeixinJSBridge.call('closeWindow'); // window.location.href = res.data.payurl; // } // else{ // B.msg("支付完成之后点击确认", function(){ // B.doing("正在获取支付结果..."); // B.callapi('queryPayResult', {orderid:orderid}, function(res){ // B.done(); // if(res && res.data){ // cbk(res.data); // } // }); // }); // window.top.open(res.data.payurl); // } } }); } }); }; B.splitstrip = function(str, sp){ if(str){ if(!sp) sp = ' '; var strs = str.split(sp); var arr = []; for (var i = 0; i < strs.length; i++) { var s=strs[i].trim(); if(s.length>0) arr.push(s); }; return arr; } else{ return []; } }; }(IR, jQuery); B = Base = IR; $(function(){ $.each($('.ctl-childsel'), function(index, val) { Base.initChildSel($(val)); }); });