|
|
@@ -0,0 +1,155 @@
|
|
|
+Component({
|
|
|
+ options: {
|
|
|
+ addGlobalClass: true
|
|
|
+ },
|
|
|
+ lifetimes: {
|
|
|
+ attached() {
|
|
|
+ if (wx.getStorageSync('SearchHistory')) this.setData({
|
|
|
+ history: wx.getStorageSync('SearchHistory')
|
|
|
+ })
|
|
|
+ getApp().globalData.Language.getLanguagePackage(this)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ properties: {
|
|
|
+ active: {
|
|
|
+ type: [Number, String],
|
|
|
+ value: 0
|
|
|
+ },
|
|
|
+ tabs: {
|
|
|
+ type: Array,
|
|
|
+ value: [{
|
|
|
+ title: "中止"
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ onChangeTab: {
|
|
|
+ type: Function
|
|
|
+ },
|
|
|
+ onSearch: {
|
|
|
+ type: Function
|
|
|
+ },
|
|
|
+ threshold: {
|
|
|
+ type: [String, Number],
|
|
|
+ value: 4
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data: {
|
|
|
+
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ onChange({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ this.triggerEvent("onChangeTab", detail)
|
|
|
+ },
|
|
|
+ /* 开启关闭搜索 */
|
|
|
+ clickSearch() {
|
|
|
+ this.setData({
|
|
|
+ startUsing: !this.data.startUsing
|
|
|
+ });
|
|
|
+ setTimeout(this.setListHeight, 400)
|
|
|
+ },
|
|
|
+ /* 搜索 */
|
|
|
+ confirmSearch(e) {
|
|
|
+ if (this.data.condition == e.detail.value) return;
|
|
|
+ this.setData({
|
|
|
+ condition: e.detail.value
|
|
|
+ })
|
|
|
+ this.triggerEvent("onSearch", e.detail.value)
|
|
|
+ },
|
|
|
+ /* 开始搜索 */
|
|
|
+ startSearch({
|
|
|
+ detail
|
|
|
+ }) {
|
|
|
+ if (this.data.condition == detail) return;
|
|
|
+ this.setData({
|
|
|
+ condition: detail
|
|
|
+ })
|
|
|
+ this.triggerEvent("onSearch", detail)
|
|
|
+ if (this.data.record || detail == '') {
|
|
|
+ let list = this.data.history;
|
|
|
+ if (list.findIndex(v => v == detail) == -1) {
|
|
|
+ list.push(detail)
|
|
|
+ this.setData({
|
|
|
+ history: list
|
|
|
+ });
|
|
|
+ wx.setStorageSync("SearchHistory", list)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ /* 取消搜索 */
|
|
|
+ endSearch() {
|
|
|
+ this.setData({
|
|
|
+ condition: ""
|
|
|
+ })
|
|
|
+ this.triggerEvent("onSearch", "")
|
|
|
+ },
|
|
|
+ /* 删除搜索历史 */
|
|
|
+ deleteHistory(e) {
|
|
|
+ let that = this;
|
|
|
+ wx.showModal({
|
|
|
+ cancelText: getApp().globalData.Language.getMapText('取消'),
|
|
|
+ confirmText: getApp().globalData.Language.getMapText('确定'),
|
|
|
+ title: getApp().globalData.Language.getMapText('提示'),
|
|
|
+ content: getApp().globalData.Language.getMapText('是否删除所有搜索历史'),
|
|
|
+ complete: ({
|
|
|
+ confirm
|
|
|
+ }) => {
|
|
|
+ if (confirm) {
|
|
|
+ wx.setStorageSync("SearchHistory", [])
|
|
|
+ that.setData({
|
|
|
+ history: []
|
|
|
+ });
|
|
|
+ this.setListHeight();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /* 快速搜索 */
|
|
|
+ clickTag(e) {
|
|
|
+ const {
|
|
|
+ name
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ this.setData({
|
|
|
+ condition: name
|
|
|
+ });
|
|
|
+ this.triggerEvent("onSearch", name)
|
|
|
+ },
|
|
|
+ /* 单独删除 */
|
|
|
+ delteTag(e) {
|
|
|
+ const {
|
|
|
+ name
|
|
|
+ } = e.currentTarget.dataset;
|
|
|
+ this.setData({
|
|
|
+ history: this.data.history.filter(v => v != name)
|
|
|
+ });
|
|
|
+ wx.setStorageSync('SearchHistory', this.data.history);
|
|
|
+ this.setListHeight();
|
|
|
+ },
|
|
|
+ /* 设置列表高度 */
|
|
|
+ setListHeight() {
|
|
|
+ let pages = getCurrentPages()[getCurrentPages().length - 1].selectComponent("#ListBox");
|
|
|
+ if (pages) pages.automaticSetHei();
|
|
|
+ },
|
|
|
+ /* 搜索框焦点 */
|
|
|
+ onFocus() {
|
|
|
+ this.setData({
|
|
|
+ showHistory: true
|
|
|
+ });
|
|
|
+ setTimeout(this.setListHeight, 50);
|
|
|
+ },
|
|
|
+ /* 搜索框失焦 */
|
|
|
+ onBlur() {
|
|
|
+ this.setData({
|
|
|
+ showHistory: false
|
|
|
+ })
|
|
|
+ setTimeout(this.setListHeight, 50);
|
|
|
+ },
|
|
|
+ clickFiltration() {
|
|
|
+ let page = getCurrentPages()[getCurrentPages().length - 1];
|
|
|
+ let filtrate = page.selectComponent("#filtrate");
|
|
|
+ if (filtrate) {
|
|
|
+ filtrate.setData({ show: true });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+})
|