123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- // 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<l;i++){
- if(e.detail.scrollTop<list[i].top){
- // scrollinit = list[i?i-1:i].initial;
- scrollinit=(i?i-1:i)
- break;
- }
- }
- _self.setData({scrollinit:scrollinit})
- },50)
- },
- loadBrandRecommend:function(){
- var _self = this;
- get(pathmap.brandrecommend, {
- }, function (json) {
- _self.setData({
- brandrecommend:json.data
- })
- })
- }
- }
- })
|