riku
2022-08-09 87f6bb4bcb2446b9c9065b58391ae400cd358b77
智能咨询搜索界面
已修改6个文件
已添加5个文件
198 ■■■■ 文件已修改
app.json 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consulthome/consulthome.js 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consulthome/consulthome.wxml 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consultresult/consultresult.js 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consultresult/consultresult.json 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consultresult/consultresult.wxml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consultresult/consultresult.wxss 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consultsearch/consultsearch.js 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/module_consult/consultsearch/consultsearch.wxml 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/baserequest.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/consultservice.js 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app.json
@@ -1,5 +1,4 @@
{
  "entryPagePath": "pages/module_consult/consultsearch/consultsearch",
  "pages": [
    "pages/login/login",
    "pages/home/home",
@@ -18,7 +17,8 @@
    "pages/test/test",
    "pages/promisesign/promisesign",
    "pages/module_consult/consulthome/consulthome",
    "pages/module_consult/consultsearch/consultsearch"
    "pages/module_consult/consultsearch/consultsearch",
    "pages/module_consult/consultresult/consultresult"
  ],
  "window": {
    "backgroundTextStyle": "light",
pages/module_consult/consulthome/consulthome.js
@@ -54,38 +54,31 @@
  },
  /**
   * ç”Ÿå‘½å‘¨æœŸå‡½æ•°--监听页面隐藏
   */
  onHide: function () {
  },
  /**
   * ç”Ÿå‘½å‘¨æœŸå‡½æ•°--监听页面卸载
   */
  onUnload: function () {
  },
  /**
   * é¡µé¢ç›¸å…³äº‹ä»¶å¤„理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  },
  /**
   * é¡µé¢ä¸Šæ‹‰è§¦åº•事件的处理函数
   */
  onReachBottom: function () {
  },
  /**
   * ç”¨æˆ·ç‚¹å‡»å³ä¸Šè§’分享
   */
  onShareAppMessage: function () {
  goto (e) {
    var url = ""
    var index = e.currentTarget.dataset.index
    switch (index) {
      case "0":
        url = ""
        break;
      case "1":
        url = "/pages/module_consult/consultsearch/consultsearch"
        break;
      case "2":
        url = ""
        break;
    }
    if (url != "") {
      wx.navigateTo({
        url: url
      })
    } else {
      wx.showToast({
        title: '功能敬请期待',
        duration: 1000,
        icon: 'none',
        mask: true,
      })
    }
  }
})
pages/module_consult/consulthome/consulthome.wxml
@@ -8,21 +8,21 @@
  </view>
  <view class="page__bd">
    <view class="flex-h">
      <view class="card">
      <view class="card" bindtap="goto" data-index="0">
        <image src="/res/icons/con_pro_bg.png" class="card-bg" mode="scaleToFill"/>
        <view class="card-title">常见问题</view>
        <view class="card-abstract">常见企业环保问题</view>
        <image src="/res/icons/con_pro.png" mode="aspectFit" class="icon"></image>
      </view>
      <view class="divider"></view>
      <view class="card middle">
      <view class="card middle" bindtap="goto" data-index="1">
        <image src="/res/icons/con_lib_bg.png" class="card-bg" mode="scaleToFill"/>
        <view class="card-title">环保知识库</view>
        <view class="card-abstract">环保法律法规</view>
        <image src="/res/icons/con_lib.png" mode="aspectFit" class="icon"></image>
      </view>
      <view class="divider"></view>
      <view class="card">
      <view class="card" bindtap="goto" data-index="2">
        <image src="/res/icons/con_qa_bg.png" class="card-bg" mode="scaleToFill"/>
        <view class="card-title">智能咨询</view>
        <view class="card-abstract">环保专家 åœ¨çº¿å’¨è¯¢</view>
pages/module_consult/consultresult/consultresult.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,28 @@
// pages/module_consult/consultresult/consultresult.js
const consultservice = require("../../../service/consultservice")
const app = getApp()
Page({
  /**
   * é¡µé¢çš„初始数据
   */
  data: {
    keyword: ''
  },
  /**
   * ç”Ÿå‘½å‘¨æœŸå‡½æ•°--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    this.getOpenerEventChannel().on('acceptDataFromOpenerPage', function (data) {
      console.log(data);
      that.data.keyword = data.keyword
    })
  },
  search () {
    consultservice.search(app)
  }
})
pages/module_consult/consultresult/consultresult.json
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,3 @@
{
  "usingComponents": {}
}
pages/module_consult/consultresult/consultresult.wxml
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,2 @@
<!--pages/module_consult/consultresult/consultresult.wxml-->
<text>pages/module_consult/consultresult/consultresult.wxml</text>
pages/module_consult/consultresult/consultresult.wxss
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1 @@
/* pages/module_consult/consultresult/consultresult.wxss */
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({
  /**
   * é¡µé¢çš„初始数据
@@ -17,7 +20,7 @@
   * ç”Ÿå‘½å‘¨æœŸå‡½æ•°--监听页面加载
   */
  onLoad: function (options) {
    this.getHotTopic()
  },
  /**
@@ -25,6 +28,10 @@
   */
  onReady: function () {
  },
  onShow: function () {
    this.getLocalHistory()
  },
  clearInput() {
@@ -45,20 +52,59 @@
   * æœç´¢
   */
  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.histroy.indexOf(this.data.value) == -1) {
      this.data.histroy.unshift(this.data.value)
      wx.setStorage({
        data: JSON.stringify(this.data.histroy),
        key: 'search_history',
      })
    }
  },
  /**
   * èŽ·å–æœ¬åœ°ç¼“å­˜æœç´¢åŽ†å²
   */
  getLocalHistory() {
    var that = this
    wx.getStorage({
      key: 'search_history',
      success: (res) => {
        let h = JSON.parse(res.data)
        that.setData({
          histroy: h
        })
      },
    })
  },
  /**
   * èŽ·å–çƒ­é—¨æœç´¢å†…å®¹
   */
  getHotTopic() {
    var that = this
    consultservice.getTopicLaw(app.globalData.accessToken.userId, {
      success (res) {
        that.setData({
          hotTopic: res
        })
      }
    })
  },
})
pages/module_consult/consultsearch/consultsearch.wxml
@@ -1,24 +1,23 @@
<!--pages/module_consult/consultsearch/consultsearch.wxml-->
<view class="page">
  <view class="page__hd">
    <view class="search-bar" bindtap="search">
    <view class="search-bar">
      <mp-icon icon="search" size="15" color="black"></mp-icon>
      <text>{{searchTips}}</text>
      <input type="text" class="search-bar__input" placeholder="{{placeholder}}" value="{{value}}" focus="{{focus}}" bindinput="inputChange" />
      <text class="weui-icon-clear" hover-class="weui-active" wx:if="{{value.length > 0}}" bindtap="clearInput"></text>
    </view>
    <view class="btn" bindtap="search">搜索</view>
    <view class="btn" bindtap="search">{{value.length > 0 ? '搜索' : '取消'}}</view>
  </view>
  <view class="page__bd">
    <view wx:if="{{histroy.length > 0}}">
      <view>历史记录</view>
      <text wx:for="{{history}}"></text>
      <text wx:for="{{history}}" wx:key="index">{{item}}</text>
    </view>
    <view>大家都在搜</view>
    <view wx:for="{{hotTopic}}">
    <view wx:for="{{hotTopic}}" wx:key="index">
      <text>{{index + 1}}</text>
      <text>{{item}}</text>
      <text>{{item.name}}</text>
      <image src=""></image>
    </view>
  </view>
service/baserequest.js
@@ -51,12 +51,16 @@
    // }
  }
  fun1.fail = function (error) {
    console.log("--------------请求错误----------------" + fun.url);
    console.log(error);
    wx.showToast({
      title: '网络连接失败',
      icon: 'none'
    })
    if (fun.fail) {
    fun.fail(error)
  }
  }
  fun1.complete = fun.complete
  wx.request(fun1)
}
service/consultservice.js
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,28 @@
const $f = require('./baserequest')
module.exports = {
  //根据关键字搜索法律法规
  searchLaw: function (userId, keyword, fun) {
    let cb = {
      url: `/consultation/search/law`,
      params: {
        userId: userId,
        keyword: keyword
      },
    }
    Object.assign(cb, fun)
    $f.get(cb)
  },
  //获取热门
  getTopicLaw: function (userId, fun) {
    let cb = {
      url: `/consultation/topic/law`,
      params: {
        userId: userId,
      },
    }
    Object.assign(cb, fun)
    $f.get(cb)
  },
}