// components/carslider.js import { get,post } from "../../common/request.js" import stylemap from "../../common/stylemap" import pathmap from "../../common/pathmap" var app = getApp() Component({ /** * 组件的属性列表 */ properties: { "show":{ value:false, type:Boolean }, "brandrecommend":{ value:[], type:Array }, "hasmodel":{ value:false, type:Boolean }, "getbrand":{ value:"", type:String }, "getseries":{ value:"", type:String } }, /** * 组件的初始数据 */ data: { windowh:app.globalData.windowh }, ready:function(){ this.getBrands(); var initialheight = Math.round((app.globalData.windowh-300)/26/app.globalData.scale); this.setData(Object.assign({ initialheight:initialheight },stylemap)); // if(!this.data.brandrecommend.length){ // this.loadBrandRecommend(); // } }, /** * 组件的方法列表 */ methods: { getBrands:function(){ var _self=this; get(this.data.getbrand||pathmap.getbrand, {}, function (json) { var initiallist = {}; var brandlist = []; var list = Object.prototype.toString.call(json.data)=="[object Array]"?json.data:json.data.brand; for(var i = 65; i < 91; i++){ initiallist[String.fromCharCode(i)] = []; } list.forEach(function(item){ if(Object.prototype.toString.call(initiallist[item.initial])=="[object Array]"){ initiallist[item.initial].push(item); } }) var inith = _self.data.brandrecommend.length?392:0; var scale = app.globalData.scale; for(var name in initiallist){ var l = initiallist[name].length; if(l>0){ brandlist.push({ initial:name, list:initiallist[name], top:inith/scale }); inith = inith+45+l*79; } } _self.setData({ brandlist:brandlist }) }) }, getBrandDetail:function(e){ var _self = this; var brandinfo = e.currentTarget.dataset; var series = []; get(this.data.getseries||pathmap.serieslist, {brand_id:brandinfo.id}, function (json) { series = Object.prototype.toString.call(json.data)=="[object Array]"?json.data:json.data.car_series; _self.setData({ serieslist:{ belong:brandinfo, list:series } // , // searchdata:Object.assign(_self.data.searchdata,{brand:brandinfo.id,car_series:""}) }) }) }, getModel:function(series){ var _self = this; get(pathmap.carmodel,{ car_series_id:series.car_series_id },function(json){ _self.setData({ modellist:json.data }) }) }, selectSeries:function(e){ var _self = this; var series = e.currentTarget.dataset.series; var data = {} if(this.data.hasmodel){ data.showmodel = true; this.getModel(series); }else{ data.serieslist = ""; this.triggerEvent("select",{series:series}); } this.setData(data); }, selectModel:function(e){ var _self = this; var model = e.currentTarget.dataset.model; var data = {serieslist:"",showmodel:false} this.triggerEvent("select",{model:model}); this.setData(data); }, filterBack:function(){ this.triggerEvent("close"); this.setData({serieslist:""}) }, modelBack:function(){ this.setData({showmodel:false}); }, scrollInit:function(e){ var init = e.currentTarget.dataset.init; this.setData({ scrolltoinit:init }) }, waitScroll:null, brandScroll:function(e) { var _self = this; //this.setData({ brandScrollTop: e.detail.scrollTop }) if(this.waitScroll){ try{ clearTimeout(this.waitScroll); }catch(err){} } this.waitScroll = setTimeout(function(){ var scrollinit = ""; var list = _self.data.brandlist; for(var i=0,l=list.length;i