index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <view class="f-straight wrapper">
  3. <uni-forms ref="form" :modelValue="formData" :rules="rules" validateTrigger="bind" label-width="90px" label-align="right">
  4. <uni-forms-item label="企业LOGO" name="logoUrl" class="f-straight" required>
  5. <view style="display: flex;flex-wrap: wrap;">
  6. <view class="upload-img" v-if="formData?.logoUrl">
  7. <uni-icons size="35" type="clear" color="#fe574a" style="position: absolute;right: -15px; top: -15px; z-index: 9" @click="formData.logoUrl = ''"></uni-icons>
  8. <image :src="formData?.logoUrl" mode="contain" style="width: 200rpx;height: 200rpx;" @click="handlePreviewImage"></image>
  9. </view>
  10. <view v-else class="upload-file" @click="uploadPhotos">
  11. <uni-icons type="plusempty" size="50" color="#f1f1f1"></uni-icons>
  12. </view>
  13. </view>
  14. </uni-forms-item>
  15. <uni-forms-item label="企业全称" name="name" required>
  16. <uni-easyinput v-model="formData.name" placeholder="请输入企业全称" />
  17. </uni-forms-item>
  18. <uni-forms-item label="展示名称" name="anotherName" required>
  19. <uni-easyinput v-model="formData.anotherName" placeholder="请输入对外展示名称" />
  20. </uni-forms-item>
  21. <uni-forms-item label="企业官网" name="website" clearable>
  22. <uni-easyinput v-model="formData.website" placeholder="请输入企业官网" />
  23. </uni-forms-item>
  24. <uni-forms-item label="联系人" name="contact" clearable>
  25. <uni-easyinput v-model="formData.contact" placeholder="请输入联系人" />
  26. </uni-forms-item>
  27. <uni-forms-item label="联系电话" name="phone" clearable>
  28. <uni-easyinput v-model="formData.phone" placeholder="请输入联系电话" />
  29. </uni-forms-item>
  30. <uni-forms-item label="开业时间" name="openTime">
  31. <picker mode="date" :value="formData.openTime" :disabled="endDisabled" fields="month" :end="endDate" @change="e => formData.openTime = e.detail.value">
  32. <view class="uni-input ss-m-t-20" :style="{'opacity': endDisabled ? '0.5' : '1'}">{{ formData.openTime || '请选择开业时间' }}</view>
  33. </picker>
  34. <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>
  35. </uni-forms-item>
  36. <uni-forms-item label="所在行业" name="industryId" required>
  37. <uni-data-picker
  38. v-model="formData.industryId"
  39. :localdata="dictObj.industryTreeData"
  40. :clear-icon="false"
  41. popup-title="请选择所在行业"
  42. :clear="false"
  43. :map="{ text: 'nameCn', value: 'id' }"
  44. ></uni-data-picker>
  45. </uni-forms-item>
  46. <uni-forms-item label="企业规模" name="scale" required>
  47. <uni-data-picker
  48. v-model="formData.scale"
  49. :localdata="dictObj.scale"
  50. :clear-icon="false"
  51. popup-title="请选择企业规模"
  52. :clear="false"
  53. :map="{ text: 'label', value: 'value' }"
  54. ></uni-data-picker>
  55. </uni-forms-item>
  56. <uni-forms-item label="企业介绍" name="introduce" required>
  57. <uni-easyinput v-model="formData.introduce" type="textarea" placeholder="请输入企业介绍" />
  58. </uni-forms-item>
  59. <view class="f-horizon-center">
  60. <button type="primary" size="default" class="send-button" @click="submit">提 交</button>
  61. </view>
  62. </uni-forms>
  63. </view>
  64. </template>
  65. <script setup>
  66. import { ref, unref } from 'vue'
  67. import { userStore } from '@/store/user'
  68. import { dictObj } from '@/utils/position.js'
  69. import { uploadFile } from '@/api/file'
  70. import { timesTampChange, convertYearMonthToTimestamp } from '@/utils/date'
  71. import { updateEnterpriseInfo, updateEnterpriseLogo, getEnterpriseInfo } from '@/api/enterprise'
  72. const form = ref()
  73. const useUserStore = userStore()
  74. const sofar = ref([])
  75. const date = new Date()
  76. const endDate = date.getFullYear() + '-' + (date.getMonth() + 1) // 不可选时间
  77. const formData = ref({})
  78. // 获取企业信息
  79. const getInfo = async () => {
  80. const { data } = await getEnterpriseInfo()
  81. formData.value = data || {
  82. logoUrl: '',
  83. name: '',
  84. anotherName: '',
  85. website: '',
  86. openTime: '',
  87. contact: '',
  88. phone: '',
  89. industryId: '',
  90. scale: '',
  91. introduce: ''
  92. }
  93. if (!data.openTime) {
  94. endDisabled.value = true
  95. }
  96. if (data.prepare) {
  97. sofar.value = [1]
  98. }
  99. formData.value.openTime = formData.value.openTime ? timesTampChange(data.openTime, 'Y-M') : null
  100. }
  101. getInfo()
  102. // 筹备中
  103. const endDisabled = ref(false)
  104. const handleChangeSofar = (e) => {
  105. const value = e.detail.value.length ? e.detail.value[0] : ''
  106. endDisabled.value = value ? true : false
  107. }
  108. // 图片预览
  109. const handlePreviewImage = () => {
  110. uni.previewImage({
  111. current: 0,
  112. urls: [formData.value.logoUrl]
  113. })
  114. }
  115. // 选择头像
  116. const uploadPhotos = () => {
  117. wx.chooseImage({
  118. count: 1,
  119. sizeType: ['original', 'compressed'],
  120. sourceType: ['album', 'camera'],
  121. success: function(res){
  122. const size = res.tempFiles[0]?.size || 0
  123. if (size >= 31457280) {
  124. uni.showToast({
  125. icon: 'none',
  126. title: '头像上传大小不得超过 20MB !',
  127. duration: 2000
  128. })
  129. return
  130. }
  131. const path = res.tempFilePaths[0]
  132. uploadFile(path, 'img').then(res => {
  133. formData.value.logoUrl = res.data
  134. }).catch(error => {
  135. uni.showToast({
  136. icon: 'error',
  137. title: '图片上传失败!',
  138. duration: 2000
  139. })
  140. })
  141. }
  142. })
  143. }
  144. const rules = {
  145. logoUrl:{
  146. rules: [{required: true, errorMessage: '请上传企业logo' }]
  147. },
  148. name:{
  149. rules: [{required: true, errorMessage: '请输入企业全称' }]
  150. },
  151. introduce:{
  152. rules: [{required: true, errorMessage: '请输入企业介绍' }]
  153. },
  154. anotherName : {
  155. rules: [{required: true, errorMessage: '请选择企业对外展示名称' }]
  156. },
  157. industryId: {
  158. rules: [{required: true, errorMessage: '请选择企业所在行业' }]
  159. },
  160. scale: {
  161. rules: [{required: true, errorMessage: '请选择企业规模' }]
  162. }
  163. }
  164. const submit = async () => {
  165. const valid = await unref(form).validate()
  166. if (!valid) return
  167. formData.value.openTime = sofar.value.length ? null : formData.value.openTime ? convertYearMonthToTimestamp(formData.value.openTime) : null
  168. formData.value.prepare = sofar.value.length ? true : false
  169. const { logoUrl, ...rest } = formData.value
  170. await updateEnterpriseLogo(logoUrl)
  171. await updateEnterpriseInfo(rest)
  172. uni.showToast({ title: '编辑成功', icon: 'success' })
  173. await useUserStore.getUserInfos()
  174. getInfo()
  175. setTimeout(() => {
  176. uni.navigateBack({
  177. delta: 1
  178. })
  179. }, 1000)
  180. }
  181. </script>
  182. <style lang="less" scoped>
  183. .wrapper{
  184. padding: 15px;
  185. padding-top: 30px;
  186. }
  187. .upload-img{
  188. position: relative;
  189. width: 200rpx;
  190. height: 200rpx;
  191. border: 1px solid #f1f1f1;
  192. margin: 10rpx;
  193. }
  194. .upload-file{
  195. width: 200rpx;
  196. height: 200rpx;
  197. border: 1px solid #f1f1f1;
  198. margin: 10rpx;
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. border-radius: 10rpx;
  203. }
  204. </style>