save.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <v-card class="pa-5 card-box d-flex align-center justify-center flex-column" style="height: 600px;">
  3. <CtForm ref="formPageRef" :items="items" style="width: 600px;"></CtForm>
  4. <div>
  5. <v-btn class="half-button mr-3" color="primary" variant="outlined" @click="handleCancel">{{ $t('common.cancel') }}</v-btn>
  6. <v-btn color="primary" class="half-button" @click="handleSave">{{ $t('common.submit') }}</v-btn>
  7. </div>
  8. </v-card>
  9. </template>
  10. <script setup>
  11. defineOptions({ name: 'system-post-add'})
  12. import { reactive, ref } from 'vue'
  13. import { useRouter, useRoute } from 'vue-router'
  14. import { useI18n } from '@/hooks/web/useI18n'
  15. import { getEnterprisePostDetail, createEnterprisePost, updateEnterprisePost } from '@/api/recruit/enterprise/system/post'
  16. import Snackbar from '@/plugins/snackbar'
  17. const route = useRoute()
  18. const router = useRouter()
  19. const { t } = useI18n()
  20. const formPageRef = ref()
  21. let query = reactive({})
  22. const items = ref({
  23. options: [
  24. {
  25. type: 'ifRadio',
  26. key: 'status',
  27. value: '0',
  28. label: '状态 *',
  29. width: 90,
  30. items: [
  31. { label: '正常', value: '0' },
  32. { label: '停用', value: '1' }
  33. ]
  34. },
  35. {
  36. type: 'text',
  37. key: 'nameCn',
  38. value: null,
  39. label: '岗位中文名称 *',
  40. rules: [v => !!v || '请填写岗位中文名称']
  41. },
  42. {
  43. type: 'text',
  44. key: 'nameEn',
  45. value: null,
  46. label: '岗位英文名称 *',
  47. rules: [v => !!v || '请填写岗位英文名称']
  48. },
  49. {
  50. type: 'text',
  51. key: 'code',
  52. value: null,
  53. label: '岗位缩写'
  54. },
  55. {
  56. type: 'number',
  57. key: 'sort',
  58. value: null,
  59. label: '岗位级别 *',
  60. rules: [v => !!v || '请填写岗位级别']
  61. },
  62. {
  63. type: 'text',
  64. key: 'remark',
  65. value: null,
  66. label: '备注'
  67. }
  68. ]
  69. })
  70. const getPostDetail = async (id) => {
  71. const data = await getEnterprisePostDetail(id)
  72. if (!data) return
  73. query.id = data.id
  74. items.value.options.forEach(val => {
  75. val.value = data[val.key]
  76. })
  77. }
  78. const handleCancel = () => {
  79. router.push('/recruit/enterprise/systemManagement/postManagement')
  80. }
  81. const handleSave = async () => {
  82. const { valid } = await formPageRef.value.formRef.validate()
  83. if (!valid) return
  84. items.value.options.forEach(val => {
  85. query[val.key] = val.value
  86. })
  87. const api = query.id ? updateEnterprisePost : createEnterprisePost
  88. await api(query)
  89. Snackbar.success(t('common.submittedSuccessfully'))
  90. handleCancel()
  91. }
  92. if (route.query && route.query.id) {
  93. if (route.query.id) getPostDetail(route.query.id)
  94. }
  95. </script>
  96. <style scoped lang="scss">
  97. </style>