index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. <view v-if="!isEdit">
  41. <view class="color-primary font-size-15 ss-m-b-20 font-weight-bold">手机号码验证</view>
  42. <uni-forms
  43. ref="validFormRef"
  44. v-model="validData"
  45. :rules="validRules"
  46. validateTrigger="bind"
  47. labelWidth="140"
  48. labelAlign="center"
  49. >
  50. <uni-forms-item name="phone" label="手机号" required>
  51. <uni-easyinput placeholder="请输入手机号" v-model="validData.phone" :inputBorder="false" type="number" />
  52. </uni-forms-item>
  53. <uni-forms-item name="code" label="验证码" required>
  54. <uni-easyinput
  55. placeholder="请输入六位数验证码"
  56. v-model="validData.code"
  57. :inputBorder="false"
  58. type="number"
  59. maxlength="6"
  60. >
  61. <template v-slot:right>
  62. <button
  63. class="login-code"
  64. :disabled="isMobileEnd"
  65. :class="{ 'code-btn-end': isMobileEnd }"
  66. @tap="handleRegisterCode"
  67. >
  68. {{ getSmsTimer('smsRegister') }}
  69. </button>
  70. </template>
  71. </uni-easyinput>
  72. </uni-forms-item>
  73. </uni-forms>
  74. </view>
  75. <button class="send-button ss-m-t-50" @tap="handleNext">下一步</button>
  76. </view>
  77. </template>
  78. <script setup>
  79. // 扫码登录注册
  80. import { ref, unref } from 'vue'
  81. import { uploadFile } from '@/api/file'
  82. import { getBusinessLicenseOCR } from '@/api/common'
  83. import { mobile, code } from '@/utils/validate'
  84. import { getSmsCode, getSmsTimer } from '@/utils/code'
  85. import { userStore } from '@/store/user'
  86. const useUserStore = userStore()
  87. const validFormRef = ref(null)
  88. const formRef = ref()
  89. const formData = ref({
  90. prepare: true,
  91. businessLicenseUrl: '',
  92. name: '',
  93. anotherName: '',
  94. code: '',
  95. description: ''
  96. })
  97. const isMobileEnd = ref(false)
  98. const validData = ref({
  99. phone: '',
  100. code: ''
  101. })
  102. const validRules = ref({
  103. code,
  104. phone: mobile
  105. })
  106. const required = ref({
  107. code: false,
  108. businessLicenseUrl: false
  109. })
  110. // 获取验证码
  111. const handleRegisterCode = () => {
  112. if (!validData.value.phone) {
  113. uni.showToast({
  114. title: '请输入手机号',
  115. icon: 'none',
  116. duration: 2000
  117. })
  118. return
  119. }
  120. getSmsCode('smsRegister', validData.value.phone)
  121. }
  122. const formRules = ref({
  123. name:{
  124. rules: [{required: true, errorMessage: '请输入企业名称' }]
  125. },
  126. anotherName:{
  127. rules: [{required: true, errorMessage: '请输入企业对外展示名称' }]
  128. },
  129. prepare: {
  130. rules: [{required: true, errorMessage: '请选择贵企业是否在筹备中' }]
  131. }
  132. })
  133. // 图片预览
  134. const handlePreviewImage = () => {
  135. uni.previewImage({
  136. current: 0,
  137. urls: [formData.value.businessLicenseUrl]
  138. })
  139. }
  140. // 图片删除
  141. const handleDeleteImg = () => {
  142. formData.value.businessLicenseUrl = ''
  143. business.value = {}
  144. formData.value.ocr = null
  145. formData.value.code = ''
  146. formData.value.name = ''
  147. }
  148. // 识别营业执照图片
  149. const business = ref({})
  150. const getOcr = async () => {
  151. uni.showLoading({ title: '识别中...' })
  152. try {
  153. const { data } = await getBusinessLicenseOCR(formData.value.businessLicenseUrl)
  154. if (data && Object.keys(data).length) {
  155. formData.value.code = data.code
  156. formData.value.name = data.name
  157. business.value = data
  158. } else {
  159. formData.value.businessLicenseUrl = ''
  160. uni.showToast({
  161. title: '识别失败,请重新上传清晰合法图片',
  162. icon: 'none',
  163. duration: 2000
  164. })
  165. }
  166. } catch (error) {
  167. formData.value.businessLicenseUrl = ''
  168. console.error(error, 'error')
  169. uni.hideLoading()
  170. uni.showToast({
  171. title: '识别失败,请重新上传清晰合法图片',
  172. icon: 'none',
  173. duration: 2000
  174. })
  175. } finally {
  176. uni.hideLoading()
  177. }
  178. }
  179. // 选择营业执照
  180. const uploadPhotos = () => {
  181. wx.chooseImage({
  182. count: 1,
  183. sizeType: ['original', 'compressed'],
  184. sourceType: ['album', 'camera'],
  185. success: function(res){
  186. const size = res.tempFiles[0]?.size || 0
  187. if (size >= 31457280) {
  188. uni.showToast({
  189. icon: 'none',
  190. title: '上传图片大小不得超过 20MB !',
  191. duration: 2000
  192. })
  193. return
  194. }
  195. const path = res.tempFilePaths[0]
  196. uploadFile(path, 'img').then(res => {
  197. formData.value.businessLicenseUrl = res.data
  198. getOcr()
  199. }).catch(error => {
  200. uni.showToast({
  201. icon: 'error',
  202. title: '图片上传失败!',
  203. duration: 2000
  204. })
  205. })
  206. }
  207. })
  208. }
  209. // 是否筹备中
  210. const handleChangePrepare = (e, clear = true) => {
  211. const prepare = e.detail.value
  212. for(let i in required.value) {
  213. required.value[i] = !prepare
  214. }
  215. formRules.value.code = { rules: !prepare ? [{required: true, errorMessage: '请填写统一社会信用代码' }] : [] }
  216. formRules.value.businessLicenseUrl = { rules: !prepare ? [{required: true, errorMessage: '请上传营业执照' }] : [] }
  217. if (clear) formRef.value.clearValidate()
  218. }
  219. // 申请拒绝-重新提交数据回显
  220. const applyInfo = ref(uni.getStorageSync('entRegisterData') ? JSON.parse(uni.getStorageSync('entRegisterData')) : {})
  221. const isEdit = ref(false)
  222. console.log(applyInfo.value, '申请拒绝-重新提交数据回显', uni.getStorageSync('entRegisterData'))
  223. if (applyInfo.value && Object.keys(applyInfo.value).length > 0 && applyInfo.value.status === '2') {
  224. isEdit.value = true
  225. for (let i in formData.value) {
  226. formData.value[i] = applyInfo.value[i]
  227. }
  228. business.value = applyInfo.value?.orc || {}
  229. handleChangePrepare({ detail: { value: applyInfo.value.prepare }}, false)
  230. }
  231. // 登录
  232. const handleNext = async () => {
  233. // 基本信息效验
  234. const validate = await unref(formRef).validate()
  235. if (!validate) return
  236. // 营业执照
  237. if (business.value && Object.keys(business.value).length) formData.value.ocr = business.value
  238. if (isEdit.value) formData.value.id = applyInfo.value.id
  239. uni.setStorageSync('registerInfo', JSON.stringify(formData.value))
  240. // 手机号及验证码效验
  241. if (!isEdit.value) {
  242. const phoneValid = await unref(validFormRef).validate()
  243. if (!phoneValid) return
  244. try {
  245. await useUserStore.handleRegister({ ...validData.value, autoRegister: true, account: validData.value.phone })
  246. // 查看用户是否有在申请中的数据,有申请中的数据则跳转等待审核页面
  247. const { code } = await useUserStore.getPersonalApplyingData()
  248. if (code) return uni.navigateTo({ url: '/pages/register/review?hasData=true' })
  249. // 没有注册中企业跳转下一步填写联系人信息
  250. uni.navigateTo({ url: '/pages/register/contact' })
  251. } finally {}
  252. } else {
  253. uni.navigateTo({ url: '/pages/register/contact?isEdit=true' })
  254. }
  255. }
  256. </script>
  257. <style scoped lang="scss">
  258. .wrapper{
  259. padding: 15px;
  260. padding-top: 30px;
  261. }
  262. .upload-img{
  263. position: relative;
  264. width: 200rpx;
  265. height: 200rpx;
  266. border: 1px solid #f1f1f1;
  267. margin: 10rpx;
  268. }
  269. .upload-file{
  270. width: 200rpx;
  271. height: 200rpx;
  272. border: 1px solid #f1f1f1;
  273. margin: 10rpx;
  274. display: flex;
  275. justify-content: center;
  276. align-items: center;
  277. border-radius: 10rpx;
  278. }
  279. .login-code {
  280. width: 73px;
  281. min-width: 73px;
  282. color: #00B760;
  283. text-align: center;
  284. font-size: 12px;
  285. cursor: pointer;
  286. padding: 0;
  287. }
  288. </style>