// pages/channelOrder/index.js
const app = getApp();
var dateTimePicker = require("../../utils/dateTimePicker.js");
var dateUtil = require("../../utils/dateUtil.js");
import { customRequest } from '../../utils/request.js';
const mydate = new Date();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    iosDialog2: false,
    testMap: [],
    recordDetail: {},
    allOrders: [],
    allShow: false,
    orders: [],
    height: 22,
    openShow: true,
    // userServeRecords:[{},{},{},{},{},{},{},{},{}],
    userId: "",
    record: {},
    statusText: "",
    timeText: "",
    timeText2: "",
    timeStr: "",
    timeStr2: "",
    userServeRecords: {},
    desp: "",
    despModal: "",
    isTimeShow: true,
    isTimeShowDbl: true,
    status: "",
    from: "",
    getStatus: "",
    showDialog: false,
    iosDialog1: false,
    stateItems: [
      { value: "25", name: "已接到" },
      { value: "26", name: "未接到" },
    ],
    startYear: 2022,
    endYear: new Date().getFullYear(),
    currentTime: "",
    currentTime1: "",
    currentTime2: "",
    checkedState: "",
    currOrderId: -1,
    binded: null,
  },
  editUser () {
    wx.navigateTo({
      url: "../newEnroll/enrollEdit/index?from=editUser",
    });
  },
  showInfo2 (e) {
    console.log(JSON.parse(e.currentTarget.dataset.detail));

    this.setData({
      iosDialog2: true,
      recordDetail: JSON.parse(e.currentTarget.dataset.detail),
    });
  },
  preventTouchMove () {
    return true;
  },
  close2: function () {
    console.log("close");

    this.setData({
      iosDialog2: false,
    });
  },
  copyClose2 () {
    var that = this;

    var text = "姓名：" + that.data.recordDetail.userName + "/" + (that.data.recordDetail.sex == 1 ? "男" : "女") + "/" + that.data.recordDetail.age + "岁" + (that.data.recordDetail.nation == "族" ? "" : "/" + that.data.recordDetail.nation) + "\n电话：" + (that.data.recordDetail.tel == "" || that.data.recordDetail.tel == undefined || that.data.recordDetail.tel == null ? "-" : that.data.recordDetail.tel) + "\n身份证号：" + (that.data.recordDetail.idCard == "" ? "-" : that.data.recordDetail.idCard) + "\n家庭地址：" + (that.data.recordDetail.address == "" || that.data.recordDetail.address == undefined || that.data.recordDetail.address == null ? "-" : that.data.recordDetail.address) + "\n报名岗位：" + that.data.recordDetail.storeJobName + "\n政策：" + that.data.recordDetail.policy;

    wx.setClipboardData({
      data: text,
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data); // data
            that.close2();
          },
        });
      },
    });
  },

  showInfo () {
    this.setData({
      iosDialog1: true,
    });
  },
  showImgs (e) {
    var that = this;
    let curr = [];
    that.data.urls.forEach((item) => {
      curr.push(item.url);
    });
    wx.previewImage({
      current: e.currentTarget.dataset.src, // 当前显示图片的 http 链接
      urls: curr, // 需要预览的图片 http 链接列表
    });
  },
  getImgs (userId) {
    var that = this;
    customRequest("/imgs/list/" + userId + "?type=20", { header: 'headers', method: 'GET', data: {} }).then((res) => {
      let currFils = [];
      let regs = /\.(jpg|jpeg|png)(\?.*)?$/;
      if (app.isNotEmptyCheck(res.data.data.userImgs)) {
        res.data.data.userImgs.forEach((item) => {
          if (regs.test(item.url.toLowerCase())) {
            currFils.push({ url: item.url, id: item.id });
          }
        });
      }

      that.setData({
        files: currFils.slice(0, 4),
        urls: currFils,
      });
    })
    // wx.request({
    //   url: app.globalData.ip + "/imgs/list/" + userId + "?type=20",
    //   header: app.globalData.headers,
    //   method: "GET",
    //   success: function (res) {
    //     console.log(res);
    //     let currFils = [];
    //     let regs = /\.(jpg|jpeg|png)(\?.*)?$/;
    //     if (app.isNotEmptyCheck(res.data.data.userImgs)) {
    //       res.data.data.userImgs.forEach((item) => {
    //         if (regs.test(item.url.toLowerCase())) {
    //           currFils.push({ url: item.url, id: item.id });
    //         }
    //       });
    //     }

    //     that.setData({
    //       files: currFils.slice(0, 4),
    //       urls: currFils,
    //     });
    //     // }
    //   },
    //   fail: function (res) {
    //     console.log(res);
    //   },
    // });
  },
  copyClose () {
    var that = this;
    var text =
      "姓名：" +
      that.data.record.userName +
      "/" +
      (that.data.record.sex == 1 ? "男" : "女") +
      "/" +
      that.data.record.age +
      "岁" +
      (that.data.record.nation == "族" ? "" : "/" + that.data.record.nation) +
      "\n身份证号：" +
      (that.data.record.idCard == "" ? "-" : that.data.record.idCard) +
      "\n企业岗位：" +
      that.data.allOrders[0].storeJobName +
      (that.data.allOrders[0].isTimeShowDbl && that.data.allOrders[0].status != 30 && that.data.allOrders[0].status != 48 && that.data.allOrders[0].status != 50 && that.data.allOrders[0].status != 35 ? "\n" + that.data.allOrders[0].timeText2 + "：" + that.data.allOrders[0].timeStr2 : "") +
      (that.data.allOrders[0].isTimeShow ? "\n" + that.data.allOrders[0].timeText + "：" + that.data.allOrders[0].timeStr : "") +
      (that.data.allOrders[0].isTimeShowDbl && (that.data.allOrders[0].status == 30 || that.data.allOrders[0].status == 48) ? "\n" + that.data.allOrders[0].timeText2 + "：" + that.data.allOrders[0].timeStr2 : "") +
      "\n电话：" +
      (that.data.record.tel == "" ? "-" : that.data.record.tel);

    wx.setClipboardData({
      data: text,
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data); // data
            that.close1();
          },
        });
      },
    });
  },

  close1: function () {
    console.log("close");

    this.setData({
      iosDialog1: false,
    });
  },

  makePhone (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.tel, //仅为示例，并非真实的电话号码
    });
  },
  getDesp (e) {
    this.setData({
      desp: e.detail.value,
    });
  },
  getPolicy (e) {
    console.log(e.detail.value);

    let currData = {};
    currData["policy"] = e.detail.value;
    currData["orderId"] = this.data.userId;
    customRequest("/yishoudan/user/apply/order/changeOrderPolicy", { header: 'headers', method: 'GET', data: currData }).then((res) => {

    })
    // wx.request({
    //   url: app.globalData.ip + "/yishoudan/user/apply/order/changeOrderPolicy",
    //   method: "GET",
    //   data: currData,
    //   header: app.globalData.headers,
    //   success: function (res) {
    //     console.log(res);
    //   },
    // });
  },
  ifZhankai (e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.data.orders.forEach((item) => {
      if (item.id == id) {
        item.isOpen = true;
      }
    });
    that.setData({
      orders: that.data.orders,
    });
  },
  ifZhedie (e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.data.orders.forEach((item) => {
      if (item.id == id) {
        item.isOpen = false;
      }
    });
    that.setData({
      orders: that.data.orders,
    });
  },
  clearDesp () {
    this.setData({
      desp: "",
    });
  },
  getModalDesp (e) {
    this.setData({
      despModal: e.detail.value,
    });
  },
  // clearDesp(){
  //   this.setData({
  //     despModal:""
  //   });
  // },
  submitDesp () {
    var that = this;
    if (this.data.desp == "") {
      return;
    } else {
      wx.showLoading({
        title: "添加中...",
      });
      let currData = {};
      currData["desp"] = this.data.desp;
      currData["orderId"] = this.data.userId;
      customRequest("/yishoudan/user/apply/order/changeOrderDesp", { header: 'headers', method: 'GET', data: currData }).then((res) => {
        that.setData({
          desp: "",
        });
        wx.hideLoading({
          success: (res) => {
            that.getDetail();

            wx.createSelectorQuery()
              .select(".bb4")
              .boundingClientRect((res) => {
                // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
                // 2使用wx.pageScrollTo()将页面滚动到对应位置
                wx.pageScrollTo({
                  scrollTop: 400, // 滚动到的位置（距离顶部 px）
                  duration: 300, //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
                });
              })
              .exec();
          },
        });
      })
      // wx.request({
      //   url: app.globalData.ip + "/yishoudan/user/apply/order/changeOrderDesp",
      //   method: "GET",
      //   data: currData,
      //   header: app.globalData.headers,
      //   success: function (res) {
      //     console.log(res);
      //     that.setData({
      //       desp: "",
      //     });
      //     wx.hideLoading({
      //       success: (res) => {
      //         that.getDetail();

      //         wx.createSelectorQuery()
      //           .select(".bb4")
      //           .boundingClientRect((res) => {
      //             // 到这里，我们可以从res中读到class为bb4的top，即离顶部的距离（px）
      //             // 2使用wx.pageScrollTo()将页面滚动到对应位置
      //             wx.pageScrollTo({
      //               scrollTop: 400, // 滚动到的位置（距离顶部 px）
      //               duration: 300, //滚动所需时间 如果不需要滚动过渡动画，设为0（ms）
      //             });
      //           })
      //           .exec();
      //       },
      //     });
      //   },
      // });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    wx.showLoading({
      title: "加载中...",
    });
    console.log(options.userId);
    this.setData({
      userId: options.userId,
      from: options.from,
    });
    if (options.binded) {
      this.setData({
        binded: options.binded,
      });
    }
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear, this.data.currentTime);
    console.log(obj.dateTime);

    this.setData({
      dateTimeArray: obj.dateTimeArray,
      dateTimeArray2: obj.dateTimeArray2,
      dateTime: obj.dateTime,
      dateTime1: obj.dateTime,
      dateTime2: obj.dateTime,
    });
  },
  openText (e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.data.orders.forEach((item) => {
      if (item.id == id) {
        item.isOpen = true;
      }
    });
    that.setData({
      orders: that.data.orders,
    });
  },
  closeText (e) {
    var that = this;
    let id = e.currentTarget.dataset.id;
    that.data.orders.forEach((item) => {
      if (item.id == id) {
        item.isOpen = false;
      }
    });
    that.setData({
      orders: that.data.orders,
    });
  },
  goChoose () {
    wx.navigateTo({
      url: "/pages/changeStatus/index?orderId=" + this.data.userId + "&from=" + this.data.from,
    });
  },
  getDetail () {
    var that = this;

    return new Promise(function (resolve, reject) {
      // setTimeout(function(){
      //   var query = wx.createSelectorQuery();
      //   query.select('#text').boundingClientRect();
      //   query.exec((res) => {
      //     res[0].height;
      //     console.log(res[0].height);
      //     that.setData({
      //       height: res[0].height
      //     })
      //   })
      // },10)
      customRequest("/yishoudan/agency/user/details/" + that.data.userId, { header: 'headers', method: 'GET', data: {} }).then((res) => {
        console.log(res.data.data);
        // console.log(res.data.data.orders);
        var statusText = "";
        var timeText = "";
        var timeText2 = "";
        var timeStr = "";
        var timeStr2 = "";
        // var status = res.data.data.allOrders[0].status

        let userinfo = res.data.data.allOrders[0];
        let userinfo2 = {};
        (userinfo2["name"] = userinfo.userName), (userinfo2["nationality"] = userinfo.nation), (userinfo2["num"] = userinfo.idCard), (userinfo2["currentImg"] = userinfo.idCardImageUrl), (userinfo2["sex"] = userinfo.sex), (userinfo2["age"] = userinfo.age), (userinfo2["idCard"] = userinfo.idCard), (userinfo2["userId"] = userinfo.userId), (userinfo2["tel"] = userinfo.tel), (userinfo2["address"] = userinfo.address), wx.setStorageSync("townsManInfo", { ...userinfo2 });

        if (res.data.data.allOrders[0].nation.substr(res.data.data.allOrders[0].nation.length - 1, 1) != "族") {
          res.data.data.allOrders[0].nation = res.data.data.allOrders[0].nation + "族";
        }

        that.getImgs(userinfo.userId);

        that.setData({
          orders: res.data.data.orders,
        });
        that.data.orders.forEach((item, index) => {
          console.log(item);
          item.isOpen = false;

          if (item.status == 60 || item.status == 40) {
            item.isTimeShow = false;
          } else {
            item.isTimeShow = true;
          }
          if (item.status == 25) {
            item.isTimeShowDbl = false;
          } else {
            item.isTimeShowDbl = true;
          }

          if (item.status == 10) {
            item.statusText = "审核中";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);

            item.timeText2 = "接待时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
          } else if (item.status == 20) {
            item.statusText = "待接待";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
            item.timeText2 = "接待时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
          } else if (item.status == 21) {
            item.statusText = "审核未通过";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
            item.timeText2 = "接待时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
          } else if (item.status == 25) {
            item.statusText = "待面试";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
          } else if (item.status == 26) {
            item.statusText = "未接到";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);

            item.timeText2 = "接待时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
          } else if (item.status == 30) {
            item.statusText = "待入职";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);

            item.timeText2 = "约入职时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.willEntryTime);
          } else if (item.status == 35) {
            item.statusText = "面试未通过";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
          } else if (item.status == 40) {
            item.statusText = "在职中";
            item.timeText2 = "入职时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.entryTime);
          } else if (item.status == 48) {
            item.statusText = "约离职";
            item.timeText = "入职时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.entryTime);
            item.timeText2 = "约离职时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.willLeaveTime);
          } else if (item.status == 45) {
            item.statusText = "通过未入职";
            item.timeText = "面试时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
            item.timeText2 = "约入职时间";
            item.timeStr2 = dateUtil.formatDateYMDHM(item.willEntryTime);
          } else if (item.status == 50) {
            item.statusText = "已离职";
            item.timeText = "离职时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.leaveTime);
          } else if (item.status == 60) {
            item.statusText = "已完成";
            item.timeText = "离职时间";
            item.timeStr = dateUtil.formatDateYMDHM(item.leaveTime);
          }
        });

        // wx.setStorage({key: "timeText",data: timeText})
        // wx.setStorage({key: "status",data: status})
        // wx.setStorage({key: "timeStr",data: timeStr})

        // wx.setStorage({key: "timeText2",data: timeText2})
        // wx.setStorage({key: "timeStr2",data: timeStr2})

        // res.data.data.serveRecords.forEach((item,index)=>{

        //   if(item.desp.substr(item.desp.length-3,3) == "备注："){
        //     item.desp = item.desp.replace(/备注：/g,"")
        //   }
        //   // console.log(item.status);
        //   if(item.type == 1){
        //     // debugger;
        //     item["statusText"] =  "报名审核中"
        //   }else if(item.type == 2){
        //     item["statusText"] =  "待接待"
        //   }else if(item.type == 3){
        //     item["statusText"] =  "待入职"
        //   }else if(item.type == 4){
        //     item["statusText"] =  "在职中"
        //   }else if(item.type == 5){
        //     item["statusText"] =  "已离职"
        //   }else if(item.type == 9){
        //     item["statusText"] =  "约离职"
        //   }else if(item.type == 6){
        //     item["statusText"] =  "已完成"
        //   }else if(item.type == 11){
        //     item["statusText"] =  "审核未通过"
        //   }else if(item.type == 12){
        //     item["statusText"] =  "已接到"
        //   }else if(item.type == 13){
        //     item["statusText"] =  "未接到"
        //   }else if(item.type == 14){
        //     item["statusText"] =  "面试未通过"
        //   }else if(item.type == 15){
        //     item["statusText"] =  "未入职"
        //   }
        // })

        // console.log(status)
        // console.log(that.data.stateItems);

        // if(status == 25){
        //   that.data.stateItems = [
        //     {value: '30', name: '面试通过'},
        //     {value: '35', name: '面试未通过'},
        //   ]
        // }else if(status == 30){
        //   that.data.stateItems = [
        //     {value: '40', name: '在职中'},
        //     {value: '45', name: '通过未入职'},
        //   ]
        // }else if(status == 40 || status == 48){
        //   that.data.stateItems = [
        //     {value: '40', name: '在职中'},
        //     {value: '48', name: '约离职'},
        //     {value: '50', name: '已离职'}
        //   ]
        // }else if(status == 10){
        //   that.data.stateItems = [
        //     {value: '20', name: '审核通过'},
        //     {value: '21', name: '审核未通过'}
        //   ]
        // }else if(status == 20){
        //   that.data.stateItems = [
        //     {value: '25', name: '已接到'},
        //     {value: '26', name: '未接到'},
        //   ]
        // }
        //判断是否显示时间

        // res.data.data.serveRecords.forEach((item,index)=>{
        //   // console.log(item.desp.indexOf("备注："));
        //   // console.log(item.desp.substr(item.desp.length-3,3));
        //   if(item.desp.substr(item.desp.length-3,3) == "备注："){
        //     item.desp = item.desp.replace(/备注：/g,"")
        //   }
        // })
        res.data.data.allOrders.forEach((item1) => {
          for (var key in item1.records) {
            // console.log(key, item1.records[key]);

            item1.records[key].forEach((item, index) => {
              if (item.desp.substr(item.desp.length - 3, 3) == "备注：") {
                item.desp = item.desp.replace(/备注：/g, "");
              }

              if (item.type == 1) {
                item["statusText"] = "报名审核中";
              } else if (item.type == 2) {
                item["statusText"] = "待接待";
              } else if (item.type == 3) {
                item["statusText"] = "待入职";
              } else if (item.type == 4) {
                item["statusText"] = "在职中";
              } else if (item.type == 5) {
                item["statusText"] = "已离职";
              } else if (item.type == 9) {
                item["statusText"] = "约离职";
              } else if (item.type == 6) {
                item["statusText"] = "已完成";
              } else if (item.type == 11) {
                item["statusText"] = "审核未通过";
              } else if (item.type == 12) {
                item["statusText"] = "已接到";
              } else if (item.type == 13) {
                item["statusText"] = "未接到";
              } else if (item.type == 14) {
                item["statusText"] = "面试未通过";
              } else if (item.type == 15) {
                item["statusText"] = "未入职";
              }
            });
            // item1.records[key].sort((a,b)=>{
            //   return b.createTime - a.createTime
            // })
          }
        });
        let changeNum = ["十", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
        let newArr = res.data.data.allOrders;
        newArr.forEach((item, index) => {
          let idx = (index + 1).toString();
          let arr = idx.split("");
          let first;
          let second;
          let third;
          if (arr[0]) {
            first = changeNum[arr[0]];
          }
          if (arr[0] == 1 && idx % 10 == 0) {
            first = "";
          }
          if (arr[0] == 1 && arr[1] && idx % 10 != 0) {
            first = changeNum[0];
            second = changeNum[arr[1]];
          }
          if (arr[0] != 1 && arr[1] && idx % 10 != 0) {
            first = changeNum[arr[0]] + "十";
            second = changeNum[arr[1]];
          }
          if (arr[1] && idx % 10 == 0) {
            second = changeNum[0];
          }
          item.idxText = (first || "") + (second || "") + (third || "");
          item.index = index + 1;
        });
        console.log(newArr);
        that.setData({
          allOrders: newArr,
        });

        that.setData({
          // height: 0,
          allShow: true,
          orders: that.data.orders,
          record: res.data.data.allOrders[0],
          statusText: statusText,
          timeText,
          timeText2,
          timeStr,
          timeStr2,
          currentTime: timeStr,
          currentTime1: timeStr,
          currentTime2: timeStr2,
          stateItems: that.data.stateItems,
          userServeRecords: res.data.data.serveRecords,
        });
        resolve(res);

      })
      // wx.request({
      //   url: app.globalData.ip + "/yishoudan/agency/user/details/" + that.data.userId,
      //   method: "GET",
      //   header: app.globalData.headers,
      //   success: function (res) {
      //     console.log(res.data.data);
      //     // console.log(res.data.data.orders);
      //     var statusText = "";
      //     var timeText = "";
      //     var timeText2 = "";
      //     var timeStr = "";
      //     var timeStr2 = "";
      //     // var status = res.data.data.allOrders[0].status

      //     let userinfo = res.data.data.allOrders[0];
      //     let userinfo2 = {};
      //     (userinfo2["name"] = userinfo.userName), (userinfo2["nationality"] = userinfo.nation), (userinfo2["num"] = userinfo.idCard), (userinfo2["currentImg"] = userinfo.idCardImageUrl), (userinfo2["sex"] = userinfo.sex), (userinfo2["age"] = userinfo.age), (userinfo2["idCard"] = userinfo.idCard), (userinfo2["userId"] = userinfo.userId), (userinfo2["tel"] = userinfo.tel), (userinfo2["address"] = userinfo.address), wx.setStorageSync("townsManInfo", { ...userinfo2 });

      //     if (res.data.data.allOrders[0].nation.substr(res.data.data.allOrders[0].nation.length - 1, 1) != "族") {
      //       res.data.data.allOrders[0].nation = res.data.data.allOrders[0].nation + "族";
      //     }

      //     that.getImgs(userinfo.userId);

      //     that.setData({
      //       orders: res.data.data.orders,
      //     });
      //     that.data.orders.forEach((item, index) => {
      //       console.log(item);
      //       item.isOpen = false;

      //       if (item.status == 60 || item.status == 40) {
      //         item.isTimeShow = false;
      //       } else {
      //         item.isTimeShow = true;
      //       }
      //       if (item.status == 25) {
      //         item.isTimeShowDbl = false;
      //       } else {
      //         item.isTimeShowDbl = true;
      //       }

      //       if (item.status == 10) {
      //         item.statusText = "审核中";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);

      //         item.timeText2 = "接待时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
      //       } else if (item.status == 20) {
      //         item.statusText = "待接待";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
      //         item.timeText2 = "接待时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
      //       } else if (item.status == 21) {
      //         item.statusText = "审核未通过";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
      //         item.timeText2 = "接待时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
      //       } else if (item.status == 25) {
      //         item.statusText = "待面试";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
      //       } else if (item.status == 26) {
      //         item.statusText = "未接到";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);

      //         item.timeText2 = "接待时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.receptionTime);
      //       } else if (item.status == 30) {
      //         item.statusText = "待入职";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);

      //         item.timeText2 = "约入职时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.willEntryTime);
      //       } else if (item.status == 35) {
      //         item.statusText = "面试未通过";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
      //       } else if (item.status == 40) {
      //         item.statusText = "在职中";
      //         item.timeText2 = "入职时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.entryTime);
      //       } else if (item.status == 48) {
      //         item.statusText = "约离职";
      //         item.timeText = "入职时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.entryTime);
      //         item.timeText2 = "约离职时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.willLeaveTime);
      //       } else if (item.status == 45) {
      //         item.statusText = "通过未入职";
      //         item.timeText = "面试时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.interviewTime);
      //         item.timeText2 = "约入职时间";
      //         item.timeStr2 = dateUtil.formatDateYMDHM(item.willEntryTime);
      //       } else if (item.status == 50) {
      //         item.statusText = "已离职";
      //         item.timeText = "离职时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.leaveTime);
      //       } else if (item.status == 60) {
      //         item.statusText = "已完成";
      //         item.timeText = "离职时间";
      //         item.timeStr = dateUtil.formatDateYMDHM(item.leaveTime);
      //       }
      //     });

      //     // wx.setStorage({key: "timeText",data: timeText})
      //     // wx.setStorage({key: "status",data: status})
      //     // wx.setStorage({key: "timeStr",data: timeStr})

      //     // wx.setStorage({key: "timeText2",data: timeText2})
      //     // wx.setStorage({key: "timeStr2",data: timeStr2})

      //     // res.data.data.serveRecords.forEach((item,index)=>{

      //     //   if(item.desp.substr(item.desp.length-3,3) == "备注："){
      //     //     item.desp = item.desp.replace(/备注：/g,"")
      //     //   }
      //     //   // console.log(item.status);
      //     //   if(item.type == 1){
      //     //     // debugger;
      //     //     item["statusText"] =  "报名审核中"
      //     //   }else if(item.type == 2){
      //     //     item["statusText"] =  "待接待"
      //     //   }else if(item.type == 3){
      //     //     item["statusText"] =  "待入职"
      //     //   }else if(item.type == 4){
      //     //     item["statusText"] =  "在职中"
      //     //   }else if(item.type == 5){
      //     //     item["statusText"] =  "已离职"
      //     //   }else if(item.type == 9){
      //     //     item["statusText"] =  "约离职"
      //     //   }else if(item.type == 6){
      //     //     item["statusText"] =  "已完成"
      //     //   }else if(item.type == 11){
      //     //     item["statusText"] =  "审核未通过"
      //     //   }else if(item.type == 12){
      //     //     item["statusText"] =  "已接到"
      //     //   }else if(item.type == 13){
      //     //     item["statusText"] =  "未接到"
      //     //   }else if(item.type == 14){
      //     //     item["statusText"] =  "面试未通过"
      //     //   }else if(item.type == 15){
      //     //     item["statusText"] =  "未入职"
      //     //   }
      //     // })

      //     // console.log(status)
      //     // console.log(that.data.stateItems);

      //     // if(status == 25){
      //     //   that.data.stateItems = [
      //     //     {value: '30', name: '面试通过'},
      //     //     {value: '35', name: '面试未通过'},
      //     //   ]
      //     // }else if(status == 30){
      //     //   that.data.stateItems = [
      //     //     {value: '40', name: '在职中'},
      //     //     {value: '45', name: '通过未入职'},
      //     //   ]
      //     // }else if(status == 40 || status == 48){
      //     //   that.data.stateItems = [
      //     //     {value: '40', name: '在职中'},
      //     //     {value: '48', name: '约离职'},
      //     //     {value: '50', name: '已离职'}
      //     //   ]
      //     // }else if(status == 10){
      //     //   that.data.stateItems = [
      //     //     {value: '20', name: '审核通过'},
      //     //     {value: '21', name: '审核未通过'}
      //     //   ]
      //     // }else if(status == 20){
      //     //   that.data.stateItems = [
      //     //     {value: '25', name: '已接到'},
      //     //     {value: '26', name: '未接到'},
      //     //   ]
      //     // }
      //     //判断是否显示时间

      //     // res.data.data.serveRecords.forEach((item,index)=>{
      //     //   // console.log(item.desp.indexOf("备注："));
      //     //   // console.log(item.desp.substr(item.desp.length-3,3));
      //     //   if(item.desp.substr(item.desp.length-3,3) == "备注："){
      //     //     item.desp = item.desp.replace(/备注：/g,"")
      //     //   }
      //     // })
      //     res.data.data.allOrders.forEach((item1) => {
      //       for (var key in item1.records) {
      //         // console.log(key, item1.records[key]);

      //         item1.records[key].forEach((item, index) => {
      //           if (item.desp.substr(item.desp.length - 3, 3) == "备注：") {
      //             item.desp = item.desp.replace(/备注：/g, "");
      //           }

      //           if (item.type == 1) {
      //             item["statusText"] = "报名审核中";
      //           } else if (item.type == 2) {
      //             item["statusText"] = "待接待";
      //           } else if (item.type == 3) {
      //             item["statusText"] = "待入职";
      //           } else if (item.type == 4) {
      //             item["statusText"] = "在职中";
      //           } else if (item.type == 5) {
      //             item["statusText"] = "已离职";
      //           } else if (item.type == 9) {
      //             item["statusText"] = "约离职";
      //           } else if (item.type == 6) {
      //             item["statusText"] = "已完成";
      //           } else if (item.type == 11) {
      //             item["statusText"] = "审核未通过";
      //           } else if (item.type == 12) {
      //             item["statusText"] = "已接到";
      //           } else if (item.type == 13) {
      //             item["statusText"] = "未接到";
      //           } else if (item.type == 14) {
      //             item["statusText"] = "面试未通过";
      //           } else if (item.type == 15) {
      //             item["statusText"] = "未入职";
      //           }
      //         });
      //         // item1.records[key].sort((a,b)=>{
      //         //   return b.createTime - a.createTime
      //         // })
      //       }
      //     });
      //     let changeNum = ["十", "一", "二", "三", "四", "五", "六", "七", "八", "九"];
      //     let newArr = res.data.data.allOrders;
      //     newArr.forEach((item, index) => {
      //       let idx = (index + 1).toString();
      //       let arr = idx.split("");
      //       let first;
      //       let second;
      //       let third;
      //       if (arr[0]) {
      //         first = changeNum[arr[0]];
      //       }
      //       if (arr[0] == 1 && idx % 10 == 0) {
      //         first = "";
      //       }
      //       if (arr[0] == 1 && arr[1] && idx % 10 != 0) {
      //         first = changeNum[0];
      //         second = changeNum[arr[1]];
      //       }
      //       if (arr[0] != 1 && arr[1] && idx % 10 != 0) {
      //         first = changeNum[arr[0]] + "十";
      //         second = changeNum[arr[1]];
      //       }
      //       if (arr[1] && idx % 10 == 0) {
      //         second = changeNum[0];
      //       }
      //       item.idxText = (first || "") + (second || "") + (third || "");
      //       item.index = index + 1;
      //     });
      //     console.log(newArr);
      //     that.setData({
      //       allOrders: newArr,
      //     });

      //     that.setData({
      //       // height: 0,
      //       allShow: true,
      //       orders: that.data.orders,
      //       record: res.data.data.allOrders[0],
      //       statusText: statusText,
      //       timeText,
      //       timeText2,
      //       timeStr,
      //       timeStr2,
      //       currentTime: timeStr,
      //       currentTime1: timeStr,
      //       currentTime2: timeStr2,
      //       stateItems: that.data.stateItems,
      //       userServeRecords: res.data.data.serveRecords,
      //     });
      //     resolve(res);
      //   },
      // });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () {
    var that = this;

    console.log(that.data.userId);
    // wx.request({x
    //   url: app.globalData.ip + "/yishoudan/user/apply/order/markHasRead?orderId=" + that.data.userId,
    //   header: app.globalData.headers,
    //   method: "GET",
    //   success: function (res) {
    //     console.log(res);
    //   },
    // });

    that.getDetail().then((res) => {
      console.log(res);

      console.log(res.data.data.allOrders[0].status != 10);

      if (this.data.from == "project") {
        // 10 为输入框状态
        if (res.data.data.allOrders[0].status != 10) {
          var query = wx.createSelectorQuery();
          query.select("#text").boundingClientRect();
          query.exec((res) => {
            res[0].height;
            that.setData({
              height: res[0].height,
            });
          });
        }
      } else {
        that.setData({
          height: "22.001",
        });
      }

      wx.hideLoading({
        success: (res) => { },
      });

      if (app.isNotEmptyCheck(wx.getStorageSync("statusTemp"))) {
        var statusTemp = wx.getStorageSync("statusTemp");
        console.log(statusTemp);
        console.log(that.data.status);
      }
    });
  },

  pickerTap: function (e) {
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear, this.data.currentTime);
    console.log(obj.dateTimeArray);
    for (let index = 0; index < obj.dateTimeArray[0].length; index++) {
      obj.dateTimeArray[0][index] = obj.dateTimeArray[0][index] + "年";
    }
    for (let index = 0; index < obj.dateTimeArray[1].length; index++) {
      obj.dateTimeArray[1][index] = obj.dateTimeArray[1][index] + "月";
    }
    for (let index = 0; index < obj.dateTimeArray[2].length; index++) {
      obj.dateTimeArray[2][index] = obj.dateTimeArray[2][index] + "日";
    }

    this.setData({
      dateTimeArray: obj.dateTimeArray,
      dateTime: obj.dateTime,
    });
  },

  pickerTap2: function (e) {
    var obj = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear, this.data.currentTime2);
    console.log(obj);
    for (let index = 0; index < obj.dateTimeArray[0].length; index++) {
      obj.dateTimeArray[0][index] = obj.dateTimeArray[0][index] + "年";
    }
    for (let index = 0; index < obj.dateTimeArray[1].length; index++) {
      obj.dateTimeArray[1][index] = obj.dateTimeArray[1][index] + "月";
    }
    for (let index = 0; index < obj.dateTimeArray[2].length; index++) {
      obj.dateTimeArray[2][index] = obj.dateTimeArray[2][index] + "日";
    }

    console.log(obj.dateTimeArray);
    console.log(obj.dateTime);

    this.setData({
      dateTimeArray2: obj.dateTimeArray,
      dateTime2: obj.dateTime,
    });
  },

  changeDateTime (e) {
    var dateTimeArray = this.data.dateTimeArray,
      dateTime = e.detail.value;
    this.setData({
      // dateTime: e.detail.value,
      currentTime: dateTimeArray[0][dateTime[0]].replace("年", "") + "-" + dateTimeArray[1][dateTime[1]].replace("月", "") + "-" + dateTimeArray[2][dateTime[2]].replace("日", "") + " " + dateTimeArray[3][dateTime[3]],
    });
    console.log(this.data.dateTimeArray);
    console.log(this.data.currentTime);
  },

  changeDateTime1 (e) {
    var that = this;
    var dateTimeArray = this.data.dateTimeArray,
      dateTime = e.detail.value;
    this.setData({
      checkedState: this.data.status,
      currentTime1: dateTimeArray[0][dateTime[0]].replace("年", "") + "-" + dateTimeArray[1][dateTime[1]].replace("月", "") + "-" + dateTimeArray[2][dateTime[2]].replace("日", "") + " " + dateTimeArray[3][dateTime[3]],
      currentTime: dateTimeArray[0][dateTime[0]].replace("年", "") + "-" + dateTimeArray[1][dateTime[1]].replace("月", "") + "-" + dateTimeArray[2][dateTime[2]].replace("日", "") + " " + dateTimeArray[3][dateTime[3]],
    });
    console.log(this.data.dateTimeArray);
    console.log(this.data.currentTime);
    console.log(this.data.status);
    that.updateJob(1);
  },
  changeDateTime2 (e) {
    var that = this;
    var dateTimeArray2 = this.data.dateTimeArray2,
      dateTime2 = e.detail.value;
    this.setData({
      checkedState: this.data.status,
      currentTime2: dateTimeArray2[0][dateTime2[0]].replace("年", "") + "-" + dateTimeArray2[1][dateTime2[1]].replace("月", "") + "-" + dateTimeArray2[2][dateTime2[2]].replace("日", "") + " " + dateTimeArray2[3][dateTime2[3]],
    });
    console.log(this.data.dateTimeArray2);
    console.log(this.data.currentTime2);
    console.log(this.data.status);
    that.updateJob(1);
  },

  changeDateTimeColumn (e) {
    var arr = this.data.dateTime,
      dateArr = this.data.dateTimeArray;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    for (let index = 0; index < dateArr[2].length; index++) {
      dateArr[2][index] = dateArr[2][index] + "日";
    }
    // .replace("年",'').replace("月",'').replace("日",'')
    this.setData({
      dateTimeArray: dateArr,
      dateTime: arr,
    });
  },
  changeDateTimeColumn2 (e) {
    var arr = this.data.dateTime2,
      dateArr = this.data.dateTimeArray2;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    for (let index = 0; index < dateArr[2].length; index++) {
      dateArr[2][index] = dateArr[2][index] + "日";
    }
    // .replace("年",'').replace("月",'').replace("日",'')
    this.setData({
      dateTimeArray2: dateArr,
      dateTime2: arr,
    });
  },

  changeStatus (e) {
    var that = this;
    that.setData({
      currOrderId: e.currentTarget.dataset.id,
    });
    if (that.data.status != 21 && that.data.status != 50 && that.data.status != 60 && that.data.status != 26 && that.data.status != 35 && that.data.status != 45) {
      this.setData({
        showDialog: true,
        checkedState: "",
      });
    }
  },
  close () {
    // console.log(this.data.checkedState + "获取到的单选");

    this.setData({
      showDialog: false,
      despModal: "",
    });
  },
  radioChange (e) {
    console.log("radio发生change事件，携带value值为：", e.detail.value);
    var that = this;
    let stateItems = that.data.stateItems;
    for (let i = 0; i < stateItems.length; i++) {
      if (stateItems[i].value == e.detail.value) {
        that.setData({
          checkedState: e.detail.value,
        });
      }
    }
    console.log(that.data.checkedState + "点击的单选");
    // this.setData({
    // 	["userInfo.sex"]: currentSex,
    // 	sex,
    // });
  },
  submitModal () {
    var that = this;
    console.log(that.data.checkedState + "获取到的单选");
    console.log(that.data.despModal + "获取到的输入框");

    if (that.data.checkedState == 20 || that.data.checkedState == 21) {
      // console.log(that.data.height)

      that.setData({
        height: "22.001",
      });
    }

    console.log(that.data.height);

    if (app.isEmptyCheck(that.data.checkedState)) {
      wx.showToast({
        title: "请先选择状态",
        icon: "error",
        duration: 1000,
      });
      return;
    }

    if (that.data.status == 30 || that.data.status == 40) {
      if (app.isEmptyCheck(that.data.currentTime)) {
        wx.showToast({
          title: "请先选择时间",
          icon: "error",
          duration: 1000,
        });
        return;
      }
    }

    that.updateJob(2);
  },
  updateJob (num) {
    var that = this;
    let currData = {};

    currData["status"] = that.data.checkedState;
    currData["desp"] = that.data.despModal;
    currData["orderId"] = that.data.currOrderId;

    if (num == 2) {
      if (that.data.status == 30) {
        currData["entryTime"] = that.data.currentTime;
      } else if (that.data.status == 25) {
        currData["willEntryTime"] = that.data.currentTime;
      } else if (that.data.status == 40) {
        currData["leaveTime"] = that.data.currentTime;
      } else if (that.data.status == 48) {
        currData["willLeaveTime"] = that.data.currentTime;
      } else {
        currData["interviewTime"] = that.data.currentTime;
      }
    } else {
      if (that.data.status == 30) {
        currData["interviewTime"] = that.data.currentTime;
        currData["willEntryTime"] = that.data.currentTime2;
      } else if (that.data.status == 40) {
        currData["entryTime"] = that.data.currentTime2;
      } else if (that.data.status == 48) {
        currData["entryTime"] = that.data.currentTime;
        currData["willLeaveTime"] = that.data.currentTime2;
      } else if (that.data.status == 50) {
        currData["leaveTime"] = that.data.currentTime;
      } else {
        currData["interviewTime"] = that.data.currentTime;
        currData["receptionTime"] = that.data.currentTime2;
      }
    }
    customRequest( "/yishoudan/user/apply/order/changeOrderStatusAndDesp",{header:'headers', method: 'POST', data: currData}).then((res)=>{
      that.getDetail();
      that.close();
    })
    // wx.request({
    //   url: app.globalData.ip + "/yishoudan/user/apply/order/changeOrderStatusAndDesp",
    //   method: "POST",
    //   header: app.globalData.headers,
    //   data: currData,
    //   success: function (res) {
    //     that.getDetail();
    //     that.close();
    //   },
    //   fail: function () { },
    // });
  },
  reset () {
    var that = this;

    let currData = {};

    console.log("reset");

    // var stateItems = [
    //   {value: '25', name: '已接到'},
    //   {value: '26', name: '未接到'},
    // ]

    that.setData({
      stateItems: [
        { value: "25", name: "已接到" },
        { value: "26", name: "未接到" },
      ],
    });

    currData["status"] = 10;
    currData["orderId"] = that.data.userId;
    customRequest("/yishoudan/user/apply/order/changeOrderStatusAndDesp",{header:'headers', method: 'POST', data: currData}).then((res)=>{
      that.getDetail();
    
    })
    // wx.request({
    //   url: app.globalData.ip + "/yishoudan/user/apply/order/changeOrderStatusAndDesp",
    //   method: "POST",
    //   header: app.globalData.headers,
    //   data: currData,
    //   success: function (res) {
    //     that.getDetail();
    //   },
    //   fail: function () { },
    // });
  },

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

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

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

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

  /**
   * 用户点击右上角分享
   */
onShareAppMessage() {
  return app.sharePageImage()
},
});
