brandlist.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. // components/carslider.js
  2. import { get,post } from "../../common/request.js"
  3. import stylemap from "../../common/stylemap"
  4. import pathmap from "../../common/pathmap"
  5. var app = getApp()
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. "show":{
  12. value:false,
  13. type:Boolean
  14. },
  15. "brandrecommend":{
  16. value:[],
  17. type:Array
  18. },
  19. "hasmodel":{
  20. value:false,
  21. type:Boolean
  22. }
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. windowh:app.globalData.windowh
  29. },
  30. ready:function(){
  31. this.getBrands();
  32. var initialheight = Math.round((app.globalData.windowh-300)/26/app.globalData.scale);
  33. this.setData(Object.assign({
  34. initialheight:initialheight
  35. },stylemap));
  36. if(!this.data.brandrecommend.length){
  37. this.loadBrandRecommend();
  38. }
  39. },
  40. /**
  41. * 组件的方法列表
  42. */
  43. methods: {
  44. getBrands:function(){
  45. var _self=this;
  46. get(pathmap.getbrand, {}, function (json) {
  47. var initiallist = {};
  48. var brandlist = []
  49. for(var i = 65; i < 91; i++){
  50. initiallist[String.fromCharCode(i)] = [];
  51. }
  52. json.data.brand.forEach(function(item){
  53. if(Object.prototype.toString.call(initiallist[item.initial])=="[object Array]"){
  54. initiallist[item.initial].push(item);
  55. }
  56. })
  57. var inith = 392;
  58. var scale = app.globalData.scale;
  59. for(var name in initiallist){
  60. var l = initiallist[name].length;
  61. if(l>0){
  62. brandlist.push({
  63. initial:name,
  64. list:initiallist[name],
  65. top:inith/scale
  66. });
  67. inith = inith+45+l*79;
  68. }
  69. }
  70. _self.setData({
  71. brandlist:brandlist
  72. })
  73. })
  74. },
  75. getBrandDetail:function(e){
  76. var _self = this;
  77. var brandinfo = e.currentTarget.dataset;
  78. var series = [];
  79. get(pathmap.serieslist, {brand_id:brandinfo.id}, function (json) {
  80. series = json.data.car_series;
  81. _self.setData({
  82. serieslist:{
  83. belong:brandinfo,
  84. list:series
  85. }
  86. // ,
  87. // searchdata:Object.assign(_self.data.searchdata,{brand:brandinfo.id,car_series:""})
  88. })
  89. })
  90. },
  91. getModel:function(series){
  92. var _self = this;
  93. get(pathmap.carmodel,{
  94. car_series_id:series.car_series_id
  95. },function(json){
  96. _self.setData({
  97. modellist:json.data
  98. })
  99. })
  100. },
  101. selectSeries:function(e){
  102. var _self = this;
  103. var series = e.currentTarget.dataset.series;
  104. var data = {}
  105. if(this.data.hasmodel){
  106. data.showmodel = true;
  107. this.getModel(series);
  108. }else{
  109. data.serieslist = "";
  110. this.triggerEvent("select",{series:series});
  111. }
  112. this.setData(data);
  113. },
  114. selectModel:function(e){
  115. var _self = this;
  116. var model = e.currentTarget.dataset.model;
  117. var data = {serieslist:"",showmodel:false}
  118. this.triggerEvent("select",{model:model});
  119. this.setData(data);
  120. },
  121. filterBack:function(){
  122. this.triggerEvent("close");
  123. this.setData({serieslist:""})
  124. },
  125. modelBack:function(){
  126. this.setData({showmodel:false});
  127. },
  128. scrollInit:function(e){
  129. var init = e.currentTarget.dataset.init;
  130. this.setData({
  131. scrolltoinit:init
  132. })
  133. },
  134. waitScroll:null,
  135. brandScroll:function(e) {
  136. var _self = this;
  137. //this.setData({ brandScrollTop: e.detail.scrollTop })
  138. if(this.waitScroll){
  139. try{
  140. clearTimeout(this.waitScroll);
  141. }catch(err){}
  142. }
  143. this.waitScroll = setTimeout(function(){
  144. var scrollinit = "";
  145. var list = _self.data.brandlist;
  146. for(var i=0,l=list.length;i<l;i++){
  147. if(e.detail.scrollTop<list[i].top){
  148. // scrollinit = list[i?i-1:i].initial;
  149. scrollinit=(i?i-1:i)
  150. break;
  151. }
  152. }
  153. _self.setData({scrollinit:scrollinit})
  154. },50)
  155. },
  156. loadBrandRecommend:function(){
  157. var _self = this;
  158. get(pathmap.brandrecommend, {
  159. }, function (json) {
  160. _self.setData({
  161. brandrecommend:json.data
  162. })
  163. })
  164. }
  165. }
  166. })