index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view style="padding: 30rpx;">
  3. <uni-forms ref="formRef" :modelValue="formData" :rules="formRules" validateTrigger="bind" label-width="80px" label-align="right" label-position="left">
  4. <uni-forms-item name="time" label="面试时间" required>
  5. <uni-datetime-picker v-model="formData.time" type="datetime" :border="true" returnType="timestamp" :hide-second="true" />
  6. </uni-forms-item>
  7. <uni-forms-item name="jobId" label="招聘职位" required>
  8. <uni-data-select v-model="formData.jobId" :disabled="jobDisabled" :localdata="jobList" @change="handleChangeJob" placeholder="请选择招聘职位"></uni-data-select>
  9. </uni-forms-item>
  10. <uni-forms-item name="address" label="面试地点" required>
  11. <uni-easyinput v-model="formData.address" placeholder="请输入面试地点"></uni-easyinput>
  12. </uni-forms-item>
  13. <uni-forms-item name="invitePhone" label="联系电话" required>
  14. <uni-easyinput v-model="formData.invitePhone" placeholder="请输入联系电话"></uni-easyinput>
  15. </uni-forms-item>
  16. <uni-forms-item name="remark" label="备注事项">
  17. <uni-easyinput v-model="formData.remark" type="textarea" placeholder="请输入备注事项"></uni-easyinput>
  18. </uni-forms-item>
  19. </uni-forms>
  20. <button class="send-button" @tap="handleSubmit">提 交</button>
  21. </view>
  22. </template>
  23. <script setup>
  24. import { ref, unref } from 'vue'
  25. import { onLoad } from '@dcloudio/uni-app'
  26. import { userStore } from '@/store/user'
  27. import { mobile } from '@/utils/validate'
  28. import { getJobAdvertised } from '@/api/new/position'
  29. import { formatName } from '@/utils/getText'
  30. import { getInterviewInviteDefaultTime } from '@/utils/date'
  31. import { saveInterviewInvite } from '@/api/new/interview'
  32. const formRef = ref(null)
  33. const useUserStore = userStore()
  34. const jobDisabled = ref(false)
  35. const formData = ref({
  36. userId: null,
  37. address: null,
  38. invitePhone: useUserStore?.userInfo?.phone || '',
  39. time: getInterviewInviteDefaultTime().timeStamp,
  40. jobId: null,
  41. remark: null,
  42. type: 1
  43. })
  44. const formRules = {
  45. time: {
  46. rules: [{ required: true, errorMessage: '请选择面试时间' }]
  47. },
  48. invitePhone: mobile,
  49. address: {
  50. rules: [{ required: true, errorMessage: '请输入面试地点' }]
  51. },
  52. jobId: {
  53. rules: [{ required: true, errorMessage: '请选择邀请面试的职位' }]
  54. }
  55. }
  56. // 职位列表
  57. const jobList = ref([])
  58. const getJobList = async (jobId) => {
  59. const { data } = await getJobAdvertised({ status: 0 })
  60. jobList.value = data.map(e => {
  61. return { text: formatName(e.name), value: e.id, ...e }
  62. })
  63. // 有职位id的则默认选中
  64. if (jobId) {
  65. formData.value.jobId = jobId
  66. formData.value.address = jobList.value.find(item => item.value === jobId)?.address
  67. jobDisabled.value = true
  68. }
  69. }
  70. const handleChangeJob = (e) =>{
  71. const job = jobList.value.find(item => item.value === e)
  72. if (!job) return
  73. formData.value.address = job.address
  74. }
  75. onLoad(async (options) => {
  76. const { id, jobId } = options
  77. if (!id) {
  78. uni.showToast({
  79. title: '缺少人员id',
  80. icon: 'none'
  81. })
  82. setTimeout(() => {
  83. uni.navigateBack({ delta: 1 })
  84. }, 1000)
  85. return
  86. }
  87. formData.value.userId = id
  88. await getJobList(jobId)
  89. })
  90. // 提交
  91. const handleSubmit = async () => {
  92. const valid = await unref(formRef).validate()
  93. if (!valid) return
  94. uni.showLoading({ title: '提交中' })
  95. try {
  96. await saveInterviewInvite(formData.value)
  97. uni.hideLoading()
  98. uni.showToast({
  99. title: '提交成功',
  100. icon: 'success'
  101. })
  102. setTimeout(() => {
  103. uni.navigateBack({ delta: 1 })
  104. }, 1000)
  105. } catch {
  106. uni.hideLoading()
  107. }
  108. }
  109. </script>
  110. <style scoped lang="scss">
  111. </style>