index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <view class="f-straight wrapper">
  3. <uni-forms ref="formRef" :modelValue="formData" :rules="formRules" validateTrigger="bind" label-width="105px" label-align="right" label-position="left">
  4. <uni-forms-item name="prepare" label="筹备中" required>
  5. <uni-data-checkbox
  6. v-model="formData.prepare"
  7. selectedColor="#00B760"
  8. selectedTextColor="#00B760"
  9. :localdata="[{ text: '是', value: true }, { text: '否', value: false }]"
  10. @change="handleChangePrepare"
  11. />
  12. </uni-forms-item>
  13. <uni-forms-item name="businessLicenseUrl" label="营业执照" :required="required['businessLicenseUrl']">
  14. <view style="display: flex;flex-wrap: wrap;">
  15. <view class="upload-img" v-if="formData?.businessLicenseUrl">
  16. <uni-icons size="35" type="clear" color="#fe574a" style="position: absolute; right: -15px; top: -15px; z-index: 9" @click="handleDeleteImg"></uni-icons>
  17. <image :src="formData?.businessLicenseUrl" mode="contain" style="width: 200rpx;height: 200rpx;" @click="handlePreviewImage"></image>
  18. </view>
  19. <view v-else class="upload-file" @click="uploadPhotos">
  20. <uni-icons type="plusempty" size="50" color="#f1f1f1"></uni-icons>
  21. </view>
  22. <view class="ss-m-t-10 color-999">上传营业执照支持jpg、jpeg、png格式,图片大小不得超过20M</view>
  23. </view>
  24. </uni-forms-item>
  25. <uni-forms-item name="name" label="企业名称" required>
  26. <uni-easyinput v-model="formData.name" placeholder="请输入"></uni-easyinput>
  27. <view class="ss-m-t-10 color-999">注:需与营业执照一致,上传营业执照可自动识别</view>
  28. </uni-forms-item>
  29. <uni-forms-item name="anotherName" label="对外展示名称" required>
  30. <uni-easyinput v-model="formData.anotherName" placeholder="请输入"></uni-easyinput>
  31. </uni-forms-item>
  32. <uni-forms-item name="code" label="社会信用代码" :required="required['code']">
  33. <uni-easyinput v-model="formData.code" placeholder="请输入"></uni-easyinput>
  34. <view class="ss-m-t-10 color-999">注:需与营业执照一致,上传营业执照可自动识别</view>
  35. </uni-forms-item>
  36. <uni-forms-item name="description" label="备注/说明">
  37. <uni-easyinput v-model="formData.description" placeholder="请输入" type="textarea"></uni-easyinput>
  38. </uni-forms-item>
  39. </uni-forms>
  40. <button class="send-button" @tap="handleNext">下一步</button>
  41. </view>
  42. </template>
  43. <script setup>
  44. // 扫码登录注册
  45. import { ref, unref } from 'vue'
  46. import { uploadFile } from '@/api/file'
  47. import { getBusinessLicenseOCR } from '@/api/common'
  48. const formRef = ref()
  49. const formData = ref({
  50. prepare: true,
  51. businessLicenseUrl: '',
  52. name: '',
  53. anotherName: '',
  54. code: '',
  55. description: ''
  56. })
  57. const required = ref({
  58. code: false,
  59. businessLicenseUrl: false
  60. })
  61. const otherRules = ref({
  62. businessLicenseUrl: {
  63. rules: [{required: true, errorMessage: '请上传营业执照' }]
  64. },
  65. code: {
  66. rules: [{required: true, errorMessage: '请填写统一社会信用代码' }]
  67. }
  68. })
  69. const formRules = ref({
  70. name:{
  71. rules: [{required: true, errorMessage: '请输入企业名称' }]
  72. },
  73. anotherName:{
  74. rules: [{required: true, errorMessage: '请输入企业对外展示名称' }]
  75. },
  76. prepare: {
  77. rules: [{required: true, errorMessage: '请选择贵企业是否在筹备中' }]
  78. }
  79. })
  80. // 图片预览
  81. const handlePreviewImage = () => {
  82. uni.previewImage({
  83. current: 0,
  84. urls: [formData.value.businessLicenseUrl]
  85. })
  86. }
  87. // 图片删除
  88. const handleDeleteImg = () => {
  89. formData.value.businessLicenseUrl = ''
  90. business.value = {}
  91. formData.value.ocr = null
  92. formData.value.code = ''
  93. formData.value.name = ''
  94. }
  95. // 识别营业执照图片
  96. const business = ref({})
  97. const getOcr = async () => {
  98. uni.showLoading({ title: '识别中...' })
  99. try {
  100. const { data } = await getBusinessLicenseOCR(formData.value.businessLicenseUrl)
  101. if (data && Object.keys(data).length) {
  102. formData.value.code = data.code
  103. formData.value.name = data.name
  104. business.value = data
  105. } else {
  106. formData.value.businessLicenseUrl = ''
  107. uni.showToast({
  108. title: '识别失败,请重新上传清晰合法图片',
  109. icon: 'none',
  110. duration: 2000
  111. })
  112. }
  113. } catch (error) {
  114. formData.value.businessLicenseUrl = ''
  115. console.error(error, 'error')
  116. uni.hideLoading()
  117. uni.showToast({
  118. title: '识别失败,请重新上传清晰合法图片',
  119. icon: 'none',
  120. duration: 2000
  121. })
  122. } finally {
  123. uni.hideLoading()
  124. }
  125. }
  126. // 选择营业执照
  127. const uploadPhotos = () => {
  128. wx.chooseImage({
  129. count: 1,
  130. sizeType: ['original', 'compressed'],
  131. sourceType: ['album', 'camera'],
  132. success: function(res){
  133. const size = res.tempFiles[0]?.size || 0
  134. if (size >= 31457280) {
  135. uni.showToast({
  136. icon: 'none',
  137. title: '上传图片大小不得超过 20MB !',
  138. duration: 2000
  139. })
  140. return
  141. }
  142. const path = res.tempFilePaths[0]
  143. uploadFile(path, 'img').then(res => {
  144. formData.value.businessLicenseUrl = res.data
  145. getOcr()
  146. }).catch(error => {
  147. uni.showToast({
  148. icon: 'error',
  149. title: '图片上传失败!',
  150. duration: 2000
  151. })
  152. })
  153. }
  154. })
  155. }
  156. // 是否筹备中
  157. const handleChangePrepare = (e, clear = true) => {
  158. const prepare = e.detail.value
  159. for(let i in required.value) {
  160. required.value[i] = !prepare
  161. }
  162. if (!prepare) {
  163. formRules.value = Object.assign(formRules.value, otherRules.value)
  164. } else {
  165. delete formRules.value.code
  166. delete formRules.value.businessLicenseUrl
  167. }
  168. if (clear) formRef.value.clearValidate()
  169. }
  170. // 申请拒绝-重新提交数据回显
  171. const applyInfo = ref(uni.getStorageSync('entRegisterData') ? JSON.parse(uni.getStorageSync('entRegisterData')) : {})
  172. console.log(applyInfo.value, '申请拒绝-重新提交数据回显')
  173. if (applyInfo.value && Object.keys(applyInfo.value).length > 0 && applyInfo.value.status === '2') {
  174. for (let i in formData.value) {
  175. formData.value[i] = applyInfo.value[i]
  176. }
  177. business.value = applyInfo.value?.orc || {}
  178. handleChangePrepare({ detail: { value: applyInfo.value.prepare }}, false)
  179. }
  180. // 登录
  181. const handleNext = async () => {
  182. const validate = await unref(formRef).validate()
  183. if (!validate) return
  184. if (business.value && Object.keys(business.value).length) formData.value.ocr = business.value
  185. const isEdit = applyInfo.value && Object.keys(applyInfo.value).length > 0 && applyInfo.value.status === '2'
  186. if (isEdit) formData.value.id = applyInfo.value.id
  187. console.log(formData.value, 'index-next-formData')
  188. uni.setStorageSync('registerInfo', JSON.stringify(formData.value))
  189. uni.navigateTo({
  190. url: isEdit ? '/pages/register/contact?isEdit=true' : '/pages/register/contact'
  191. })
  192. }
  193. </script>
  194. <style scoped lang="scss">
  195. .wrapper{
  196. padding: 15px;
  197. padding-top: 30px;
  198. }
  199. .upload-img{
  200. position: relative;
  201. width: 200rpx;
  202. height: 200rpx;
  203. border: 1px solid #f1f1f1;
  204. margin: 10rpx;
  205. }
  206. .upload-file{
  207. width: 200rpx;
  208. height: 200rpx;
  209. border: 1px solid #f1f1f1;
  210. margin: 10rpx;
  211. display: flex;
  212. justify-content: center;
  213. align-items: center;
  214. border-radius: 10rpx;
  215. }
  216. </style>