import { searchScene } from '../../../../services/inspection/fetchScene'; import { useLoading } from '../../../../behaviors/loading'; Page({ behaviors: [useLoading], data: { placeholder: '输入关键词搜索场景', searchValue: '', isSearch: false, searchResult: [], historyWords: [], dialog: { title: '确认删除当前历史记录', showCancelButton: true, message: '', }, dialogShow: false, }, historyTag: 'inspectionScene', deleteType: 0, deleteIndex: '', onLoad(options) {}, onShow() { this.queryHistory(); }, onReachBottom() { this._loadMore(); }, queryHistory() { wx.getStorage({ key: this.historyTag, success: res => { this.setData({ historyWords: res.data, }); }, }); }, //删除某个历史记录 deleteCurr(e) { const { index } = e.currentTarget.dataset; const { dialog } = this.data; this.deleteIndex = index; this.setData({ dialog: { ...dialog, message: '确认删除当前历史记录', deleteType: 0, }, dialogShow: true, }); }, //清空历史记录 handleClearHistory() { const { dialog } = this.data; this.deleteType = 1; this.setData({ dialog: { ...dialog, message: '确认删除所有历史记录', }, dialogShow: true, }); }, confirm() { const { historyWords } = this.data; const { deleteType, deleteIndex } = this; if (deleteType === 0) { historyWords.splice(deleteIndex, 1); this.setData({ historyWords, dialogShow: false, }); } else { this.setData({ historyWords: [], dialogShow: false }); } wx.setStorage({ key: this.historyTag, data: [], }); }, close() { this.setData({ dialogShow: false }); }, //点击历史记录 handleHistoryTap(e) { const { historyWords } = this.data; const { dataset } = e.currentTarget; const _searchValue = historyWords[dataset.index || 0] || ''; if (_searchValue) { this.setData({ searchValue: _searchValue }); this._startLoad(); } }, //点击搜索 handleSubmit() { const { historyWords, searchValue } = this.data; if (historyWords.indexOf(searchValue) == -1) { historyWords.push(searchValue); this.setData({ historyWords }); } wx.setStorage({ key: this.historyTag, data: historyWords, }); this._startLoad(); }, //清除搜索 handleClear() { this.setData({ searchValue: '', searchResult: [], isSearch: false }); }, handleChange() { if (this.data.searchValue == '') { this.setData({ searchResult: [], isSearch: false }); } }, _fetchData(page) { const { searchValue } = this.data; if (searchValue.length === 0) return; this.setData({ isSearch: true }); const area = { sceneName: searchValue, }; return searchScene(area, page).then(res => { this.setData({ searchResult: page == 1 ? res.data : this.data.searchResult.concat(res.data), }); return res.head; }); }, handCellClick(e) { const scene = e.detail; wx.navigateTo({ url: '/pages/inspection/detail/index', success: result => { result.eventChannel.emit('acceptInspectionDetailData', { scene: scene, time: new Date(), }); }, }); }, });