index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <!-- 校验是否完善人才必填信息 -->
  2. <template>
  3. <scroll-view class="scrollBox" scroll-y="true">
  4. <view class="content">
  5. <view class="text-center ss-m-b-50 font-size-20 color-primary MiSans-Medium">请完善您的基本信息</view>
  6. <uni-forms
  7. ref="baseInfoRef"
  8. v-model="formData"
  9. :rules="formRules"
  10. validateTrigger="bind"
  11. label-width="86px"
  12. labelAlign="center"
  13. >
  14. <uni-forms-item label="头像" name="avatar" class="f-straight" required>
  15. <view style="display: flex;flex-wrap: wrap;">
  16. <view class="upload-img" v-if="formData?.avatar">
  17. <uni-icons size="35" type="clear" color="#fe574a" style="position: absolute;right: -15px; top: -15px; z-index: 9" @click="formData.avatar = ''"></uni-icons>
  18. <image :src="formData?.avatar" mode="contain" style="width: 200rpx;height: 200rpx;" @click="handlePreviewImage"></image>
  19. </view>
  20. <view v-else class="upload-file" @click="uploadPhotos">
  21. <uni-icons type="plusempty" size="50" color="#f1f1f1"></uni-icons>
  22. </view>
  23. </view>
  24. </uni-forms-item>
  25. <uni-forms-item name="name" label="姓名" required>
  26. <uni-easyinput placeholder="请输入姓名" v-model="formData.name" :inputBorder="false" type="text"></uni-easyinput>
  27. </uni-forms-item>
  28. <uni-forms-item name="sex" label="性别" required>
  29. <uni-data-picker v-model="formData.sex" :localdata="dictObj.sex" :clear-icon="false" popup-title="请选择性别" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  30. </uni-forms-item>
  31. <uni-forms-item name="phone" label="联系电话" required>
  32. <uni-easyinput placeholder="请输入联系电话" v-model="formData.phone" :inputBorder="false" type="number"></uni-easyinput>
  33. </uni-forms-item>
  34. <uni-forms-item name="email" label="常用邮箱" required>
  35. <uni-easyinput v-model="formData.email" placeholder="请输入常用邮箱" />
  36. </uni-forms-item>
  37. <uni-forms-item required label="出生日期" name="birthday">
  38. <uni-datetime-picker type="date" return-type="timestamp" v-model="formData.birthday" />
  39. </uni-forms-item>
  40. <uni-forms-item name="enterpriseName" label="任职企业名称" required>
  41. <uni-easyinput placeholder="请填写任职企业名称(可填暂无)" v-model="formData.enterpriseName" :clear-icon="true" type="text"></uni-easyinput>
  42. </uni-forms-item>
  43. <uni-forms-item name="positionName" label="任职职位名称" required>
  44. <uni-easyinput placeholder="请填写任职职位名称(可填暂无)" v-model="formData.positionName" :clear-icon="true" type="text"></uni-easyinput>
  45. </uni-forms-item>
  46. <uni-forms-item name="interestedPositionId" label="意向职位" required>
  47. <uni-data-picker v-model="formData.interestedPositionId" :localdata="dictObj.positionSecondData" :clear-icon="false" popup-title="请选择意向职位" :map="{ text: 'nameCn', value: 'id' }"></uni-data-picker>
  48. </uni-forms-item>
  49. <uni-forms-item name="jobStatus" label="求职状态" required>
  50. <uni-data-picker v-model="formData.jobStatus" :localdata="dictObj.jobStatus" :clear-icon="false" popup-title="请选择求职状态" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  51. </uni-forms-item>
  52. <uni-forms-item name="expType" label="工作经验" required>
  53. <uni-data-picker v-model="formData.expType" :localdata="dictObj.exp" :clear-icon="false" popup-title="请选择工作经验" :clear="false" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  54. </uni-forms-item>
  55. <uni-forms-item name="eduType" label="最高学历" required>
  56. <uni-data-picker v-model="formData.eduType" :localdata="dictObj.edu" :clear-icon="false" popup-title="请选择最高学历" :clear="false" :map="{ text: 'label', value: 'value' }"></uni-data-picker>
  57. </uni-forms-item>
  58. </uni-forms>
  59. <view class="f-horizon-center">
  60. <button type="primary" size="default" class="send-button" @click="submit">提 交</button>
  61. </view>
  62. <view class="f-horizon-center">
  63. <view class="changeRole" @tap="handleLogout">切换账号</view>
  64. </view>
  65. </view>
  66. <uni-popup ref="logoutPopup" type="dialog">
  67. <uni-popup-dialog type="warn" cancelText="取消" confirmText="确定" title="系统提示" content="确认退出账号?" @confirm="handleLogoutConfirm" @close="handleLogoutClose">
  68. </uni-popup-dialog>
  69. </uni-popup>
  70. </scroll-view>
  71. </template>
  72. <script setup>
  73. import { ref, unref, onMounted, nextTick } from 'vue'
  74. import { mobile, emailRequired } from '@/utils/validate'
  75. import { dictObj } from '@/utils/position.js'
  76. import { savePersonSimpleInfo } from '@/api/user'
  77. import { showAuthModal } from '@/hooks/useModal'
  78. import { userStore } from '@/store/user'; const useUserStore = userStore()
  79. import { uploadFile } from '@/api/file'
  80. const baseInfoRef = ref()
  81. const formData = ref({ // 必填项目
  82. name: null,
  83. sex: null,
  84. phone: null,
  85. email: null,
  86. birthday: '1990-01-01',
  87. enterpriseName: null,
  88. positionName: null,
  89. interestedPositionId: null,
  90. jobStatus: null,
  91. expType: null,
  92. eduType: null,
  93. })
  94. onMounted(() => {
  95. nextTick(() => {
  96. const baseInfo = useUserStore?.baseInfo || null
  97. if (baseInfo && Object.keys(baseInfo).length) {
  98. Object.keys(formData.value).forEach(key => {
  99. formData.value[key] = baseInfo[key] || baseInfo[key] === 0 ? baseInfo[key] : formData.value[key] ? formData.value[key] : null
  100. })
  101. }
  102. if (!formData.value.phone && useUserStore?.phone) formData.value.phone = useUserStore.phone
  103. })
  104. })
  105. const formRules = {
  106. avatar:{
  107. rules: [{required: true, errorMessage: '请上传头像' }]
  108. },
  109. name:{
  110. rules: [{required: true, errorMessage: '请输入姓名' }]
  111. },
  112. sex : {
  113. rules: [{required: true, errorMessage: '请选择您的性别' }]
  114. },
  115. phone: mobile,
  116. birthday:{
  117. rules: [{required: true, errorMessage: '请选择您的出生日期' }]
  118. },
  119. enterpriseName:{
  120. rules: [{required: true, errorMessage: '请填写任职企业名称(可填暂无)' }]
  121. },
  122. positionName:{
  123. rules: [{required: true, errorMessage: '请填写任职职位名称(可填暂无)' }]
  124. },
  125. email: emailRequired,
  126. expType: {
  127. rules: [{required: true, errorMessage: '请选择您的工作年限' }]
  128. },
  129. eduType: {
  130. rules: [{required: true, errorMessage: '请选择您的最高学历' }]
  131. },
  132. jobStatus: {
  133. rules: [{required: true, errorMessage: '请选择您的求职状态' }]
  134. }
  135. }
  136. const logoutPopup = ref()
  137. // 退出登录
  138. const handleLogout = () => {
  139. logoutPopup.value.open()
  140. }
  141. const handleLogoutClose = () => {
  142. logoutPopup.value.close()
  143. }
  144. const handleLogoutConfirm = async () => {
  145. await useUserStore.handleLogout()
  146. showAuthModal()
  147. }
  148. // 图片预览
  149. const handlePreviewImage = () => {
  150. uni.previewImage({
  151. current: 0,
  152. urls: [formData.value.avatar]
  153. })
  154. }
  155. // 选择头像
  156. const uploadPhotos = () => {
  157. wx.chooseImage({
  158. count: 1,
  159. sizeType: ['original', 'compressed'],
  160. sourceType: ['album', 'camera'],
  161. success: function(res){
  162. const size = res.tempFiles[0]?.size || 0
  163. if (size >= 31457280) {
  164. uni.showToast({
  165. icon: 'none',
  166. title: '头像上传大小不得超过 20MB !',
  167. duration: 2000
  168. })
  169. return
  170. }
  171. const path = res.tempFilePaths[0]
  172. uploadFile(path, 'img').then(res => {
  173. formData.value.avatar = res.data
  174. }).catch(error => {
  175. uni.showToast({
  176. icon: 'error',
  177. title: '图片上传失败!',
  178. duration: 2000
  179. })
  180. })
  181. }
  182. })
  183. }
  184. const dealQuery = () => {
  185. const interestedList = [{ positionId: formData.value.interestedPositionId || null }]
  186. const workExpList = [{
  187. enterpriseName: formData.value.enterpriseName || null,
  188. positionName: formData.value.positionName || null,
  189. }]
  190. return { ...formData.value, interestedList, workExpList }
  191. }
  192. const submit = async () => {
  193. const validate = await unref(baseInfoRef).validate()
  194. if (!validate) return uni.showToast({ title: '请将信息补充完整', icon: 'none' })
  195. try {
  196. const query = dealQuery()
  197. await savePersonSimpleInfo(query)
  198. uni.showToast({ title: '保存成功', icon: 'none' })
  199. await useUserStore.getInfo()
  200. // await useUserStore.getUserInfo()
  201. } catch (err) {
  202. uni.showToast({ title: err?.msg || '保存失败', icon: 'none' })
  203. }
  204. }
  205. </script>
  206. <style lang="scss" scoped>
  207. .scrollBox {
  208. width: 100vw;
  209. // height: 100vh;
  210. height: calc(100vh - 30rpx);
  211. margin-bottom: 30rpx;
  212. }
  213. .content {
  214. padding: 30rpx;
  215. }
  216. .changeRole {
  217. color: var(--color-666);
  218. font-size: 15px;
  219. line-height: 26px;
  220. margin-bottom: 40rpx;
  221. }
  222. .upload-img{
  223. position: relative;
  224. width: 200rpx;
  225. height: 200rpx;
  226. border: 1px solid #f1f1f1;
  227. margin: 10rpx;
  228. }
  229. .upload-file{
  230. width: 200rpx;
  231. height: 200rpx;
  232. border: 1px solid #f1f1f1;
  233. margin: 10rpx;
  234. display: flex;
  235. justify-content: center;
  236. align-items: center;
  237. border-radius: 10rpx;
  238. }
  239. </style>