position.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { reactive, ref } from 'vue'
  2. import { getDict } from '@/hooks/web/useDictionaries'
  3. import { getPublicRatio } from '@/api/recruit/enterprise/position'
  4. const dictObj = reactive({
  5. payUnit: [], // 薪资单位
  6. scale: [], // 规模
  7. industry: [], // 行业
  8. edu: [], // 学历
  9. exp: [], // 工作经验
  10. area: [], // 地区
  11. jobStatus: [], // 求职状态
  12. marital: [], // 婚姻状态
  13. financing: [] // 融资阶段
  14. })
  15. const dictList = ref([
  16. { type: 'menduner_pay_unit', value: 'payUnit', key: 'payUnit', label: 'payName' },
  17. { type: 'menduner_financing_status', value: 'financing', key: 'financingStatus', label: 'financingName' },
  18. { type: 'menduner_scale', value: 'scale', key: 'scale', label: 'scaleName' },
  19. { type: 'menduner_job_status', value: 'jobStatus', key: 'jobStatus', label: 'jobStatusName' },
  20. { type: 'menduner_marital_status', value: 'marital', key: 'maritalStatus', label: 'maritalStatusName' },
  21. { type: 'menduner_industry_type', value: 'industry', key: 'industryId', label: 'industryName', params: {}, apiType: 'industryList', nameKey: 'nameCn', valueKey: 'id' },
  22. { type: 'menduner_education_type', value: 'edu', key: 'eduType', label: 'eduName' },
  23. { type: 'menduner_exp_type', value: 'exp', key: 'expType', label: 'expName' },
  24. { type: 'menduner_area_type', value: 'area', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaList', nameKey: 'name', valueKey: 'id' },
  25. { type: 'positionData', value: 'position', key: 'positionId', label: 'positionName', params: {}, apiType: 'positionData', nameKey: 'nameCn', valueKey: 'id' }
  26. ])
  27. // 字典
  28. const getDictList = async () => {
  29. dictList.value.forEach(async (val) => {
  30. const { data } = await getDict(val.type, val.params, val.apiType)
  31. dictObj[val.value] = data
  32. })
  33. }
  34. export const getDictListData = async () => {
  35. await getDictList()
  36. }
  37. getDictListData()
  38. export const dealDictArrayData = (res, list) => {
  39. res = list.map(item => {
  40. Object.keys(item).map(e => {
  41. const data = dictList.value.find(k => k.key === e)
  42. if (!data) return
  43. const valueKey = data.nameKey ? data.nameKey : 'label'
  44. const idKey = data.valueKey ? data.valueKey : 'value'
  45. if (!dictObj[data.value] || !Object.keys(dictObj[data.value]).length) return
  46. const result = dictObj[data.value].find(val => val[idKey] === item[e])
  47. if (!result) return
  48. item[data.label] = result[valueKey] || ''
  49. })
  50. return { ...item, active: false, select: false }
  51. })
  52. return res
  53. }
  54. export const dealDictObjData = (res, obj) => {
  55. res = obj
  56. Object.keys(obj).map(e => {
  57. const data = dictList.value.find(k => k.key === e)
  58. if (!data) return
  59. const valueKey = data.nameKey ? data.nameKey : 'label'
  60. const idKey = data.valueKey ? data.valueKey : 'value'
  61. const result = dictObj[data.value]?.find(val => val[idKey] === obj[e])
  62. if (!result) return
  63. res[data.label] = result[valueKey]
  64. res = { ...obj, ...res }
  65. })
  66. return res
  67. }
  68. // 获取单个字典对应的数值
  69. export const getDictValueWithLabel = (dict, value, valueKey = 'value', labelKey = 'label') => {
  70. let result = ''
  71. getDict(dict).then(({ data }) => {
  72. if (!data || !data.length) return
  73. const obj = data.find(e => e[valueKey] === value)
  74. if (!obj) return
  75. result = obj[labelKey]
  76. })
  77. return result
  78. }
  79. // 计算众聘佣金
  80. let data
  81. const list = ['headhuntRate', 'recommendRate', 'cvRate'] // 平台、推荐人、投递人
  82. const getRation = async () => {
  83. data = await getPublicRatio()
  84. }
  85. getRation()
  86. export const commissionCalculation = (count, type) => {
  87. if (!data || !Object.keys(data).length) return
  88. const ratio = parseFloat(data[list[type]]) / 100
  89. const value = (count * ratio)/100 // 后端需要除100
  90. return value % 1 === 0 ? Math.floor(value) : value.toFixed(2)
  91. }