workExperience.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="f-straight wrapper">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px">
  4. <uni-forms-item label="企业名称" name="enterpriseName" required>
  5. <uni-combox :candidates="enterpriseData" placeholder="企业名称" v-model="formData.enterpriseName" @input="handleSearchEnterprise"></uni-combox>
  6. </uni-forms-item>
  7. <uni-forms-item label="职位名称" name="positionName" required>
  8. <uni-combox :candidates="positionData" placeholder="职位名称" v-model="formData.positionName"></uni-combox>
  9. </uni-forms-item>
  10. <uni-forms-item label="开始时间" name="startTime" required>
  11. <picker mode="date" :value="formData.startTime" fields="month" :end="endDate" @change="e => formData.startTime = e.detail.value">
  12. <view class="uni-input ss-m-t-20">{{ formData.startTime }}</view>
  13. </picker>
  14. </uni-forms-item>
  15. <uni-forms-item label="结束时间" name="endTime" required>
  16. <view class="d-flex">
  17. <picker mode="date" :value="formData.endTime" :disabled="endDisabled" fields="month" :end="endDate" @change="e => formData.endTime = e.detail.value">
  18. <view class="uni-input ss-m-t-20" :style="{'opacity': endDisabled ? '0.5' : '1'}">{{ formData.endTime }}</view>
  19. </picker>
  20. <uni-data-checkbox selectedColor="#00B760" class="ss-m-l-50 ss-m-t-14" multiple v-model="sofar" :localdata="[{ text: '至今', value: 1 }]" @change="handleChangeSofar"></uni-data-checkbox>
  21. </view>
  22. </uni-forms-item>
  23. <uni-forms-item label="工作内容" name="content" required>
  24. <uni-easyinput type="textarea" v-model="formData.content" autoHeight placeholder="请输入内容"></uni-easyinput>
  25. </uni-forms-item>
  26. </uni-forms>
  27. </view>
  28. </template>
  29. <script setup>
  30. import { cloneDeep } from 'lodash-es'
  31. import { ref, watch, unref } from 'vue'
  32. import { getDict } from '@/hooks/useDictionaries.js'
  33. import { convertYearMonthToTimestamp, timesTampChange } from '@/utils/date.js'
  34. import { removeEmptyProperties } from "@/utils/index"
  35. const props = defineProps({
  36. id: {
  37. type: String,
  38. default: ''
  39. },
  40. text: {
  41. type: String,
  42. default: ''
  43. },
  44. data: {
  45. type: Object,
  46. default: () => ({})
  47. }
  48. })
  49. let formData = ref({
  50. startTime: '2014-01',
  51. endTime: '2018-01'
  52. })
  53. const sofar = ref([])
  54. const endDisabled = ref(false)
  55. const enterpriseData = ref([])
  56. const positionData = ref([])
  57. const form = ref()
  58. const date = new Date()
  59. const endDate = date.getFullYear() + '-' + (date.getMonth() + 1) // 不可选时间
  60. const searchData = ref({
  61. enterprise: [],
  62. position: []
  63. })
  64. const getInfo = (data) => {
  65. data.startTime = data.startTime ? timesTampChange(data.startTime, 'Y-M') : '2014-01'
  66. data.endTime = data.endTime ? timesTampChange(data.endTime, 'Y-M') : null
  67. if (!data.endTime) {
  68. endDisabled.value = true
  69. data.endTime = '2018-01'
  70. sofar.value = [1]
  71. }
  72. formData.value = cloneDeep(data) || {
  73. startTime: '2014-01',
  74. endTime: '2018-01'
  75. }
  76. }
  77. watch(
  78. () => props.data,
  79. (newVal) => {
  80. if (newVal && Object.keys(newVal)) {
  81. const data = removeEmptyProperties(newVal)
  82. getInfo(data)
  83. }
  84. },
  85. { immediate: true },
  86. )
  87. const rules = {
  88. enterpriseName:{
  89. rules: [{required: true, errorMessage: '请输入企业名称' }]
  90. },
  91. positionName:{
  92. rules: [{required: true, errorMessage: '请输入职位名称' }]
  93. },
  94. startTime:{
  95. rules: [{required: true, errorMessage: '请选择开始时间' }]
  96. },
  97. content:{
  98. rules: [{required: true, errorMessage: '请输入工作内容' }]
  99. }
  100. }
  101. // 企业搜索
  102. const handleSearchEnterprise = (e) => {
  103. if (!e) return enterpriseData.value = []
  104. enterpriseSearchByName({ name: e }).then(res => {
  105. searchData.value.enterprise = res.data
  106. enterpriseData.value = res.data && res.data?.length ? res.data.map(e => e.value) : []
  107. })
  108. }
  109. let positionTreeChildrenData = []
  110. getDict('positionTreeData', null, 'positionTreeData').then(({ data }) => {
  111. data = data.data?.length && data.data || []
  112. data.forEach(e => {
  113. if (e?.children?.length) positionTreeChildrenData = positionTreeChildrenData.concat(e.children)
  114. })
  115. searchData.value.position = positionTreeChildrenData
  116. positionData.value = positionTreeChildrenData.map(e => e.nameCn)
  117. })
  118. // 至今
  119. const handleChangeSofar = (e) => {
  120. const value = e.detail.value.length ? e.detail.value[0] : ''
  121. endDisabled.value = value ? true : false
  122. }
  123. const submit = async () => {
  124. try {
  125. const valid = await unref(form).validate()
  126. // if (!valid) return { id: props.id, data: null}
  127. if (!formData.value.endTime && !sofar.value.length) return uni.showToast({ icon: 'none', title: '请选择工作经历的结束时间' })
  128. //
  129. const startTime = convertYearMonthToTimestamp(formData.value.startTime)
  130. const endTime = sofar.value.length ? null : convertYearMonthToTimestamp(formData.value.endTime)
  131. if (endTime && startTime > endTime) {
  132. uni.showToast({ icon: 'none', title: '开始时间不能大于结束时间' })
  133. return
  134. }
  135. return { id: props.id, data: { ...formData.value, startTime, endTime }}
  136. } catch (error) {
  137. return { text: props.text }
  138. }
  139. }
  140. defineExpose({
  141. id: props.id,
  142. submit
  143. })
  144. </script>
  145. <style lang="less" scoped>
  146. .wrapper{
  147. padding: 15px;
  148. // padding-top: 30px;
  149. }
  150. .upload-img{
  151. position: relative;
  152. width: 200rpx;
  153. height: 200rpx;
  154. border: 1px solid #f1f1f1;
  155. margin: 10rpx;
  156. }
  157. .upload-file{
  158. width: 200rpx;
  159. height: 200rpx;
  160. border: 1px solid #f1f1f1;
  161. margin: 10rpx;
  162. display: flex;
  163. justify-content: center;
  164. align-items: center;
  165. border-radius: 10rpx;
  166. }
  167. </style>