workExperience.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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="#00897B" 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. const props = defineProps({
  35. id: {
  36. type: String,
  37. default: ''
  38. },
  39. data: {
  40. type: Object,
  41. default: () => ({})
  42. }
  43. })
  44. let formData = ref({
  45. startTime: '2014-01',
  46. endTime: '2018-01'
  47. })
  48. const sofar = ref([])
  49. const endDisabled = ref(false)
  50. const enterpriseData = ref([])
  51. const positionData = ref([])
  52. const form = ref()
  53. const date = new Date()
  54. const endDate = date.getFullYear() + '-' + (date.getMonth() + 1) // 不可选时间
  55. const searchData = ref({
  56. enterprise: [],
  57. position: []
  58. })
  59. const getInfo = (data) => {
  60. data.startTime = data.startTime ? timesTampChange(data.startTime, 'Y-M') : '2014-01'
  61. data.endTime = data.endTime ? timesTampChange(data.endTime, 'Y-M') : null
  62. if (!data.endTime) {
  63. endDisabled.value = true
  64. data.endTime = '2018-01'
  65. sofar.value = [1]
  66. }
  67. formData.value = cloneDeep(data) || {
  68. startTime: '2014-01',
  69. endTime: '2018-01'
  70. }
  71. }
  72. watch(
  73. () => props.data,
  74. (newVal) => {
  75. if (newVal && Object.keys(newVal)) {
  76. getInfo(newVal)
  77. }
  78. },
  79. { immediate: true },
  80. )
  81. const rules = {
  82. enterpriseName:{
  83. rules: [{required: true, errorMessage: '请输入企业名称' }]
  84. },
  85. positionName:{
  86. rules: [{required: true, errorMessage: '请输入职位名称' }]
  87. },
  88. startTime:{
  89. rules: [{required: true, errorMessage: '请选择开始时间' }]
  90. },
  91. content:{
  92. rules: [{required: true, errorMessage: '请输入工作内容' }]
  93. }
  94. }
  95. // 企业搜索
  96. const handleSearchEnterprise = (e) => {
  97. if (!e) return enterpriseData.value = []
  98. enterpriseSearchByName({ name: e }).then(res => {
  99. searchData.value.enterprise = res.data
  100. enterpriseData.value = res.data && res.data?.length ? res.data.map(e => e.value) : []
  101. })
  102. }
  103. let positionTreeChildrenData = []
  104. getDict('positionTreeData', null, 'positionTreeData').then(({ data }) => {
  105. data = data.data?.length && data.data || []
  106. data.forEach(e => {
  107. if (e?.children?.length) positionTreeChildrenData = positionTreeChildrenData.concat(e.children)
  108. })
  109. searchData.value.position = positionTreeChildrenData
  110. positionData.value = positionTreeChildrenData.map(e => e.nameCn)
  111. })
  112. // 至今
  113. const handleChangeSofar = (e) => {
  114. const value = e.detail.value.length ? e.detail.value[0] : ''
  115. endDisabled.value = value ? true : false
  116. }
  117. const submit = async () => {
  118. const valid = await unref(form).validate()
  119. if (!valid) return { id: props.id, data: null}
  120. if (!formData.value.endTime && !sofar.value.length) return uni.showToast({ icon: 'none', title: '请选择工作经历的结束时间' })
  121. //
  122. const startTime = convertYearMonthToTimestamp(formData.value.startTime)
  123. const endTime = sofar.value.length ? null : convertYearMonthToTimestamp(formData.value.endTime)
  124. return { id: props.id, data: { ...formData.value, startTime, endTime }}
  125. }
  126. defineExpose({
  127. id: props.id,
  128. submit
  129. })
  130. </script>
  131. <style lang="less" scoped>
  132. .wrapper{
  133. padding: 15px;
  134. // padding-top: 30px;
  135. }
  136. .upload-img{
  137. position: relative;
  138. width: 200rpx;
  139. height: 200rpx;
  140. border: 1px solid #f1f1f1;
  141. margin: 10rpx;
  142. }
  143. .upload-file{
  144. width: 200rpx;
  145. height: 200rpx;
  146. border: 1px solid #f1f1f1;
  147. margin: 10rpx;
  148. display: flex;
  149. justify-content: center;
  150. align-items: center;
  151. border-radius: 10rpx;
  152. }
  153. </style>