SearchPage.js 2.75 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
//index.js
//获取应用实例
var app = getApp()
Page({
data: {
list: [
{ zar: 12, title: "title1", content: "content1content1content1content1content1content1content1content1content1content1content1ds到场定损", image: "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg" }
, { zar: 12, title: "title2", content: "content2", image: "http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg" }
, { zar: 12, title: "title2", content: "content2", image: "http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg" }
, { zar: 12, title: "title1", content: "content1", image: "http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg" }
, { zar: 12, title: "title2", content: "content2", image: "http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg" }
, { zar: 12, title: "title2", content: "content2", image: "http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg" }
],
selectHide: false,
inputValue: '',
getSearch: [],
modalHidden: true,
searching:true
},
onLoad: function () {
},
onShow: function () {
var getSearch = wx.getStorageSync('searchData');
this.setData({
getSearch: getSearch,
inputValue: ''
})
console.log('search is onshow', getSearch)
},
/*-------------------- 交互----------*/
// 设置缓存
setSearchStorage: function () {
let data;
let localStorageValue = [];
if (this.data.inputValue != '') {
//调用API从本地缓存中获取数据
var searchData = wx.getStorageSync('searchData') || []
searchData.push(this.data.inputValue)
wx.setStorageSync('searchData', searchData)
this.setData({
getSearch: searchData,
})
} else {
console.log('空白')
}
},
// 加载数据
loadData(){

},
/*-------------------- 交互----------*/
// 返回
back: function () {
wx.navigateBack({
})
},
// 清除输入框
clearInput: function () {
this.setData({
inputValue: ''
})
},
// 输入完成
inputEnd:function(e){
this.setData({
inputValue: e.detail.value,
searching: true
})
this.setSearchStorage()
},
// 清除所有历史
clearAll: function () {
wx.setStorageSync('searchData', [])
this.setData({
getSearch: [],
})
},
// 选择该项历史
selectThis: function (e) {
},
// 删除该项历史
deletThis: function (e) {
console.log(e)
var data = this.data.getSearch
data.splice(e.currentTarget.dataset.index,1)
this.setData({
getSearch: data
})
},
bindInput: function (e) {
this.setData({
inputValue: e.detail.value
})
console.log('bindInput' + this.data.inputValue)
}
})