From edd35a251b58b1fad17015deda92324f74458434 Mon Sep 17 00:00:00 2001
From: unknown <unknown@example.com>
Date: 星期三, 17 八月 2022 00:05:30 +0800
Subject: [PATCH] 台账模块、智能咨询模块

---
 pages/module_consult/consultsearch/consultsearch.js |  145 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 99 insertions(+), 46 deletions(-)

diff --git a/pages/module_consult/consultsearch/consultsearch.js b/pages/module_consult/consultsearch/consultsearch.js
index ce2483c..44a31a9 100644
--- a/pages/module_consult/consultsearch/consultsearch.js
+++ b/pages/module_consult/consultsearch/consultsearch.js
@@ -1,4 +1,7 @@
 // pages/module_consult/consultsearch/consultsearch.js
+const consultservice = require("../../../service/consultservice")
+const app = getApp()
+
 Page({
   /**
    * 椤甸潰鐨勫垵濮嬫暟鎹�
@@ -8,7 +11,7 @@
     placeholder: '鎼滅储',
     value: '',
 
-    histroy: [],
+    history: [],
 
     hotTopic: [],
   },
@@ -17,7 +20,7 @@
    * 鐢熷懡鍛ㄦ湡鍑芥暟--鐩戝惉椤甸潰鍔犺浇
    */
   onLoad: function (options) {
-
+    this.getHotTopic()
   },
 
   /**
@@ -27,61 +30,111 @@
 
   },
 
+  onShow: function () {
+    this.getLocalHistory()
+  },
+
   clearInput() {
-    // @ts-ignore
     this.setData({
       value: '',
       focus: true,
       result: []
-    }); // @ts-ignore
-
-    this.triggerEvent('clear');
-  },
-
-  // @ts-ignore
-  inputFocus(e) {
-    // this.setData({
-    //     searchState: true
-    // })
-    // @ts-ignore
-    this.triggerEvent('focus', e.detail);
-  },
-
-  // @ts-ignore
-  inputBlur(e) {
-    this.setData({
-      focus: false
     });
-    this.triggerEvent('blur', e.detail);
   },
 
-  // @ts-ignore
   inputChange(e) {
     this.setData({
       value: e.detail.value
     });
-    this.triggerEvent('input', e.detail);
-
-    // if (Date.now() - this.lastSearch < this.data.throttle) {
-    //   return;
-    // }
-
-    if (typeof this.data.search !== 'function') {
-      return;
-    }
-
-    this.lastSearch = Date.now();
-    this.timerId = setTimeout(() => {
-      if (Date.now() - this.lastSearch < this.data.throttle) {
-        return;
-      }
-      this.data.search(e.detail.value).then(json => {
-        this.setData({
-          result: json
-        });
-      }).catch(err => {
-        console.error('search error', err);
-      });
-    }, this.data.throttle);
   },
+
+  /**
+   * 鎼滅储
+   */
+  search() {
+    if (this.data.value.length == 0) {
+      wx.navigateBack({
+        delta: 1,
+      })
+      return
+    }
+    var that = this
+    wx.navigateTo({
+      url: '/pages/module_consult/consultresult/consultresult',
+      success: (res) => {
+        // 閫氳繃 eventChannel 鍚戣鎵撳紑椤甸潰浼犻�佹暟鎹�
+        res.eventChannel.emit('acceptDataFromOpenerPage', {
+          keyword: that.data.value
+        })
+      },
+    })
+    
+    if (this.data.history.indexOf(this.data.value) == -1) {
+      let h = this.data.history
+      h.unshift(this.data.value)
+      if (h.length > 10) {
+        h = h.slice(0, 10)
+      }
+      this.setData({
+        history: h
+      })
+      wx.setStorage({
+        data: JSON.stringify(h),
+        key: 'search_history',
+      })
+    }
+  },
+
+  selectHistory (e) {
+    var i = e.currentTarget.dataset.index
+    var kw = this.data.history[i]
+    this.setData({
+      value: kw
+    })
+    this.search()
+  },
+
+  /**
+   * 鑾峰彇鏈湴缂撳瓨鎼滅储鍘嗗彶
+   */
+  getLocalHistory() {
+    var that = this
+    wx.getStorage({
+      key: 'search_history',
+      success: (res) => {
+        let h = JSON.parse(res.data)
+        that.setData({
+          history: h
+        })
+      },
+    })
+  },
+
+  /**
+   * 鑾峰彇鐑棬鎼滅储鍐呭
+   */
+  getHotTopic() {
+    var that = this
+    consultservice.getTopicLaw(app.globalData.accessToken.userId, {
+      success (res) {
+        that.setData({
+          hotTopic: res
+        })
+      }
+    })
+  },
+
+  gotoDetail (e) {
+    var i = e.currentTarget.dataset.index
+    var fileId = this.data.hotTopic[i].mfGuid
+    wx.navigateTo({
+      url: '/pages/module_consult/consultdetail/consultdetail',
+      success: (res) => {
+        // 閫氳繃 eventChannel 鍚戣鎵撳紑椤甸潰浼犻�佹暟鎹�
+        res.eventChannel.emit('acceptDataFromOpenerPage', {
+          fileId: fileId
+        })
+      },
+    })
+  }
 })
\ No newline at end of file

--
Gitblit v1.9.3