|
|
@@ -27,7 +27,7 @@
|
|
|
<view
|
|
|
class="item margin-right-sm margin-bottom-sm dflex bg-drak border-radius-lg padding-tb-xs padding-lr"
|
|
|
v-for="(item,index) in historyDatas" :key="index" @click="search('history', item)">
|
|
|
- <text>{{item.keyword}}</text>
|
|
|
+ <text>{{item}}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
@@ -84,13 +84,19 @@
|
|
|
loadData() {
|
|
|
let _self=this
|
|
|
//搜索历史列表
|
|
|
- searchlist().then((res) => {
|
|
|
- if(res.success){
|
|
|
- _self.historyDatas = res.data.list
|
|
|
- }else{
|
|
|
- _self.$message.warning('没有符合条件的数据!')
|
|
|
- }
|
|
|
- })
|
|
|
+ let history = uni.getStorageSync('historyKeyword');
|
|
|
+ console.log(history,'history')
|
|
|
+ if (history) {
|
|
|
+ _self.historyDatas = history.split(',');
|
|
|
+ }
|
|
|
+ console.log(_self.historyDatas,'_self.historyDatas')
|
|
|
+ // searchlist().then((res) => {
|
|
|
+ // if(res.success){
|
|
|
+ // _self.historyDatas = res.data.list
|
|
|
+ // }else{
|
|
|
+ // _self.$message.warning('没有符合条件的数据!')
|
|
|
+ // }
|
|
|
+ // })
|
|
|
//热门搜索列表
|
|
|
searchhot().then((res) => {
|
|
|
if(res.success){
|
|
|
@@ -100,6 +106,21 @@
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ //判断条数和去重
|
|
|
+ removeRepeat: function (value) {
|
|
|
+ for (let i = 0; i < this.historyDatas.length; i++) {
|
|
|
+ if (value === this.historyDatas[i]) {
|
|
|
+ this.historyDatas.splice(i, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (this.historyDatas.length < 10) {
|
|
|
+ this.historyDatas.unshift(value);
|
|
|
+ } else {
|
|
|
+ this.historyDatas.pop();
|
|
|
+ this.historyDatas.unshift(value);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
|
|
|
shuru(event){
|
|
|
this.keyword=event.detail.value
|
|
|
@@ -109,18 +130,10 @@
|
|
|
search(type, item) {
|
|
|
switch (type) {
|
|
|
case 'history':
|
|
|
- this.keyword=item.keyword
|
|
|
- for( var i=0;i<this.historyDatas.length;i++){
|
|
|
- if(item.keyword=this.historyDatas[i].keyword){
|
|
|
- var id=this.historyDatas[i].id
|
|
|
- var userId=this.historyDatas[i].userId
|
|
|
- var searchCnt=parseInt(this.historyDatas[i].searchCnt)+1
|
|
|
- var createBy=this.historyDatas[i].createBy
|
|
|
- var createTime=this.historyDatas[i].createTime
|
|
|
- }
|
|
|
- }
|
|
|
+ this.removeRepeat(item);
|
|
|
+ uni.setStorageSync('historyKeyword', this.historyDatas.toString());
|
|
|
this.$api.togoodslist({
|
|
|
- keyword: item.keyword,
|
|
|
+ keyword: item,
|
|
|
userId:userId,
|
|
|
searchCnt:searchCnt,
|
|
|
createBy:createBy,
|
|
|
@@ -147,6 +160,8 @@
|
|
|
});
|
|
|
break;
|
|
|
default:
|
|
|
+ this.removeRepeat(this.keyword);
|
|
|
+ uni.setStorageSync('historyKeyword', this.historyDatas.toString());
|
|
|
this.$api.togoodslist({
|
|
|
keyword: this.keyword,
|
|
|
searchCnt:1,
|
|
|
@@ -168,14 +183,8 @@
|
|
|
content: '清空搜索历史',
|
|
|
success: function(res) {
|
|
|
if (res.confirm) {
|
|
|
- var data=ids
|
|
|
- searchclear(data).then((res) => {
|
|
|
- if(res.success){
|
|
|
- _this.historyDatas = [];
|
|
|
- return;
|
|
|
- }
|
|
|
- _this.$api.msg(res.msg)
|
|
|
- })
|
|
|
+ uni.removeStorageSync('historyKeyword') //删除缓存
|
|
|
+ _this.historyDatas=[]
|
|
|
} else if (res.cancel) {
|
|
|
console.log('用户点击取消');
|
|
|
}
|