requirement.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <!-- -->
  2. <template>
  3. <view class="f-straight wrapper">
  4. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px" label-align="right">
  5. <uni-forms-item label="招聘类型" name="type" required>
  6. <uni-data-picker popup-title="请选择招聘类型" v-model="formData.type" :localdata="jobType" :clear-icon="false" :map="{ text: 'key', value: 'value'}" @change="typeChange"></uni-data-picker>
  7. </uni-forms-item>
  8. <uni-forms-item label="学历要求" name="eduType" required>
  9. <uni-data-picker popup-title="请选择学历要求" v-model="formData.eduType" :localdata="dictObj?.edu_extend || []" :clear-icon="false" :map="{ text: 'label', value: 'value'}"></uni-data-picker>
  10. </uni-forms-item>
  11. <uni-forms-item label="工作经验" name="expType" required>
  12. <uni-data-picker popup-title="请选择工作经验" v-model="formData.expType" :localdata="dictObj?.exp_extend || []" :clear-icon="false" :map="{ text: 'label', value: 'value'}"></uni-data-picker>
  13. </uni-forms-item>
  14. <uni-forms-item label="最低薪资" name="payFrom" :required="salary?.length === 0" label-width="90px">
  15. <view class="d-flex">
  16. <uni-number-box v-model="formData.payFrom" :disabled="salary?.length > 0" :min="1" :max="999999999" :step="salaryStep" :width="100" @change="payChange"></uni-number-box>
  17. <uni-data-checkbox v-model="salary" multiple :localdata="[{ text: '薪资面议', value: 1 }]" selectedColor="#00B760" class="ss-m-l-20" @change="salaryCheckboxChange"></uni-data-checkbox>
  18. </view>
  19. </uni-forms-item>
  20. <uni-forms-item label="最高薪资" name="payTo" :required="salary?.length === 0" label-width="90px">
  21. <uni-number-box v-model="formData.payTo" :disabled="salary?.length > 0" :min="payToMin" :max="999999999" :step="salaryStep" :width="100"></uni-number-box>
  22. </uni-forms-item>
  23. <uni-forms-item label="计薪时段" name="payUnit" :required="salary?.length === 0">
  24. <uni-data-picker popup-title="请选择计薪时段" v-model="formData.payUnit" :placeholder="salary?.length > 0 ? '薪资面议' : '请选择'" :readonly="salary?.length > 0" :localdata="dictObj?.payUnit || []" :clear-icon="false" :map="{ text: 'label', value: 'value'}"></uni-data-picker>
  25. </uni-forms-item>
  26. <uni-forms-item label="工作城市" name="areaId" required label-width="90px">
  27. <uni-data-picker popup-title="请选择工作城市" v-model="formData.areaId" :localdata="dictObj?.areaTreeData_extend || []" :clear-icon="false" :map="{ text: 'name', value: 'id'}"></uni-data-picker>
  28. </uni-forms-item>
  29. <uni-forms-item required label="详情地址" name="address">
  30. <uni-easyinput v-model="formData.address" placeholder="请填写详细地址"></uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item label="职位关键字" name="tagList">
  33. <view class="tagsBox" @tap="portraitOpen">
  34. <view class="tags" v-if="tagList?.length">
  35. <view
  36. v-for="tag in tagList"
  37. :key="tag"
  38. class="tag"
  39. >
  40. {{ tag }}
  41. </view>
  42. </view>
  43. <uni-icons
  44. type="icon-Edit"
  45. color="#00B760"
  46. class="ss-m-t-20"
  47. custom-prefix="iconfont"
  48. size="18"
  49. ></uni-icons>
  50. </view>
  51. </uni-forms-item>
  52. </uni-forms>
  53. <portrait ref="portraitRef" @submit="portraitSubmit"></portrait>
  54. </view>
  55. </template>
  56. <script setup>
  57. import { ref, unref, watch } from 'vue'
  58. import { dictObj } from '@/utils/position.js'
  59. import { getEnterprisePubJobTypePermission } from '@/api/new/position'
  60. import portrait from './portrait.vue'
  61. const emit = defineEmits(['requireTypeChange'])
  62. const props = defineProps({
  63. data: {
  64. type: Object,
  65. default: () => {}
  66. }
  67. })
  68. const formData = ref({
  69. type: props.data?.type || '',
  70. eduType: props.data?.eduType ? props.data?.eduType : props.data?.eduType === null ? -1 : '',
  71. expType: props.data?.expType ? props.data?.expType : props.data?.expType === null ? -1 : '',
  72. payFrom: props.data?.payFrom || '',
  73. payTo: props.data?.payTo || '',
  74. payUnit: props.data?.payUnit || '',
  75. areaId: props.data?.areaId ? props.data?.areaId : props.data?.areaId === null ? -1 : '',
  76. address: props.data?.address || '',
  77. })
  78. const tagList = ref(props.data?.tagList?.length ? props.data.tagList : [])
  79. watch(
  80. () => props.data,
  81. (newVal) => {
  82. salary.value = newVal?.payUnit === null ? [1] : []
  83. if (!salary.value?.length) {
  84. formData.value.payFrom = null
  85. formData.value.payTo = null
  86. formData.value.payUnit = null
  87. }
  88. },
  89. { immediate: true },
  90. { deep: true }
  91. )
  92. // const salaryDisabled = computed(() => {
  93. // return Boolean(salary?.value.length)
  94. // })
  95. const salaryCheckboxChange = (e) => {
  96. const bool = e.detail.value.length ? e.detail.value[0] : ''
  97. salary.value = bool ? [1] : []
  98. formData.value.payFrom = null
  99. formData.value.payTo = null
  100. formData.value.payUnit = null
  101. }
  102. const rules = {
  103. type:{
  104. rules: [{required: true, errorMessage: '请选择招聘类型' }]
  105. },
  106. eduType:{
  107. rules: [{required: true, errorMessage: '请选择学历要求' }]
  108. },
  109. expType:{
  110. rules: [{required: true, errorMessage: '请选择工作经验' }]
  111. },
  112. areaId:{
  113. rules: [{required: true, errorMessage: '请选择工作城市' }]
  114. },
  115. address:{
  116. rules: [{required: true, errorMessage: '请填写详细地址' }]
  117. },
  118. // 薪资
  119. payFrom: {
  120. rules: [
  121. {
  122. validateFunction: function (rule, value, data, callback) {
  123. if (!salary?.value.length) {
  124. callback('请填写最低薪资')
  125. }
  126. if (value < 1) {
  127. callback('数额不得小于1')
  128. }
  129. return true
  130. }
  131. },
  132. {
  133. validateFunction: function (rule, value, data, callback) {
  134. if (!formData.value?.payTo || (Number(value) < formData.value.payTo ? Number(formData.value.payTo) : 0)) {
  135. return true
  136. } else {
  137. callback('应低于最高薪资')
  138. }
  139. }
  140. }
  141. ]
  142. },
  143. payTo: {
  144. rules: [
  145. {
  146. validateFunction: function (rule, value, data, callback) {
  147. if (!salary?.value.length) {
  148. callback('请填写最高薪资')
  149. }
  150. if (value < 1) {
  151. callback('数额不得小于1')
  152. }
  153. return true
  154. }
  155. },
  156. {
  157. validateFunction: function (rule, value, data, callback) {
  158. if (!formData.value?.payFrom || (Number(value) > formData.value?.payFrom ? Number(formData.value?.payFrom) : 0)) {
  159. return true
  160. } else {
  161. callback('应高于最低薪资')
  162. }
  163. }
  164. }
  165. ]
  166. },
  167. payUnit: {
  168. // rules: [{required: true, errorMessage: '请选择计薪时段' }]
  169. rules: [
  170. {
  171. validateFunction: function (rule, value, data, callback) {
  172. if (!salary?.value.length) {
  173. callback('请选择计薪时段')
  174. }
  175. return true
  176. }
  177. }
  178. ]
  179. }
  180. }
  181. // const salaryRules = {}
  182. const jobType = ref([])
  183. const getJobTypeList = async () => {
  184. const res = await getEnterprisePubJobTypePermission()
  185. jobType.value = res?.data?.length ? res.data : []
  186. }
  187. getJobTypeList()
  188. // 薪资面议
  189. const salaryStep = 1000
  190. const payToMin = ref(0)
  191. const payChange = (val) => {
  192. payToMin.value = val
  193. if (val > formData.value.payTo) formData.value.payTo = val + salaryStep
  194. }
  195. const portraitRef = ref()
  196. const portraitOpen = () => {
  197. portraitRef.value?.handleOpen()
  198. }
  199. const portraitSubmit = (arr) => {
  200. tagList.value = arr?.length ? arr : []
  201. }
  202. const typeChange = (e) => {
  203. const bool = Boolean(e?.detail?.value?.length ? e.detail.value[0]?.text === '实习' : false)
  204. emit('requireTypeChange', bool)
  205. }
  206. const form = ref()
  207. const salary = ref(props.data?.payUnit === null ? [1] : [])
  208. const getQuery = async () => {
  209. const valid = await unref(form).validate()
  210. if (!valid) return
  211. const obj = {
  212. hirePrice: 0,
  213. hire: false,
  214. salary: Boolean(salary.value?.length),
  215. tagList: tagList.value,
  216. ...formData.value
  217. }
  218. obj && Object.keys(obj).length && Object.keys(obj).forEach(key => {
  219. if (['areaId', 'eduType', 'expType'].includes(key) && obj[key] === -1) obj[key] = null
  220. if (obj.salary && ['payFrom', 'payTo', 'payUnit'].includes(key)) obj[key] = null
  221. })
  222. return obj
  223. }
  224. defineExpose({
  225. getQuery
  226. })
  227. </script>
  228. <style lang="scss" scoped>
  229. $px: 30rpx;
  230. .positionTemplate {
  231. display: flex;
  232. .picker {
  233. flex: 1;
  234. margin-right: 5px;
  235. }
  236. .btn {
  237. width: 90px;
  238. line-height: 34px;
  239. }
  240. }
  241. .tagsBox {
  242. display: flex;
  243. flex-wrap: wrap;
  244. .tags {
  245. padding-top: 10px;
  246. display: flex;
  247. flex-wrap: wrap;
  248. .tag {
  249. margin: 0 10rpx 10rpx 0;
  250. border: 2rpx solid #00B760;
  251. color: #00B760;
  252. white-space: nowrap;
  253. padding: 4rpx 10rpx;
  254. border-radius: 10rpx;
  255. font-size: 24rpx;
  256. }
  257. }
  258. }
  259. </style>