position.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import { reactive, ref } from 'vue'
  2. import { getDict } from '../hooks/useDictionaries'
  3. import { getPublicRatio } from '@/api/user'
  4. export const dictObj = reactive({
  5. payUnit: [], // 薪资单位
  6. scale: [], // 规模
  7. industry: [], // 行业
  8. edu: [], // 学历
  9. exp: [], // 工作经验
  10. area: [], // 地区
  11. jobStatus: [], // 求职状态
  12. marital: [], // 婚姻状态
  13. financing: [], // 融资阶段
  14. sex: [],
  15. jobType: [],
  16. areaTreeData: [],
  17. areaTreeDataExtend: [],
  18. eduSystemType: []
  19. })
  20. const dictList = ref([
  21. { type: 'menduner_pay_unit', value: 'payUnit', key: 'payUnit', label: 'payName' },
  22. { type: 'menduner_sex', value: 'sex', key: 'sex', label: 'sexName' },
  23. { type: 'menduner_job_type', value: 'jobType', key: 'jobType', label: 'jobTypeName' },
  24. { type: 'menduner_financing_status', value: 'financing', key: 'financingStatus', label: 'financingName' },
  25. { type: 'menduner_scale', value: 'scale', key: 'scale', label: 'scaleName' },
  26. { type: 'menduner_job_seek_status', value: 'jobStatus', key: 'jobStatus', label: 'jobStatusName' },
  27. { type: 'menduner_marital_status', value: 'marital', key: 'maritalStatus', label: 'maritalStatusName' },
  28. { type: 'menduner_industry_type', value: 'industry', key: 'industryId', label: 'industryName', params: {}, apiType: 'industryList', nameKey: 'nameCn', valueKey: 'id' },
  29. { type: 'menduner_education_type', value: 'edu', key: 'eduType', label: 'eduName' },
  30. { type: 'menduner_education_system_type', value: 'eduSystemType', key: 'eduSystemType', label: 'eduSystemName' },
  31. { type: 'menduner_exp_type', value: 'exp', key: 'expType', label: 'expName' },
  32. { type: 'menduner_area_type', value: 'area', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaList', nameKey: 'name', valueKey: 'id' },
  33. { type: 'positionData', value: 'position', key: 'positionId', label: 'positionName', params: {}, apiType: 'positionData', nameKey: 'nameCn', valueKey: 'id' },
  34. { type: 'areaTreeData', value: 'areaTreeData', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaTreeData', nameKey: 'name', valueKey: 'id' },
  35. { type: 'areaTreeDataExtend', value: 'areaTreeDataExtend', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaTreeDataExtend', nameKey: 'name', valueKey: 'id' },
  36. { type: 'positionTreeData', value: 'positionTreeData', key: 'positionTreeId', label: 'positionName', params: {}, apiType: 'positionTreeData', nameKey: 'nameCn', valueKey: 'id' },
  37. { type: 'industryTreeData', value: 'industryTreeData', key: 'industryTreeId', label: 'industryName', params: {}, apiType: 'industryTreeData', nameKey: 'nameCn', valueKey: 'id' },
  38. ])
  39. // 字典
  40. const getDictList = async () => {
  41. dictList.value.forEach(async (val) => {
  42. const { data } = await getDict(val.type, val.params, val.apiType)
  43. dictObj[val.value] = data.data
  44. })
  45. }
  46. export const getDictListData = async () => {
  47. await getDictList()
  48. }
  49. getDictListData()
  50. export const dealDictArrayData = (res, list) => {
  51. res = list.map(item => {
  52. Object.keys(item).map(e => {
  53. const data = dictList.value.find(k => k.key === e)
  54. if (!data) return
  55. const valueKey = data.nameKey ? data.nameKey : 'label'
  56. const idKey = data.valueKey ? data.valueKey : 'value'
  57. if (!dictObj[data.value] || !Object.keys(dictObj[data.value]).length) return
  58. const result = dictObj[data.value].find(val => val[idKey] === item[e])
  59. if (!result) return
  60. item[data.label] = result[valueKey] || ''
  61. })
  62. return { ...item, active: false, select: false }
  63. })
  64. return res
  65. }
  66. export const dealDictObjData = (res, obj) => {
  67. res = obj
  68. Object.keys(obj).map(e => {
  69. const data = dictList.value.find(k => k.key === e)
  70. if (!data) return
  71. const valueKey = data.nameKey ? data.nameKey : 'label'
  72. const idKey = data.valueKey ? data.valueKey : 'value'
  73. const result = dictObj[data.value]?.find(val => val[idKey] === obj[e])
  74. if (!result) return
  75. res[data.label] = result[valueKey]
  76. res = { ...obj, ...res }
  77. })
  78. return res
  79. }
  80. // 计算众聘佣金
  81. let data
  82. const list = ['headhuntRate', 'recommendRate', 'cvRate'] // 平台、推荐人、投递人
  83. const getRation = async () => {
  84. const res = await getPublicRatio()
  85. data = res?.data
  86. }
  87. getRation()
  88. export const rechargeRatio = () => { return 10 }
  89. export const commissionCalculation = (count, type) => {
  90. if (!data || !Object.keys(data).length) return
  91. // 所占的百分比
  92. const ratio = parseFloat(data[list[type]]) / 100 // 所占的百分比-> 50%变为0.5 (不能改)
  93. // 积分变成金额
  94. const value = count * ratio / rechargeRatio()
  95. return value % 1 === 0 ? Math.floor(value) : value.toFixed(2)
  96. }
  97. // "分"和"元" 转化。 type-> toCent:提交给后端需要乘以100; toYuan:回显需要除以100)
  98. export const FenYuanTransform = (count, type='toYuan') => {
  99. if ((count - 0) === 0) return 0
  100. if (!count) return ''
  101. const Magnification = type === 'toCent' ? 100 : 1/100
  102. return type === 'toCent' ? (count - 0)*Magnification : ((count - 0)*Magnification).toFixed(2)
  103. }