position.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_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. ])
  33. // 字典
  34. const getDictList = async () => {
  35. dictList.value.forEach(async (val) => {
  36. const { data } = await getDict(val.type, val.params, val.apiType)
  37. dictObj[val.value] = data.data
  38. })
  39. }
  40. export const getDictListData = async () => {
  41. await getDictList()
  42. }
  43. getDictListData()
  44. export const dealDictArrayData = (res, list) => {
  45. res = list.map(item => {
  46. Object.keys(item).map(e => {
  47. const data = dictList.value.find(k => k.key === e)
  48. if (!data) return
  49. const valueKey = data.nameKey ? data.nameKey : 'label'
  50. const idKey = data.valueKey ? data.valueKey : 'value'
  51. if (!dictObj[data.value] || !Object.keys(dictObj[data.value]).length) return
  52. const result = dictObj[data.value].find(val => val[idKey] === item[e])
  53. if (!result) return
  54. item[data.label] = result[valueKey] || ''
  55. })
  56. return { ...item, active: false, select: false }
  57. })
  58. return res
  59. }
  60. export const dealDictObjData = (res, obj) => {
  61. res = obj
  62. Object.keys(obj).map(e => {
  63. const data = dictList.value.find(k => k.key === e)
  64. if (!data) return
  65. const valueKey = data.nameKey ? data.nameKey : 'label'
  66. const idKey = data.valueKey ? data.valueKey : 'value'
  67. const result = dictObj[data.value]?.find(val => val[idKey] === obj[e])
  68. if (!result) return
  69. res[data.label] = result[valueKey]
  70. res = { ...obj, ...res }
  71. })
  72. return res
  73. }
  74. // 获取单个字典对应的数值
  75. export const getDictValueWithLabel = (dict, value, valueKey = 'value', labelKey = 'label') => {
  76. let result = ''
  77. getDict(dict).then(({ data }) => {
  78. if (!data || !data.length) return
  79. const obj = data.find(e => e[valueKey] === value)
  80. if (!obj) return
  81. result = obj[labelKey]
  82. })
  83. return result
  84. }
  85. // 计算众聘佣金
  86. let data
  87. const list = ['headhuntRate', 'recommendRate', 'cvRate'] // 平台、推荐人、投递人
  88. const getRation = async () => {
  89. const res = await getPublicRatio()
  90. data = res?.data
  91. }
  92. getRation()
  93. export const rechargeRatio = () => { return 10 }
  94. export const commissionCalculation = (count, type) => {
  95. if (!data || !Object.keys(data).length) return
  96. // 所占的百分比
  97. const ratio = parseFloat(data[list[type]]) / 100 // 所占的百分比-> 50%变为0.5 (不能改)
  98. // 积分变成金额
  99. const value = count * ratio / rechargeRatio()
  100. return value % 1 === 0 ? Math.floor(value) : value.toFixed(2)
  101. }
  102. // "分"和"元" 转化。 type-> toCent:提交给后端需要乘以100; toYuan:回显需要除以100)
  103. export const FenYuanTransform = (count, type='toYuan') => {
  104. if ((count - 0) === 0) return 0
  105. if (!count) return ''
  106. const Magnification = type === 'toCent' ? 100 : 1/100
  107. return type === 'toCent' ? (count - 0)*Magnification : ((count - 0)*Magnification).toFixed(2)
  108. }