const _my = require("../../__antmove/api/index.js")(my);
const wx = _my;
// pages/regular_visit_records/regular_visit_records.js
const {
  userWhiteVisitList
} = require("../../utils/api/api");
const app = getApp();
import international from "../../international/appointment_scence/index";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    international: international,
    language: app.data.language,
    list_apply: [],
    list_invite: [],
    //tab的current
    currentPage: 0,
    searchData_apply: {
      data: {
        visitingType: null,
        userWhiteCheckVOList: [{}]
      },
      pageNum: 1,
      pageSize: 6,
      pages: 1
    },
    searchData_invite: {
      data: {
        visitingType: null,
        userWhiteCheckVOList: [{}]
      },
      pageNum: 1,
      pageSize: 10,
      pages: 1
    },
    total: null
  },
  //详情
  goDteail(e) {
    let item = e.target.dataset.item;
    wx.navigateTo({
      url: "/pages/regular_visit_details/regular_visit_details?isRegular=true&&list=" + JSON.stringify(item)
    });
  },
  //获得切换tab的index
  changeSwiper(e) {
    var {
      currentPage
    } = this.data;
    switch (e.currentTarget.dataset.type) {
      case "click":
        currentPage = e.currentTarget.dataset.index;
        break;
      case "slide":
        currentPage = e.detail.current;
        break;
      default:
        break;
    }
    this.setData({
      currentPage
    });
    if (currentPage == 0 && this.data.list_apply.length == 0 || currentPage == 1 && this.data.list_invite.length == 0) {
      this.getList(1, currentPage);
    }
  },
  // scrollView触底事件
  reachBottom(e) {
    this.getList(e.currentTarget.dataset.type);
  },
  // 获取列表 type-> 1:初始化 2：下拉加载  currentPage-> 0: 申请记录 1：邀请记录
  getList(type) {
    let {
      searchData_apply,
      searchData_invite,
      list_apply,
      list_invite,
      currentPage
    } = this.data;
    let obj = currentPage === 0 ? searchData_apply : searchData_invite;
    if (type === 2 && obj.pageNum + 1 > obj.pages) return;
    obj.data.visitingType = currentPage;
    obj.data.userWhiteCheckVOList[0].adminId = app.data.adminInfo.adminId;
    obj.data.userWhiteCheckVOList[0].userWhitelistId = app.data.adminInfo.userWhitelistId;
    obj.pageNum = type === 1 ? 1 : obj.pageNum + 1;
    userWhiteVisitList(obj).then(res => {
      if (currentPage === 0) {
        list_apply = type === 1 ? res.data.list : list_apply.concat(res.data.list);
        searchData_apply.pages = res.data.pages;
        this.setData({
          list_apply: list_apply,
          total: res.data.total
        });
      } else {
        list_invite = type === 1 ? res.data.list : list_invite.concat(res.data.list);
        searchData_invite.pages = res.data.pages;
        this.setData({
          list_invite: list_invite,
          total: res.data.total
        });
      }
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList(1);
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  antmoveAction: function () {
    //执行时动态赋值，请勿删除
  }
});