var_createClass=function(){functiona(e,c){for(varb=0;b<c.length;b++){vard=c[b];d.enumerable=d.enumerable||false;d.configurable=true;if("value"ind){d.writable=true}Object.defineProperty(e,d.key,d)}}returnfunction(d,b,c){if(b){a(d.prototype,b)}if(c){a(d,c)}returnd}}();function_classCallCheck(a,b){if(!(ainstanceofb)){thrownewTypeError("Cannot call a class as a function")}}varERROR_CONF={KEY_ERR:311,KEY_ERR_MSG:"key格式错误",PARAM_ERR:310,PARAM_ERR_MSG:"请求参数信息有误",SYSTEM_ERR:600,SYSTEM_ERR_MSG:"系统错误",WX_ERR_CODE:1000,WX_OK_CODE:200};varBASE_URL="https://apis.map.qq.com/ws/";varURL_SEARCH=BASE_URL+"place/v1/search";varURL_SUGGESTION=BASE_URL+"place/v1/suggestion";varURL_GET_GEOCODER=BASE_URL+"geocoder/v1/";varURL_CITY_LIST=BASE_URL+"district/v1/list";varURL_AREA_LIST=BASE_URL+"district/v1/getchildren";varURL_DISTANCE=BASE_URL+"distance/v1/";varUtils={location2query:functionlocation2query(c){if(typeofc=="string"){returnc}varb="";for(vara=0;a<c.length;a++){vare=c[a];if(!!b){b+=";"}if(e.location){b=b+e.location.lat+","+e.location.lng}if(e.latitude&&e.longitude){b=b+e.latitude+","+e.longitude}}returnb},getWXLocation:functiongetWXLocation(c,b,a){wx.getLocation({type:"gcj02",success:c,fail:b,complete:a})},getLocationParam:functiongetLocationParam(b){if(typeofb=="string"){vara=b.split(",");if(a.length===2){b={latitude:b.split(",")[0],longitude:b.split(",")[1]}}else{b={}}}returnb},polyfillParam:functionpolyfillParam(a){a.success=a.success||function(){};a.fail=a.fail||function(){};a.complete=a.complete||function(){}},checkParamKeyEmpty:functioncheckParamKeyEmpty(c,b){if(!c[b]){vara=this.buildErrorConfig(ERROR_CONF.PARAM_ERR,ERROR_CONF.PARAM_ERR_MSG+b+"参数格式有误");c.fail(a);c.complete(a);returntrue}returnfalse},checkKeyword:functioncheckKeyword(a){return!this.checkParamKeyEmpty(a,"keyword")},checkLocation:functioncheckLocation(c){vara=this.getLocationParam(c.location);if(!a||!a.latitude||!a.longitude){varb=this.buildErrorConfig(ERROR_CONF.PARAM_ERR,ERROR_CONF.PARAM_ERR_MSG+" location参数格式有误");c.fail(b);c.complete(b);returnfalse}returntrue},buildErrorConfig:functionbuildErrorConfig(a,b){return{status:a,message:b}},buildWxRequestConfig:functionbuildWxRequestConfig(c,a){varb=this;a.header={"content-type":"application/json"};a.method="GET";a.success=function(d){vare=d.data;if(e.status===0){c.success(e)}else{c.fail(e)}};a.fail=function(d){d.statusCode=ERROR_CONF.WX_ERR_CODE;c.fail(b.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,result.errMsg))};a.complete=function(d){vare=+d.statusCode;switch(e){caseERROR_CONF.WX_ERR_CODE:c.complete(b.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,d.errMsg));break;caseERROR_CONF.WX_OK_CODE:varf=d.data;if(f.status===0){c.complete(f)}else{c.complete(b.buildErrorConfig(f.status,f.message))}break;default:c.complete(b.buildErrorConfig(ERROR_CONF.SYSTEM_ERR,ERROR_CONF.SYSTEM_ERR_MSG))}};returna},locationProcess:functionlocationProcess(f,e,c,a){vard=this;c=c||function(g){g.statusCode=ERROR_CONF.WX_ERR_CODE;f.fail(d.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,g.errMsg))};a=a||function(g){if(g.statusCode==ERROR_CONF.WX_ERR_CODE){f.complete(d.buildErrorConfig(ERROR_CONF.WX_ERR_CODE,g.errMsg))}};if(!f.location){d.getWXLocation(e,c,a)}else{if(d.checkLocation(f)){varb=Utils.getLocationParam(f.location);e(b)}}}};varQQMapWX=function(){functionb(i){_classCallCheck(this,b);if(!i.key){throwError("key值不能为空")}this.key=i.key}_createClass(b,[{key:"search",value:functionf(i){varl=this;i=i||{};Utils.polyfillParam(i);if(!Utils.checkKeyword(i)){return}vark={keyword:i.keyword,orderby:i.orderby||"_distance",page_size:i.page_size||10,page_index:i.page_index||1,output:"json",key:l.key};if(i.address_format){k.address_format=i.address_format}if(i.filter){k.filter=i.filter}varn=i.distance||"1000";varj=i.auto_extend||1;varm=functionm(o){k.boundary="nearby("+o.latitude+","+o.longitude+","+n+","+j+")";wx.request(Utils.buildWxRequestConfig(i,{url:URL_SEARCH,data:k}))};Utils.locationProcess(i,m)}},{key:"getSuggestion",value:functionh(i){vark=this;i=i||{};Utils.polyfillParam(i);if(!Utils.checkKeyword(i)){return}varj={keyword:i.keyword,region:i.region||"全国",region_fix:i.region_fix||0,policy:i.policy||0,output:"json",key:k.key};wx.request(Utils.buildWxRequestConfig(i,{url:URL_SUGGESTION,data:j}))}},{key:"reverseGeocoder",value:functiona(i){vark=this;i=i||{};Utils.polyfillParam(i);varj={coord_type:i.coord_type||5,get_poi:i.get_poi||0,output:"json",key:k.key};if(i.poi_options){j.poi_options=i.poi_options}varl=functionl(m){j.location=m.latitude+","+m.longitude;wx.request(Utils.buildWxRequestConfig(i,{url:URL_GET_GEOCODER,data:j}))};Utils.locationProcess(i,l)}},{key:"geocoder",value:functiong(i){vark=this;i=i||{};Utils.polyfillParam(i);if(Utils.checkParamKeyEmpty(i,"address")){return}varj={address:i.address,output:"json",key:k.key};wx.request(Utils.buildWxRequestConfig(i,{url:URL_GET_GEOCODER,data:j}))}},{key:"getCityList",value:functionc(i){vark=this;i=i||{};Utils.polyfillParam(i);varj={output:"json",key:k.key};wx.request(Utils.buildWxRequestConfig(i,{url:URL_CITY_LIST,data:j}))}},{key:"getDistrictByCityId",value:functiond(i){vark=this;i=i||{};Utils.polyfillParam(i);if(Utils.checkParamKeyEmpty(i,"id")){return}varj={id:i.id||"",output:"json",key:k.key};wx.request(Utils.buildWxRequestConfig(i,{url:URL_AREA_LIST,data:j}))}},{key:"calculateDistance",value:functione(i){vark=this;i=i||{};Utils.polyfillParam(i);if(Utils.checkParamKeyEmpty(i,"to")){return}varj={mode:i.mode||"walking",to:Utils.location2query(i.to),output:"json",key:k.key};varl=functionl(m){j.from=m.latitude+","+m.longitude;wx.request(Utils.buildWxRequestConfig(i,{url:URL_DISTANCE,data:j}))};if(i.from){i.location=i.from}Utils.locationProcess(i,l)}}]);returnb}();module.exports=QQMapWX;