import dateUtil from './dateUtil.js'
/**
 * 如果是null '' 'null' 'undefined'
 * @param item
 * @returns
 */
export function isEmptyCheck (value) {
  if (value == null || value === "" || value == "null" || typeof value == "undefined") {
    return true;
  }

  return false;
}
/**
* 全拷贝
*
*
*/
export function fullCopy (data) {
  return JSON.parse(JSON.stringify(data))
}
/**
 * 如果不是是null '' 'null' 'undefined'
 * @param item
 * @returns
 */

export function isNotEmptyCheck (value) {
  return !isEmptyCheck(value);
}
/**
 * 根据状态工单类型ID获取名称
 */

export function getDistanceName (distance) {
  let str = "";

  if (isNotEmptyCheck(distance)) {
    if (distance > 1000) {
      var dis = distance / 1000;
      dis = dis.toFixed(1);
      str = dis + "km";
    } else {
      str = distance + "m";
    }
  }

  return str;
}
/**
 * 业务类型
 */

export function jobTypeArray () {
  let jobTypeArray = [
    {
      id: "0",
      name: "代理招聘",
      name2: "代理招聘",
      value: "0",
      text: "代理招聘",
      checked: false,
    },
    {
      id: "1",
      name: "劳务派遣",
      name2: "全职",
      value: "1",
      text: "劳务派遣",
      checked: false,
    },
    {
      id: "2",
      name: "劳务外包",
      name2: "兼职",
      value: "2",
      text: "劳务外包",
      checked: false,
    },
    {
      id: "4",
      name: "劳务外包挂靠",
      name2: "劳务外包挂靠",
      value: "4",
      text: "劳务外包挂靠",
      checked: false,
    },
  ];
  return jobTypeArray;
}
/**
 * 根据业务类型ID获取名称
 */

export function getJobTypeById (id) {
  let str = "";
  let array = jobTypeArray();
  array.forEach((item) => {
    if (item.id == id) {
      str = item.name;
    }
  });
  return str;
}
/**
 * 工种类型
 */

export function workTypeArray () {
  let workTypeArray = [
    {
      id: 0,
      name: "全职",
      value: "0",
      text: "全职",
      checked: false,
    },
    {
      id: 1,
      name: "兼职",
      value: "1",
      text: "兼职",
      checked: false,
    },
    {
      id: 2,
      name: "寒暑假工",
      value: "2",
      text: "寒暑假工",
      checked: false,
    },
    {
      id: 3,
      name: "实习生",
      value: "3",
      text: "实习生",
      checked: false,
    },
    {
      id: 4,
      name: "零工",
      value: "4",
      text: "零工",
      checked: false,
    },
  ];
  return workTypeArray;
}
/**
 * 根据工种类型ID获取名称
 */

export function getWorkTypeById (id) {
  let str = "";
  let array = workTypeArray();
  array.forEach((item) => {
    if (item.id == id) {
      str = item.name;
    }
  });
  return str;
}
/**
 * 根据工种类型ID获取名称
 */

export function getGenderByMinAge (res) {
  // console.log("==================", res);
  let str = "";
  if (res.minAgeMan && res.minAgeWoman) {
    str = "男女不限";
  } else if (res.minAgeMan && !res.minAgeWoman) {
    str = "仅限男性";
  } else if (!res.minAgeMan && res.minAgeWoman) {
    str = "仅限女性";
  }
  return str;
}
/**
 * 根据传递的scene参数，获取里面的内容
 */
export function sceneToJson (sceneStr) {
  let json = {};
  let array = sceneStr.split(",");
  array.forEach((item) => {
    let arr = item.split("=");
    let key = arr[0];
    let value = arr[1];
    json[key] = value;
  });
  return json;
}

var isMarry = [
  // { id: "", name: "请选择"},
  { id: "未婚", name: "未婚" },
  { id: "已婚", name: "已婚" },
  { id: "离异", name: "离异" },
  { id: "其它", name: "其它" },
];

var isMarry2 = [
  { id: "", name: "请选择" },
  { id: "未婚", name: "未婚" },
  { id: "已婚", name: "已婚" },
  { id: "离异", name: "离异" },
  { id: "其它", name: "其它" },
];

var education = [
  // { id: "", name: "请选择"},
  { id: "初中", name: "初中" },
  { id: "中专", name: "中专" },
  { id: "高中", name: "高中" },
  { id: "大专", name: "大专" },
  { id: "本科及以上", name: "本科及以上" },
];
// { id: "-1", name: "请选择" },
var sex = [
  { id: "1", name: "男" },
  { id: "2", name: "女" },
];

var attendanceStatus = [
  { id: "-1", name: "请选择" },
  { id: "1", name: "旷工" },
  { id: "2", name: "正常出勤" },
  // { id: "3", name: "上班缺卡"},
  // { id: "4", name: "下班缺卡"}
];

var attendanceStatus2 = [
  { id: "-1", name: "请选择" },
  { id: "1", name: "旷工" },
  { id: "2", name: "正常出勤" },
  { id: "3", name: "上班缺卡" },
  { id: "4", name: "下班缺卡" },
  { id: "5", name: "请假" },
  { id: "6", name: "休息" },
];

var signatoryTypeArray = [
  { id: "0", name: "甲方" },
  { id: "1", name: "乙方" },
  { id: "2", name: "丙方" },
  { id: "3", name: "丁方" },
  { id: "4", name: "午方" },
  { id: "5", name: "己方" },
  { id: "6", name: "庚方" },
  { id: "7", name: "辛方" },
  { id: "8", name: "壬方" },
  { id: "9", name: "癸方" },
];

var contractTypeArray = [
  { id: "0", name: "个人" },
  { id: "1", name: "企业" },
];

var hourArray = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"];

var timeArray1 = [["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"], ["00", "30"], ["-"], ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"], ["00", "30"]];
//是否可以面试
var interviewArray = [
  { id: "0", name: "请选择" },
  { id: "1", name: "可以面试" },
  { id: "2", name: "不能面试" },
];

//面试反馈状态
var interviewStatusArray = [
  { id: "0", name: "请选择", checked: false },
  { id: "1", name: "不缺人", checked: false },
  { id: "2", name: "候选人不合适", checked: false },
  { id: "3", name: "面试时间不合适", checked: false },
  { id: "4", name: "面试地点不合适", checked: false },
  { id: "10", name: "爽约", checked: false },
  { id: "11", name: "未通过-形象不符", checked: false },
  { id: "12", name: "未通过-能力不匹配", checked: false },
  { id: "13", name: "放弃", checked: false },
  { id: "21", name: "通过-无法安置", checked: false },
  { id: "20", name: "通过-候选人考虑中", checked: false },
  { id: "29", name: "通过-安排入职", checked: false },
];
//面试反馈状态
var interviewStatusArray1 = [
  { id: "0", name: "请选择", checked: false },
  { id: "1", name: "不缺人", checked: false },
  { id: "2", name: "候选人不合适", checked: false },
  { id: "3", name: "面试时间不合适", checked: false },
  { id: "4", name: "面试地点不合适", checked: false },
];
//面试反馈状态
var interviewStatusArray2 = [
  { id: "0", name: "请选择", checked: false },
  { id: "10", name: "爽约", checked: false },
  { id: "13", name: "放弃", checked: false },
  { id: "11", name: "未通过-形象不符", checked: false },
  { id: "12", name: "未通过-能力不匹配", checked: false },
  { id: "21", name: "通过-无法安置", checked: false },
  { id: "20", name: "通过-候选人考虑中", checked: false },
  { id: "29", name: "通过-安排入职", checked: false },
];
//入职反馈状态
var entryStatusArray = [
  { id: "0", name: "请选择", checked: false },
  { id: "1", name: "候选人主动放弃", checked: false },
  { id: "2", name: "候选人被淘汰", checked: false },
  { id: "10", name: "已入职", checked: false },
];

var workType = [
  { id: "1", name: "全职" },
  { id: "2", name: "兼职" },
  { id: "3", name: "小时工" },
];
var workType2 = [
  { id: "0", name: "请选择" },
  { id: "1", name: "全职" },
  { id: "2", name: "兼职" },
  { id: "3", name: "小时工" },
];
var workType3 = [
  { id: "0", name: "长期工" },
  { id: "1", name: "短期工" },
  { id: "2", name: "寒暑假工" },
  { id: "3", name: "实习生" },
];
var workType4 = [
  { id: "-1", name: "请选择" },
  { id: "0", name: "长期工" },
  { id: "1", name: "短期工" },
  { id: "2", name: "寒暑假工" },
  { id: "3", name: "实习生" },
];
//职位工资结算周期
var settlementCycleArray = [
  { id: "0", name: "月结", checked: false },
  { id: "1", name: "半月结", checked: false },
  { id: "2", name: "周结", checked: false },
  { id: "3", name: "日结", checked: false },
  { id: "4", name: "次结", checked: false },
];

//职位计薪方式
var salaryTypeArray = [
  { id: "0", name: "按月计薪", subName: "月计", checked: false, type: 1 },
  { id: "1", name: "按日计薪", subName: "日计", checked: false, type: 1 },
  { id: "2", name: "按时计薪", subName: "时计", checked: false, type: 1 },
  { id: "3", name: "按次计薪", subName: "次计", checked: false, type: 1 },
];

var hopeLive = [
  { id: "", name: "请选择" },
  { id: "住宿舍", name: "住宿舍" },
  { id: "不住宿舍", name: "不住宿舍" },
];

var workExp = [
  // { id: "", name: "请选择"},
  { id: "无工作经验", name: "无工作经验" },
  { id: "餐饮管理经验", name: "餐饮管理经验" },
  { id: "餐饮服务岗经验", name: "餐饮服务岗经验" },
  { id: "非餐饮岗位经验", name: "非餐饮岗位经验" },
  { id: "星级酒店前厅岗位经验", name: "星级酒店前厅岗位经验" },
  { id: "其他", name: "其他" },
];

var education2 = [
  { id: "", name: "请选择" },
  { id: "初中", name: "初中" },
  { id: "中专", name: "中专" },
  { id: "高中", name: "高中" },
  { id: "大专", name: "大专" },
  { id: "本科及以上", name: "本科及以上" },
];

var bankAuth = [
  { id: "0", name: "未认证" },
  { id: "1", name: "已认证" },
  { id: "2", name: "审核中" },
];

var auth = [
  { id: "0", name: "未认证" },
  { id: "1", name: "已认证" },
];

var healthAuth = [
  { id: "0", name: "未绑定" },
  { id: "1", name: "已绑定" },
];

function CommonUtil () { }

export function getHealthArray () {
  return healthAuth;
}

export function getAuthArray () {
  return auth;
}
//初始化picker选中项
export function initAuthPicker (id) {
  for (var i = 0; i < auth.length; i++) {
    if (auth[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getAuthValue (index) {
  return auth[index].id;
}

export function getIsMarryArray () {
  return isMarry;
}
//初始化picker选中项
export function initIsMarryPicker (name) {
  for (var i = 0; i < isMarry.length; i++) {
    if (isMarry[i].name == name) {
      return i;
    }
  }
  return 0;
}
export function getIsMarryValue (index) {
  return isMarry[index].id;
}

export function getEducationArray () {
  return education;
}
//初始化picker选中项
export function initEducationPicker (name) {
  for (var i = 0; i < education.length; i++) {
    if (education[i].name == name) {
      return i;
    }
  }
  return 0;
}
export function getEducationValue (index) {
  return education[index].id;
}

export function getSexValue (index) {
  return sex[index].id;
}

export function getSexArray () {
  return sex;
}
//初始化picker选中项
export function initSexPicker (id) {
  for (var i = 0; i < sex.length; i++) {
    if (sex[i].id == id) {
      return i;
    }
  }
  return 0;
}

export function getAttendanceStatus () {
  return attendanceStatus;
}
export function getAttendanceStatusValue (index) {
  return attendanceStatus[index].id;
}
export function getAttendanceStatusIndex (id) {
  for (var i = 0; i < attendanceStatus.length; i++) {
    if (attendanceStatus[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getAttendanceStatusName (id) {
  for (var i = 0; i < attendanceStatus.length; i++) {
    if (attendanceStatus[i].id == id) {
      return attendanceStatus[i].name;
    }
  }
  return "";
}
export function getAttendanceStatusNameOfIndex (index) {
  for (var i = 0; i < attendanceStatus.length; i++) {
    if (index == i) {
      return attendanceStatus[i].name;
    }
  }
  return "";
}

export function getAttendanceStatus2 () {
  return attendanceStatus2;
}
export function getAttendanceStatusValue2 (index) {
  return attendanceStatus2[index].id;
}
export function getAttendanceStatusIndex2 (id) {
  for (var i = 0; i < attendanceStatus2.length; i++) {
    if (attendanceStatus2[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getAttendanceStatusName2 (id) {
  for (var i = 0; i < attendanceStatus2.length; i++) {
    if (attendanceStatus2[i].id == id) {
      return attendanceStatus2[i].name;
    }
  }
  return "";
}
export function getAttendanceStatusNameOfIndex2 (index) {
  for (var i = 0; i < attendanceStatus2.length; i++) {
    if (index == i) {
      return attendanceStatus2[i].name;
    }
  }
  return "";
}

export function getSignatoryTypeArray () {
  return signatoryTypeArray;
}

export function getContractTypeArrayArray () {
  return contractTypeArray;
}

export function getHourArray () {
  return hourArray;
}

export function getTimeArray1 () {
  return timeArray1;
}

export function getInterviewArray () {
  return interviewArray;
}
export function getInterviewArrayName (id) {
  for (var i = 0; i < interviewArray.length; i++) {
    if (interviewArray[i].id == id) {
      return interviewArray[i].name;
    }
  }
  return "";
}

export function getInterviewStatusArray () {
  return interviewStatusArray;
}
export function getInterviewStatusName (id) {
  for (var i = 0; i < interviewStatusArray.length; i++) {
    if (interviewStatusArray[i].id == id) {
      return interviewStatusArray[i].name;
    }
  }
  return "";
}
export function getInterviewStatusArray1 () {
  return interviewStatusArray1;
}
export function getInterviewStatusName1 (id) {
  for (var i = 0; i < interviewStatusArray1.length; i++) {
    if (interviewStatusArray1[i].id == id) {
      return interviewStatusArray1[i].name;
    }
  }
  return "";
}
export function getInterviewStatusIndex1 (id) {
  for (var i = 0; i < interviewStatusArray1.length; i++) {
    if (interviewStatusArray1[i].id == id) {
      return i;
    }
  }
  return -1;
}

export function getInterviewStatusArray2 () {
  return interviewStatusArray2;
}
export function getInterviewStatusName2 (id) {
  for (var i = 0; i < interviewStatusArray2.length; i++) {
    if (interviewStatusArray2[i].id == id) {
      return interviewStatusArray2[i].name;
    }
  }
  return "";
}
export function getInterviewStatusIndex2 (id) {
  for (var i = 0; i < interviewStatusArray2.length; i++) {
    if (interviewStatusArray2[i].id == id) {
      return i;
    }
  }
  return -1;
}

export function getEntryStatusArray () {
  return entryStatusArray;
}

export function getEntryStatusName (id) {
  for (var i = 0; i < entryStatusArray.length; i++) {
    if (entryStatusArray[i].id == id) {
      return entryStatusArray[i].name;
    }
  }
  return "";
}
export function getEntryStatusIndex (id) {
  for (var i = 0; i < entryStatusArray.length; i++) {
    if (entryStatusArray[i].id == id) {
      return i;
    }
  }
  return -1;
}

export function getWorkTypeArray () {
  return workType;
}
//初始化picker选中项
export function initWorkTypePicker (id) {
  for (var i = 0; i < workType.length; i++) {
    if (workType[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getWorkTypeValue (index) {
  return workType[index].id;
}

export function getWorkType2Array () {
  return workType2;
}
//初始化picker选中项
export function initWorkType2Picker (id) {
  for (var i = 0; i < workType2.length; i++) {
    if (workType2[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getWorkType2Value (index) {
  return workType2[index].id;
}

export function getWorkType3Array () {
  return workType3;
}
//初始化picker选中项
export function initWorkType3Picker (id) {
  for (var i = 0; i < workType3.length; i++) {
    if (workType3[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getWorkType3Value (index) {
  return workType3[index].id;
}
export function getWorkType3Name (id) {
  for (var i = 0; i < workType3.length; i++) {
    if (workType3[i].id == id) {
      return workType3[i].name;
    }
  }
  return "";
}

export function getWorkType4Array () {
  return workType4;
}
//初始化picker选中项
export function initWorkType4Picker (id) {
  for (var i = 0; i < workType4.length; i++) {
    if (workType4[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getWorkType4Value (index) {
  return workType4[index].id;
}
export function getWorkType4Name (id) {
  for (var i = 0; i < workType4.length; i++) {
    if (workType4[i].id == id) {
      return workType4[i].name;
    }
  }
  return "";
}

export function getSettlementCycleArray () {
  return settlementCycleArray;
}
export function getSettlementCycleName (id) {
  for (var i = 0; i < settlementCycleArray.length; i++) {
    if (settlementCycleArray[i].id == id) {
      return settlementCycleArray[i].name;
    }
  }
  return "";
}

export function getSalaryTypeArray () {
  return salaryTypeArray;
}
export function getSalaryTypeName (id) {
  for (var i = 0; i < salaryTypeArray.length; i++) {
    if (salaryTypeArray[i].id == id) {
      return salaryTypeArray[i].name;
    }
  }
  return "";
}
export function getSalaryTypeSubName (id) {
  for (var i = 0; i < salaryTypeArray.length; i++) {
    if (salaryTypeArray[i].id == id) {
      return salaryTypeArray[i].subName;
    }
  }
  return "";
}

export function getHopeLiveArray () {
  return hopeLive;
}
//初始化picker选中项
export function initHopeLivePicker (name) {
  for (var i = 0; i < hopeLive.length; i++) {
    if (hopeLive[i].id == name) {
      return i;
    }
  }
  return 0;
}
export function getHopeLiveValue (index) {
  return hopeLive[index].id;
}

export function getWorkExpArray () {
  return workExp;
}
//初始化picker选中项
export function initWorkExpPicker (name) {
  for (var i = 0; i < workExp.length; i++) {
    if (workExp[i].name == name) {
      return i;
    }
  }
  return 0;
}
export function getWorkExpValue (index) {
  return workExp[index].id;
}

export function getEducation2Array () {
  return education2;
}
//初始化picker选中项
export function initEducation2Picker (name) {
  for (var i = 0; i < education2.length; i++) {
    if (education2[i].name == name) {
      return i;
    }
  }
  return 0;
}
export function getEducation2Value (index) {
  return education2[index].id;
}

export function getIsMarry2Array () {
  return isMarry2;
}
//初始化picker选中项
export function initIsMarry2Picker (name) {
  for (var i = 0; i < isMarry2.length; i++) {
    if (isMarry2[i].name == name) {
      return i;
    }
  }
  return 0;
}
export function getIsMarry2Value (index) {
  return isMarry2[index].id;
}

export function getBankAuthArray () {
  return bankAuth;
}

//初始化picker选中项
export function initBankAuthPicker (id) {
  for (var i = 0; i < bankAuth.length; i++) {
    if (bankAuth[i].id == id) {
      return i;
    }
  }
  return 0;
}
export function getBankAuthValue (index) {
  return bankAuth[index].id;
}
/**
 *
 * @param district 省市县
 * @param detailPosition 详细地址
 * @returns {string}
 */
export function getStoreAddress (district, detailPosition) {
  var res = "";
  if (isNotEmptyCheck(district)) {
    var tmpArr = district.split(",");
    tmpArr.forEach((item) => {
      item = item == 'undefined' ? '-' : item
    })
    if (tmpArr.length == 3 && tmpArr[0] == tmpArr[1]) {
      res += tmpArr[1] + tmpArr[2];
    } else {
      res += district.replace(/,/g, "");
    }
  }
  if (isNotEmptyCheck(detailPosition)) {
    res += detailPosition;
  }
  return res;
}

/**
 * 代理推广明细事件
 */
export function agencyPromotionDetailEventArray () {
  let agencyPromotionDetailEventArray = [
    { id: "10", name: "扫码", value: "10", text: "扫码", checked: false },
    { id: "20", name: "报名", value: "20", text: "报名", checked: false },
    { id: "30", name: "面试", value: "30", text: "面试", checked: false },
    { id: "40", name: "入职", value: "40", text: "入职", checked: false },
    { id: "50", name: "离职", value: "50", text: "离职", checked: false },
  ];
  return agencyPromotionDetailEventArray;
}
/**
 * 根据代理推广明细事件ID获取名称
 */
export function getAgencyPromotionDetailEventNameId (id) {
  let str = "";
  let array = agencyPromotionDetailEventArray();
  array.forEach((item) => {
    if (item.id == id) {
      str = item.name;
    }
  });
  return str;
}

/**
 * 代理推广明细佣金状态
 */
export function agencyPromotionDetailMoneyStatusArray () {
  let agencyPromotionDetailMoneyStatusArray = [
    { id: "0", name: "无佣金", value: "0", text: "无佣金", checked: false },
    { id: "10", name: "待结算", value: "10", text: "待结算", checked: false },
    { id: "20", name: "已结算", value: "20", text: "已结算", checked: false },
    { id: "30", name: "已失效", value: "30", text: "已失效", checked: false },
  ];
  return agencyPromotionDetailMoneyStatusArray;
}
/**
 * 根据代理推广明细佣金状态ID获取名称
 */
export function getAgencyPromotionDetailMoneyStatusNameId (id) {
  let str = "";
  let array = agencyPromotionDetailMoneyStatusArray();
  array.forEach((item) => {
    if (item.id == id) {
      str = item.name;
    }
  });
  return str;
}

export function moneyToFixed (money, fixed = 2, multiplicator = 100) {
  if (money != 0 && money != null && money != "" && money != undefined) {
    return cutZero(new Number(money / multiplicator).toFixed(fixed));
  } else {
    return "0";
  }
}
export function cutZero (old) {
  //拷贝一份 返回去掉零的新串
  let newstr = old;
  //循环变量 小数部分长度
  var leng = old.length - old.indexOf(".") - 1;
  //判断是否有效数
  if (old.indexOf(".") > -1) {
    //循环小数部分
    for (var i = leng; i > 0; i--) {
      //如果newstr末尾有0
      if (newstr.lastIndexOf("0") > -1 && newstr.substr(newstr.length - 1, 1) == 0) {
        var k = newstr.lastIndexOf("0");
        //如果小数点后只有一个0 去掉小数点
        if (newstr.charAt(k - 1) == ".") {
          return newstr.substring(0, k - 1);
        } else {
          //否则 去掉一个0
          newstr = newstr.substring(0, k);
        }
      } else {
        //如果末尾没有0
        return newstr;
      }
    }
  }
  return old;
}
export function getCurrentPageUrlWithArgs () {
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1];
  const url = currentPage.route;
  const options = currentPage.options;
  let urlWithArgs = `/${url}?`;
  for (let key in options) {
    const value = options[key];
    urlWithArgs += `${key}=${value}&`;
  }
  urlWithArgs = urlWithArgs.substring(0, urlWithArgs.length - 1);
  return urlWithArgs;
}

export function getDateArrayOfScope () {
  // var multiArray = [['2000年', '2001年'], ['01月', '02月', '03月', '04月', '05月'], ['-'],['2000年', '2001年'], ['01月', '02月', '03月', '04月', '05月']];
  var multiArray = [[], ["01月", "02月", "03月", "04月", "05月", "06月", "07月", "08月", "09月", "10月", "11月", "12月"], ["-"], [], ["01月", "02月", "03月", "04月", "05月", "06月", "07月", "08月", "09月", "10月", "11月", "12月"]];

  var date = new Date();
  var end = date.getFullYear();

  var yearArray = [];
  for (var i = 1990; i <= end; i++) {
    yearArray.push(i + "年");
  }

  multiArray[0] = yearArray;
  multiArray[3] = yearArray;

  return multiArray;
}

export function educationArray () {
  let educationArray = [
    { id: "初中", name: "初中" },
    { id: "高中", name: "高中" },
    { id: "大专", name: "大专" },
    { id: "本科", name: "本科" },
    { id: "硕士", name: "硕士" },
    { id: "博士", name: "博士" },
  ];
  return educationArray;
}

/**
 * 时间格式化  2017-01-01
 * @param val
 * @returns {string}
 */
export function formatDateYMD (val) {
  if (val == null || val == "") {
    return null;
  }

  if ((val != null || val == "") && typeof val == "string") {
    if (val.indexOf("T")) {
      val = val.replace("T", " "); //原来L端可能返回的时间格式有带T的格式，处理一下
    }
    val = val.replace("-", "/").replace("-", "/");
  }
  var value = new Date(val);
  //console.log(val);
  var fmt = "yyyy-MM-dd";
  var o = {
    "M+": value.getMonth() + 1, //月份
    "d+": value.getDate(), //日
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (value.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    }
  }
  return fmt;
}
/**
 * 根据薪资类型和薪资值获取薪资展示 数字突出显示
 */
export function getSalaryClassifyValue (salaryClassify, salaryClassifyValue) {
  var hourlyPay = moneyToFixed(salaryClassifyValue);
  // console.log(hourlyPay);
  // console.log(salaryClassify);
  // if (salaryClassify == 0) {
  return hourlyPay;
  // return `${hourlyPay}元/时`;
  // } else if (salaryClassify == 1) {
  // 	return `${hourlyPay}元/天`;
  // } else if (salaryClassify == 2) {
  // 	return `补${hourlyPay}元`;
  // } else if (salaryClassify == 3) {
  // 	return `返${hourlyPay}元`;
  // } else if (salaryClassify == 4) {
  // 	return "计件";
  // } else if (salaryClassify == 5) {
  // 	return `保底${hourlyPay}元`;
  // } else if (salaryClassify == 6) {
  // 	return `面议`;
  // } else if (salaryClassify == 7) {
  // 	return `月薪`;
  // } else {
  // 	// return '请配置薪资';
  // 	return "-";
  // }
}
/**
 * 根据薪资类型和薪资值获取薪资展示 海报分享使用
 */
export function getSalaryClassifyValue1 (salaryClassify, salaryClassifyValue) {
  var hourlyPay = moneyToFixed(salaryClassifyValue);
  // console.log(hourlyPay);
  // console.log(salaryClassifyValue);
  if (salaryClassify == 0) {
    return `${hourlyPay}元/时`;
  } else if (salaryClassify == 1) {
    return `${hourlyPay}元/天`;
  } else if (salaryClassify == 2) {
    return `补${hourlyPay}元`;
  } else if (salaryClassify == 3) {
    return `返${hourlyPay}元`;
  } else if (salaryClassify == 4) {
    return "计件";
  } else if (salaryClassify == 5) {
    return `保底${hourlyPay}元`;
  } else if (salaryClassify == 6) {
    return `面议`;
  } else if (salaryClassify == 7) {
    return `月薪`;
  } else {
    // return '请配置薪资';
    return "-";
  }
}
export function getReturnFeeTypeName1ById (id, value) {
  let str = "";
  // console.log(id+'returnFeeType');
  let array = this.returnFeeTypeArray(value);
  str = "--";

  array.forEach((item) => {
    if (item.id == id) {
      str = item.name1;
    }
  });
  return str;
}
export function returnFeeTypeArray (value) {
  let returnFeeTypeArray = [
    { id: 0, value: "0", text: "按时", name: "小时", name1: `${value}元/时` },
    { id: 1, value: "1", text: "按日", name: "天", name1: `${value}元/日` },
    { id: 2, value: "2", text: "按月", name: "月", name1: `${value}元/月` },
    { id: 3, value: "3", text: "按次", name: "次", name1: `${value}元/次` },
    { id: 4, value: "4", text: "按件", name: "件", name1: `${value}元/公斤` },
    { id: 5, value: "5", text: "百分比", name: "百分比", name1: `工人收入${value}%` },
    { id: 6, value: "6", text: "共计", name: "人", name1: `共${value}元` },
    { id: 7, value: "7", name1: "费用待定" },
  ];

  return returnFeeTypeArray;
}

/**
 * 代理成员角色类型
 */
export function agencyRoleTypeArray () {
  let workTypeArray = [
    { id: 1, name: "创建人", value: "1", text: "创建人", checked: false },
    { id: 2, name: "管理员", value: "2", text: "管理员", checked: false },
    { id: 3, name: "成员", value: "3", text: "成员", checked: false },
  ];
  return workTypeArray;
}
export function agencyPermissionArray () {
  //查看职位、报名、查看报名、查看老乡、修改密码、修改手机号、新增成员、修改成员信息、删除成员
  let workTypeArray = [
    { id: 1, name: "查看职位", value: "job:list", text: "查看职位", checked: false },
    { id: 2, name: "报名", value: "apply:add", text: "报名", checked: false },
    { id: 3, name: "查看报名", value: "apply:list", text: "查看报名", checked: false },
    { id: 4, name: "查看老乡", value: "apply:user", text: "查看老乡", checked: false },
    { id: 5, name: "修改密码", value: "user:pwd", text: "修改密码", checked: false },
    { id: 6, name: "修改手机号", value: "user:tel", text: "修改手机号", checked: false },
    { id: 7, name: "新增成员", value: "user:add", text: "新增成员", checked: false },
    { id: 8, name: "修改成员信息", value: "user:update", text: "修改成员信息", checked: false },
    { id: 9, name: "删除成员", value: "user:del", text: "删除成员", checked: false },
  ];
  return workTypeArray;
}
/**
 * 根据代理成员角色ID获取名称
 */
export function getAgencyRoleTypeById (id) {
  let str = "";
  let array = agencyRoleTypeArray();
  array.forEach((item) => {
    if (item.id == id) {
      str = item.name;
    }
  });
  return str;
}

/**
 * 根据代理权限ID获取名称
 */
export function getAgencyPermissionNameById (permissionStr) {
  let str = "";
  let array = agencyPermissionArray();
  let names = [];
  let permissions = permissionStr.split(",");
  array.forEach((item) => {
    if (permissions.indexOf(item.value) >= 0) {
      names.push(item.name);
    }
  });
  return names.join("，");
}

/**
 * 根据代理角色获取权限
 */
export function getAgencyPermissionsByRole (role) {
  if (role == 1) {
    return "job:list,apply:add,apply:list,apply:user,user:pwd,user:tel,user:add,user:update,user:del";
  } else {
    return "job:list,apply:add,apply:list,apply:user,user:pwd,user:tel";
  }
}
/* 
  处理详情地址
*/
export function setJobInfoPosition (pos) {
  let city = [];
  let citys = [];
  if (isNotEmptyCheck(pos)) {
    city = pos.split(",");
  }
  city.forEach((i) => {
    if (isNotEmptyCheck(i)) {
      citys.push(i);
    }
  });
  citys = citys.join(",").replace(/,/g, "丨");
  return citys;
}
export function setJobInfoPositionv3 (str) {
  var reg = /.+?(省|市|自治区|自治州|县|区)/g; // 省市区的正则
  let matches = str.match(reg);
  let result = '';

  if (matches && matches.length > 0) {
    switch (matches.length) {
      case 1:
        result = matches[0];
        break;
      case 2:
        if (matches[0].includes('省') || matches[0].includes('自治区') || matches[0].includes('自治州')) {
          result = `${matches[0]}丨${matches[1]}`;
        } else {
          result = `${matches[0]}丨${matches[1]}`;
        }
        break;
      case 3:
        if (matches[0].includes('省') || matches[0].includes('自治区') || matches[0].includes('自治州')) {
          if (matches[1].includes('市') && matches[2].includes('市')) {
            result = `${matches[0]}丨${matches[2]}`;
          } else {
            if (matches[2].includes('县')) {
              result = `${matches[0]}丨${matches[2]}`;
            } else {
              result = `${matches[0]}丨${matches[1]}`;
            }
          }
        } else if (matches[1].includes('市')) {
          result = `${matches[0]}丨${matches[2]}`;
        } else {
          result = `${matches[1]}丨${matches[2]}`;
        }
        break;
      default:
        result = str;
        break;
    }
  } else {
    result = str;
  }

  return result;
}
/* 
  处理详情地址
*/
export function setJobListInfoPosition (pos) {
  let city = [];
  let citys = [];
  if (isNotEmptyCheck(pos)) {
    city = pos.split(",");
  }
  city.forEach((i, index) => {
    if (isNotEmptyCheck(i) && index < 2) {
      if (i == "undefined") {
        i = '-'
      }
      citys.push(i);
    }
  });
  citys = citys.join(",").replace(/,/g, " | ");
  return citys || "-";
}

export const cutShareImg = (imgUrl) => {
  return new Promise((resolve) => {
    wx.getImageInfo({
      src: imgUrl, // 原图路径
      success: (res) => {
        let ctx = wx.createCanvasContext("canvas");
        let canvasW = 0;
        let canvasH = res.height;
        // 把比例设置为 宽比高 5:4
        canvasW = (res.height * 5) / 4;
        // 为画框设置背景色，注意要放在画图前，图会覆盖在背景色上
        ctx.fillStyle = "#fff";
        ctx.fillRect(0, 0, canvasW, canvasH);
        // ctx.drawImage(res.path, (res.width - canvasW) / 2, 0, canvasW, canvasH, 0, 0, canvasW, canvasH)
        ctx.drawImage(
          res.path,
          0,
          0,
          canvasW,
          canvasH,
          (canvasW - res.width) / 2, // 宽度从中间向两边填充
          0,
          canvasW,
          canvasH
        );
        console.log(res);

        ctx.draw(false, (test) => {
          console.log(test);
          wx.canvasToTempFilePath({
            width: canvasW,
            height: canvasH,
            destWidth: 750, // 标准的iphone6尺寸的两倍，生成高清图
            destHeight: 600,
            canvasId: "canvas",
            fileType: "jpg", // 注意jpg默认背景为透明
            success: (res) => {
              // 设置分享图片路径
              console.log(res);
              resolve(res.tempFilePath);
            },
          });
        });
      },
    });
  });
};

// function isEmptyCheck(str) {
// 	if (str == null || str == "" || str == "null" || str == "undefined" || typeof str == "undefined") {
// 		return true;
// 	}
// 	return false;
// }
// function isNotEmptyCheck(str) {
// 	return !isEmptyCheck(str);
// }

/**
 * 处理后台返回的职位列表
 *
 *
 *
 */

export function disposeJobListData (recordList) {
  var that = this;
  console.log(recordList);
  recordList.forEach((item) => {
    item["workType"] = getWorkTypeById(item.workTypeMulti);

    if (isNotEmptyCheck(item.distance)) {
      item["distanceKm"] = getDistanceName(item.distance);
    }
    //年龄
    var ageStr = "";
    if (isNotEmptyCheck(item.minAge) && isNotEmptyCheck(item.maxAge)) {
      ageStr = item.minAge + "-" + item.maxAge + "岁";
    } else if (isNotEmptyCheck(item.minAge)) {
      ageStr = item.minAge + "岁以上";
    } else if (isNotEmptyCheck(item.maxAge)) {
      ageStr = item.maxAge + "岁以下";
    }
    item["age"] = ageStr;
    // console.log(item.salaryClassify, '=============', item.salaryClassifyValue);
    item["salaryClassifyValueHaibao"] = getSalaryClassifyValue1(item.salaryClassify, item.salaryClassifyValue);
    item["salaryClassifyValue"] = getSalaryClassifyValue(item.salaryClassify, item.salaryClassifyValue);
    // x天前更新
    item["update"] = dateUtil.timeShowXXX2(item.updateTime);
    // console.log('item["update"]',item["update"]);
    item.genderRestrict = getGenderByMinAge(item);

    // //时薪
    // var hourlyPayStr = '';
    // var hasHourlyPay = false;
    // if (isNotEmptyCheck(item.hourlyPay)) {
    //     hourlyPayStr = item.hourlyPay + '元/小时';
    //     hasHourlyPay = true;
    // } else if (isNotEmptyCheck(item.dayPay)) {
    //     hourlyPayStr = item.dayPay + '元/日';
    //     hasHourlyPay = true;
    // } else {
    //     if (isNotEmptyCheck(item.minMonthlyPay) && isNotEmptyCheck(item.maxMonthlyPay)) {
    //         if (item.minMonthlyPay == item.maxMonthlyPay) {
    //             hourlyPayStr = item.minMonthlyPay;
    //         } else {
    //             hourlyPayStr = item.minMonthlyPay + '-' + item.maxMonthlyPay;
    //         }
    //     } else if (isNotEmptyCheck(item.minMonthlyPay)) {
    //         hourlyPayStr = item.minMonthlyPay;
    //     } else if (isNotEmptyCheck(item.maxMonthlyPay)) {
    //         hourlyPayStr = item.maxMonthlyPay;
    //     }
    // }
    // item["hourlyPay"] = hourlyPayStr;
    //月薪
    var monthlyPayStr = "";
    // if (hasHourlyPay) {
    if (isNotEmptyCheck(item.minMonthlyPay) && isNotEmptyCheck(item.maxMonthlyPay)) {
      if (item.minMonthlyPay == item.maxMonthlyPay) {
        monthlyPayStr = item.minMonthlyPay;
      } else {
        monthlyPayStr = item.minMonthlyPay + "-" + item.maxMonthlyPay;
      }
    } else if (isNotEmptyCheck(item.minMonthlyPay)) {
      monthlyPayStr = item.minMonthlyPay;
    } else if (isNotEmptyCheck(item.maxMonthlyPay)) {
      monthlyPayStr = item.maxMonthlyPay;
    }
    // console.log(monthlyPayStr);
    // }
    item["monthlyPay"] = monthlyPayStr;
    //地址深圳丨龙岗区丨
    let citys = setJobInfoPositionv3(item.storeAddr);

    // console.log('citys',citys);
    var districtStr = "";
    if (isNotEmptyCheck(item.district)) {
      var districtArr = item.district.split(",");
      // districtArr.forEach((item) => {
      //   if (item == 'undefined') {
      //     console.log(item);
      //     item = '-'
      //     console.log(item);
      //   }
      // })
      if (districtArr.length < 3) {
        districtStr = districtArr[districtArr.length - 1];
      } else {
        // console.log(districtArr);
        districtStr = districtArr[1] + "丨" + districtArr[2];
      }
      //districtStr = districtArr[1] + '丨' + districtArr[2];
    }
    item["district"] = citys;
    item["districtStr"] = districtStr;
    //职位特色
    item.jobSpecialLabelNameArray = [];
    getJobSpecialLabelNamesArray(item.jobSpecialLabelNames).forEach((i, index) => {
      if (index <= 2) {
        item["jobSpecialLabelNameArray"].push(i);
      }
    });
    // item["jobSpecialLabelNames"] = ;
  });

  return recordList;
}
/**
 * 通过出生日期获取年龄
 *
 *
 */
export function getAgeByBirthday (strBirthday) {
  //strBirthday = util.formatTime(strBirthday);转换成yyyy-MM-dd形式
  var returnAge;
  var strBirthdayArr = strBirthday.split("-");
  var birthYear = strBirthdayArr[0];
  var birthMonth = strBirthdayArr[1];
  var birthDay = strBirthdayArr[2];
  var d = new Date();
  var nowYear = d.getFullYear();
  var nowMonth = d.getMonth() + 1;
  var nowDay = d.getDate();
  if (nowYear == birthYear) {
    returnAge = 0; //同年 则为0岁
  } else {
    var ageDiff = nowYear - birthYear; //年之差
    if (ageDiff > 0) {
      if (nowMonth == birthMonth) {
        var dayDiff = nowDay - birthDay; //日之差
        if (dayDiff < 0) {
          returnAge = ageDiff - 1;
        } else {
          returnAge = ageDiff;
        }
      } else {
        var monthDiff = nowMonth - birthMonth; //月之差
        if (monthDiff < 0) {
          returnAge = ageDiff - 1;
        } else {
          returnAge = ageDiff;
        }
      }
    } else {
      returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
    }
  }
  return returnAge; //返回周岁年龄
}
function getJobSpecialLabelNamesArray (jobSpecialLabelNames) {
  if (isNotEmptyCheck(jobSpecialLabelNames)) {
    return jobSpecialLabelNames.split(", ");
  }
  return [];
}

export function query (id, fn) {
  let query = wx.createSelectorQuery();
  query.select(id).boundingClientRect();
  // query.selectViewport().scrollOffset();
  query.exec(fn);
}

export function policyNumToHanZi (i) {
  let pickerStr;
  if (i <= 9) {
    switch (i) {
      case 1:
        pickerStr = "政策一";
        break;
      case 2:
        pickerStr = "政策二";
        break;
      case 3:
        pickerStr = "政策三";
        break;
      case 4:
        pickerStr = "政策四";
        break;
      case 5:
        pickerStr = "政策五";
        break;
      case 6:
        pickerStr = "政策六";
        break;
      case 7:
        pickerStr = "政策七";
        break;
      case 8:
        pickerStr = "政策八";
        break;
      case 9:
        pickerStr = "政策九";
        break;
      case 10:
        pickerStr = "政策十";
        break;
      default:
        pickerStr = "政策" + (i + 1);
        break;
    }
  }
  return pickerStr
}

export let nationArray = [
  // 民族的数组
  {
    id: "01",
    name: "汉族",
  },
  {
    id: "02",
    name: "蒙古族",
  },
  {
    id: "03",
    name: "满族",
  },
  {
    id: "04",
    name: "朝鲜族",
  },
  {
    id: "05",
    name: "赫哲族",
  },
  {
    id: "06",
    name: "达斡尔族",
  },
  {
    id: "07",
    name: "鄂温克族",
  },
  {
    id: "08",
    name: "鄂伦春族",
  },
  {
    id: "09",
    name: "回族",
  },
  {
    id: "10",
    name: "东乡族",
  },
  {
    id: "11",
    name: "土族",
  },
  {
    id: "12",
    name: "撒拉族",
  },
  {
    id: "13",
    name: "保安族",
  },
  {
    id: "14",
    name: "裕固族",
  },
  {
    id: "15",
    name: "维吾尔族",
  },
  {
    id: "16",
    name: "哈萨克族",
  },
  {
    id: "17",
    name: "柯尔克孜族",
  },
  {
    id: "18",
    name: "锡伯族",
  },
  {
    id: "19",
    name: "塔吉克族",
  },
  {
    id: "20",
    name: "乌孜别克族",
  },
  {
    id: "21",
    name: "俄罗斯族",
  },
  {
    id: "22",
    name: "塔塔尔族",
  },
  {
    id: "23",
    name: "藏族",
  },
  {
    id: "24",
    name: "门巴族",
  },
  {
    id: "25",
    name: "珞巴族",
  },
  {
    id: "26",
    name: "羌族",
  },
  {
    id: "27",
    name: "彝族",
  },
  {
    id: "28",
    name: "白族",
  },
  {
    id: "29",
    name: "哈尼族",
  },
  {
    id: "30",
    name: "傣族",
  },
  {
    id: "31",
    name: "傈僳族",
  },
  {
    id: "32",
    name: "佤族",
  },
  {
    id: "33",
    name: "拉祜族",
  },
  {
    id: "34",
    name: "纳西族",
  },
  {
    id: "35",
    name: "景颇族",
  },
  {
    id: "36",
    name: "布朗族",
  },
  {
    id: "37",
    name: "阿昌族",
  },
  {
    id: "38",
    name: "普米族",
  },
  {
    id: "39",
    name: "怒族",
  },
  {
    id: "40",
    name: "德昂族",
  },
  {
    id: "41",
    name: "独龙族",
  },
  {
    id: "42",
    name: "基诺族",
  },
  {
    id: "43",
    name: "苗族",
  },
  {
    id: "44",
    name: "布依族",
  },
  {
    id: "45",
    name: "侗族",
  },
  {
    id: "46",
    name: "水族",
  },
  {
    id: "47",
    name: "仡佬族",
  },
  {
    id: "48",
    name: "壮族",
  },
  {
    id: "49",
    name: "瑶族",
  },
  {
    id: "50",
    name: "仫佬族",
  },
  {
    id: "51",
    name: "毛南族",
  },
  {
    id: "52",
    name: "京族",
  },
  {
    id: "53",
    name: "土家族",
  },
  {
    id: "54",
    name: "黎族",
  },
  {
    id: "55",
    name: "畲族",
  },
  {
    id: "56",
    name: "高山族",
  },
];
export const fillTextLineBreak = (ctx, text, x, y, lw, lh, color = "#333", font = "32", weight = "500") => {
  var i = 0;
  var n = 0;
  var r = -1;
  var initHeight = 0;
  ctx.font = weight + " " + font + "px Arial"; //字体大小
  ctx.fillStyle = color; //字体颜色
  console.log(text);
  while (i < text.length) {
    while (ctx.measureText(text.substring(n, i)).width < lw && i < text.length) {
      i++;
    }
    r++;
    ctx.fillText(text.substring(n, i), x, y + lh * r);
    n = i;
  }
  initHeight = lh * r;
  // wx.setStorageSync("initHeight", initHeight);
};
export const roundRect = (ctx, img, bg_x, bg_y, bg_w, bg_h, bg_r) => {
  // 开始绘制
  ctx.save();
  ctx.beginPath();
  ctx.arc(bg_x + bg_r, bg_y + bg_r, bg_r, Math.PI, Math.PI * 1.5);
  ctx.arc(bg_x + bg_w - bg_r, bg_y + bg_r, bg_r, Math.PI * 1.5, Math.PI * 2);
  ctx.arc(bg_x + bg_w - bg_r, bg_y + bg_h - bg_r, bg_r, 0, Math.PI * 0.5);
  ctx.arc(bg_x + bg_r, bg_y + bg_h - bg_r, bg_r, Math.PI * 0.5, Math.PI);
  ctx.clip();
  ctx.drawImage(img, bg_x, bg_y, bg_w, bg_h);
  // 恢复之前保存的绘图上下文
  ctx.restore();
};
export const roundRect_yuan = (ctx, x, y, size) => {
  // 开始绘制
  ctx.save(); // 保存
  ctx.beginPath(); // 开始绘制
  // ctx.arc(100, 75, 50, 0, 2 * Math.PI)
  ctx.arc(size / 2 + x, size / 2 + y, size / 2, 0, Math.PI * 2, false);
  ctx.clip();
  // 恢复之前保存的绘图上下文
  ctx.restore();
};

export function roundRect1 (ctx, x, y, w, h, r, color) {
  //绘制圆角矩形(无填充色))
  ctx.save();
  ctx.fillStyle = color;
  ctx.strokeStyle = color;
  ctx.lineJoin = "round"; //交点设置成圆角
  ctx.lineWidth = r;
  ctx.strokeRect(x + r / 2, y + r / 2, w - r, h - r);
  ctx.fillRect(x + r, y + r, w - r * 2, h - r * 2);
  ctx.stroke();
  ctx.closePath();
}