// pages/callPhone/callPhone.js
let app = getApp();
import { customRequest } from '../../utils/request.js';
import {
  timeShowXXX,
  getUserApplyOrderStatusById,
  formatDateYMDHM,
} from "../../utils/dateUtil";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    chaShowed: false,
    tabs: [
      { title: "全部" },
      { title: "审核中" },
      { title: "待接待" },
      { title: "待面试" },
      { title: "待入职" },
      { title: "在职中" },
      { title: "已完成" },
    ],
    isTrigger: false,
    activeTab: 0,
    navlist: -1,
    statusmark: 1,
    inputVal: "搜索姓名/手机号",
    hasMoreData: false, // 获取更多数据是否显示

    // 状态栏高度
    statusBarHeight: wx.getStorageSync("statusBarHeight"),
    // 导航栏高度
    navigationBarHeight: wx.getStorageSync("navigationBarHeight"),
    // 胶囊按钮高度
    menuButtonHeight: wx.getStorageSync("menuButtonHeight"),
    // 胶囊信息
    menuButton: wx.getStorageSync("menuButtonInfo"),
    navigatorHeight: 60,
    searchParam: {
      pageSize: 200,
      pageNum: 1,
    },
    billList: [],
    underReviewList: [],
    underReviewNum: "",
    timer: null, // 防抖
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    if (options.info) {
      let info = JSON.parse(options.info);
      console.log(info);
      this.data.searchParam.pageNum = 1;
      this.data.searchParam = { ...this.data.searchParam, ...info };
      console.log(this.data.searchParam);
      switch (info.type) {
        case 10:
          this.data.dateType = "报名时间";
          this.data.dateVal = "createTime";
          break;
        case 20:
          this.data.dateType = "面试时间";
          this.data.dateVal = "status25OperateTime";
          break;
        case 30:
          this.data.dateType = "通过时间";
          this.data.dateVal = "status30OperateTime";
          break;
        case 40:
          this.data.dateType = "入职时间";
          this.data.dateVal = "status40OperateTime";
          break;
        case 50:
          this.data.dateType = "入职时间";
          this.data.dateVal = "status40OperateTime";
          break;
      }
      this.setData({
        info,
        dateVal: this.data.dateVal,
        dateType: this.data.dateType,
      });
    }

    let data = {
      mark: {
        ind: options.status,
      },
    };

    // this.changeactive(data);
    // this.getBillNum();
  },
  onScrollRefresh () {
    this.data.billList = [];
    this.data.searchParam.pageNum = 1;
    this.getList();
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.data.billList = [];
    this.getList();
  },

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

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

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

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return app.sharePageImage()
  },
  getBillNum () {
    let that = this;
    customRequest("/yishoudan/user/apply/order/listStatisticsNum", {
      header: 'headers', method: 'GET', data: {
        code: that.data.wxCode,
        type: "yishoudan",
      }
    }).then((res) => {
      if (res.data.status == 200) {
        that.setData({
          underReviewNum: res.data.data.num10,
        });
      }
    })
    // wx.request({
    //   url: app.globalData.ip + "/yishoudan/user/apply/order/listStatisticsNum",
    //   header: app.globalData.headers,
    //   data: {
    //     code: that.data.wxCode,
    //     // iv: iv,
    //     // encryptedData: encryptedData,
    //     type: "yishoudan",
    //   },
    //   success (res) {
    //     console.log(res);
    //     if (res.data.status == 200) {
    //       that.setData({
    //         underReviewNum: res.data.data.num10,
    //       });
    //     }
    //   },
    // });
  },
  // changeactive: function (e) {
  // 	this.data.searchParam.pageNum = 1;
  // 	this.setData({
  // 		navlist: e.mark.ind,
  // 		searchParam: this.data.searchParam,
  // 		["searchParam.status"]: e.mark.ind,
  // 		billList: [],
  // 	});
  // 	this.getList();
  // },
  onScrollToLower () {
    console.log(this.data.searchParam);
    if (this.data.hasMoreData) {
      this.data.searchParam.pageNum = this.data.searchParam.pageNum + 1;
      this.getList();
    }
  },
  getList: function (under) {
    var that = this;
    console.log(that.data.searchParam);

    that.data.isLoading = true;
    wx.showLoading({
      title: "加载中",
    });
    that.data.searchParam.keys =
      that.data.inputVal == "搜索姓名/手机号" ? "" : that.data.inputVal;
    // debugger;
    customRequest("/yishoudan/statistics/agency/teamDetail", { header: 'headers', method: 'post', data: that.data.searchParam }).then((res) => {
      let data = res.data;
      if (res.data.status == 200) {
        if (
          res.data.data.pageBean.recordList != null &&
          res.data.data.pageBean.recordList.length > 0
        ) {
          res.data.data.pageBean.recordList.forEach((item) => {
            item.createTime = formatDateYMDHM(item.createTime);
            item.status20OperateTime = formatDateYMDHM(item.status20OperateTime);
            item.status25OperateTime = formatDateYMDHM(item.status25OperateTime);
            item.status30OperateTime = formatDateYMDHM(item.status30OperateTime);
            item.status40OperateTime = formatDateYMDHM(item.status40OperateTime);
            item.status48OperateTime = formatDateYMDHM(item.status48OperateTime);
            item.status50OperateTime = formatDateYMDHM(item.status50OperateTime);
            item.status = getUserApplyOrderStatusById(item.status);
          });
        }

        if (
          res.data.data.pageBean.recordList != null &&
          res.data.data.pageBean.recordList.length < 20
        ) {
          var recordListTemp = res.data.data.pageBean.recordList;
          that.data.billList = that.data.billList.concat(recordListTemp);
          that.setData({
            hasMoreData: false,
          });
        } else {
          var recordListTemp = res.data.data.pageBean.recordList;
          that.data.billList = that.data.billList.concat(recordListTemp);
          that.setData({
            hasMoreData: true,
          });
        }

        that.setData({
          billList: that.data.billList,
          isTrigger: false,
        });
        console.log('that.data.billList that.data.billList that.data.billList that.data.billList that.data.billList that.data.billList ',that.data.billList );
        // }
        wx.hideLoading();
      } else {
        app.showTips(that, res.data.msg);
      }
      that.data.isLoading = false;
    }).catch(() => {
      that.data.isLoading = false;

    })
    // wx.request({
    //   url: app.globalData.ip + "/yishoudan/statistics/agency/teamDetail",
    //   data: that.data.searchParam,
    //   header: app.globalData.headers,
    //   method: "post",
    //   success: function (res) {
    //     // debugger;
    //     console.log(res.data);
    //     let data = res.data;
    //     if (res.data.status == 200) {
    //       if (
    //         res.data.data.pageBean.recordList != null &&
    //         res.data.data.pageBean.recordList.length > 0
    //       ) {
    //         res.data.data.pageBean.recordList.forEach((item) => {
    //           item.createTime = formatDateYMDHM(item.createTime);
    //           item.status20OperateTime = formatDateYMDHM(item.status20OperateTime);
    //           item.status25OperateTime = formatDateYMDHM(item.status25OperateTime);
    //           item.status30OperateTime = formatDateYMDHM(item.status30OperateTime);
    //           item.status40OperateTime = formatDateYMDHM(item.status40OperateTime);
    //           item.status48OperateTime = formatDateYMDHM(item.status48OperateTime);
    //           item.status50OperateTime = formatDateYMDHM(item.status50OperateTime);
    //           item.status = getUserApplyOrderStatusById(item.status);
    //         });
    //       }
    //       console.log(res.data.data.pageBean.recordList);
    //       console.log(that.data.dateVal);
    //       // if (under) {
    //       // 	that.setData({
    //       // 		underReviewList: JSON.parse(JSON.stringify(res.data.data.pageBean.recordList)),
    //       // 	});
    //       // 	let list = JSON.stringify(that.data.underReviewList);
    //       // 	wx.navigateTo({
    //       // 		url: "/pages/underReview/index?list=" + list,
    //       // 	});
    //       // 	// wx.hideLoading();
    //       // } else {
    //       // let list = that.data.billList;
    //       // 	that.setData({
    //       //     billList: list.concat(res.data.data.pageBean.recordList),
    //       //     isTrigger:false
    //       // 	});
    //       // }
    //       // else {
    //       // 	that.setData({
    //       // 		billList: res.data.data.pageBean.recordList,
    //       // 	});
    //       // }
    //       // if (res.data.data.pageBean.recordCount > that.data.billList.length) {
    //       // 	that.setData({
    //       // 		hasMoreData: true,
    //       // 	});
    //       // } else {
    //       // 	that.setData({
    //       // 		hasMoreData: false,
    //       // 	});
    //       // }

    //       if (
    //         res.data.data.pageBean.recordList != null &&
    //         res.data.data.pageBean.recordList.length < 20
    //       ) {
    //         var recordListTemp = res.data.data.pageBean.recordList;
    //         that.data.billList = that.data.billList.concat(recordListTemp);
    //         that.setData({
    //           hasMoreData: false,
    //         });
    //       } else {
    //         var recordListTemp = res.data.data.pageBean.recordList;
    //         that.data.billList = that.data.billList.concat(recordListTemp);
    //         that.setData({
    //           hasMoreData: true,
    //         });
    //       }

    //       that.setData({
    //         billList: that.data.billList,
    //         isTrigger: false,
    //       });

    //       // }
    //       wx.hideLoading();
    //     } else {
    //       app.showTips(that, res.data.msg);
    //     }
    //     that.data.isLoading = false;
    //   },
    //   fail: function (res) {
    //     console.log(res);
    //     that.data.isLoading = false;
    //   },
    // });
  },
  goSearch () {
    wx.navigateTo({
      url: "../search/index?from=process",
    });
  },
  inputTyping: function (e) {
    this.setData({
      inputVal: e.detail.value,
    });
    console.log(this.data.inputVal == "");
    if (this.data.inputVal == "") {
      this.data.billList = [];
      this.data.searchParam.pageNum = 1;
      this.data.searchParam.keys = "";
      this.getList();
    }
  },
  searchKey: function (e) {
    console.log(e);
    this.data.billList = [];
    this.data.searchParam.pageNum = 1;
    this.data.searchParam.keys = this.data.inputVal;
    this.getList();
  },
  // searchinput: function (e) {
  // 	let that = this;
  // 	this.setData({
  // 		inputVal: e.detail.value,
  // 	});
  // 	this.data.searchParam.keys = e.detail.value;
  // 	this.data.searchParam.pageNum = 1;
  // 	that.setData({
  // 		billList: [],
  // 		searchParam: this.data.searchParam,
  // 	});
  // 	if (that.data.timer) {
  // 		clearTimeout(that.data.timer);
  // 	}
  // 	that.data.timer = setTimeout(() => {
  // 		this.getList();
  // 	}, 500);
  // },
  clearInput () {
    let that = this;
    this.data.billList = [];
    this.setData({
      inputVal: "搜索姓名/手机号",
      chaShowed: false,
    });

    this.data.searchParam.keys = "";
    this.data.searchParam.pageNum = 1;
    this.setData({
      searchParam: this.data.searchParam,
    });
    this.getList();
  },
  toDetail (e) {
    console.log(e.mark.id);
    console.log(this.data.statusmark);
    wx.navigateTo({
      url: `/pages/billDetail/index?id=${e.mark.id}&relationId=${e.mark.relationId}`,
    });
  },
});
