position.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. })
  18. const dictList = ref([
  19. { type: 'menduner_pay_unit', value: 'payUnit', key: 'payUnit', label: 'payName' },
  20. { type: 'menduner_sex', value: 'sex', key: 'sex', label: 'sexName' },
  21. { type: 'menduner_job_type', value: 'jobType', key: 'jobType', label: 'jobTypeName' },
  22. { type: 'menduner_financing_status', value: 'financing', key: 'financingStatus', label: 'financingName' },
  23. { type: 'menduner_scale', value: 'scale', key: 'scale', label: 'scaleName' },
  24. { type: 'menduner_job_seek_status', value: 'jobStatus', key: 'jobStatus', label: 'jobStatusName' },
  25. { type: 'menduner_marital_status', value: 'marital', key: 'maritalStatus', label: 'maritalStatusName' },
  26. { type: 'menduner_industry_type', value: 'industry', key: 'industryId', label: 'industryName', params: {}, apiType: 'industryList', nameKey: 'nameCn', valueKey: 'id' },
  27. { type: 'menduner_education_type', value: 'edu', key: 'eduType', label: 'eduName' },
  28. { type: 'menduner_exp_type', value: 'exp', key: 'expType', label: 'expName' },
  29. { type: 'menduner_area_type', value: 'area', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaList', nameKey: 'name', valueKey: 'id' },
  30. { type: 'positionData', value: 'position', key: 'positionId', label: 'positionName', params: {}, apiType: 'positionData', nameKey: 'nameCn', valueKey: 'id' },
  31. { type: 'areaTreeData', value: 'areaTreeData', key: 'areaId', label: 'areaName', params: {}, apiType: 'areaTreeData', nameKey: 'name', valueKey: 'id' },
  32. { type: 'positionTreeData', value: 'positionTreeData', key: 'positionTreeId', label: 'positionName', params: {}, apiType: 'positionTreeData', nameKey: 'nameCn', valueKey: 'id' },
  33. { type: 'industryTreeData', value: 'industryTreeData', key: 'industryTreeId', label: 'industryName', params: {}, apiType: 'industryTreeData', nameKey: 'nameCn', valueKey: 'id' },
  34. ])
  35. // 字典
  36. const getDictList = async () => {
  37. dictList.value.forEach(async (val) => {
  38. const { data } = await getDict(val.type, val.params, val.apiType)
  39. dictObj[val.value] = data.data
  40. })
  41. }
  42. export const getDictListData = async () => {
  43. await getDictList()
  44. }
  45. getDictListData()
  46. export const dealDictArrayData = (res, list) => {
  47. res = list.map(item => {
  48. Object.keys(item).map(e => {
  49. const data = dictList.value.find(k => k.key === e)
  50. if (!data) return
  51. const valueKey = data.nameKey ? data.nameKey : 'label'
  52. const idKey = data.valueKey ? data.valueKey : 'value'
  53. if (!dictObj[data.value] || !Object.keys(dictObj[data.value]).length) return
  54. const result = dictObj[data.value].find(val => val[idKey] === item[e])
  55. if (!result) return
  56. item[data.label] = result[valueKey] || ''
  57. })
  58. return { ...item, active: false, select: false }
  59. })
  60. return res
  61. }
  62. export const dealDictObjData = (res, obj) => {
  63. res = obj
  64. Object.keys(obj).map(e => {
  65. const data = dictList.value.find(k => k.key === e)
  66. if (!data) return
  67. const valueKey = data.nameKey ? data.nameKey : 'label'
  68. const idKey = data.valueKey ? data.valueKey : 'value'
  69. const result = dictObj[data.value]?.find(val => val[idKey] === obj[e])
  70. if (!result) return
  71. res[data.label] = result[valueKey]
  72. res = { ...obj, ...res }
  73. })
  74. return res
  75. }
  76. // 获取单个字典对应的数值
  77. export const getDictValueWithLabel = (dict, value, valueKey = 'value', labelKey = 'label') => {
  78. let result = ''
  79. getDict(dict).then(({ data }) => {
  80. if (!data || !data.length) return
  81. const obj = data.find(e => e[valueKey] === value)
  82. if (!obj) return
  83. result = obj[labelKey]
  84. })
  85. return result
  86. }
  87. // 计算众聘佣金
  88. let data
  89. const list = ['headhuntRate', 'recommendRate', 'cvRate'] // 平台、推荐人、投递人
  90. const getRation = async () => {
  91. const res = await getPublicRatio()
  92. data = res?.data
  93. }
  94. getRation()
  95. export const rechargeRatio = () => { return 10 }
  96. export const commissionCalculation = (count, type) => {
  97. if (!data || !Object.keys(data).length) return
  98. // 所占的百分比
  99. const ratio = parseFloat(data[list[type]]) / 100 // 所占的百分比-> 50%变为0.5 (不能改)
  100. // 积分变成金额
  101. const value = count * ratio / rechargeRatio()
  102. return value % 1 === 0 ? Math.floor(value) : value.toFixed(2)
  103. }
  104. // "分"和"元" 转化。 type-> toCent:提交给后端需要乘以100; toYuan:回显需要除以100)
  105. export const FenYuanTransform = (count, type='toYuan') => {
  106. if ((count - 0) === 0) return 0
  107. if (!count) return ''
  108. const Magnification = type === 'toCent' ? 100 : 1/100
  109. return type === 'toCent' ? (count - 0)*Magnification : ((count - 0)*Magnification).toFixed(2)
  110. }