// pages/forum/forum.js
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

    imgs: null, //本地图片地址
    articleData: null, //文章数据
    banner: [
      // "https://kongbai121.xyz/images/systemData/title3.jpg",
      // "https://kongbai121.xyz/images/systemData/title5.jpg",
      "/images/bg2.jpg",
      // "/images/bg1.jpg",
      "/images/bg3.jpg",
      "/images/bg4.jpg"
      // "https://kongbai121.xyz/images/systemData/title1.jpg"
    ],
    word:"",
    background: ["red", "pink", "yellowgreen"],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 5000,
    duration: 500,
    circular: true,
    select: false,
    grades_loge: '/images/homePage/xia.pngs'
  },



  //-------------------------高级查询------------------

  houduanTab_input(e){
    this.setData({
      inputData:e.detail.value
    })
  },
  mySelect(e) {
    var that = this;
    wx.request({
      url: app.globalData.myUrl + '/Article/list',
      data: {
        'title': that.data.inputData,
      },
      method: 'GET',
      success: (res) => {
        // console.log(res.data);
        that.setData({
          articleData: res.data
        });
      },
      fail: (res) => {},
    })
  },

  //----------------------------清空搜索框---------------------------------
  empty(){
    console.log(123);
    this.setData({
      inputData:''
    })
  },

  //----------------------------查询所有文章-------------------------------
  listArticle() {
    var that = this;
    wx.request({
      url: app.globalData.myUrl + '/Article/list',
      method: 'GET',
      success: (res) => {
        // console.log(res.data);
        that.setData({
          articleData: res.data
        });
      },
      fail: (res) => {},
    })
  },

  //-------------------------文章发布-----------------------------------
  release(){
    var that = this;
    if (!app.globalData.hasLogin) {
      wx.showModal({
        title: '提示',
        content: '你还没有登录喔',
        success: function (res) {
          if (res.confirm) { //这里是点击了确定以后
            wx.switchTab({
              url: '/pages/own/own',
            })
          } else { //这里是点击了取消以后
            that.errShowToast('你还没有登录喔');
          }
        }
      })
      return;
    }
    wx.navigateTo({
      url:'/pages/release/release'
    })
  },

  //-------------------------获取指定文章详情----------------------------
  getArticle(e) {
    wx.navigateTo({
      url:'/pages/data/data?id='+e.currentTarget.id
    })
  },

  //---------------------------函数封装------------------------------
  errShowToast: function (toastText) {
    wx.showToast({
      title: toastText,
      image: '/images/password.png',
      duration: 2000
    });
  },
  sucShowToast: function (toastText) {
    wx.showToast({
      title: toastText,
      duration: 2000
    });
  },



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

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      inputData:''
    });
    this.listArticle();
  },

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

  },

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

  },

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

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

  },

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

  }
})