// packageD/auction/auction/auction_vip/auction_vip.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: '',
    id: wx.getStorageSync('yz_uid'),
    password:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // if(options.id){
    //   this.setData({
    //     id:options.id
    //   })
    // }
    this.getSearch();
  },
  goshop(e){
    let id = e.currentTarget.dataset.info.member_id;
    wx.navigateTo({
      url: '/packageD/auction/auctioneer-shop/auctioneer_shop/auctioneer_shop?id='+id,
    });
  },
  golist(e){
    console.log(e);
    let id = e.currentTarget.dataset.info.goods_id;
    let member_id = e.currentTarget.dataset.info.member_id;
    wx.navigateTo({
      url: '/packageD/auction/auction/auction_good/auction_good?id='+id+"&member_id="+member_id,
    });
  },
  yanzhen(e){
    console.log(e.currentTarget.dataset.info.member_id);
    let item = e.currentTarget.dataset.info;
    let id = e.currentTarget.dataset.info.goods_id;
    let member_id = e.currentTarget.dataset.info.member_id;
    if(item.is_verify == 1){
      // wx.navigateTo({
      //   url: '/packageD/auction/auctioneer-shop/auctioneer_shop/auctioneer_shop?id='+id,
      // })
      if(this.data.status == '1'){
        wx.navigateTo({
          url: '/packageD/auction/auction/auction_good/auction_good?id='+id+"&member_id="+member_id,
        });
      }else{
        wx.navigateTo({
          url: '/packageD/auction/auctioneer-shop/auctioneer_shop/auctioneer_shop?id='+id,
        });
      }
    }else{
      this.setData({
        showone:true,
        select_item : item,
        yanzGoodId:id,
        yanzMemberId:member_id
      });
    }
  },
  is_password(e) {
    this.setData({
      password: e.detail.value
    });
  },
  isCoverLayer_passwork(e){
    this.setData({
      showone:false,
      password:''
    });
  },
  // 店铺密码确认
  confirm(){
    if(app._isTextEmpty(this.data.password)){
      wx.showToast({
        title: 'title',
      });
    }
    let json = {
      art:'verifyPassword',
      auction_id:this.data.select_item.member_id,
      passwd:this.data.password
    };
    var that = this;
    let urlStr = app.getNetAddresss('plugin.auction.api.index.getAuctionData');
    app._getNetWork({
      url: urlStr,
      data: json,
      success: function (resdata) {
        var res = resdata.data;
        if (res.result == 1) {
          that.setData({
            showone:false
          });
          if(that.data.status == '1'){
            wx.navigateTo({
              url: '/packageD/auction/auction/auction_good/auction_good?id='+that.data.yanzGoodId+"&member_id="+that.data.select_item.member_id,
            });
          }else{
            wx.navigateTo({
              url: '/packageD/auction/auctioneer-shop/auctioneer_shop/auctioneer_shop?id='+that.data.select_item.member_id,
            });
          }
         
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  selectTap() {
    this.setData({
      select: !this.data.select
    });
    // console.log(this.data.select)
  },
  tapinput(e){
    this.setData({
      keyword:e.detail.value
    });
  },
  nametap(e) {
    this.setData({
      is_name: e.currentTarget.dataset.name,
      select: false,
      status: e.currentTarget.dataset.name == "Auction" ? '2' : '1',
      datas: [],
      page: 1,
      current_page: 1,
      last_page: 1
    });
    this.getSearch();
  },
  gosearchIn(){
    console.log('点击搜索');
    this.getSearch();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

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

  },

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

  },

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

  },

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

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

  },
  getMoreSearch() {
    var that = this;
    let urlStr = app.getNetAddresss('plugin.auction.api.index.getAuctionData');
    let json = {
      keyword: that.data.keyword,
      status: this.data.status,
      auc_status: '',
      is_new: '',
      is_recommend: '',
      auctioneer_id: '',
      art: 'getSearch',
      page: this.data.page,
      is_pass:'1'
    };
    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,
            total:res.data.getSearch.total
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getSearch() {
    var that = this;
    let urlStr = app.getNetAddresss('plugin.auction.api.index.getAuctionData');
    let json = {
      keyword: that.data.keyword,
      status: this.data.status,
      auc_status: '',
      is_new: '',
      is_recommend: '',
      auctioneer_id: '',
      art: 'getSearch',
      page: this.data.page,
      is_pass:'1'
    };
    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,
            total:res.data.getSearch.total
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getStatus() {
    var that = this;
    let urlStr = app.getNetAddresss('plugin.auction.api.index.getAuctionData');
    let json = {
      member_id: this.data.id
    };
    app._getNetWork({
      url: urlStr,
      data: json,
      success: function (resdata) {
        var response = resdata.data;
        if (response.result == 1) {
          that.setData({
            status: response.data.getVerify.status,
          });
        } else {
          wx.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000,
          });
        }
      },
      fail: function (res) {
        console.log(res);
        wx.showToast({
          title: res.msg,
          icon: "none",
          duration: 1000
        });
      }
    });
  },
});