searchsecond.js 5.1 KB
// pages/search/search.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    showlist: 0,
    array: ['视频', '图片'],
    index: 0,
    type_id: 1,
    keyword: '',
    historylist: [],
    searcharr: [],
    page: 1,
    sousuoword: true,
    address: [],
    price: [],
    text: [],
    addressarr: [],
    textarr: [],
    pricearr: [],
    selad: -1,
    selte: -1,
    selword: -1,
    home_type_id:'',
    sontype_id: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options,'888899999')
    if (options.index != undefined) {
      this.setData({
        sontype_id: options.sontype_id,
        type_id: options.type_id,
        addressarr: options.addressarr,
        textarr:options.textarr,
        pricearr:options.pricearr,
        keyword:options.keyword,
        index: options.index
      })
    }
    // this.setData({
    //   type_id: app.globalData.type_id,
    //   addressarr: app.globalData.addressarr,
    //   textarr:app.globalData.textarr,
    //   pricearr:app.globalData.pricearr,
    //   keyword:app.globalData.keyword,
    //   index: app.globalData.index
    // })
    this.getsousuo()
  },

  // 输入关键字搜索
  enterword(e) {
    console.log(e)
    this.setData({
      keyword: e.detail.value,
      sousuoword: true,
      // addressarr:[],
      // pricearr:[],
      // textarr:[]
    })
    console.log(this.data.keyword)
  },

  // 输入内容
  shuru(e) {
    console.log(e);
    this.setData({
      keyword: e.detail.value,
      sousuoword: true
    })
  },
  sousuo() {
    // if (this.data.keyword == '') {
    //   wx.showToast({
    //     title: '请输入搜索内容',
    //     icon: 'none'
    //   })
    // } else {
    // }
    this.setData({
      page: 1,
      searcharr: [],
      sousuoword: false
    })
    this.getsousuo();
  },

  // 搜索列表
  getsousuo() {
    let that = this;
    console.log(that.data.type_id)
    let url = 'index/video';
    let param = {
      home_type_id:that.data.home_type_id,
      type_id: that.data.type_id,
      sontype_id: that.data.sontype_id,
      keyword: that.data.keyword,
      page: that.data.page,
      pageNum: 10
    }
    app.post(url, param, 'post').then((res) => {
      console.log(res);
      that.setData({
        searcharr: that.data.searcharr.concat(res.info)
      })
      // that.setData({
      //   sousuoword: true
      // })
      that.setData({
        showlist: 1,
        show: false
      })
      // if (res.length != 0 && this.data.type_id == 1) {
      //   that.setData({
      //     showlist: 1,
      //     show: false
      //   })
      // } else if (res.length != 0 && this.data.type_id == 2) {
      //   that.setData({
      //     showlist: 2,
      //     show: false
      //   })
      // } else if (res.length != 0 && this.data.type_id == 3) {
      //   that.setData({
      //     showlist: 3,
      //     show: false
      //   })
      // } else {
      //   that.setData({
      //     show: false
      //   })
      // }
    }).catch((err) => {

    })
  },

  // 播放视频
  govideo(e) {
    console.log(e)
    let url = e.currentTarget.dataset.url;
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/videodetail/videodetail?id=' + id,
    })
    // wx.navigateTo({
    //   url: '/pages/videoplay/videoplay?url=' + url,
    // })
  },

  govideomei(e) {
    let url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: '/pages/videoplay/videoplay?url=' + url,
    })
  },

  gopic(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/picdetail/picdetail?id=' + id,
    })
  },
  // 点击加载更多
  jiazai() {

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

  },

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

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

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    // wx.redirectTo({
    //   url: '/pages/search/search',
    // })
    // wx.navigateBack
  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.show == false) {
      let newpage = this.data.page;
      newpage++;
      this.setData({
        page: newpage
      })

      this.getsousuo()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let that=this;
    wx.setStorageSync('userid', that.data.user_id)
    return {
      imageUrl:'',
      title: '', // 转发后 所显示的title
      path:'/pages/searchsecond/searchsecond?textarr='+this.data.textarr+'&pricearr='+this.data.pricearr+'&keyword='+this.data.keyword+'&type_id='+this.data.type_id+'&index='+this.data.index,
      // path:'',
      success: (res)=>{    // 成功后要做的事情
          console.log(res)
      },
      fail: function (res) {
          // 分享失败
          console.log(res)
      }
  }
  }
})