brandlist.js 4.3 KB

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