text: !function(){function e(){}function t(t,i){var n,a,r,l,d,o,c=new e,u=null;$(t).html('<div class="vehicle-model-filter-wrap">'+s.M2+s.M1+"</div>"),a=$(t).find(".vehicle-model-filter-wrap"),r=a.find(".vehicle-model-filter-module"),l=r.eq(1),d=r.eq(0),this.$elements=n={$wrap:a,$module:r,$M1:l,$M2:d,$content:l.find(".vehicle-model-filter-content"),$loading:l.find(".vehicle-model-filter-preloader"),$compare:l.find(".result-compare"),$number:l.find(".result-number"),$remainder:l.find(".result-remainder"),$result:l.find(".vehicle-model-filter-result"),$resultList:l.find(".result-list"),$filter:l.find(".filter-list"),$footer:l.find(".vehicle-model-filter-footer"),$brandInput:d.find(".m2-select-brand input"),$brandList:d.find(".m2-select-brand ul"),$seriesList:d.find(".m2-select-series select")},this.work=c,o={vin:"",productionDate:"",displacement:"",power:"",errorTip:c.errorTip,success:c.success,manualInput:c.manualInput},$.extend(o,i),this.common=u={vin:o.vin,seriesid:"",productionDate:o.productionDate,displacement:o.displacement,power:o.power,niankuan:[],brand:"",series:"",model:"",seriesyear:""},c.errorTip=o.errorTip,c.success=o.success,c.manualInput=o.manualInput,c.filterHad=[],c.niankuanList=[],c.init(this,n,u)}var i="http://vmodel.youyiche.com",n={getAllBrand:i+"/series/allbrands",getSeriesByBrandid:i+"/series/getbybrandid",getSeriesByVin:i+"/series/getbyvin",getFilterResult:i+"/model/search",getNiankuanBySeriesid:i+"/series/getniankuan",getVehicleModelDetail:i+"/model/getcarmodeldetail"},a={seriesList:'<option value="">请选择车系</option>'},s={M1:'<div class="vehicle-model-filter-module vehicle-model-filter-M1"><div class="vehicle-model-filter-content"><div class="vehicle-model-filter-result"><dl><dt><div class="clearfix"><span class="pull-left">共有<b class="result-number vehicle-stress"></b>款车符合条件：</span><a href="#" target="_blank" class="pull-right result-compare vehicle-stress">图片对比</a></div></dt><dd class="vehicle-m1-list"><ul class="result-list"></ul></dd><dd class="vehicle-m1-more text-right"><a href="#" class="vehicle-stress result-remainder" data-handle="handleM1LookMore"></a></dd><dd class="vehicle-m1-manual text-right"><span class="vehicle-stress" data-handle="handleM1ToManual">上面这些车型都不对？请手工填写车型</span></dd></dl></div><div class="vehicle-model-filter-condition vehicle-model-filter-list"><ul class="filter-list"></ul></div><div class="vehicle-model-filter-footer vehicle-btn-group-specific"><span class="btn btn-danger btn-vehicle-sure" data-handle="handleM1ConfirmModelEnd">就是这款车</span><p class="vehicle-jump"><span class="vehicle-stress" data-handle="handleM1ToManual">上面这款车不对？请手工填写车型</span></p></div></div><div class="vehicle-model-filter-preloader"></div></div>',M2:'<div class="vehicle-model-filter-module vehicle-model-filter-M2"><div class="form-horizontal"><div class="vehicle-model-filter-series"><ul class="filter-series-list clearfix"><li class="filter-series-item clearfix m2-select-brand"><label class="filter-series-item-title control-label">品牌</label><div class="filter-series-item-content filter-series-item-brand"><input type="text" class="form-control" data-handle-input="handleM2InputBrand" data-handle-change="handleM2ChangeBrand" placeholder="请选择品牌" /><ul></ul></div></li><li class="filter-series-item clearfix m2-select-series"><label class="filter-series-item-title control-label">车系</label><div class="filter-series-item-content filter-series-item-series"><select class="filter-series-select form-control" data-handle-change="handleM2ChangeSeries">'+a.seriesList+"</select></div></li></ul></div></div></div>"};e.prototype={constructor:e,lineWrapLength:4,lineWrapLengthTitle:7,pinpaiList:null,errorTip:function(e){alert(e)},success:function(e,t){console.log(t)},manualInput:function(){},removeZero:function(e){var t=e.split(/[\/-]/),i=[];return $.each(t,function(){parseInt(this,10)&&i.push(parseInt(this,10))}),i.join("/")},ajaxResponseError:function(e,t){0==e.errno?t(e):this.errorTip(e.errmsg)},lineWrapCondition:function(e,t){var i={className:"",value:e};return"number"==typeof e&&(e=e.toString()),e.length>t&&(e.length==t+1?i.className=" small":(i.className=" small linewrap",i.value=e.substring(0,t)+"<br />"+e.substring(t))),i},createHTMLSingleResult:function(e,t){var i=t>2?" remainder-item":"",n='<li class="clearfix'+i+'"><p class="title pull-left"><a href="'+e[1]+'" target="_blank" title="'+e[0]+'">'+e[0]+'</a></p><p class="confirm pull-right"><a href="#" class="vehicle-stress" data-modelid="'+e[2]+'" data-handle="handleM1ConfirmModel">是这款</a></p></li>';return n},createHTMLSingleConditionNot:function(e,t){var i,n,a,s,r,l="",d=e[2].length,o=t?"handleM1ChooseNiankuan":"handleM1ChooseCondition";for(a=this.lineWrapCondition(e[1],this.lineWrapLengthTitle),n=0;n<d;n++){if(s="",r=this.lineWrapCondition(e[2][n],this.lineWrapLength),t&&t.length)for(var c=0;c<t.length;c++)if(e[2][n]==t[c]){s="yet ";break}l+='<span class="'+s+"btn-condition"+r.className+'" data-handle="'+o+'" title="'+e[2][n]+'">'+r.value+"</span>"}return i='<li class="filter-item clearfix"><div class="filter-item-title'+a.className+'">'+a.value+'</div><div class="filter-item-content"><div class="condition-list" data-name="'+e[1]+'" data-key="'+e[0]+'">'+l+"</div></div></li>"},createHTMLSingleConditionHad:function(e){var t,i,n;return t=this.lineWrapCondition(e.name,this.lineWrapLengthTitle),i=this.lineWrapCondition(e.value,this.lineWrapLength),n='<li class="filter-item clearfix"><div class="filter-item-title'+t.className+'">'+t.value+'</div><div class="filter-item-content"><div class="condition-list" data-name="'+e.name+'" data-key="'+e.key+'"><span class="yet btn-condition'+i.className+'" data-handle="handleM1CancelCondition" title="'+e.value+'">'+i.value+"</span></div></div></li>"},createHTMLNiankuanCondition:function(e){var t="",i=["niankuan","年款",this.niankuanList];return t=this.createHTMLSingleConditionNot(i,e.niankuan)},createHTMLSelectList:function(e){for(var t=a.seriesList,i=0,n=e.length;i<n;i++)t+='<option value="'+e[i][1]+'">'+e[i][0]+"</option>";return t},getBrandOrSeriesList:function(e,t){var i=this;$.getJSON(e,function(e){i.ajaxResponseError(e,function(e){var i=e.data.list||[];t(i)})})},getNiankuanBySeriesid:function(e,t){var i=this,a=i.removeZero(e.productionDate),s=n.getNiankuanBySeriesid+"?seriesid="+e.seriesid;a&&(s+="&proyear="+a),$.getJSON(s,function(n){i.ajaxResponseError(n,function(){i.niankuanList=n.data.list.allyears,e.niankuan=i.updateNiankuan(n.data.list.seriesyear),i.updateAdditional(e,n.data.list.displacement,n.data.list.power),t&&t()})})},getSeriesByVin:function(e,t,i){var a,s=this;a=n.getSeriesByVin+"?vin="+e.vin,$.getJSON(a,function(n){0!=n.errno?s.invalidVIN(t,e):(e.seriesid=n.data.seriesid,e.brand=n.data.brand,e.series=n.data.series,s.pinpaiList?s.inputBrandAndSeries(e,e.brand,t,!0):s.getBrandList(e,t,function(){s.inputBrandAndSeries(e,e.brand,t,!0)}),s.getNiankuanBySeriesid(e,i))})},getFilterResult:function(e,t,i){for(var a,s,r=this,l="?vin="+t.vin+"&seriesid="+t.seriesid+"&niankuan="+t.niankuan,d=n.getFilterResult+l,o={},c=0,u=r.filterHad.length;c<u;c++)a=r.filterHad[c].key,s=r.filterHad[c].value,o[a]=s;e.$content.hide(),e.$loading.show(),$.ajax({url:d,type:"POST",data:o,dataType:"json",success:function(n){r.ajaxResponseError(n,function(n){e.$loading.hide(),e.$content.show(),r.showFilterResult(e,n,t),i&&i(n)})}})},getVehicleModelDetail:function(e,t){var i=this,a=n.getVehicleModelDetail+"?modelid="+t;$.getJSON(a,function(t){i.ajaxResponseError(t,function(t){i.success(e,t)})})},getBrandList:function(e,t,i){var a=this;a.getBrandOrSeriesList(n.getAllBrand,function(e){a.pinpaiList=e,i&&i()})},inputBrandAndSeries:function(e,t,i,n){for(var s=0;s<this.pinpaiList.length;s++)if(t==this.pinpaiList[s][0]){brandid=this.pinpaiList[s][1];break}brandid?(i.$brandInput.val(t),this.showSeriesList(i,brandid,function(){n&&i.$seriesList.val(e.seriesid)})):i.$seriesList.html(a.seriesList)},showBrandList:function(e,t,i){var n=[],a="";$.each(this.pinpaiList,function(){var e=this[0].toLocaleUpperCase(),t=this[2].toLocaleUpperCase(),a=i.toLocaleUpperCase();0!=e.indexOf(a)&&0!=t.indexOf(a)||n.push(this)}),$.each(n,function(){var e='<li data-handle="handleM2SelectBrand" data-brandId="'+this[1]+'">'+this[0]+"</li>";a+=e}),n.length&&e.$brandList.html(a).show()},showSeriesList:function(e,t,i){var a=this,s=n.getSeriesByBrandid+"?brandid="+t;a.getBrandOrSeriesList(s,function(t){var n=a.createHTMLSelectList(t);e.$seriesList.html(n),i&&i()})},showFilterResult:function(e,t,i){var n,a,s,r=t.data.list,l="",d=t.data.filter,o=this.filterHad,c=r.length,u=d.length,h=o.length,f="",p="",m="";for(e.$compare.attr("href",t.data.compare),e.$number.text(r.length),l=r.length>3?"还有"+(r.length-3)+"条，点击展开查看":"",e.$remainder.text(l),n=0;n<c;n++)f+=this.createHTMLSingleResult(r[n],n);for(p+=this.createHTMLNiankuanCondition(i),a=0;a<h;a++)p+=this.createHTMLSingleConditionHad(o[a]);for(s=0;s<u;s++)m+=this.createHTMLSingleConditionNot(d[s]);!e.$result.hasClass("had-show-remainder")&&e.$result.toggleClass("show-remainder",c<4),e.$footer.toggleClass("show",1==c),e.$resultList.html(f),e.$filter.html(p+m)},showModule:function(e,t){e.$module.eq(t).show().siblings().hide()},updateSeriesid:function(e,t,i){var n=this;t.brand=e.$brandInput.val(),t.series=e.$seriesList.find("option:selected").text(),t.seriesid=i,t.niankuan=[],this.filterHad=[],this.getNiankuanBySeriesid(t,function(){n.getFilterResult(e,t)})},updateNiankuan:function(e){var t=[],i=this.niankuanList;if(!e||0==e.length)return t;for(var n=0;n<e.length;n++)for(var a=0;a<i.length;a++)e[n]==i[a]&&t.push(e[n]);return t},updateAdditional:function(e,t,i){var n={key:t.attr,name:t.attrcn},a={key:i.attr,name:i.attrcn},s=function(e,t,i,n){n&&$.each(i,function(i,a){parseFloat(this)==parseFloat(n)&&(e.value=this,t.filterHad.push(e))})};s(n,this,t.value,e.displacement),s(a,this,i.value,e.power)},invalidVIN:function(e,t){e.$content.hide(),this.pinpaiList||this.getBrandList(t,e),this.reset(e)},reset:function(e){e.$compare.attr("href","#"),e.$number.text("0"),e.$resultList.html(""),e.$filter.html(""),e.$brandInput.val(""),e.$seriesList.html(a.seriesList)},start:function(e,t){var i=this;return 17!=t.vin.length?void i.invalidVIN(e,t):void i.getSeriesByVin(t,e,function(){i.getFilterResult(e,t)})},init:function(e,t,i){var n=this;$(document).on("click.model",function(e){$(e.target).parents(".filter-series-item-brand").length||t.$brandList&&t.$brandList.hide()}),t.$wrap.on("click",function(a){var s=$(a.target).data("handle");s&&a.preventDefault(),s&&r[s](e,t,n,i,a)}),t.$wrap.on("change",function(a){var s=$(a.target).data("handleChange");s&&r[s](e,t,n,i,a)}),t.$wrap.on("input propertychange",function(a){var s=$(a.target).data("handleInput");s&&r[s](e,t,n,i,a)}),t.$brandInput.on("focus",function(a){var s=$(a.target).data("handleInput");s&&r[s](e,t,n,i,a)}),n.start(t,i)}};var r={handleM1LookMore:function(e,t,i,n,a){t.$result.addClass("show-remainder had-show-remainder")},handleM1ToManual:function(e,t,i,n,a){i.manualInput()},handleM1ConfirmModel:function(e,t,i,n,a){var s=$(a.target).data("modelid");i.getVehicleModelDetail(e,s)},handleM1ConfirmModelEnd:function(e,t,i,n,a){var s=t.$resultList.find("li").first().find(".confirm a").data("modelid");i.getVehicleModelDetail(e,s)},handleM1ChooseNiankuan:function(e,t,i,n,a){var s=$(a.target).attr("title");$(a.target).hasClass("yet")?$.each(n.niankuan,function(e,t){t==s&&n.niankuan.splice(e,1)}):n.niankuan.push(s),i.getFilterResult(t,n)},handleM1ChooseCondition:function(e,t,i,n,a){var s={key:$(a.target).parent().data("key"),name:$(a.target).parent().data("name"),value:$(a.target).attr("title")};i.filterHad.push(s),i.getFilterResult(t,n)},handleM1CancelCondition:function(e,t,i,n,a){var s=$(a.target).parents("li").index()-1;i.filterHad.splice(s,1),i.getFilterResult(t,n)},handleM2InputBrand:function(e,t,i,n,a){var s=$(a.target).val();a.stopPropagation(),i.showBrandList(t,n,s)},handleM2SelectBrand:function(e,t,i,n,a){var s=$(a.target).text(),r=$(a.target).data("brandid");t.$brandInput.val(s),t.$brandList.hide(),i.showSeriesList(t,r)},handleM2ChangeBrand:function(e,t,i,n,a){var s=$(a.target).val();i.inputBrandAndSeries(n,s,t)},handleM2ChangeSeries:function(e,t,i,n,a){var s=$(a.target).val();s&&i.updateSeriesid(t,n,s)}};t.prototype={constructor:t,update:function(e,t,i,n){this.common.vin=e,this.common.productionDate=t||"",this.common.displacement=i||"",this.common.power=n||"",this.common.niankuan=[],this.common.brand="",this.common.series="",this.common.model="",this.common.seriesyear="",this.work.filterHad=[],this.work.niankuanList=[],this.work.start(this.$elements,this.common)}},window.VehicleModelFilter=t}($);