import {
  imgServerUrl} from '../../config/config.js'
import {
  myInterViewList
} from '../../services/index.js'
var app = getApp();

Page({
  data: {
    imgServerUrl: imgServerUrl,
    pageNo: 1, //当前分页
    isScroll: true, //是否可以滚动
    groupOn: 0,
    list: [],
    showNoMore: "没有更多信息...", //显示已无更多
  },

  //下拉刷新
  onPullDownRefresh: function () {
    this.setData({
      pageNo: 1, //当前分页
      isScroll: true, //是否可以滚动
      list: [],
    })
    this.fetchData()
  },

  onReachBottom: function () {
    var pageNo = this.data.pageNo + 1;
    this.setData({
      pageNo
    })
    this.fetchData()
  },
  onLoad() {
    this.setData({
      pageNo: 1, //当前分页
      isScroll: true, //是否可以滚动
      list: [],
    })
    this.fetchData()
  },
  onShow: function () {

  },

  //获取我的申请岗位
  fetchData() {
    if (!this.data.isScroll) {
      return false
    }
    let paramsObj = {
      pageNo: this.data.pageNo,
      user_id: app.globalData.userId,
      user_token: app.globalData.userToken,
      member_id: app.globalData.memberId
    }
    myInterViewList(paramsObj).then(data => {
      var pageNo = data.data.pageNo;
      let setData = {};
      // 是否可以滚动加载数据
      if (data.data.isLast) {
        setData.isScroll = false
      }
      if (data.data.myInterView.length != 0) {
        setData.list = this.data.list.concat(data.data.myInterView.map(value => {
          // 获取面试邀请ID
          value.hpPosition.position.id = value.id;
          return value.hpPosition.position
        }))
        setData.pageNo = pageNo;
      } else {
        setData.list = this.data.list;
      }
      this.setData({
        ...setData
      })
    })
  },
  //去详情页
  toDetail(e) {
    const {
      id,
      cate
    } = e.detail;
    wx.navigateTo({
      url: '../interview-detail/index?interviewId=' + id,
    })
  },
})