zx 3 years ago
parent b578bd31e0
commit 9e69b227df

@ -5,22 +5,53 @@ Component({
brandList: [],
brandForm: {
brand: ''
}
},
history: [],
},
methods: {
toBrandInsight(e) {
let id = e.currentTarget.dataset.id; //获取点击的id
wx.setStorageSync('sBrand', id);
let name = e.currentTarget.dataset.id.brandname; //获取点击的name
let obj = {
brandname: name,
img: e.currentTarget.dataset.id.img
};
if(wx.getStorageSync('historyBrand').length == 0) {
let arr = [obj];
wx.setStorageSync('historyBrand', arr);
this.setData({history: arr})
} else {
let o = {
brandname: name,
img: e.currentTarget.dataset.id.img
}
let isAdded = false;
for(let i=0;i<this.data.history.length;i++) { //列表中已存在则移到最前,否则添加到最前
if(JSON.stringify(this.data.history[i]) == JSON.stringify(o)) {
isAdded = true;
let arr = wx.getStorageSync('historyBrand');
arr.splice(i, 1);
let replaceArr = [o, ...arr];
wx.setStorageSync('historyBrand', replaceArr);
this.setData({history: replaceArr})
}
}
if(!isAdded) {
let newArr = [o, ...wx.getStorageSync('historyBrand')]
wx.setStorageSync('historyBrand', newArr);
this.setData({history: newArr})
}
}
wx.setStorageSync('sBrand', name);
wx.navigateTo({
url: "/pages/insight/pages/brandInsight/index"
})
},
handlerSearch(value) {
}
},
lifetimes: {
attached() {
if(wx.getStorageSync('historyBrand')) {
this.setData({history: wx.getStorageSync('historyBrand')})
}
wx.showToast({
title: '加载中',
icon: 'loading',
@ -32,12 +63,12 @@ Component({
token: 't%2BrswgjvzGM=',
}).then(res => {
let arr = []
let recommandArr = [];
res.forEach(ele => {
if(ele.firstword == '热门') {
recommandArr.push(ele)
}
});
// let recommandArr = [];
// res.forEach(ele => {
// if(ele.firstword == '热门') {
// recommandArr.push(ele)
// }
// });
for (let i = 65; i <= 90; i++) {
arr.push({
name: String.fromCharCode(i),
@ -53,19 +84,12 @@ Component({
}
this.setData({
brandList:arr,
recommandBrand: recommandArr,
// recommandBrand: recommandArr,
});
setTimeout(() =>{
wx.hideToast();
},500)
});
//推荐品牌
// app.globalData.request({
// action: 'getRecommendSeries',
// token: 't%2BrswgjvzGM=',
// }).then(res => {
// console.log(res);
// });
},
},
})

@ -1,9 +1,9 @@
<view>
<view style="height: 40px;"></view>
<van-search style="width: 100%;" background="#006BFF" model:value="{{ brandForm.brand }}" placeholder="请输入品牌名称" bind:search="handlerSearch" />
<!-- <van-search style="width: 100%;" background="#006BFF" model:value="{{ brandForm.brand }}" placeholder="请输入品牌名称" bind:search="handlerSearch" /> -->
<view class="bs-tabs">
<scroll-view class="bs-tab-sv" scroll-x="true">
<view class="bs-tab-sv-item" wx:for="{{recommandBrand}}" wx:key="index" data-id="{{item.brandname}}" bindtap="toBrandInsight">
<view class="bs-tab-sv-item" wx:for="{{history}}" wx:key="index" data-id="{{item}}" bindtap="toBrandInsight">
<image class="userAvatar" src="{{item.img}}" />
<view class="bs-tab-title">{{item.brandname}}</view>
</view>
@ -12,7 +12,7 @@
<van-index-bar class="bs-bar" sticky-offset-top="40">
<view wx:for="{{brandList}}" wx:for-item="item" wx:key="index">
<van-index-anchor index="{{item.name}}" />
<van-cell wx:for="{{item.data}}" wx:for-item="it" wx:key="index" clickable data-id="{{it.brandname}}" bind:click="toBrandInsight">
<van-cell wx:for="{{item.data}}" wx:for-item="it" wx:key="index" clickable data-id="{{it}}" bind:click="toBrandInsight">
<view slot="title" class="cell-item">
<image slot="icon" class="bs-item-image" src="{{it.img}}" />
<text>{{it.brandname}}</text>

@ -1,11 +1,11 @@
const app = getApp();
Component({
data: {
recommandBrand: [],
brandList: [],
modalList: [],
popShow: false,
currentBrand: '',
history: []
},
methods: {
modalChoose(e) {
@ -57,6 +57,24 @@ Component({
},
toModalInsight(value) {
let id = value.target.dataset.id;
if(wx.getStorageSync('historyModal').length == 0) {
let arr = [id];
wx.setStorageSync('historyModal', arr);
this.setData({history: arr})
} else {
if(wx.getStorageSync('historyModal').indexOf(id) == -1) {
let newArr = [id, ...wx.getStorageSync('historyModal')];
wx.setStorageSync('historyModal', newArr);
this.setData({history: newArr})
} else {
let newArr = wx.getStorageSync('historyModal');
let index = wx.getStorageSync('historyModal').indexOf(id);
newArr.splice(index, 1);
let result = [id, ...newArr];
wx.setStorageSync('historyModal', result);
this.setData({history: result})
}
}
app.globalData.request({
action: 'getBrandName',
token: 't%2BrswgjvzGM=',
@ -77,6 +95,9 @@ Component({
},
lifetimes: {
attached() {
if(wx.getStorageSync('historyModal')) {
this.setData({history: wx.getStorageSync('historyModal')})
}
//页面数据
app.globalData.request({
action: 'getUserBrand',

@ -1,14 +1,14 @@
<view>
<view style="height: 40px;"></view>
<van-search style="width: 100%;" background="#006BFF" placeholder="请输入车型名称" bind:search="handlerSearch" />
<!-- <view class="bs-tabs">
<view class="bs-tabs">
<scroll-view class="bs-tab-sv" scroll-x="true">
<view class="bs-tab-sv-item" wx:for="{{recommandBrand}}" wx:key="index">
<image class="userAvatar" src="{{item.img}}" />
<view class="bs-tab-title">{{item.title}}</view>
<view class="bs-tab-sv-item" wx:for="{{history}}" wx:key="index">
<!-- <image class="userAvatar" src="{{item.img}}" /> -->
<view class="bs-tab-title" data-id="{{item}}" bindtap="toModalInsight">{{item}}</view>
</view>
</scroll-view>
</view> -->
</view>
<van-index-bar class="bs-bar" sticky-offset-top="40">
<view wx:for="{{brandList}}" wx:for-item="item" wx:key="index">
<van-index-anchor index="{{item.name}}" />

@ -85,7 +85,7 @@
.bs-tabs {
width: 100%;
margin-top: 0px;
height: 120rpx;
height: 90rpx;
background: #fff;
border-top-left-radius: 12px;
border-top-right-radius: 12px;

@ -34,7 +34,7 @@ Page({
sSeriesName: wx.getStorageSync('sSeriesName') || '',
}).then(res => {
this.setData({
percent: res.countPercent * 100 + '%'
percent: (res.countPercent * 100).toFixed(2) + '%'
})
});
app.globalData.request({

Loading…
Cancel
Save