brandlist.js 4.6 KB

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