businessInformation.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <!-- 工商信息 -->
  2. <template>
  3. <div style="width: 900px;margin: 0 auto">
  4. <CtForm ref="CtFormRef" class="mt-3" :items="formItems">
  5. <template #businessLicense>
  6. <!-- 上传照片 -->
  7. <div class="d-flex flex-column mb-6">
  8. <div style="color: var(--color-999);">
  9. <!-- <span class="mr-1" style="color: var(--v-error-base);">*</span> -->
  10. <span>上传营业执照</span>
  11. <span>支持jpg、jpeg、png格式,图片大小不得超过10M</span>
  12. </div>
  13. <div class="file-box">
  14. <Img
  15. class="mt-3"
  16. tips="上传图片"
  17. :value="licenseUrl"
  18. :showSnackbar="false"
  19. @imgClick="showPreview = !showPreview"
  20. :showCursor="true"
  21. @success="handleUploadImg"
  22. @delete="handleDeleteImg"
  23. ></Img>
  24. </div>
  25. </div>
  26. </template>
  27. </CtForm>
  28. <Loading :visible="loading"></Loading>
  29. <PreviewImg v-if="showPreview" :current="current" :list="[licenseUrl]" @close="showPreview = !showPreview"></PreviewImg>
  30. <div class="text-center">
  31. <v-btn color="primary" class="buttons mt-3 mb-10" @click="handleSave">{{ $t('common.save') }}</v-btn>
  32. </div>
  33. </div>
  34. </template>
  35. <script setup>
  36. import CtForm from '@/components/CtForm'
  37. import { getEnterpriseBusiness, updateEnterpriseBusiness } from '@/api/enterprise'
  38. import Snackbar from '@/plugins/snackbar'
  39. import { reactive, ref } from 'vue'
  40. import { useI18n } from '@/hooks/web/useI18n'
  41. import { getBusinessLicenseOCR } from '@/api/common'
  42. import Confirm from '@/plugins/confirm'
  43. // import { getDict } from '@/hooks/web/useDictionaries'
  44. const emit = defineEmits(['complete'])
  45. defineOptions({name: 'informationSettingsComponents-businessInformation'})
  46. const { t } = useI18n()
  47. const showPreview = ref(false)
  48. const current = ref(0)
  49. let licenseUrl = ref('')
  50. // 图片预览
  51. const loading = ref(false)
  52. const formItems = ref({
  53. options: [
  54. {
  55. slotName: 'businessLicense',
  56. noParam: true,
  57. },
  58. {
  59. type: 'text',
  60. key: 'name',
  61. value: '',
  62. col: 6,
  63. flexStyle: 'mr-3',
  64. label: '企业名称 *',
  65. rules: [v => !!v || '请输入企业名称']
  66. },
  67. {
  68. type: 'text',
  69. key: 'representative',
  70. value: '',
  71. col: 6,
  72. label: '法定代表人 *',
  73. rules: [v => !!v || '请输入法定代表人']
  74. },
  75. {
  76. type: 'text',
  77. key: 'code',
  78. value: '',
  79. col: 6,
  80. flexStyle: 'mr-3',
  81. label: '统一社会信用代码 *',
  82. rules: [v => !!v || '请输入统一社会信用代码']
  83. },
  84. {
  85. type: 'text',
  86. key: 'type',
  87. value: '',
  88. col: 6,
  89. label: '企业类型 *',
  90. rules: [v => !!v || '请输入企业类型']
  91. },
  92. {
  93. type: 'datePicker',
  94. key: 'establishmentTime',
  95. value: '2010-01-01',
  96. label: '成立时间 *',
  97. format: 'YYYY-MM-DD',
  98. defaultValue: new Date(2010, 1, 1),
  99. labelWidth: 120,
  100. col: 6,
  101. flexStyle: 'mr-3'
  102. },
  103. {
  104. type: 'text',
  105. key: 'registeredCapital',
  106. value: '',
  107. col: 6,
  108. // suffix: '万元',
  109. label: '注册资金 *',
  110. rules: [v => !!v || '请输入注册资金']
  111. },
  112. {
  113. type: 'text',
  114. key: 'approvalTime',
  115. value: '',
  116. col: 6,
  117. flexStyle: 'mr-3',
  118. label: '核准日期 *',
  119. rules: [v => !!v || '请输入核准日期']
  120. },
  121. {
  122. type: 'text',
  123. key: 'registrationAuthority',
  124. value: '',
  125. col: 6,
  126. label: '注册机关 *',
  127. rules: [v => !!v || '请输入注册机关']
  128. },
  129. {
  130. type: 'text',
  131. key: 'businessStatus',
  132. value: '',
  133. col: 6,
  134. flexStyle: 'mr-3',
  135. label: '经营状态 *',
  136. rules: [v => !!v || '请输入经营状态']
  137. },
  138. {
  139. type: 'text',
  140. key: 'businessTerm',
  141. value: null,
  142. col: 6,
  143. class: 'mb-3',
  144. label: '营业期限(示例:2020-03-13 至 2030-03-13) *',
  145. rules: [v => !!v || '请填写营业期限']
  146. },
  147. {
  148. type: 'text',
  149. key: 'area',
  150. value: '',
  151. col: 6,
  152. flexStyle: 'mr-3',
  153. label: '所属地区 *',
  154. rules: [v => !!v || '请输入所属地区']
  155. },
  156. {
  157. type: 'text',
  158. key: 'formerName',
  159. value: '',
  160. col: 6,
  161. label: '曾用名',
  162. },
  163. {
  164. type: 'text',
  165. key: 'address',
  166. value: '',
  167. label: '注册地址 *',
  168. rules: [v => !!v || '请输入注册地址']
  169. },
  170. {
  171. type: 'textarea',
  172. key: 'businessScope',
  173. value: null,
  174. resize: true,
  175. counter: 1600,
  176. rows: 5,
  177. label: '经营范围 *',
  178. outlined: true,
  179. rules: [v => !!v || '请输入经营范围']
  180. },
  181. ]
  182. })
  183. const business = ref({})
  184. const CtFormRef = ref()
  185. const query = reactive({})
  186. // const info = JSON.parse(localStorage.getItem('userApplyInfo'))
  187. // licenseUrl.value = info?.businessLicenseUrl ?? ''
  188. const handleSave = async () => {
  189. const { valid } = await CtFormRef.value.formRef.validate()
  190. if (!valid) return
  191. formItems.value.options.forEach(e => {
  192. if (e.noParam) return
  193. query[e.key] = e.value
  194. })
  195. query.businessUrl = licenseUrl.value
  196. if (!query.establishmentTime) return Snackbar.warning('请选择成立时间')
  197. await updateEnterpriseBusiness(query)
  198. Snackbar.success('编辑成功')
  199. isUpdate = true
  200. getBaseInfo()
  201. }
  202. let isUpdate = false // 是否同时更新基本信息
  203. // 完成度展示
  204. const completeFun = (completeCount = 0) => {
  205. const totalCount = formItems.value.options?.length || 0
  206. emit('complete', { totalCount, completeCount, id: 'businessInformation', isUpdate })
  207. isUpdate = false // 重置
  208. }
  209. // 识别营业执照图片
  210. const getOcr = async () => {
  211. loading.value = true
  212. try {
  213. const data = await getBusinessLicenseOCR(licenseUrl.value)
  214. if (data && Object.keys(data).length) {
  215. Confirm(t('common.confirmTitle'), '是否根据营业执照内容替换以下相关信息').then(() => {
  216. formItems.value.options.forEach(e => {
  217. if (e.noParam) return
  218. // if (e.key in data) {
  219. if (data[e.key]) {
  220. e.value = data[e.key]
  221. }
  222. })
  223. business.value = data
  224. })
  225. } else {
  226. licenseUrl.value = ''
  227. Confirm(t('common.confirmTitle'), '营业执照图片识别失败,请重新上传清晰合法图片', { hideCancelBtn: true })
  228. }
  229. } catch (error) {
  230. licenseUrl.value = ''
  231. Confirm(t('common.confirmTitle'), error, { hideCancelBtn: true })
  232. } finally {
  233. loading.value = false
  234. }
  235. }
  236. // 上传
  237. const handleUploadImg = (url) => {
  238. licenseUrl.value = url
  239. if (licenseUrl.value) {
  240. getOcr()
  241. }
  242. }
  243. const handleDeleteImg = () => {
  244. licenseUrl.value = ''
  245. // business.value = {}
  246. // formItems.value.options.find(e => e.key === 'code').value = ''
  247. // formItems.value.options.find(e => e.key === 'name').value = ''
  248. // saveRegisterInfo()
  249. }
  250. // 获取基本信息
  251. const getBaseInfo = async () => {
  252. let completeCount = 0 // 非必填的需要completeCount++
  253. try {
  254. const data = await getEnterpriseBusiness()
  255. if (!data || !Object.keys(data).length) return completeFun(completeCount)
  256. query.id = JSON.parse(localStorage.getItem('entBaseInfo')).id
  257. formItems.value.options.forEach(item => {
  258. if (item.noParam) return completeCount++
  259. item.value = data[item.key]
  260. // 完成度展示
  261. if (!item.rules?.length || (item.value !== undefined && item.value !== null && item.value !== '')) completeCount++
  262. })
  263. licenseUrl.value = data.businessUrl
  264. // 完成度展示
  265. completeFun(completeCount)
  266. } catch (error) {
  267. completeFun(completeCount)
  268. }
  269. }
  270. getBaseInfo()
  271. </script>
  272. <style lang="scss" scoped>
  273. .file-box {
  274. display: flex;
  275. flex-wrap: wrap; /* 允许换行 */
  276. width: 100%; /* 设置容器宽度 */
  277. .file-item {
  278. height: 80px;
  279. width: 100px;
  280. border-radius: 5px;
  281. margin-right: 8px;
  282. margin-top: 12px;
  283. // border: 1px solid rgb(188, 188, 188);
  284. border: 1px solid rgba(188, 188, 188, 0.5);
  285. }
  286. .file-input-box {
  287. position: relative;
  288. border: 1px solid rgb(188, 188, 188);
  289. cursor: pointer;
  290. .icon {
  291. position: absolute;
  292. top: 45%;
  293. left: 50%;
  294. transform: translate(-50%, -50%);
  295. color: var(--color-999);
  296. }
  297. }
  298. // 验证是否为空
  299. .verifyAct {
  300. color: var(--v-error-base);
  301. border: 1px solid var(--v-error-base);
  302. .icon { color: var(--v-error-base); }
  303. }
  304. }
  305. </style>