index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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
  6. v-model="formData.time"
  7. type="datetime"
  8. :border="true"
  9. returnType="timestamp"
  10. :hide-second="true"
  11. @change="handleDate"
  12. />
  13. </uni-forms-item>
  14. <uni-forms-item name="jobId" label="招聘职位" required>
  15. <view style="max-width: calc(100vw - 110px);">
  16. <uni-data-select v-model="formData.jobId" :disabled="jobDisabled" :localdata="jobList" @change="handleChangeJob" placeholder="请选择招聘职位"></uni-data-select>
  17. </view>
  18. </uni-forms-item>
  19. <uni-forms-item name="address" label="面试地点" required>
  20. <uni-easyinput v-model="formData.address" placeholder="请输入面试地点"></uni-easyinput>
  21. </uni-forms-item>
  22. <uni-forms-item name="invitePhone" label="联系电话" required>
  23. <uni-easyinput v-model="formData.invitePhone" placeholder="请输入联系电话"></uni-easyinput>
  24. </uni-forms-item>
  25. <uni-forms-item name="remark" label="备注事项">
  26. <uni-easyinput v-model="formData.remark" type="textarea" placeholder="请输入备注事项"></uni-easyinput>
  27. </uni-forms-item>
  28. </uni-forms>
  29. <button class="send-button" @tap="handleSubmit">提 交</button>
  30. </view>
  31. </template>
  32. <script setup>
  33. import { ref, unref } from 'vue'
  34. import { onLoad } from '@dcloudio/uni-app'
  35. import { userStore } from '@/store/user'
  36. import { mobile } from '@/utils/validate'
  37. import { getJobAdvertised } from '@/api/new/position'
  38. import { formatName } from '@/utils/getText'
  39. import { getInterviewInviteDefaultTime } from '@/utils/date'
  40. import { saveInterviewInvite } from '@/api/interview'
  41. import { send } from '@/hooks/useIM'
  42. const formRef = ref(null)
  43. const useUserStore = userStore()
  44. const jobDisabled = ref(false)
  45. const formData = ref({
  46. userId: null,
  47. address: null,
  48. invitePhone: useUserStore?.userInfo?.phone || '',
  49. time: getInterviewInviteDefaultTime().timeStamp,
  50. jobId: null,
  51. remark: null,
  52. type: 1
  53. })
  54. const formRules = {
  55. time: {
  56. rules: [{ required: true, errorMessage: '请选择面试时间' }]
  57. },
  58. invitePhone: mobile,
  59. address: {
  60. rules: [{ required: true, errorMessage: '请输入面试地点' }]
  61. },
  62. jobId: {
  63. rules: [{ required: true, errorMessage: '请选择邀请面试的职位' }]
  64. }
  65. }
  66. // 职位列表
  67. const jobList = ref([])
  68. const getJobList = async (jobId) => {
  69. const { data } = await getJobAdvertised({ status: '0', exTime: 0 })
  70. jobList.value = data.map(e => {
  71. return { text: formatName(e.name), value: e.id, data: e }
  72. })
  73. // 有职位id的则默认选中
  74. if (jobId) {
  75. formData.value.jobId = jobId
  76. formData.value.address = jobList.value.find(item => item.value === jobId)?.data.address
  77. jobDisabled.value = true
  78. }
  79. }
  80. const handleChangeJob = (e) => {
  81. const job = jobList.value.find(item => item.value === e)
  82. if (!job) return
  83. formData.value.address = job.data.address
  84. // 沟通-面试邀请需携带职位信息
  85. if (channerl.value && Object.keys(channerl.value).length > 0) formData.value.positionInfo = job
  86. }
  87. const handleDate = (val) => {
  88. const selectedDate = new Date(val)
  89. const currentDate = new Date()
  90. if (selectedDate < currentDate) {
  91. uni.showToast({
  92. title: '面试时间不得小于当前时间',
  93. icon: 'none',
  94. duration: 2000
  95. })
  96. }
  97. }
  98. const channerl = ref({})
  99. onLoad(async (options) => {
  100. // 编辑面试、重新邀约
  101. if (options?.editData) {
  102. const obj = JSON.parse(decodeURIComponent(options.editData))
  103. for (let key in formData.value) {
  104. formData.value[key] = obj[key]
  105. }
  106. formData.value.id = obj.id
  107. if (obj.jobFairId) formData.value.jobFairId = obj.jobFairId
  108. // 有实习时间的则为学生,需传递实习时间
  109. if (obj?.practiceStartTime && obj?.practiceEndTime) {
  110. formData.value.practiceStartTime = obj.practiceStartTime
  111. formData.value.practiceEndTime = obj.practiceEndTime
  112. }
  113. await getJobList()
  114. return
  115. }
  116. // 沟通-面试邀请
  117. if (options?.chartData) {
  118. const obj = JSON.parse(decodeURIComponent(options.chartData))
  119. formData.value.userId = obj.id
  120. channerl.value = {
  121. channelID: obj.channelID,
  122. channelType: obj.channelType
  123. }
  124. await getJobList()
  125. return
  126. }
  127. const { id, jobId } = options
  128. if (!id) {
  129. uni.showToast({
  130. title: '缺少人员id',
  131. icon: 'none'
  132. })
  133. setTimeout(() => {
  134. uni.navigateBack({ delta: 1 })
  135. }, 1000)
  136. return
  137. }
  138. formData.value.userId = id
  139. await getJobList(jobId)
  140. })
  141. // 提交
  142. const handleSubmit = async () => {
  143. const valid = await unref(formRef).validate()
  144. if (!valid) return
  145. const selectedDate = new Date(formData.value.time)
  146. const currentDate = new Date()
  147. if (selectedDate < currentDate) {
  148. uni.showToast({
  149. title: '面试时间不得小于当前时间',
  150. icon: 'none',
  151. duration: 2000
  152. })
  153. return
  154. }
  155. uni.showLoading({ title: '提交中' })
  156. try {
  157. await saveInterviewInvite(formData.value)
  158. // 从沟通过来的需要发消息
  159. if (channerl.value && Object.keys(channerl.value).length > 0) send(JSON.stringify(formData.value), channerl.value, 101)
  160. uni.hideLoading()
  161. uni.showToast({
  162. title: '提交成功',
  163. icon: 'success'
  164. })
  165. channerl.value = {}
  166. setTimeout(() => {
  167. uni.navigateBack({ delta: 1 })
  168. }, 1000)
  169. } catch {
  170. uni.hideLoading()
  171. }
  172. }
  173. </script>
  174. <style scoped lang="scss">
  175. </style>