index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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" :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 { getJobAdvertisedList } 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 formData = ref({
  35. userId: null,
  36. address: null,
  37. invitePhone: useUserStore?.userInfo?.phone || '',
  38. time: getInterviewInviteDefaultTime().timeStamp,
  39. jobId: null,
  40. remark: null,
  41. type: 1
  42. })
  43. const formRules = {
  44. time: {
  45. rules: [{ required: true, errorMessage: '请选择面试时间' }]
  46. },
  47. invitePhone: mobile,
  48. address: {
  49. rules: [{ required: true, errorMessage: '请输入面试地点' }]
  50. },
  51. jobId: {
  52. rules: [{ required: true, errorMessage: '请选择邀请面试的职位' }]
  53. }
  54. }
  55. // 职位列表
  56. const jobList = ref([])
  57. const getJobList = async () => {
  58. const { data } = await getJobAdvertisedList({ pageNo: 1, pageSize: 10, hasExpiredData: false, status: 0 })
  59. jobList.value = data?.list.map(e => {
  60. return { text: formatName(e.name), value: e.id, ...e }
  61. })
  62. }
  63. const handleChangeJob = (e) =>{
  64. const job = jobList.value.find(item => item.value === e)
  65. if (!job) return
  66. formData.value.address = job.address
  67. }
  68. onLoad(async (options) => {
  69. const { id } = options
  70. if (!id) {
  71. uni.showToast({
  72. title: '缺少人员id',
  73. icon: 'none'
  74. })
  75. setTimeout(() => {
  76. uni.navigateBack({ delta: 1 })
  77. }, 1000)
  78. return
  79. }
  80. formData.value.userId = id
  81. await getJobList()
  82. })
  83. // 提交
  84. const handleSubmit = async () => {
  85. const valid = await unref(formRef).validate()
  86. if (!valid) return
  87. uni.showLoading({ title: '提交中' })
  88. try {
  89. await saveInterviewInvite(formData.value)
  90. uni.hideLoading()
  91. uni.showToast({
  92. title: '提交成功',
  93. icon: 'success'
  94. })
  95. setTimeout(() => {
  96. uni.navigateBack({ delta: 1 })
  97. }, 1000)
  98. } catch {
  99. uni.hideLoading()
  100. }
  101. }
  102. </script>
  103. <style scoped lang="scss">
  104. </style>