riku
2022-10-12 741d1f7b2e2ac1c3f89d80dfac7625e3427e2367
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
const b_loadingStatus = require("../../../base/behaviors/b_loadingStatus")
const consultservice = require("../../../service/consultservice")
const app = getApp()
 
/**
 * 智能在线咨询的搜索逻辑
 */
module.exports = Behavior({
  behaviors: [b_loadingStatus],
  data: {
    //搜索结果
    results: []
  },
  methods: {
    loadmore(cPage) {
      this.search(this.obj, ++cPage)
    },
    /**
     * 根据关键字及查询类型搜索
     * @param keyword 关键字,若关键字为空白,则按照热门的逻辑搜索
     * @param type 查询类型,包括[1:法规文件,2:法规条目,3:执法案例,4:环保问题],不填写时表示查询所有类型的前5条
     */
    search(obj, cPage = 1, perPage = this.data.perPage) {
      this.obj = obj
      this.setData({loading: true})
      // const t = setTimeout(() => { this.setData({loading: false}) }, 10000);
      var that = this
      const {keyword, type} = obj
      consultservice.searchLaw(app.globalData.accessToken.userId, keyword, cPage, perPage, {
        onPage(head) {
          that.setData({
            cPage: head.page,
            tPage: head.totalPage,
            perPage: perPage
          })
        },
        success(res) {
          let results = that.data.results
          //当分页为第一页时,代表数据全部刷新,删去上一次获取的记录,否则为获取更多数据,保留前一次获取的记录
          if (that.data.cPage == 1) results = []
          results = results.concat(res)
          that.setData({
            results
          })
        },
        complete() {
          that.setData({loading: false})
          clearTimeout(t)
        }
      }, type)
    },
  }
})