微信小程序多表独立查询

时间:2020-07-03 09:15:48   收藏:0   阅读:208

代码如下:

wxml文件
<view class="search">
  <view class="search_arr">
    <icon class="searchcion" size="20" type="search"></icon>
    <input placeholder="请输入搜索产品名称" bindconfirm="gosearch" type="text" confirm-type="search"></input>
  </view>
</view>
wxss文件
.search{
  margin: 2% 0% 2% 1%;
  width: 98%;
}
.search_arr{
  border: 1px solid #d0d0d0;
  border-radius: 10rpx;
}
.search_arr input{
  margin-left: 60rpx;
  height: 60rpx;
  border-radius: 5px;
}
.searchcion {
  margin: 10rpx 10rpx 10rpx -5rpx;
  position: absolute;
  left: 25rpx;
  z-index: 2;
  width: 20px;
  height: 20px;
  text-align: center;
}
js文件
我这里是从五个表里面查询
gosearch: function(e){
    var that = this;
    var search = e.detail.value; 
    if (search){
      db.collection("panotherlist").where({
        text: search
      }).get().then(res => {
        if(res.data.length != 0){
          that.data.sresult = JSON.stringify(res.data);
        }
        db.collection("pcuttinglist").where({
          text: search
        }).get().then(res => {
          if (res.data.length != 0) {
            that.data.sresult = that.data.sresult + JSON.stringify(res.data);
          }
          db.collection("pdrilllist").where({
            text: search
          }).get().then(res => {
            if (res.data.length != 0) {
              that.data.sresult = that.data.sresult + JSON.stringify(res.data);
            }
            db.collection("pgrindinglist").where({
              text: search
            }).get().then(res => {
              if (res.data.length != 0) {
                that.data.sresult = that.data.sresult + JSON.stringify(res.data);
              }
              db.collection("ppollpicklist").where({
                text: search
              }).get().then(res => {
                if (res.data.length != 0) {
                  that.data.sresult = that.data.sresult + JSON.stringify(res.data);
                }
                if ((JSON.parse(that.data.sresult)).length === 0) {
                  wx.showToast({
                    title: ‘暂时没有该产品您可以联系我们的客服添加相关产品‘,
                    icon: ‘none‘,
                    duration: 2000
                  })
                } else {
                  wx.navigateTo({
                    url: ‘../searchShow/searchShow?value=‘ + encodeURIComponent(that.data.sresult)
                  })
                }
              })
            })
          })
        })
        }).catch(err => {
          console.log(err)
        })
    }else{
      wx.showToast({
        title: ‘输入不能为空‘,
        icon: ‘none‘,
        duration: 1500
      })
    }
  }
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!