index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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.times = new Date(item.time.replace("-","/")).getTime();
  59. })
  60. list.sort(function(a,b){
  61. return a.times<b.times
  62. })
  63. list.forEach(function(item,index){
  64. if(index%2==1){
  65. item.labels=["精选"];
  66. }else{
  67. item.labels=["热议"];
  68. }
  69. })
  70. //console.log(JSON.stringify(list));
  71. if(list.length==1){
  72. list = list.concat(list,list);
  73. }
  74. _self.setData({
  75. goodcars: list
  76. })
  77. })
  78. },
  79. loadRecommendedCar:function(e){
  80. var _self = this;
  81. get(pathmap.recommended, {
  82. offset: 0,
  83. limit: 9
  84. }, function (json) {
  85. var list = retCartData(json.data.list)
  86. _self.setData({
  87. recommended: list
  88. })
  89. })
  90. },
  91. loadLikeCar:function(){
  92. var _self = this;
  93. get(pathmap.like, {
  94. offset: 0,
  95. limit: 10
  96. }, function (json) {
  97. var list = retCartData(json.data.list)
  98. _self.setData({
  99. like: list
  100. })
  101. })
  102. },
  103. /*
  104. 切换头部banner自定义指示点
  105. */
  106. switchTab: function (e) {
  107. var banner = this.data.banner;
  108. banner.forEach(function(item,index){
  109. item.selected = e.detail.current == index;
  110. });
  111. this.setData({
  112. banner: banner
  113. });
  114. },
  115. /*
  116. 切换今日推荐自定义指示点
  117. */
  118. switchReTab:function(e){
  119. var recommended = this.data.recommended;
  120. // var i, item;
  121. // for (i = 0; item = recommended[i]; ++i) {
  122. // item.selected = e.detail.current == i;
  123. // }
  124. recommended.forEach(function(item,index){
  125. item.selected = e.detail.current == index;
  126. })
  127. this.setData({
  128. recommended: recommended
  129. });
  130. },
  131. submitsearchinfo:function(obj){
  132. if(obj){
  133. var info = "";
  134. for(var name in obj){
  135. info+=`${name}=${obj[name]}`;
  136. }
  137. wx.navigateTo({ url: `../buy/buy?${info}`});
  138. }
  139. },
  140. testPost:function(){
  141. post(pathmap.login,{
  142. mobile:17343011102,
  143. code:1234
  144. },{
  145. "Content-Type":"application/x-www-form-urlencoded"
  146. },function(){
  147. })
  148. },
  149. catchTouchMove:function(){
  150. return false
  151. }
  152. // /*
  153. // 搜索失去聚焦事件
  154. // */
  155. // inputBlur:function(e){
  156. // inputBlur.call(this,e);
  157. // },
  158. // /*
  159. // 触发搜索聚焦事件
  160. // */
  161. // searchFocus: function (e) {
  162. // searchFocus.call(this, e);
  163. // }
  164. // /*
  165. // 搜索确定时事件
  166. // */
  167. // inputConfirm:function(e){
  168. // inputConfirm.call(this,e)
  169. // },
  170. // scroll:function(e){
  171. // this.setData({
  172. // scrolltop: e.detail.scrollTop == 0
  173. // })
  174. // },
  175. // checkshowout:function(e){
  176. // },
  177. // checkshowoutend:function(e){
  178. // }
  179. })