markerApplication.js 9.52 KB
/*! dili 2016-01-06 */
var region=function(){var regions=[],param={floor:0},MultiLevel=function(){var _this=this,config={data:{},view:"",parameter:{url:"",setUrl:"",id:0,field:{pid:"parentId",did:"regionId",name:"regionName"},param:"parentId",setNmae:"city"},heads:[],sub:0,constraintTier:0,page:0,isEvents:!0,isinternation:0,forcePage:1},methods={foundView:function(verify,sub){var place=config.view.attr("data-place");place?0:place="请选择";var _v=verify,view='<div class="title"><span><input type="text" readonly="readonly" '+(_v?'class="required"':"")+"name=region"+sub+' placeholder="'+place+'"/></span><span class="s-live"></span><p class="region-data" style="display: none;"></p></div><div class="region-view"><div class="head"><ul></ul><span class="reset">重置</span></div><div class="cont clearfix"><ul></ul></div></div>';config.view.html(view),this.parseParam(),methods.events()},parseParam:function(){var param=null;try{param=config.view.attr("data"),param=param.split(","),config.parameter.setNmae=param[0],config.parameter.field.pid=param[1],config.parameter.field.did=param[2],config.parameter.field.name=param[3],config.parameter.param=param[4],config.constraintTier=parseInt(param[5]),config.forcePage=param[6]?parseInt(param[6]):1}catch(error){methods.error("朋友参数传递错误了,请仔细检查下",error)}return config.view.attr("setUrl")?(config.parameter.setUrl=config.view.attr("setUrl"),methods.setValue(),!1):void methods.http()},setUrl:function(){config.view.attr("url")?config.parameter.url=config.view.attr("url"):methods.error("朋友参数url没有设置,请仔细检查下"),config.parameter.url=config.parameter.url+"?"+config.parameter.param+"="+config.parameter.id},http:function(){return param.floor&&config.heads.length>=param.floor?(methods.setData(),!1):methods.getStorage(config.parameter.id)?(methods.setView(methods.getStorage(config.parameter.id)),!0):(methods.setUrl(),void $.ajax({type:"GET",url:config.parameter.url,dataType:"jsonp",success:function(data){methods.setStorage(data)},error:function(e,s,c){methods.error("请求数据异常~~~",{e:e,s:s,c:c})}}))},setStorage:function(data){data=methods.tidiesData(data),data&&data.length>0?(config.data[config.parameter.id]=data,methods.setView(data)):(methods.setData(),config.view.find(".region-view").hide())},tidiesData:function(data){var list=[];for(i in data)if(-9999==data[i][config.parameter.field.pid])data[i][config.parameter.field.pid]=0,list.push(data[i]),config.isinternation=1;else{if(0!=data[i][config.parameter.field.pid]||!config.isinternation)return data;data[i][config.parameter.field.pid]=-10,list.push(data[i])}return list},getStorage:function(id){return config.data[id]?config.data[id]:!1},setView:function(data){methods.setHead(data),methods.setCont(data)},setHead:function(data){config.view.find(".head ul").html("");var view="";for(i in config.heads)view+='<li class="" zindex="'+config.page+'" did="'+config.heads[i].id+'" pid="'+config.heads[i].pid+'">'+config.heads[i].name+"</li>";view+='<li class="act" zindex="'+config.page+'" pid="">请选择</li>',config.view.find(".head ul").html(view)},setCont:function(data){config.view.find(".cont ul").html("");var view="";for(i in data)"其他城市"!=data[i].regionName&&"其他省份"!=data[i].regionName&&"其他区县"!=data[i].regionName&&(view+='<li class="" zindex="'+config.page+'"                        pid="'+data[i][config.parameter.field.pid]+'"                        did="'+data[i][config.parameter.field.did]+'">'+data[i][config.parameter.field.name]+"</li>");config.view.find(".cont ul").html(view)},setData:function(data){var list=[],id=0,str="";list=data?data:config.heads;for(i in list)str+="  "+list[i].name,parseInt(i)==list.length-1&&(id=list[i].id);var isInput=config.view.prevAll(".region-hide");if(!isInput.attr("type")||"hidden"!=isInput.attr("type")&&"text"!=isInput.attr("type")){var view='<input type="hidden" class="region-hide" name="'+config.parameter.setNmae+'" value="'+(str+"/"+id)+'" />';config.view.before($(view)),isInput.val(str+"/"+id)}else isInput.val(str+"/"+id);isInput.trigger("change"),config.forcePage||$("body").trigger("click"),config.view.find(".title input").val(str),config.view.find(".region-data").html(JSON.stringify(config.heads));var _name=(config.heads.length-1,isInput.attr("name")),_errorTips=config.view.parent().siblings('label[for="'+_name+'"]');_errorTips.length>0&&_errorTips.hide()},headDel:function(id){var page=0;for(i in config.heads)config.heads[i].pid==id&&(page=parseInt(i));config.heads.splice(page,config.heads.length-page),methods.http()},headIsNmae:function(view){var text=view.html(),pid=view.attr("pid"),did=view.attr("did");for(i in config.heads)if(config.heads[i].pid==pid)return config.heads[i]={id:did,name:text,pid:pid},!1;return!0},isConstraintTier:function(){var leng=config.heads.length-1;return config.constraintTier&&leng>=config.constraintTier?!0:!1},events:function(){config.view.find(".head").on("click","li",function(){config.parameter.id=$(this).attr("pid"),methods.headDel(config.parameter.id)}),config.view.find(".cont").on("click","li",function(){config.parameter.id=$(this).attr("did"),methods.headIsNmae($(this))&&config.heads.push({id:$(this).attr("did"),name:$(this).html(),pid:$(this).attr("pid")}),/getCountryJsonpList/.test(config.view.attr("url"))&&1==config.view.attr("isLimit")&&-10==$(this).attr("pid")&&methods.setData(),methods.isConstraintTier()?(methods.setData(),config.forcePage&&methods.http()):methods.http()}),config.view.find(".title").click(function(){for(var rg=$("body").find(".m-region .region-view"),i=0,l=rg.length;l>i;i++)config.view.attr("sub")!=rg.eq(i).attr("sub")&&rg.eq(i).hide();return $(this).next().show(),!1}),config.view.find(".reset").click(function(){return _this.reset(),!1}),config.view.click(function(){return!1}),$(document).click(function(e){return $(e.target).hasClass("m-region")?!1:void config.view.find(".region-view").hide()})},error:function(txt,error){},setValue:function(){$.ajax({type:"GET",url:config.parameter.setUrl,dataType:"jsonp",success:function(data){try{data=data.reverse();var list=[];for(i in data)list.push({id:data[i][config.parameter.field.did],name:data[i][config.parameter.field.name],pid:data[i][config.parameter.field.pid]});methods.setData(list),config.parameter.id=0,config.heads=[]}catch(error){}methods.http()},error:function(error){methods.error("请求数据异常~~~",error)}})},listenChange:function(fn){var cacheInput=$('<input type="hidden" class="region_cache_'+config.view.attr("sub")+'" />');config.view.before(cacheInput),config.view.find(".cont").on("click","li",function(){var _cityNames=[],_cityIds=[];$.each(config.heads,function(i,elem){$.each(elem,function(k,v){"name"==k?_cityNames.push(v):"id"==k&&_cityIds.push(v)})}),cacheInput.val(_cityNames.join(",")+"/"+_cityIds.join(",")),"function"==typeof fn?fn():0})}};return this.start=function(view,sub,verify){config.sub=sub,config.view=$(view),config.view.attr("sub",sub),methods.foundView(verify,sub)},this.getData=function(){methods.getData()},this.update=function(){config.view.attr("setUrl")&&(config.parameter.setUrl=config.view.attr("setUrl"),methods.setValue())},this.reset=function(){config.heads=[],config.parameter.id=0,methods.http(),config.view.find(".title input").val(""),config.view.find(".s-live").html(""),config.view.prev().attr("value",""),config.view.find(".region-data").html("[]")},this.listenChange=function(fn){methods.listenChange(fn)},this};return{start:function(verify){this.allregion(verify)},allregion:function(verify){$(".m-region").each(function(){if(!$(this).attr("sub")){var ml=new MultiLevel;regions.push(ml),ml.start(this,regions.length-1,verify),ml.listenChange(verify)}})},aRegion:function(view){var ml=new MultiLevel;return regions.push(ml),ml.start(view,regions.length-1),ml},del:function(page){return page?($(".m-region").each(function(i){return i==page?(regions.splice(i,1),!0):void 0}),!1):!1},setParam:function(obj){$.extend(param,obj)}}}();define("market",function(require,exports,module){function _name(n){return $("."+n).length?$("."+n):$("#"+n)}function _index(arr,elem){var each,counter=0;for(each in arr)arr[each]===elem&&++counter;return 0===counter?(arr.push(elem),!0):!1}var market=function(options){this.o={add:"m-add",del:"m-del",sel:"m-selected",input:"i-selected",html:null,content:"region-hide"},this.o=$.extend(this.o,options),this.target=_name(this.o.add),this.init()};return market.prototype={init:function(){this.makeSel(),this.eventListener()},eventListener:function(){var data,number,_this=this,arr=[];this.target.live({click:function(){var ipt=$(this).parent().find("."+_this.o.content);ipt.length&&(data=ipt.attr("value").replace(/^\s+/,"").split(/[\/\s]+/),number=data.pop(),_index(arr,number)&&$(this).parent().after(_this.makeHtml(data.join(" 〉"))))}}),_name(this.o.sel).live({mouseenter:function(){_this.hide(_name(_this.o.del)),_this.show($(this).find("."+_this.o.del))}}),_name(this.o.del).live({click:function(){$(this).prev().mouseenter=null,$(this).click=null,arr.pop(number),$(this).parent().remove()}})},makeHtml:function(a){var _this=this,html='<div class="'+this.o.sel+'"><div>'+a+'</div> <span class="'+this.o.del+'">删除</span> <input type="hidden" class="'+this.o.input+'" value="'+a+'"/></div>';return $(_this.o.html).length?$(_this.o.html):$(html)},show:function(del){$(del).css({visibility:"visible"})},hide:function(del){$(del).css({visibility:"hidden"})},makeSel:function(){$("body").append($('<div class="'+this.o.sel+'"><span class="'+this.o.del+'"></span></div>'))}},market}),define(function(require,exports,module){var _Market=require("market");require("region"),$(function(){region.start(),new _Market({});UM.getEditor("myEditor")})});