// packageD/auction/auction/auction_more/auction_more.js
var app = getApp();
import utils from '../../../../utils/util.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    select: false,
    is_name: 'Auction',
    keyword: '',
    status: '1',
    page: 1,
    current_page: 1,
    last_page: 1,
    is_new: '',
    is_recommend: '',
    auctioneer_id: '',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    if(options.is_recommend){
      this.setData({
        is_recommend:options.is_recommend
      });
      wx.setNavigationBarTitle({
        title: '推荐拍品',
      });
    }
    if(options.is_new){
      this.setData({
        is_new:options.is_new
      });
      wx.setNavigationBarTitle({
        title: '最新拍品',
      });
    }
    this.getSearch();
  },
  toDetail(e){
    let id = e.currentTarget.dataset.id.goods_id;
    let member_id = e.currentTarget.dataset.id.member_id?e.currentTarget.dataset.id.member_id:e.currentTarget.dataset.id.auctioneer_id;
    wx.navigateTo({
      url: '/packageD/auction/auction/auction_good/auction_good?id='+id+'&member_id='+member_id,
    });
  },
  gosearch(){
    wx.navigateTo({
      url: '/packageD/auction/auction/auction_search/auction_search',
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if(this.data.current_page >= this.data.last_page){
      wx.showToast({
        title: '没有更多了',
        icon:'none',
        duration:1000
      });
    }else{
      let pagesa = this.data.page+1;
      this.setData({
        page:pagesa
      });
      this.getNew();
    }
  },

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

  },
  getSearch() {
    var that = this;
    let urlStr = app.getNetAddresss('plugin.auction.api.index.getAuctionData');
    let json = {
      keyword: that.data.keyword,
      status: that.data.status,
      auc_status: '',
      is_new: that.data.is_new,
      is_recommend: that.data.is_recommend,
      auctioneer_id: '',
      art: 'getSearch',
      page: this.data.page,
    };
    app._postNetWork({
      url: urlStr,
      data: json,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          if (res.data.getSearch.data.length == 0) {
            if (that.data.status == 1) {
              wx.showToast({
                title: '没有相关拍品',
                icon: 'none',
                duration: 1000
              });
            } else if (that.data.status == 2) {
              wx.showToast({
                title: '没有相关拍卖官',
                icon: 'none',
                duration: 1000
              });
            }
            that.setData({
              datas: []
            });
            return;
          }
          for (let i = 0; i < res.data.getSearch.data.length; i++) {
            res.data.getSearch.data[i].end_shooting = utils.formatTimeTwo(res.data.getSearch.data[i].end_shooting, 'Y-M-D h:m:s');
          }
          that.setData({
            datas: res.data.getSearch.data,
            current_page: res.data.getSearch.current_page,
            last_page: res.data.getSearch.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getNew() {
    var that = this;
    let urlStr = app.getNetAddresss('plugin.auction.api.index.getAuctionData');
    let json = {
      keyword: that.data.keyword,
      status: that.data.status,
      auc_status: '',
      is_new: that.data.is_new,
      is_recommend: that.data.is_recommend,
      auctioneer_id: '',
      art: 'getSearch',
      page: this.data.page,
    };
    app._postNetWork({
      url: urlStr,
      data: json,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          if (res.data.getSearch.data.length == 0) {
            if (that.data.status == 1) {
              wx.showToast({
                title: '没有相关拍品',
                icon: 'none',
                duration: 1000
              });
            } else if (that.data.status == 2) {
              wx.showToast({
                title: '没有相关拍卖官',
                icon: 'none',
                duration: 1000
              });
            }
            that.setData({
              datas: []
            });
            return;
          }
          for (let i = 0; i < res.data.getSearch.data.length; i++) {
            res.data.getSearch.data[i].end_shooting = utils.formatTimeTwo(res.data.getSearch.data[i].end_shooting, 'Y-M-D h:m:s');
          }
          that.setData({
            datas: this.data.datas.concat(res.data.getSearch.data),
            current_page: res.data.getSearch.current_page,
            last_page: res.data.getSearch.last_page
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  }
});