index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. if(list.length==1){
  58. list = list.concat(list,list);
  59. }
  60. _self.setData({
  61. goodcars: list
  62. })
  63. })
  64. },
  65. loadRecommendedCar:function(e){
  66. var _self = this;
  67. get(pathmap.recommended, {
  68. offset: 0,
  69. limit: 9
  70. }, function (json) {
  71. var list = retCartData(json.data.list)
  72. _self.setData({
  73. recommended: list
  74. })
  75. })
  76. },
  77. loadLikeCar:function(){
  78. var _self = this;
  79. get(pathmap.like, {
  80. offset: 0,
  81. limit: 10
  82. }, function (json) {
  83. var list = retCartData(json.data.list)
  84. _self.setData({
  85. like: list
  86. })
  87. })
  88. },
  89. /*
  90. 切换头部banner自定义指示点
  91. */
  92. switchTab: function (e) {
  93. var banner = this.data.banner;
  94. banner.forEach(function(item,index){
  95. item.selected = e.detail.current == index;
  96. });
  97. this.setData({
  98. banner: banner
  99. });
  100. },
  101. /*
  102. 切换今日推荐自定义指示点
  103. */
  104. switchReTab:function(e){
  105. var recommended = this.data.recommended;
  106. // var i, item;
  107. // for (i = 0; item = recommended[i]; ++i) {
  108. // item.selected = e.detail.current == i;
  109. // }
  110. recommended.forEach(function(item,index){
  111. item.selected = e.detail.current == index;
  112. })
  113. this.setData({
  114. recommended: recommended
  115. });
  116. },
  117. submitsearchword:function(word){
  118. wx.navigateTo({ url: `../buy/buy?key=${word}`});
  119. },
  120. testPost:function(){
  121. post(pathmap.login,{
  122. mobile:17343011102,
  123. code:1234
  124. },{
  125. "Content-Type":"application/x-www-form-urlencoded"
  126. },function(){
  127. })
  128. }
  129. // /*
  130. // 搜索失去聚焦事件
  131. // */
  132. // inputBlur:function(e){
  133. // inputBlur.call(this,e);
  134. // },
  135. // /*
  136. // 触发搜索聚焦事件
  137. // */
  138. // searchFocus: function (e) {
  139. // searchFocus.call(this, e);
  140. // }
  141. // /*
  142. // 搜索确定时事件
  143. // */
  144. // inputConfirm:function(e){
  145. // inputConfirm.call(this,e)
  146. // },
  147. // scroll:function(e){
  148. // this.setData({
  149. // scrolltop: e.detail.scrollTop == 0
  150. // })
  151. // },
  152. // checkshowout:function(e){
  153. // },
  154. // checkshowoutend:function(e){
  155. // }
  156. })