小程序模糊查询

wxml

 

       

               

                    {{item.companyname}} 

               

       

js

data: {

    showInputStatus: false,

    inputValue: '',//点击结果项之后替换到文本框的值

    // adapterSource: ["app", "application", "apply", "weixin", "WeiXin"],//本地匹配源

    adapterSource: [],//本地匹配源a

    bindSource: [],//绑定到页面的数据,根据用户输入动态变化

  },

  clean: function () {

    this.setData({

      prefix: '',

      inputValue:''

    })

  },

  bindKeyInput: function (e) {

    // 当前输入的状态

    var currentInputStatu = e.currentTarget.dataset.statu;

    // console.log(e.currentTarget.id)

    var prefix = e.detail.value//用户实时输入值

    this.setData({

      prefix:e.detail.value

    })

    console.log(prefix)

    var newSource = []//匹配的结果

    var bindSource = []

    if (prefix != "") {

      var self = this

      self.setData(

        {

          showBtnStatus1: false,

          showBtnStatus2: true

        }

      );

      wx.request({

        url: app.globalData.requestur2,  //全局地址

        method: 'get',

        data: {

          method: 'vagueSelect',

          company: prefix

        },

        success: function (info) {

          // 将获取数据显示到视图中

        var bindSource = self.data.bindSource;

        //bindSource.push(info.data.info);

        console.log(info.data.info)

        bindSource = info.data.info

          self.setData({

            bindSource: bindSource

          })

        console.log(bindSource)

          // 隐藏提示

          wx.hideLoading();

        }

      });

    } else {

      currentInputStatu = "close";

      this.setData(

        {

          isScroll: true,

          showBtnStatus1: true,

          showBtnStatus2: false

        }

      );

    }

    if (newSource.length != 0) {

      this.setData({

        bindSource: newSource

      })

    } else {

      this.setData({

        bindSource: []

      })

      currentInputStatu = "close";

      this.setData(

        {

          isScroll: "{{false}}"

        }

      );

    }

    //关闭

    if (currentInputStatu == "close") {

      this.setData(

        {

          showInputStatus: false,

          isScroll: true

        }

      );

    }

    // 显示

    if (currentInputStatu == "open") {

      this.setData(

        {

          showInputStatus: true,

          isScroll: "{{false}}"

        }

      );

    }

  },

  button:function(e) {

    var that = this

    var prefix = this.data.inputValue

    console.log(prefix)

    if (prefix == '') {

      wx.showToast({

        title: '请输入公司名称',

      })

    } else {

      wx.navigateTo({

        url: '/pages/serch/list?comname=' + prefix

      })

      that.clean()

    }


  },

  //点击选型确定input值

  itemtap: function (e) {

    var currentInputStatu = e.currentTarget.dataset.statu;

    console.log(e.target)

    this.setData({

      inputValue: e.target.id,

      bindSource: []

    })

    var self = this


    console.log(e.target.id)

    //关闭

    if (currentInputStatu == "close") {

      this.setData(

        {

          showInputStatus: false,

          isScroll: true

        }

      );

    }

    // 显示

    if (currentInputStatu == "open") {

      this.setData(

        {

          showInputStatus: true,

          isScroll: "{{false}}"

        }

      );

    }

  },

你可能感兴趣的:(小程序模糊查询)