index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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/interview'
  32. import { send } from '@/hooks/useIM'
  33. const formRef = ref(null)
  34. const useUserStore = userStore()
  35. const jobDisabled = ref(false)
  36. const formData = ref({
  37. userId: null,
  38. address: null,
  39. invitePhone: useUserStore?.userInfo?.phone || '',
  40. time: getInterviewInviteDefaultTime().timeStamp,
  41. jobId: null,
  42. remark: null,
  43. type: 1
  44. })
  45. const formRules = {
  46. time: {
  47. rules: [{ required: true, errorMessage: '请选择面试时间' }]
  48. },
  49. invitePhone: mobile,
  50. address: {
  51. rules: [{ required: true, errorMessage: '请输入面试地点' }]
  52. },
  53. jobId: {
  54. rules: [{ required: true, errorMessage: '请选择邀请面试的职位' }]
  55. }
  56. }
  57. // 职位列表
  58. const jobList = ref([])
  59. const getJobList = async (jobId) => {
  60. const { data } = await getJobAdvertised({ status: 0 })
  61. jobList.value = data.map(e => {
  62. return { text: formatName(e.name), value: e.id, data: e }
  63. })
  64. // 有职位id的则默认选中
  65. if (jobId) {
  66. formData.value.jobId = jobId
  67. formData.value.address = jobList.value.find(item => item.value === jobId)?.data.address
  68. jobDisabled.value = true
  69. }
  70. }
  71. const handleChangeJob = (e) => {
  72. const job = jobList.value.find(item => item.value === e)
  73. if (!job) return
  74. formData.value.address = job.data.address
  75. // 沟通-面试邀请需携带职位信息
  76. if (channerl.value && Object.keys(channerl.value).length > 0) formData.value.positionInfo = job
  77. }
  78. const channerl = ref({})
  79. onLoad(async (options) => {
  80. // 编辑面试、重新邀约
  81. if (options?.editData) {
  82. const obj = JSON.parse(decodeURIComponent(options.editData))
  83. for (let key in formData.value) {
  84. formData.value[key] = obj[key]
  85. }
  86. formData.value.id = obj.id
  87. if (obj.jobFairId) formData.value.jobFairId = obj.jobFairId
  88. // 有实习时间的则为学生,需传递实习时间
  89. if (obj?.practiceStartTime && obj?.practiceEndTime) {
  90. formData.value.practiceStartTime = obj.practiceStartTime
  91. formData.value.practiceEndTime = obj.practiceEndTime
  92. }
  93. await getJobList()
  94. return
  95. }
  96. // 沟通-面试邀请
  97. if (options?.chartData) {
  98. const obj = JSON.parse(decodeURIComponent(options.chartData))
  99. formData.value.userId = obj.id
  100. channerl.value = {
  101. channelID: obj.channelID,
  102. channelType: obj.channelType
  103. }
  104. await getJobList()
  105. return
  106. }
  107. const { id, jobId } = options
  108. if (!id) {
  109. uni.showToast({
  110. title: '缺少人员id',
  111. icon: 'none'
  112. })
  113. setTimeout(() => {
  114. uni.navigateBack({ delta: 1 })
  115. }, 1000)
  116. return
  117. }
  118. formData.value.userId = id
  119. await getJobList(jobId)
  120. })
  121. // 提交
  122. const handleSubmit = async () => {
  123. const valid = await unref(formRef).validate()
  124. if (!valid) return
  125. uni.showLoading({ title: '提交中' })
  126. try {
  127. await saveInterviewInvite(formData.value)
  128. // 从沟通过来的需要发消息
  129. if (channerl.value && Object.keys(channerl.value).length > 0) send(JSON.stringify(formData.value), channerl.value, 101)
  130. uni.hideLoading()
  131. uni.showToast({
  132. title: '提交成功',
  133. icon: 'success'
  134. })
  135. channerl.value = {}
  136. setTimeout(() => {
  137. uni.navigateBack({ delta: 1 })
  138. }, 1000)
  139. } catch {
  140. uni.hideLoading()
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. </style>