import { ref, onMounted } from 'vue';
import {
  Modal,
  message
} from 'ant-design-vue';
let data = {
  version: '公共组件',
  /**
   * model自定义确认弹窗
   * @params title 标题
   * @params content 内容
   * @params success 成功回调
   * @params fail 失败回调
   * @params cancelText 取消文字按钮
   * @params okText 确定文字按钮
   * @returns
   */
  gConfirmModal (
    title = '标题',
    content = '',
    success = () => { },
    fail = () => { },
    cancelText = '取消',
    okText = '确定',
    type = "default"
  ) {
    if (type == "default") {
      Modal.confirm({
        title: title,
        content: content,
        destroyOnClose: true,
        cancelText: cancelText,
        okText: okText,
        onOk () {
          return success();
        },
        onCancel () {
          return fail();
        },
      })
    } else if (type == "success") {
      Modal.success({
        title: title,
        content: content,
        destroyOnClose: true,
        cancelText: cancelText,
        okText: okText,
        onOk () {
          return success();
        },
        onCancel () {
          return fail();
        },
      })
    }

  },
  /**
   * 时间格式转换
   * @params str 时间戳或者标准时间
   * @params type 类型
   * @returns
   */
  getPointTime (str = '', type = 'default') {
    let that = this;
    let year, month, date, hours, minute, second;
    let time;
    if (type == "pointDate") {
      // 近N天
      time = new Date(new Date(new Date().getTime() - (str - 1) * 24 * 60 * 60 * 1000))
      type = "YY--MM--DD"
    } else if (type == "yesterday") {
      // 昨日
      time = new Date(new Date(new Date()).setDate(new Date(new Date()).getDate() - 1))
      type = "YY--MM--DD"
    } else if (type == "thisweek") {
      // 本周 实际是上周日到当前周的周六。周日的截止时间需特殊处理
      if (str == 'first') {
        let currentDate = new Date();
        let currentDay = currentDate.getDay();
        let daysToSunday = currentDay === 0 ? 7 : currentDay;
        let lastSunday = new Date(currentDate.getTime() - daysToSunday * 24 * 60 * 60 * 1000);
        let lastSundayYear = lastSunday.getFullYear();
        let lastSundayMonth = lastSunday.getMonth() + 1; // 注意月份是从 0 开始的，需要加 1
        let lastSundayDate = lastSunday.getDate();
        let formattedDate = lastSundayYear + '-' + String(lastSundayMonth).padStart(2, '0') + '-' + String(lastSundayDate).padStart(2, '0');
        time = formattedDate;
        type = "first-week"
      } else if (str == 'last') {
        const today = new Date();
        if (today.getDay() === 0) {
          // 周日
          time = new Date()
        } else {
          // 周一~周六
          time = new Date()
        }
        type = "YY--MM--DD"
      }
    } else if (type == "lastweek") {
      // 上周 上上周日到上周六。周日需特殊处理
      const isSun = new Date();
      if (isSun.getDay() === 0) {
        // 周日。实际开始时间为上周日到这周六
        if (str == 'first') {
          let currentDate = new Date();
          let currentDay = currentDate.getDay();
          let daysToSunday = currentDay === 0 ? 7 : currentDay;
          let lastSunday = new Date(currentDate.getTime() - daysToSunday * 24 * 60 * 60 * 1000);
          let lastSundayYear = lastSunday.getFullYear();
          let lastSundayMonth = lastSunday.getMonth() + 1; // 注意月份是从 0 开始的，需要加 1
          let lastSundayDate = lastSunday.getDate();
          let formattedDate = lastSundayYear + '-' + String(lastSundayMonth).padStart(2, '0') + '-' + String(lastSundayDate).padStart(2, '0');
          time = formattedDate;
          type = "first-week"
        } else if (str == 'last') {
          const today = new Date();
          const dayOfWeek = today.getDay();
          const diff = 6 - dayOfWeek; // 6 表示周六
          const targetSaturday = new Date(today.getFullYear(), today.getMonth(), today.getDate() + diff);
          const year = targetSaturday.getFullYear();
          const month = targetSaturday.getMonth() + 1; // 月份从 0 开始，需加 1
          const date = targetSaturday.getDate();
          const formattedDate = `${year}-${month < 10 ? '0' + month : month}-${date < 10 ? '0' + date : date}`;
          time = formattedDate;
          type = "end-week"
        }
      } else {
        // 周一~周六
        if (str == 'first') {
          function getPreviousSundayDate () {
            const today = new Date();
            const dayOfWeek = today.getDay();
            const daysSinceLastSunday = (dayOfWeek + 6) % 7 + 8;
            const previousSunday = new Date(today);
            previousSunday.setDate(today.getDate() - daysSinceLastSunday);
            return previousSunday;
          }
          time = new Date(getPreviousSundayDate());
          type = "YY--MM--DD"
        } else if (str == 'last') {
          function getPreviousSaturdayDate () {
            const today = new Date();
            const dayOfWeek = today.getDay();
            const daysSinceLastSaturday = (dayOfWeek + 6) % 7 + 2;
            const previousSaturday = new Date(today);
            previousSaturday.setDate(today.getDate() - daysSinceLastSaturday);
            return previousSaturday;
          }
          time = new Date(getPreviousSaturdayDate());
          type = "YY--MM--DD"
        }
      }
    } else if (type == "thismonth") {
      // 本月 当前月份一号到当天
      time = new Date(new Date().getFullYear(), new Date().getMonth(), 1)
      type = "YY--MM--DD"
    } else if (type == "lastmonth") {
      // 上月 上月的第一天到最后一天
      if (str == 'first') {
        time = new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1);
      } else if (str == 'last') {
        time = new Date(new Date().getFullYear(), new Date().getMonth() - 1 + 1, 0);
      }
      type = "YY--MM--DD"
    } else if (type == "first-week") {
    } else {
      // 时间戳
      time = str ? new Date(str) : new Date(new Date().getTime());
    }
    if (time && typeof time == 'object') {
      year = time.getFullYear()
      month = (time.getMonth() + 1).toString().padStart(2, '0')
      date = (time.getDate()).toString().padStart(2, '0')
      hours = (time.getHours()).toString().padStart(2, '0')
      minute = (time.getMinutes()).toString().padStart(2, '0')
      second = (time.getSeconds()).toString().padStart(2, '0')
    }
    let result;

    switch (type) {
      case 'default':// 2023-10-31 09:00:00
        result = year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second;
        break;
      case 'YY--MM--DD HH:MM':// 2023-10-31 09:00
        result = year + '-' + month + '-' + date + ' ' + hours + ':' + minute;
        break;
      case 'YY--MM--DD':// 2023-10-31
        result = year + '-' + month + '-' + date;
        break;
      case 'HH:MM:SS':// 09:00:00
        result = hours + ':' + minute + ':' + second;
        break;
      case 'first-week':// 09:00:00
        result = time;
        break;
      case 'end-week':// 09:00:00
        result = time;
        break;
      default:
        break;
    }
    return result;
  },
  /**
   * 随机字符串
   * @params length 需要生成几位的字符串
   * @returns
   */
  generateRandomString (length = 6) {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';
    for (let i = 0; i < length; i++) {
      const randomIndex = Math.floor(Math.random() * characters.length);
      result += characters[randomIndex];
    }
    return result;
  },
  /**
  * 获取服务费类型 
  * @params returnFeeType 类型
  * @params $type 1：共享 0 普通
  */
  setReturnFee (returnFee, returnFeeType, $type) {
    let servetype, $num = 1;
    if ($type == 1) {
      $num = 1;
    } else {
      $num = 100;
    }
    if (returnFeeType === 0) {
      servetype = `${returnFee / $num || "--"}元/小时`;
    } else if (returnFeeType === 1) {
      servetype = `${returnFee / $num || "--"}元/日`;
    } else if (returnFeeType === 2) {
      servetype = `${returnFee / $num || "--"}元/月`;
    } else if (returnFeeType === 3) {
      servetype = `${returnFee / $num || "--"}元/次`;
    } else if (returnFeeType === 4) {
      servetype = `${returnFee / $num || "--"}元/件`;
    } else if (returnFeeType === 5) {
      servetype = `工人收入${returnFee / $num || "--"}%`;
    } else if (returnFeeType === 6) {
      servetype = `共${returnFee / $num || "--"}元`;
    } else if (returnFeeType === 7) {
      servetype = `费用待定`;
    }
    return servetype
  },
  /* 正则表达式
   * @params $str 要替换的字符
   * @params $type 类型
   */
  regular ($str, $type) {
    if ($type == 'email') {
      return /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
        .test($str);
    }
    if ($type == 'tel') {
      return /^[1][3,4,5,7,8,9][0-9]{9}$/.test($str);
    }
    if ($type == 'grade1') {
      return /^[0-9]*$/.test($str); // 纯数字
    }
    if ($type == 'grade2') {
      return /^[A-Za-z0-9]+$/.test($str); // 数字和26个英文字母组成的字符串
    }
    if ($type == 'grade3') {
      return /^[u4E00-u9FA5A-Za-z0-9_]+$/.test($str); // 数字、26个英文字母和下划线组成的字符串
    }
  },
  /* 处理工单状态
   * @params $status 状态对象字段
   */
  userApplyOrderStatusArrayModel ($status) {
    let orderStatus = [
      { id: "10", name: "待审核", value: "10", text: "待审核", num: 0 },
      { id: "20", name: "待接待", value: "20", text: "待接待", num: 0 },
      { id: "21", name: "审核未通过", value: "21", text: "审核未通过", num: 0 },
      { id: "25", name: "待面试", value: "25", text: "待面试", num: 0 },
      { id: "26", name: "未接到", value: "26", text: "未接到", num: 0 },
      { id: "30", name: "待入职", value: "30", text: "待入职", num: 0 },
      { id: "35", name: "面试未通过", value: "35", text: "面试未通过", num: 0 },
      { id: "40", name: "已入职", value: "40", text: "已入职", num: 0 },
      { id: "48", name: "约离职", value: "48", text: "约离职", num: 0 },
      { id: "45", name: "通过未入职", value: "45", text: "通过未入职", num: 0 },
      { id: "50", name: "已离职", value: "50", text: "已离职", num: 0 },

      { id: "100", name: "待确认", value: "50", text: "待确认", num: 0 },
      { id: "101", name: "已取消", value: "50", text: "已取消", num: 0 },
      { id: "102", name: "官方审核中", value: "50", text: "官方审核中", num: 0 },
      { id: "103", name: "审核不通过", value: "50", text: "审核不通过", num: 0 },
      // { id: "60", name: "已完成", value: "60", text: "已完成", num: 0 }
    ];
    let data = [];
    data = orderStatus.filter(item => {
      return item.id == $status;
    });
    return data.length > 0 ? data[0] : "";
  },
  /* 设置倒计时
   * @params time 字符串
   */
  setDeadLine (time, type) {

    if (type) {
      // 交付助手的倒计时
      let differenceTime = new Date().getTime() - new Date(time).getTime()
      let absTime = Math.abs(differenceTime)
      var D = Math.floor(absTime / (24 * 60 * 60 * 1000));
      var leave1 = absTime % (24 * 3600 * 1000);
      var H = Math.floor(leave1 / (3600 * 1000));
      var leave2 = leave1 % (3600 * 1000);
      var M = Math.floor(leave2 / (60 * 1000));
      var leave3 = leave2 % (60 * 1000);
      var S = Math.floor(leave3 / 1000);
      // 时间正负的判断标识
      let symbol = true
      if (differenceTime < 0) {
        symbol = false
      }
      if (type == 'jiaofu') {
        if (D > 0) {
          return D + (symbol ? "天前" : '天后');
        } else if (H > 0) {
          return H + (symbol ? "小时前" : '小时后');
        } else if (M > 0) {
          return M + (symbol ? "分钟前" : '分钟后');
        } else {
          return S + (symbol ? "秒前" : '秒后');
        }
      } else if (type == '在职') {
        // 处理在职中的时间显示
        if (D > 0) {
          return type + D + '天'
        } else if (H > 0) {
          return type + H + '小时'
        } else if (M > 0) {
          return type + M + '分钟'
        } else {
          return type + S + '秒'
        }
      }

    } else {
      let differenceTime = new Date(time).getTime() - new Date().getTime()
      let absTime = Math.abs(differenceTime)
      let D = Math.floor(absTime / (24 * 60 * 60 * 1000))
      let leave1 = absTime % (24 * 3600 * 1000)
      let H = Math.floor(leave1 / (3600 * 1000)) > 9 ? Math.floor(leave1 / (3600 * 1000)) : '0' + Math.floor(leave1 / (3600 * 1000))
      let leave2 = leave1 % (3600 * 1000)
      let M = Math.floor(leave2 / (60 * 1000)) > 9 ? Math.floor(leave2 / (60 * 1000)) : '0' + Math.floor(leave2 / (60 * 1000))
      let leave3 = leave2 % (60 * 1000)
      let S = Math.floor(leave3 / 1000) > 9 ? Math.floor(leave3 / 1000) : '0' + Math.floor(leave3 / 1000)
      // 倒计时到期的判断
      let symbol = ''
      if (differenceTime < 0) {
        symbol = '-'
      }
      if (D > 0) {
        return symbol + D + '天'
      } else if (H > 0) {
        return symbol + H + ':' + M + ':' + S
      } else if (M > 0) {
        return symbol + M + ':' + S
      } else {
        return symbol + S + '秒'
      }
    }

  },
  /* 复制文案
   * @params $text 文本字符串
   */
  copyText ($text) {
    if (!$text) {
      $text = '-';
    }
    var textarea = document.createElement("textarea"); //创建一个临时的 <textarea> 元素
    textarea.value = $text; //将要复制的文本赋值给 <textarea> 元素
    document.body.appendChild(textarea); //将 <textarea> 添加到页面上

    if (navigator.userAgent.match(/ipad|iphone/i)) { //判断设备类型为 iOS（包括 iPad、iPhone）
      const editable = textarea.contentEditable === 'true'; //获取当前 <textarea> 是否可编辑状态

      if (!editable) {
        textarea.setAttribute('readonly', true); //如果不可编辑则设置只读属性
      } else {
        textarea.removeAttribute('readonly'); //如果可编辑则移除只读属性
      }

      textarea.style.position = "absolute"; //隐藏 <textarea> 并定位到屏幕外部
      textarea.style.left = "-9999px";
      textarea.style.top = "-9999px";

      const range = document.createRange(); //创建选区对象
      range.selectNodeContents(textarea); //选中 <textarea> 内容

      const selection = window.getSelection(); //获取当前选区
      selection.removeAllRanges(); //清空之前的选区
      selection.addRange(range); //将新的选区添加进去

      textarea.setSelectionRange(0, 999999); //设置光标位置

      setTimeout(() => { //等待一段时间后再删除 <textarea>
        document.body.removeChild(textarea);
      }, 150);
    } else {
      textarea.select(); //非 iOS 平台直接调用 select() 方法选中所有文本
      document.execCommand('copy'); //执行复制命令
      document.body.removeChild(textarea); //完成后删除 <textarea>
    }
  },
  /* 仅服务于图片上传 
   */
  getUUID () {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
      return (c === 'x' ? (Math.random() * 16) | 0 : 'r&0x3' | '0x8').toString(16)
    })
  },
  /* 省市区格式转化
   * 转化前：河南省郑州市
   * 转化后：河南省 | 郑州市 |
   * @params $list 数组
   */
  toGetAddress ($list) {
    if ($list && $list.length > 0) {
      $list.forEach(item => {
        var districtStr = "";
        if (item.district) {
          var districtArr = item.district.split(",");
          var districtArr1 = [];
          // console.log(districtArr);
          districtArr.forEach((item1) => {
            if (item1.length != 0) {
              item1 = item1 + "丨";
              districtArr1.push(item1);
            }
          });
          if (districtArr.length < 3) {
            districtStr = districtArr1[districtArr1.length - 1];
          } else {
            districtStr = districtArr1.join("");
          }
          if (item.district.indexOf("undefined") > -1) {
            districtStr = "-丨";
          }
        }
        item["district"] = districtStr;
      });
      return $list;
    } else {
      return [];
    }
  },
  /* 性别转化
   * @params $list 数组
  */
  toGetSex ($list, $type = "default") {
    if ($list && $list.length > 0) {
      if ($type == "default") {
        $list.forEach(item => {
          if (item.gender == 1) {
            item.gender = "男 |"
          } else if (item.gender == 2) {
            item.gender = "女 |"
          } else {
            item.gender = "男女不限 |"
          };
        });
      } else if ($type == "age") {
        $list.forEach(item => {
          if (Boolean(item.minAgeWoman) === true && Boolean(item.minAgeMan) === false) {
            item.gender = "女";
          } else if (Boolean(item.minAgeWoman) === false && Boolean(item.minAgeMan) === true) {
            item.gender = "男";
          } else {
            item.gender = "男女不限";
          }
        });
      }

      return $list;
    } else {
      return "";
    }
  },
  /* 年龄转化
   * @params $list 数组
  */
  toGetAge ($list) {
    if ($list && $list.length > 0) {
      $list.forEach(item => {
        if (item.minAge && item.maxAge) {
          item["age"] = item.minAge + '-' + item.maxAge + '岁';
        } else if (item.minAge) {
          item["age"] = item.minAge + "岁以上";
        } else if (item.maxAge) {
          item["age"] = item.maxAge + "岁以下";
        } else if (item.minAge == "" && item.maxAge == "") {
          item["age"] = '-'
        }
      });
      return $list;
    } else {
      return "";
    }
  },
  /**
  * 根据薪资类型和薪资值获取薪资展示
  */
  getSalaryClassifyValue (salaryClassify, salaryClassifyValue, $type = "default") {
    var hourlyPay = this.moneyToFixed(salaryClassifyValue);
    if ($type == "default") {
      if (salaryClassify == 0) {
        return `<div class="g_flex_row_start">` +
          `	<span class="g_fs_22 g_c_f40">${hourlyPay}</span>` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_ml_2 g_mb_4">元/小时</span>` +
          `</div>`;
      } else if (salaryClassify == 1) {
        return `<div class="g_flex_row_start">` +
          `	<span class="g_fs_22 g_c_f40">${hourlyPay}</span>` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_ml_2 g_mb_4">元/天</span>` +
          `</div>`;
      } else if (salaryClassify == 2) {
        return `<div class="g_flex_row_start">` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_mr_2 g_mb_4">补</span>` +
          `	<span class="g_fs_22 g_c_f40">${hourlyPay}</span>` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_ml_2 g_mb_4">元</span>` +
          `</div>`;
      } else if (salaryClassify == 3) {
        return `<div class="g_flex_row_start">` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_mr_2 g_mb_4">返</span>` +
          `	<span class="g_fs_22 g_c_f40">${hourlyPay}</span>` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_ml_2 g_mb_4">元</span>` +
          `</div>`;
      } else if (salaryClassify == 4) {
        return `<span class="g_fs_22 g_c_f40">计件</span>`;
      } else if (salaryClassify == 5) {
        return `<div class="g_flex_row_start">` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_mr_2 g_mb_4">保底</span>` +
          `	<span class="g_fs_22 g_c_f40">${hourlyPay}</span>` +
          `   <span class="g_fs_14 g_c_f40 g_flex_column_end g_ml_2 g_mb_4">元</span>` +
          `</div>`;
      } else if (salaryClassify == 6) {
        return `<span class="g_fs_22 g_c_f40">面议</span>`;
      } else if (salaryClassify == 7) {
        return `<span class="g_fs_22 g_c_f40">月薪</span>`;
      } else {
        return "-";
      }
    } else if ($type == "clearStyle") {
      if (salaryClassify == 0) {
        return `<div class="g_flex_row_start">` +
          `	<span class="">${hourlyPay}</span>` +
          `   <span class="">元/小时</span>` +
          `</div>`;
      } else if (salaryClassify == 1) {
        return `<div class="g_flex_row_start">` +
          `	<span class="">${hourlyPay}</span>` +
          `   <span class="">元/天</span>` +
          `</div>`;
      } else if (salaryClassify == 2) {
        return `<div class="g_flex_row_start">` +
          `   <span class="">补</span>` +
          `	<span class="">${hourlyPay}</span>` +
          `   <span class="">元</span>` +
          `</div>`;
      } else if (salaryClassify == 3) {
        return `<div class="g_flex_row_start">` +
          `   <span class="">返</span>` +
          `	<span class="">${hourlyPay}</span>` +
          `   <span class="">元</span>` +
          `</div>`;
      } else if (salaryClassify == 4) {
        return `<span class="">计件</span>`;
      } else if (salaryClassify == 5) {
        return `<div class="g_flex_row_start">` +
          `   <span class="">保底</span>` +
          `	<span class="">${hourlyPay}</span>` +
          `   <span class="">元</span>` +
          `</div>`;
      } else if (salaryClassify == 6) {
        return `<span class="">面议</span>`;
      } else if (salaryClassify == 7) {
        return `<span class="">月薪</span>`;
      } else {
        return "-";
      }
    }
  },
  /**
* 根据薪资类型和薪资值获取薪资展示(无样式)
*/
  getSalaryClassifyValueUnstyle (salaryClassify, salaryClassifyValue, $type = "default") {
    var hourlyPay = this.moneyToFixed(salaryClassifyValue);
    if ($type == "default") {
      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 "-";
      }
    }
  },
  /* 同步 */
  moneyToFixed (money, fixed = 2, multiplicator = 100) {
    if (money != 0 && money != null && money != "" && money != undefined) {
      return this.cutZero(new Number(money / multiplicator).toFixed(fixed));
    } else {
      return "0";
    }
  },
  /* 同步 */
  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;
  },
  /* 处理职位列表的方法 
   */
  disposeJobListData (jobList) {
    let that = this;
    if (jobList !== undefined) {
      if (Array.isArray(jobList)) {
        jobList.forEach((item) => {
          item["workType"] = that.getWorkTypeById(item.workTypeMulti);

          if (that.isNotEmptyCheck(item.distance)) {
            item["distanceKm"] = that.getDistanceName(item.distance);
          }
          if (that.isNotEmptyCheck(item.jobDesp)) {
            item["jobDesp"] = item["jobDesp"].replaceAll("*****", "");
          }
          //年龄
          // console.log(jobList);
          var ageStr = "";
          if (that.isNotEmptyCheck(item.minAge) && that.isNotEmptyCheck(item.maxAge)) {
            ageStr = item.minAge + "-" + item.maxAge + "岁";
          } else if (that.isNotEmptyCheck(item.minAge)) {
            ageStr = item.minAge + "岁以上";
          } else if (that.isNotEmptyCheck(item.maxAge)) {
            ageStr = item.maxAge + "岁以下";
          }
          item["age"] = ageStr;
          item.updateTime = that.getPointTime(item.updateTime, 'YY--MM--DD HH:MM');
          // 更新时间距离现在的差距
          let differenceTime = new Date().getTime() - new Date(item.updateTime || new Date()).getTime();
          var D = Math.floor(differenceTime / (24 * 60 * 60 * 1000));
          var leave1 = differenceTime % (24 * 3600 * 1000);
          var H = Math.floor(leave1 / (3600 * 1000));
          var leave2 = leave1 % (3600 * 1000);
          var M = Math.floor(leave2 / (60 * 1000));
          var leave3 = leave2 % (60 * 1000);
          var S = Math.floor(leave3 / 1000);
          item.diffTime = null;
          if (D > 0) {
            item.diffTime = D + "天前";
          } else if (H > 0) {
            item.diffTime = H + "小时前";
          } else if (M > 0) {
            item.diffTime = M + "分钟前";
          } else {
            item.diffTime = S + "秒前";
          }
          if (item.returnFeeType) {
            if (item.returnFeeType === 0) {
              item.servetype = `${item.returnFee || "--"}元/小时`;
            } else if (item.returnFeeType === 1) {
              item.servetype = `${item.returnFee || "--"}元/日`;
            } else if (item.returnFeeType === 2) {
              item.servetype = `${item.returnFee || "--"}元/月`;
            } else if (item.returnFeeType === 3) {
              item.servetype = `${item.returnFee || "--"}元/次`;
            } else if (item.returnFeeType === 4) {
              item.servetype = `${item.returnFee || "--"}元/件`;
            } else if (item.returnFeeType === 5) {
              item.servetype = `工人收入${item.returnFee || "--"}%`;
            } else if (item.returnFeeType === 6) {
              item.servetype = `共${item.returnFee || "--"}元`;
            } else if (item.returnFeeType === 7) {
              item.servetype = `费用待定`;
            }
          } else {
            item.servetype = `${item.returnFee || "--"}元/小时`;
          }
          //地址深圳丨龙岗区丨
          var districtStr = "";
          if (that.isNotEmptyCheck(item.district)) {
            var districtArr = item.district.split(",");
            var districtArr1 = [];
            districtArr.forEach((item1) => {
              if (item1.length != 0) {
                item1 = item1 + "丨";
                districtArr1.push(item1);
              }
            });
            if (districtArr.length < 3) {
              districtStr = districtArr1[districtArr1.length - 1];
            } else {
              districtStr = districtArr1.join("");
            }
            if (item.district.indexOf("undefined") > -1) {
              districtStr = "-丨";
            }
          }
          item["district"] = districtStr;
          //职位特色
          item["jobSpecialLabelNames"] = that.getJobSpecialLabelNamesArray(item.jobSpecialLabelNames);
          // 特色标签
          const jobSpecialLabelNames = [];
          if (that.isNotEmptyCheck(item.jobSpecialLabelNames) && Array.isArray(item.jobSpecialLabelNames)) {
            item.jobSpecialLabelNames.forEach((item, index) => {
              if (index <= 2) {
                jobSpecialLabelNames.push(item);
              } else {
                return;
              }
            });
            item.jobSpecialLabelNames = jobSpecialLabelNames;
          }
          // 年龄限制
          if (Boolean(item.minAgeWoman) === true && Boolean(item.minAgeMan) === false) {
            item.gender = "女丨";
          } else if (Boolean(item.minAgeWoman) === false && Boolean(item.minAgeMan) === true) {
            item.gender = "男丨";
          } else {
            item.gender = "男女不限丨";
          }
        });
      } else {
        jobList["workType"] = that.getWorkTypeById(jobList.workTypeMulti);

        if (that.isNotEmptyCheck(jobList.distance)) {
          jobList["distanceKm"] = that.getDistanceName(jobList.distance);
        }
        if (that.isNotEmptyCheck(jobList.jobDesp)) {
          jobList["jobDesp"] = jobList["jobDesp"].replaceAll("*****", "");
        }
        //年龄
        var ageStr = "";
        if (that.isNotEmptyCheck(jobList.minAge) && that.isNotEmptyCheck(jobList.maxAge)) {
          ageStr = jobList.minAge + "-" + jobList.maxAge + "岁";
        } else if (that.isNotEmptyCheck(jobList.minAge)) {
          ageStr = jobList.minAge + "岁以上";
        } else if (that.isNotEmptyCheck(jobList.maxAge)) {
          ageStr = jobList.maxAge + "岁以下";
        }
        jobList["age"] = ageStr;
        if (jobList.returnFeeType) {
          if (jobList.returnFeeType === 0) {
            jobList.servetype = `${jobList.returnFee || "--"}元/小时`;
          } else if (jobList.returnFeeType === 1) {
            jobList.servetype = `${jobList.returnFee || "--"}元/日`;
          } else if (jobList.returnFeeType === 2) {
            jobList.servetype = `${jobList.returnFee || "--"}元/月`;
          } else if (jobList.returnFeeType === 3) {
            jobList.servetype = `${jobList.returnFee || "--"}元/次`;
          } else if (jobList.returnFeeType === 4) {
            jobList.servetype = `${jobList.returnFee || "--"}元/件`;
          } else if (jobList.returnFeeType === 5) {
            jobList.servetype = `工人收入${jobList.returnFee || "--"}%`;
          } else if (jobList.returnFeeType === 6) {
            jobList.servetype = `共${jobList.returnFee || "--"}元`;
          } else if (jobList.returnFeeType === 7) {
            jobList.servetype = `费用待定`;
          }
        } else {
          jobList.servetype = `${jobList.returnFee || "--"}元/小时`;
        }
        //地址深圳丨龙岗区丨
        var districtStr = "";
        if (that.isNotEmptyCheck(jobList.district) || that.isNotEmptyCheck(jobList.storeDistrict)) {
          var districtArr

          districtArr = that.isNotEmptyCheck(jobList.district) ? jobList.district.split(",") : jobList.storeDistrict.split(",")
          console.log(districtArr);
          var districtArr1 = [];
          // console.log(districtArr);
          districtArr.forEach((item1) => {
            if (item1.length != 0) {
              item1 = item1 + "丨";
              districtArr1.push(item1);
            }
          });
          console.log(districtArr1);
          if (districtArr.length > 3) {
            districtStr = districtArr1[districtArr1.length - 1];
          } else {
            districtStr = districtArr1.join("");
          }
          console.log(districtStr);
          console.log(jobList.district);
          if (jobList.district == undefined && jobList.storeDistrict == undefined) {
            districtStr = "-丨";
          }
        }
        console.log(districtStr);
        jobList["district"] = districtStr;
        //职位特色
        jobList["jobSpecialLabelNames"] = that.getJobSpecialLabelNamesArray(jobList.jobSpecialLabelNames);
        // 特色标签
        const jobSpecialLabelNames = [];
        if (that.isNotEmptyCheck(jobList.jobSpecialLabelNames) && Array.isArray(jobList.jobSpecialLabelNames)) {
          jobList.jobSpecialLabelNames.forEach((item, index) => {
            if (index <= 4) {
              jobSpecialLabelNames.push(item);
            } else {
              return;
            }
          });
          jobList.jobSpecialLabelNames = jobSpecialLabelNames;
        }
        // 年龄限制
        if (Boolean(jobList.minAgeWoman) === true && Boolean(jobList.minAgeMan) === false) {
          jobList.gender = "女";
        } else if (Boolean(jobList.minAgeWoman) === false && Boolean(jobList.minAgeMan) === true) {
          jobList.gender = "男";
        } else {
          jobList.gender = "男女不限";
        }
      }
    }
    return jobList;
  },
  /**
   * 根据工种类型ID获取名称
   */
  getWorkTypeById (id) {
    let str = "";
    let array = this.workTypeArray();
    array.forEach((item) => {
      if (item.id == id) {
        str = item.name;
      }
    });
    return str;
  },
  /**
   * 工种类型
   */
  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;
  },
  /**
   * 如果不是是null '' 'null' 'undefined'
   * @param item
   * @returns
   */
  isNotEmptyCheck (value) {
    return !this.isEmptyCheck(value);
  },
  /**
   * 如果是null '' 'null' 'undefined'
   * @param item
   * @returns
   */
  isEmptyCheck (value) {
    if (value == null || value === "" || value == "null" || typeof value == "undefined") {
      return true;
    }

    return false;
  },
  /**
   * 根据状态工单类型ID获取名称
   */
  getDistanceName (distance) {
    let str = "";

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

    return str;
  },
  getJobSpecialLabelNamesArray (jobSpecialLabelNames) {
    if (this.isNotEmptyCheck(jobSpecialLabelNames)) {
      return jobSpecialLabelNames.split(", ");
    }
    return [];
  },
  /* 新开页面 
   * @params url 路径
   * @params $params 后台跳转时参数。
   * 				   key - value 形式。value为数字或者字符串
   */
  goWiondowOpenPage (url, $params = {}) {
    let that = this;
    console.log('url', url);
    if (url == "delivery") {// 后台新开页面
      if (that.getDevStr() == "development") {
        window.open(window.location.origin + "/#/other/delivery")
      } else {
        if (window.location.origin.indexOf('www') > -1) {
          window.open('http://www.ibocai.cn/#/other/' + url);
        } else {
          window.open('http://ibocai.cn/#/other/' + url);
        }
      };
    } else if (// 前台特殊处理
      url == "systemMsg" ||
      url == "teamMsg" ||
      url == "list"
    ) {
      if (that.getDevStr() == "development") {
        window.open("http://localhost:8888/#/" + url)
      } else {
        if (window.location.origin.indexOf('www') > -1) {
          window.open('http://www.ibocai.cn/#/' + url);
        } else {
          window.open('http://ibocai.cn/#/' + url);
        }
      };
    } else if (url == "main" || url == "login") {// 前台特殊处理
      console.log('that.getDevStr()', that.getDevStr());
      if (that.getDevStr() == "development") {
        window.location.href = "http://localhost:3001/#/" + url;
        console.log(window.location.href);
      } else {
        if (window.location.origin.indexOf('www') > -1) {
          window.location.href = 'http://www.ibocai.cn/#/' + url;
        } else {
          window.location.href = 'http://ibocai.cn/#/' + url
        }
      };
    } else if (url == "boundtel") {// 前台特殊处理
      if (that.getDevStr() == "development") {
        window.open("http://localhost:8888/#/accountsetting/" + url)
      } else {
        if (window.location.origin.indexOf('www') > -1) {
          window.open('http://www.ibocai.cn/#/accountsetting/' + url);
        } else {
          window.open('http://ibocai.cn/#/accountsetting/' + url);
        }
      };
    } else {// 后台通用
      if (Object.keys($params).length == 0) {
        if (that.getDevStr() == "development") {
          window.open(window.location.origin + '/#/merchantManagement/' + url);
        } else {
          if (window.location.origin.indexOf('www') > -1) {
            window.open('http://www.ibocai.cn/#/merchantManagement/' + url);
          } else {
            window.open('http://ibocai.cn/#/merchantManagement/' + url);
          }
        };
      } else {
        let _array = [];
        let _obj = $params;
        let _str = "";
        for (let key in _obj) {
          _array.push(key + '=' + _obj[key])
        };
        _str = _array.join('&');
        if (that.getDevStr() == "development") {
          window.open(window.location.origin + '/#/merchantManagement/' + url + '?' + _str);
        } else {
          if (window.location.origin.indexOf('www') > -1) {
            window.open('http://www.ibocai.cn/#/merchantManagement/' + url + '?' + _str);
          } else {
            window.open('http://ibocai.cn/#/merchantManagement/' + url + '?' + _str);
          }
        };
      }
    }
  },
  /* 综合月薪 正则规则 
   * 价格中间的特殊字符
  */
  specStrReg ($str) {
    let list = [
      '~', '!', '@', '#', '%', '^', '&', '*', '(', ')',
      '！', '（', '）', '+', '`', '-', '=', '·',
      'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '{', '}', '|', '|',
      'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', ':', "'", '"', '：', '“', '”',
      'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', '<', '>', '?', '《', '》', '？',
      'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P',
      'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L',
      'Z', 'X', 'C', 'V', 'B', 'N', 'M',
      ' ',
    ],
      obj = {
        min: 0,
        max: 0
      }
    if ($str) {
      list.forEach((item, index) => {
        if ($str.indexOf(item) > -1 && $str.split(item)[1]) {
          obj = {
            min: $str.split(item)[0],
            max: $str.split(item)[1]
          }
        }
      })
    }
    return obj;
  },
  /* 价格转化
   * 示例：5000-6000 显示为5，000-6,000
   */
  toGetPrice (number) {
    const formatter = new Intl.NumberFormat('en-US');
    const formattedNumber = formatter.format(number);
    return formattedNumber;
  },
  /* 获取当前开发环境
   */
  getDevStr () {
    return import.meta.env.MODE;
  },
  /**
  * 发单号申请状态
  */
  getRecordStatus (status, type) {
    if (status == 1) {
      if (type == "fans") {
        return '未关注'
      } else {
        return '已关注'
      }
    } else if (status == 2) {
      return '互相关注'
    } else if (status == 3) {
      return '粉丝'
    } else if (status == 4) {
      return '未关注'
    } else if (status == 5) {
      return '验证中'
    } else if (status == 6) {
      return '已过期'
    }
  },
	getJobRequestTypeClassifyNameId (id) {
	  let str = "";
	  let array = this.jobRequestTypeClassifyArray();
	  array.forEach((item) => {
	    if (item.id == id) {
	      str = item.name;
	    }
	  });
	  return str;
	},
	jobRequestTypeClassifyArray () {
	  let jobRequestTypeClassifyArray = [
	    { id: "0", name: "学历", subName: "学历", text: "学历", value: "0", checked: false },
	    { id: "1", name: "体征", subName: "体征", text: "体征", value: "1", checked: false },
	    { id: "2", name: "衣着", subName: "衣着", text: "衣着", value: "2", checked: false },
	    { id: "10", name: "其它", subName: "其它", text: "其它", value: "10", checked: false },
	  ];
	  return jobRequestTypeClassifyArray;
	},
	getJobRequestSpecClassifyNameId (id) {
	  let str = "";
	  let array = this.jobRequestSpecClassifyArray();
	  array.forEach((item) => {
	    if (item.id == id) {
	      str = item.name;
	    }
	  });
	  return str;
	},
	jobRequestSpecClassifyArray () {
	  let jobRequestTypeClassifyArray = [
	    { id: "0", name: "工作休息", subName: "工作休息", text: "工作休息", value: "0", checked: false },
	    { id: "1", name: "薪资待遇", subName: "薪资待遇", text: "薪资待遇", value: "1", checked: false },
	    { id: "2", name: "其它特色", subName: "其它特色", text: "其它特色", value: "2", checked: false },
	    { id: "3", name: "吃住福利", subName: "吃住福利", text: "吃住福利", value: "3", checked: false },
			{ id: "4", name: "面试特色", subName: "面试特色", text: "面试特色", value: "4", checked: false },
	  ];
	  return jobRequestTypeClassifyArray;
	}
}

export default data;