index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 formRules = ref({
  62. name:{
  63. rules: [{required: true, errorMessage: '请输入企业名称' }]
  64. },
  65. anotherName:{
  66. rules: [{required: true, errorMessage: '请输入企业对外展示名称' }]
  67. },
  68. prepare: {
  69. rules: [{required: true, errorMessage: '请选择贵企业是否在筹备中' }]
  70. }
  71. })
  72. // 图片预览
  73. const handlePreviewImage = () => {
  74. uni.previewImage({
  75. current: 0,
  76. urls: [formData.value.businessLicenseUrl]
  77. })
  78. }
  79. // 图片删除
  80. const handleDeleteImg = () => {
  81. formData.value.businessLicenseUrl = ''
  82. business.value = {}
  83. formData.value.ocr = null
  84. formData.value.code = ''
  85. formData.value.name = ''
  86. }
  87. // 识别营业执照图片
  88. const business = ref({})
  89. const getOcr = async () => {
  90. uni.showLoading({ title: '识别中...' })
  91. try {
  92. const { data } = await getBusinessLicenseOCR(formData.value.businessLicenseUrl)
  93. if (data && Object.keys(data).length) {
  94. formData.value.code = data.code
  95. formData.value.name = data.name
  96. business.value = data
  97. } else {
  98. formData.value.businessLicenseUrl = ''
  99. uni.showToast({
  100. title: '识别失败,请重新上传清晰合法图片',
  101. icon: 'none',
  102. duration: 2000
  103. })
  104. }
  105. } catch (error) {
  106. formData.value.businessLicenseUrl = ''
  107. console.error(error, 'error')
  108. uni.hideLoading()
  109. uni.showToast({
  110. title: '识别失败,请重新上传清晰合法图片',
  111. icon: 'none',
  112. duration: 2000
  113. })
  114. } finally {
  115. uni.hideLoading()
  116. }
  117. }
  118. // 选择营业执照
  119. const uploadPhotos = () => {
  120. wx.chooseImage({
  121. count: 1,
  122. sizeType: ['original', 'compressed'],
  123. sourceType: ['album', 'camera'],
  124. success: function(res){
  125. const size = res.tempFiles[0]?.size || 0
  126. if (size >= 31457280) {
  127. uni.showToast({
  128. icon: 'none',
  129. title: '上传图片大小不得超过 20MB !',
  130. duration: 2000
  131. })
  132. return
  133. }
  134. const path = res.tempFilePaths[0]
  135. uploadFile(path, 'img').then(res => {
  136. formData.value.businessLicenseUrl = res.data
  137. getOcr()
  138. }).catch(error => {
  139. uni.showToast({
  140. icon: 'error',
  141. title: '图片上传失败!',
  142. duration: 2000
  143. })
  144. })
  145. }
  146. })
  147. }
  148. // 是否筹备中
  149. const handleChangePrepare = (e, clear = true) => {
  150. const prepare = e.detail.value
  151. for(let i in required.value) {
  152. required.value[i] = !prepare
  153. }
  154. formRules.value.code = { rules: !prepare ? [{required: true, errorMessage: '请填写统一社会信用代码' }] : [] }
  155. formRules.value.businessLicenseUrl = { rules: !prepare ? [{required: true, errorMessage: '请上传营业执照' }] : [] }
  156. if (clear) formRef.value.clearValidate()
  157. }
  158. // 申请拒绝-重新提交数据回显
  159. const applyInfo = ref(uni.getStorageSync('entRegisterData') ? JSON.parse(uni.getStorageSync('entRegisterData')) : {})
  160. console.log(applyInfo.value, '申请拒绝-重新提交数据回显')
  161. if (applyInfo.value && Object.keys(applyInfo.value).length > 0 && applyInfo.value.status === '2') {
  162. for (let i in formData.value) {
  163. formData.value[i] = applyInfo.value[i]
  164. }
  165. business.value = applyInfo.value?.orc || {}
  166. handleChangePrepare({ detail: { value: applyInfo.value.prepare }}, false)
  167. }
  168. // 登录
  169. const handleNext = async () => {
  170. const validate = await unref(formRef).validate()
  171. if (!validate) return
  172. if (business.value && Object.keys(business.value).length) formData.value.ocr = business.value
  173. const isEdit = applyInfo.value && Object.keys(applyInfo.value).length > 0 && applyInfo.value.status === '2'
  174. if (isEdit) formData.value.id = applyInfo.value.id
  175. console.log(formData.value, 'index-next-formData')
  176. uni.setStorageSync('registerInfo', JSON.stringify(formData.value))
  177. uni.navigateTo({
  178. url: isEdit ? '/pages/register/contact?isEdit=true' : '/pages/register/contact'
  179. })
  180. }
  181. </script>
  182. <style scoped lang="scss">
  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>