123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- //index.js
- //获取应用实例
- import {get,post} from "../../common/request.js"
- import stylemap from "../../common/stylemap"
- import pathmap from "../../common/pathmap"
- import bindTopSource from "../../common/topsource"
- import { retCartData} from "../../data/car"
- import bindSearch from "../../module/search/search.js"
- const app = getApp();
- Page({
- data: {
- windowh: app.globalData.windowh,
- banner:[],
- goodcars:[],
- recommended:[],
- like:[],
- searchfouce:false
- },
- onLoad: function () {
- var _self = this;
- //this.testPost();
- this.setData(stylemap);
- this.loadBanner();
- this.loadBrandRecommend();
- this.loadGoodCar();
- this.loadRecommendedCar();
- this.loadLikeCar();
- bindSearch(this);
- //bindTopSource(this);
- },
- loadBanner: function () {
- var _self = this;
- get(pathmap.banner, {
- terminal: 0
- }, function (json) {
- _self.setData({
- banner: json.data
- })
- })
- },
- loadBrandRecommend:function(){
- var _self = this;
- get(pathmap.brandrecommend, {
- }, function (json) {
- _self.setData({
- brandrecommend:json.data
- })
- })
- },
- loadGoodCar:function(){
- var _self = this;
- get(pathmap.goodcar, {
- offset: 0,
- limit:3
- }, function (json) {
- var list = json.data.list;
- list.forEach(function(item){
- item.times = new Date(item.time.replace("-","/")).getTime();
- })
- list.sort(function(a,b){
- return a.times<b.times
- })
- list.forEach(function(item,index){
- if(index%2==1){
- item.labels=["精选"];
- }else{
- item.labels=["热议"];
- }
- })
- //console.log(JSON.stringify(list));
- if(list.length==1){
- list = list.concat(list,list);
- }
- _self.setData({
- goodcars: list
- })
- })
- },
- loadRecommendedCar:function(e){
- var _self = this;
- get(pathmap.recommended, {
- offset: 0,
- limit: 9
- }, function (json) {
- var list = retCartData(json.data.list)
- _self.setData({
- recommended: list
- })
- })
- },
- loadLikeCar:function(){
- var _self = this;
- get(pathmap.like, {
- offset: 0,
- limit: 10
- }, function (json) {
- var list = retCartData(json.data.list)
- _self.setData({
- like: list
- })
- })
- },
- /*
- 切换头部banner自定义指示点
- */
- switchTab: function (e) {
- var banner = this.data.banner;
- banner.forEach(function(item,index){
- item.selected = e.detail.current == index;
- });
- this.setData({
- banner: banner
- });
- },
- /*
- 切换今日推荐自定义指示点
- */
- switchReTab:function(e){
- var recommended = this.data.recommended;
- // var i, item;
- // for (i = 0; item = recommended[i]; ++i) {
- // item.selected = e.detail.current == i;
- // }
- recommended.forEach(function(item,index){
- item.selected = e.detail.current == index;
- })
- this.setData({
- recommended: recommended
- });
- },
- submitsearchinfo:function(obj){
- if(obj){
- var info = "";
- for(var name in obj){
- info+=`${name}=${obj[name]}`;
- }
- wx.navigateTo({ url: `../buy/buy?${info}`});
- }
- },
- testPost:function(){
- post(pathmap.login,{
- mobile:17343011102,
- code:1234
- },{
- "Content-Type":"application/x-www-form-urlencoded"
- },function(){
- })
- },
- catchTouchMove:function(){
- return false
- }
- // /*
- // 搜索失去聚焦事件
- // */
- // inputBlur:function(e){
- // inputBlur.call(this,e);
- // },
- // /*
- // 触发搜索聚焦事件
- // */
- // searchFocus: function (e) {
- // searchFocus.call(this, e);
- // }
- // /*
- // 搜索确定时事件
- // */
- // inputConfirm:function(e){
- // inputConfirm.call(this,e)
- // },
- // scroll:function(e){
- // this.setData({
- // scrolltop: e.detail.scrollTop == 0
- // })
- // },
- // checkshowout:function(e){
- // },
- // checkshowoutend:function(e){
- // }
- })
|