businessInformation.vue 8.2 KB

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