import {
  imgServerUrl} from '../../config/config.js'
import {
  getPositionList
} 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: function() {
    this.setData({
      pageNo: 1, //当前分页
      isScroll: true, //是否可以滚动
      list: [],
    })
    this.fetchData()
  },
  //获取我的申请岗位
  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
    }
    getPositionList(paramsObj).then(data => {
      var pageNo = data.data.pageNo;
      let setData = {};
      // 是否可以滚动加载数据
      if (data.data.isLast) {
        setData.isScroll = false
      }
      if (data.data.myApplyPosition.length != 0) {
        setData.list = this.data.list.concat(data.data.myApplyPosition)
        setData.pageNo = pageNo;
      } else {
        setData.list = this.data.list;
      }
      this.setData({
        ...setData
      })
    })
  },
  //去详情页
  toDetail(e) {
    const {
      id,
      cate
    } = e.detail;
    wx.navigateTo({
      url: '../detail/index?hpPositionId=' + id + "&cate=" + cate,
    })
  },
})