search.js 3.0 KB
// pages/index/search/search.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchHistory: ['111', '222'],
    imgs: ['/images/img3.png', '/images/img3.png', '/images/img3.png'],
    more_state: false,
    list: [],
    page:1,
    keyword:'',
  },
  getSearch(e){
    this.setData({
      keyword:e.detail.value
    })
  },

  goSearch(e) {
    let that = this;
    let url = '/home/index/index';
    let param = {
      page: this.data.page,
      order: '',
      sex: '',
      style_id: '',
      stature: '',
      weight: '',
      keyword: this.data.keyword,
    }
    let header = {
      'XX-Token': wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, param, header).then((res) => {
      if (res.data.code == 20000) {
        var list = res.data.data.list
        if (list != '') {
          that.setData({
            list: list,
            page: res.data.data.page,
          })
        } else {
          wx.showToast({
            title: '暂无数据',
            icon: 'none'
          })
          that.setData({
            list: list,
            page: res.data.data.page,
          })
        }
      }
    }).catch((errMsg) => {})

  },
  previewImg(e) {
    const current = e.currentTarget.dataset.index;
    var imgs = this.data.imgs;
    wx.previewImage({
      current: imgs[current],
      urls: imgs
    })
  },

  showMore() {
    this.setData({
      more_state: !(this.data.more_state)
    })
  },

  complain() {
    wx.navigateTo({
      url: '/pages/index/comment/comment',
    })
  },

  getData() {
    let url = '/home/index/history'
    let params = {}
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      if (res.data.code == 20000) {
        this.setData({
          list: res.data.data.list
        })
      }

    })
  },

  clearHistory() {
    let url = '/home/index/historyDelete'
    let params = {}
    let header = {
      "XX-Token": wx.getStorageSync('token'),
      'XX-Device-Type': 'wxapp'
    }
    app.post(url, params, header).then((res) => {
      console.log(res)
      if (res.data.code == 20000) {

      }

    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})