add.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <div>
  3. <v-card class="pa-5">
  4. <v-timeline align="start" side="end">
  5. <v-timeline-item
  6. v-for="(val, i) in list"
  7. :key="i"
  8. :dot-color="val.color"
  9. :icon="val.icon"
  10. >
  11. <div>
  12. <h2 class="mt-n1 headline font-weight-regular">{{ val.title }}</h2>
  13. <div class="mb-4 desc">{{ val.desc }}</div>
  14. <component :is="val.path" :ref="val.ref" :itemData="itemData"></component>
  15. </div>
  16. </v-timeline-item>
  17. </v-timeline>
  18. <div class="text-center mb">
  19. <v-btn class="half-button mr-3" color="primary" variant="outlined" @click="handleCancel()">{{ $t('common.cancel') }}</v-btn>
  20. <v-btn class="half-button" color="primary" :loading="loading" @click="handleSave">{{ $t('common.release') }}</v-btn>
  21. </div>
  22. </v-card>
  23. </div>
  24. </template>
  25. <script setup>
  26. defineOptions({ name: 'enterprise-position-add'})
  27. import { ref } from 'vue'
  28. import { useRouter, useRoute } from 'vue-router'
  29. import { dealDictObjData } from '@/utils/position'
  30. import { saveJobAdvertised, getJobDetails, createTradeOrder } from '@/api/position'
  31. import baseInfo from './baseInfo.vue'
  32. import jobRequirements from './jobRequirements.vue'
  33. import Snackbar from '@/plugins/snackbar'
  34. import { useI18n } from '@/hooks/web/useI18n'
  35. import { useUserStore } from '@/store/user'
  36. const { t } = useI18n()
  37. const route = useRoute()
  38. const router = useRouter()
  39. const userStore = useUserStore()
  40. const baseInfoRef = ref()
  41. const jobRequirementsRef = ref()
  42. const itemData = ref({})
  43. const loading = ref(false)
  44. const list = [
  45. {
  46. color: '#00897B',
  47. icon: 'mdi-numeric-1',
  48. title: t('position.positionInformation'),
  49. desc: '',
  50. path: baseInfo,
  51. ref: baseInfoRef
  52. },
  53. {
  54. color: 'indigo-lighten-2',
  55. icon: 'mdi-numeric-2',
  56. title: t('position.jobRequirements'),
  57. desc: t('position.requirementDesc'),
  58. path: jobRequirements,
  59. ref: jobRequirementsRef
  60. }
  61. ]
  62. let submitParams = {}
  63. // 发布
  64. const handleSave = async () => {
  65. const baseInfo = await baseInfoRef.value[0].getQuery()
  66. if (baseInfo === 'failed') return
  67. const requirement = await jobRequirementsRef.value[0].getQuery()
  68. if (!baseInfo || !requirement) return Snackbar.warning('请将信息填写完整')
  69. submitParams = Object.assign(baseInfo, requirement, { currency_type: 0 }) // currency_type: 写死0(人民币)
  70. if (route.query && route.query.id) submitParams.id = route.query.id // 有id则为编辑
  71. if (!baseInfo.hirePrice) return Snackbar.warning('请填写点数!')
  72. saveEmit(submitParams) // 正常发布,到列表中发起支付(暂定解决方案)
  73. }
  74. const saveEmit = async () => {
  75. loading.value = true
  76. try {
  77. const res = await saveJobAdvertised(submitParams)
  78. Snackbar.success(submitParams.id ? t('common.editSuccessMsg') : t('common.publishSuccessMsg1'))
  79. // 生成订单
  80. await createTradeOrder({
  81. spuId: res,
  82. spuName: submitParams.name,
  83. price: submitParams.hirePrice,
  84. type: 2 // 发布众聘职位订单
  85. })
  86. handleCancel()
  87. } catch (error) {
  88. console.log('error', error)
  89. } finally {
  90. loading.value = false
  91. }
  92. }
  93. // 获取编辑的职位详情
  94. const getPositionDetail = async (id) => {
  95. const data = await getJobDetails({ id })
  96. if (!data && !Object.keys(data).length) return
  97. itemData.value = {...data, ...dealDictObjData({}, data)}
  98. }
  99. // 有id为编辑
  100. if (route.query && route.query.id) {
  101. if (route.query.id) getPositionDetail(route.query.id)
  102. }
  103. // 取消
  104. const handleCancel = () => {
  105. itemData.value = {}
  106. router.push({ path: '/recruit/enterprise/hirePosition' })
  107. // 新增职位发布需更新账户信息
  108. if (route.query && !route.query?.id) {
  109. setTimeout(async () => {
  110. await userStore.getEnterpriseUserAccountInfo()
  111. }, 2000)
  112. }
  113. }
  114. </script>
  115. <style scoped lang="scss">
  116. .desc {
  117. font-size: 13px;
  118. color: var(--color-666);
  119. }
  120. </style>
  121. <style lang="scss" scoped>
  122. .mb {
  123. margin-bottom: 100px;
  124. }
  125. </style>