index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //index.js
  2. //获取应用实例
  3. import {get,post} from "../../common/request.js"
  4. import stylemap from "../../common/stylemap"
  5. import pathmap from "../../common/pathmap"
  6. import bindTopSource from "../../common/topsource"
  7. import { retCartData} from "../../data/car"
  8. import bindSearch from "../../module/search/search.js"
  9. const app = getApp();
  10. Page({
  11. data: {
  12. windowh: app.globalData.windowh,
  13. banner:[],
  14. goodcars:[],
  15. recommended:[],
  16. like:[],
  17. searchfouce:false
  18. },
  19. onLoad: function () {
  20. var _self = this;
  21. //this.testPost();
  22. this.setData(stylemap);
  23. this.loadBanner();
  24. this.loadBrandRecommend();
  25. this.loadGoodCar();
  26. this.loadRecommendedCar();
  27. this.loadLikeCar();
  28. bindSearch(this);
  29. //bindTopSource(this);
  30. },
  31. loadBanner: function () {
  32. var _self = this;
  33. get(pathmap.banner, {
  34. terminal: 0
  35. }, function (json) {
  36. _self.setData({
  37. banner: json.data
  38. })
  39. })
  40. },
  41. loadBrandRecommend:function(){
  42. var _self = this;
  43. get(pathmap.brandrecommend, {
  44. }, function (json) {
  45. _self.setData({
  46. brandrecommend:json.data
  47. })
  48. })
  49. },
  50. loadGoodCar:function(){
  51. var _self = this;
  52. get(pathmap.goodcar, {
  53. offset: 0,
  54. limit:3
  55. }, function (json) {
  56. var list = json.data.list;
  57. list.forEach(function(item){
  58. item.labels = ["精选"]
  59. })
  60. if(list.length==1){
  61. list = list.concat(list,list);
  62. }
  63. _self.setData({
  64. goodcars: list
  65. })
  66. })
  67. },
  68. loadRecommendedCar:function(e){
  69. var _self = this;
  70. get(pathmap.recommended, {
  71. offset: 0,
  72. limit: 9
  73. }, function (json) {
  74. var list = retCartData(json.data.list)
  75. _self.setData({
  76. recommended: list
  77. })
  78. })
  79. },
  80. loadLikeCar:function(){
  81. var _self = this;
  82. get(pathmap.like, {
  83. offset: 0,
  84. limit: 10
  85. }, function (json) {
  86. var list = retCartData(json.data.list)
  87. _self.setData({
  88. like: list
  89. })
  90. })
  91. },
  92. /*
  93. 切换头部banner自定义指示点
  94. */
  95. switchTab: function (e) {
  96. var banner = this.data.banner;
  97. banner.forEach(function(item,index){
  98. item.selected = e.detail.current == index;
  99. });
  100. this.setData({
  101. banner: banner
  102. });
  103. },
  104. /*
  105. 切换今日推荐自定义指示点
  106. */
  107. switchReTab:function(e){
  108. var recommended = this.data.recommended;
  109. // var i, item;
  110. // for (i = 0; item = recommended[i]; ++i) {
  111. // item.selected = e.detail.current == i;
  112. // }
  113. recommended.forEach(function(item,index){
  114. item.selected = e.detail.current == index;
  115. })
  116. this.setData({
  117. recommended: recommended
  118. });
  119. },
  120. submitsearchword:function(word){
  121. if(word){
  122. wx.navigateTo({ url: `../buy/buy?keys=${word}`});
  123. }
  124. },
  125. testPost:function(){
  126. post(pathmap.login,{
  127. mobile:17343011102,
  128. code:1234
  129. },{
  130. "Content-Type":"application/x-www-form-urlencoded"
  131. },function(){
  132. })
  133. }
  134. // /*
  135. // 搜索失去聚焦事件
  136. // */
  137. // inputBlur:function(e){
  138. // inputBlur.call(this,e);
  139. // },
  140. // /*
  141. // 触发搜索聚焦事件
  142. // */
  143. // searchFocus: function (e) {
  144. // searchFocus.call(this, e);
  145. // }
  146. // /*
  147. // 搜索确定时事件
  148. // */
  149. // inputConfirm:function(e){
  150. // inputConfirm.call(this,e)
  151. // },
  152. // scroll:function(e){
  153. // this.setData({
  154. // scrolltop: e.detail.scrollTop == 0
  155. // })
  156. // },
  157. // checkshowout:function(e){
  158. // },
  159. // checkshowoutend:function(e){
  160. // }
  161. })