define(["jquery"],function(a){return{polygons:{},colors:{1:{strokeColor:"#4589ef",fillColor:"#71a3ef"},2:{strokeColor:"#1ebd4f",fillColor:"#1ecb54"},3:{strokeColor:"#06954b",fillColor:"#41ad73"},4:{strokeColor:"#9a6a38",fillColor:"#b38f66"},5:{strokeColor:"#6b543c",fillColor:"#917e6a"}}}.init=function(b){var c=new AMap.Map("allmap",{resizeEnable:!0,zoom:14,doubleClickZoom:!1,center:[b.store.location_y,b.store.location_x]});window.map=c,window.tmodtpl=b.tmodtpl,geofence.isChange=b.isChange,geofence.store=b.store,geofence.areas=b.areas,geofence.areas&&!a.isArray(geofence.areas)||(geofence.areas={}),geofence.areasOriginal=b.areas,geofence.tplArea(),geofence.tplEditor(),geofence.initDom()},geofence.tplArea=function(){var b=tmodtpl("tpl-area",geofence);a(".geofence-container").html(b)},geofence.markerStore=function(){geofence.store.location_y&&geofence.store.location_x&&new AMap.Marker({position:[geofence.store.location_y,geofence.store.location_x],offset:new AMap.Pixel(-10,-36),content:'<div class="marker-start-head-route"></div>'}).setMap(map)},geofence.tplEditor=function(){map.clearMap(),geofence.markerStore(),a.each(geofence.areas,function(a,b){var c=geofence.colors[b.colorType],d=new AMap.Polygon({path:b.path,strokeColor:c.strokeColor,strokeOpacity:.9,strokeWeight:3,fillColor:c.fillColor,fillOpacity:.8});geofence.polygons[a]=d,d.setMap(map)}),a(':hidden[name="areas"]').val(encodeURI(JSON.stringify(geofence.areas)))},geofence.initDom=function(){a(document).off("click","#area-add"),a(document).on("click","#area-add",function(){if(1==geofence.isActive)return!1;var a=geofence.getId("M",0);if(geofence.length(geofence.areas)>=5)return void Notify.info("最多可添加5个！");var b=geofence.getColor(),c=geofence.colors[b];geofence.isActive=1,geofence.areas[a]={delivery_price:0,delivery_free_price:0,send_price:0,strokeColor:c.strokeColor,fillColor:c.fillColor,isActive:1,isAdd:1,path:[],colorType:b};var d=new AMap.MouseTool(map);d.polygon(),AMap.event.addListener(d,"draw",function(b){d.close();var c=b.obj;new AMap.PolyEditor(map,c).open(),geofence.areas[a].path=c.getPath(),geofence.tplArea(),geofence.tplEditor()}),console.dir(geofence.areas),geofence.tplArea(),geofence.tplEditor()}),a(document).off("click",".area-item .editor-area-item"),a(document).on("click",".area-item .editor-area-item",function(){var b=a(this).data("id");if(!b||!geofence.polygons[b])return!1;geofence.isActive=1;var c=geofence.areas[b];c.isActive=1,c.isAdd=0,new AMap.PolyEditor(map,geofence.polygons[b]).open(),geofence.tplArea()}),a(document).off("click",".area-item .btn-reset"),a(document).on("click",".area-item .btn-reset",function(){var b=a(this).data("id");Notify.confirm("退出编辑后，此次修改将不会生效，是否确定退出？",function(){geofence.isActive=0;var a=geofence.areas[b];a.isActive=0,1==a.isAdd?delete geofence.areas[b]:geofence.areas[b]=geofence.areasOriginal[b],geofence.tplArea(),geofence.tplEditor()})}),a(document).off("click",".area-item .btn-delete"),a(document).on("click",".area-item .btn-delete",function(){var b=a(this).data("id");Notify.confirm("确定删除此区域吗？",function(){geofence.isActive=0,delete geofence.areas[b],geofence.tplArea(),geofence.tplEditor()})}),a(document).off("click",".area-item .btn-save"),a(document).on("click",".area-item .btn-save",function(){var b=a(this).data("id");Notify.confirm("确定对该区域进行修改？",function(){var a=geofence.polygons[b];geofence.areas[b].path=a.getPath(),geofence.areas[b].isActive=0,geofence.isActive=0,geofence.tplArea(),geofence.tplEditor()})}),a(document).on("input propertychange change","#area-container .diy-bind",function(){var b=a(this),c=b.data("bind"),d=b.data("bind-child"),e=b.data("bind-parent"),f="",g=this.tagName;if("INPUT"==g){var h=b.data("placeholder");f=b.val(),f=""==f?h:f}else"SELECT"==g?f=b.find("option:selected").val():"TEXTAREA"==g&&(f=b.val());f=a.trim(f),d?e?geofence.areas[d][e][c]=f:geofence.areas[d][c]=f:geofence.areas[c]=f})},geofence.getColor=function(){var b=[1,2,3,4,5];for(var c in geofence.areas){var d=a.inArray(geofence.areas[c].colorType,b);-1!=d&&b.splice(d,1)}return b.shift()},geofence.length=function(a){if(void 0===a)return 0;var b=0;for(var c in a)b++;return b},geofence.getId=function(a,b){return a+(+new Date+b)},geofence});