EnterpriseAuthentication.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <template>
  2. <div class="create-container">
  3. <div class="create-body" v-loading="loading">
  4. <div class="title">企业信息认证</div>
  5. <el-form :model="authentication" :rules="rules" ref="authentication" label-width="15%" class="demo-report">
  6. <el-form-item label="公司名" prop="enterpriseName">
  7. <el-input v-if="isModifyMode" v-model="authentication.enterpriseName"></el-input>
  8. <span v-if="!isModifyMode">{{authentication.enterpriseName}}</span>
  9. </el-form-item>
  10. <el-form-item label="公司营业执照" prop="businessLicensePhoto">
  11. <el-upload
  12. v-if="isModifyMode"
  13. class="avatar-uploader"
  14. action="https://jsonplaceholder.typicode.com/posts/"
  15. :show-file-list="false"
  16. :http-request="uploadFile"
  17. :before-upload="beforeFileUpload">
  18. <img v-if="authentication.businessLicensePhoto" :src="authentication.businessLicensePhoto" class="avatar">
  19. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  20. </el-upload>
  21. <span v-if="!isModifyMode">
  22. <el-image
  23. style="width: 100px;"
  24. :src="authentication.businessLicensePhoto"
  25. fit="scale-down"></el-image>
  26. </span>
  27. <!--<div v-if="!isModifyMode">-->
  28. <!--<span v-if="authentication.photo==null">暂无文件</span>-->
  29. <!--<a :href="authentication.photo" v-if="authentication.photo!=null"><i class="fa fa-file-text-o"></i>-->
  30. <!--{{authentication.photo}}</a>-->
  31. <!--</div>-->
  32. </el-form-item>
  33. <el-form-item v-if="!isModifyMode" label="认证状态" prop="name">
  34. <el-tag :type="authentication.authStatus.style">{{authentication.authStatus.text}}</el-tag>
  35. </el-form-item>
  36. <el-form-item v-if="!isModifyMode && authentication.authStatus.text == '认证失败'" label="失败原因" prop="name">
  37. <el-link v-if="authentication.explain!=null&&authentication.explain!=''" type="danger" disabled>
  38. {{authentication.explain}}
  39. </el-link>
  40. <el-link v-if="authentication.explain==null || authentication.explain==''" type="danger" disabled>管理员未填写
  41. </el-link>
  42. </el-form-item>
  43. <el-form-item label="公司法人姓名" prop="legalPersonName">
  44. <el-input v-if="isModifyMode" v-model="authentication.legalPersonName"></el-input>
  45. <span v-if="!isModifyMode">{{authentication.legalPersonName}}</span>
  46. </el-form-item>
  47. <!-- <el-form-item label="对公账户" prop="bankAccount">-->
  48. <!-- <el-input v-if="isModifyMode" v-model="authentication.bankAccount"></el-input>-->
  49. <!-- <span v-if="!isModifyMode">{{authentication.bankAccount}}</span>-->
  50. <!-- </el-form-item>-->
  51. <el-form-item label="统一社会信用代码" prop="unifiedSocialCreditCode">
  52. <el-input v-if="isModifyMode" v-model="authentication.unifiedSocialCreditCode"></el-input>
  53. <span v-if="!isModifyMode">{{authentication.unifiedSocialCreditCode}}</span>
  54. </el-form-item>
  55. <el-form-item label="公司地址" prop="address">
  56. <el-input v-if="isModifyMode" v-model="authentication.address"></el-input>
  57. <span v-if="!isModifyMode">{{authentication.address}}</span>
  58. </el-form-item>
  59. <el-form-item v-if="!isModifyMode">
  60. <div class="btn btn-medium btn-info" @click="modifyInfo()">修改</div>
  61. </el-form-item>
  62. <el-form-item v-if="isModifyMode">
  63. <div class="btn btn-primary btn-info" @click="updateAuthInfo()">提交</div>
  64. <div class="btn btn-primary" @click="cancelModify()">取消</div>
  65. </el-form-item>
  66. </el-form>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import Http from '@/js/http'
  72. import Apis from '@/js/api'
  73. import {notify} from '@/constants/index'
  74. import {
  75. defaultValue,
  76. getCurrentEnterpriseAuthInfo,
  77. getCurrentUser,
  78. getRolesPermissions,
  79. storageGet,
  80. storageSave,
  81. updateEnterpriseAuthInfo
  82. } from '@/js/index'
  83. export default {
  84. name: 'EnterpriseAuthentication',
  85. data () {
  86. return {
  87. userId: 0,
  88. user: {},
  89. isModifyMode: false,
  90. loading: false,
  91. authentication: {
  92. enterpriseName: '',
  93. legalPersonName: '',
  94. bankAccount: '',
  95. businessLicensePhoto: defaultValue.image,
  96. unifiedSocialCreditCode: '',
  97. address: '',
  98. authStatus: {text:"审核中", style:"warning"},
  99. explain: ''
  100. },
  101. rules: {
  102. enterpriseName: [
  103. {required: true, message: '请输入公司名称', trigger: 'blur'},
  104. {min: 3, max: 50, message: '机构名称长度在 3 到 50 个字符', trigger: 'blur'}
  105. ],
  106. businessLicensePhoto: [
  107. {
  108. validator: (rule, value, callback) => {
  109. if (value == null || value == '') {
  110. callback(new Error('公司营业执照不能为空'))
  111. } else {
  112. callback()
  113. }
  114. },
  115. trigger: 'blur'
  116. },
  117. ],
  118. legalPersonName: [
  119. {required: true, message: '请输入公司法人姓名', trigger: 'blur'}
  120. ],
  121. bankAccount: [
  122. {required: true, message: '请输入对公账户', trigger: 'blur'},
  123. {min: 16, max: 19, message: '对公账户输入有误', trigger: 'blur'},
  124. {
  125. validator: (rule, value, callback) => {
  126. if (!this.checkNumber(value)) {
  127. callback(new Error('对公账户输入有误'))
  128. } else {
  129. callback()
  130. }
  131. }, trigger: 'blur'
  132. },
  133. ],
  134. unifiedSocialCreditCode: [
  135. {required: true, message: '请输入统一社会信用代码', trigger: 'blur'},
  136. {
  137. validator: (rule, value, callback) => {
  138. if (!this.checkNumberAndWord(value)) {
  139. callback(new Error('统一社会信用代码输入有误'))
  140. } else {
  141. callback()
  142. }
  143. }, trigger: 'blur'
  144. },
  145. ],
  146. address: [
  147. {required: true, message: '请输入公司地址', trigger: 'blur'}
  148. ]
  149. }
  150. }
  151. },
  152. mounted () {
  153. this.$nextTick(() => {
  154. this.init()
  155. })
  156. },
  157. methods: {
  158. //初始化数据
  159. init () {
  160. this.setUserInfo()
  161. this.getAuthInfo()
  162. },
  163. //加载数据
  164. getAuthInfo () {
  165. this.showLoading()
  166. getCurrentEnterpriseAuthInfo(this.user.userVO.id, this.getAuthInfoSuccess, this.getAuthInfoFail)
  167. },
  168. getAuthInfoSuccess (res) {
  169. this.hideLoading()
  170. this.authentication.enterpriseName = res.enterpriseName == null ? '暂未填写' : res.enterpriseName
  171. this.authentication.legalPersonName = res.legalPersonName == null ? '暂未填写' : res.legalPersonName
  172. this.authentication.businessLicensePhoto = res.businessLicensePhoto == null ? defaultValue.image : res.businessLicensePhoto
  173. this.authentication.unifiedSocialCreditCode = res.unifiedSocialCreditCode == null ? '暂未填写' : res.unifiedSocialCreditCode
  174. this.authentication.bankAccount = res.bankAccount == null ? '暂未填写' : res.bankAccount
  175. this.authentication.address = res.address == null ? '暂未填写' : res.address
  176. this.authentication.authStatus = res.authStatus
  177. this.authentication.explain = res.explain
  178. console.log(this.authentication)
  179. },
  180. getAuthInfoFail (error) {
  181. this.hideLoading()
  182. notify('error', '加载认证信息失败:' + error.data)
  183. },
  184. //表单进入可编辑状态,可修改表单,不再使用
  185. modifyInfo () {
  186. this.isModifyMode = true
  187. },
  188. //提交认证信息
  189. updateAuthInfo () {
  190. //this.isModifyMode = false
  191. this.$refs['authentication'].validate(valid => {
  192. if (valid) {
  193. this.showLoading()
  194. const newAuthentication = {
  195. userId: this.user.userVO.id,
  196. enterpriseName: this.authentication.enterpriseName,
  197. legalPersonName: this.authentication.legalPersonName,
  198. businessLicensePhoto: this.authentication.businessLicensePhoto,
  199. unifiedSocialCreditCode: this.authentication.unifiedSocialCreditCode,
  200. bankAccount: this.authentication.bankAccount,
  201. address: this.authentication.address,
  202. }
  203. updateEnterpriseAuthInfo(this.user.userVO.id, newAuthentication, this.updateAuthInfoSuccess, this.updateAuthInfoFail)
  204. } else {
  205. notify('error', '表单填写错误!')
  206. return false
  207. }
  208. })
  209. },
  210. updateAuthInfoSuccess (res) {
  211. this.hideLoading()
  212. this.cancelModify()
  213. console.log(res)
  214. this.authentication.enterpriseName = res.enterpriseName == null ? '暂未填写' : res.enterpriseName
  215. this.authentication.legalPersonName = res.legalPersonName == null ? '暂未填写' : res.legalPersonName
  216. this.authentication.businessLicensePhoto = res.businessLicensePhoto == null ? defaultValue.image : res.businessLicensePhoto
  217. this.authentication.unifiedSocialCreditCode = res.unifiedSocialCreditCode == null ? '暂未填写' : res.unifiedSocialCreditCode
  218. this.authentication.bankAccount = res.bankAccount == null ? '暂未填写' : res.bankAccount
  219. this.authentication.address = res.address == null ? '暂未填写' : res.address
  220. notify('success', '认证信息修改成功,正在为您刷新用户信息')
  221. getCurrentUser().then(res => {
  222. storageSave('user', res)
  223. this.user = res
  224. this.sendBusMessage()
  225. //this.rolesPermissions = getRolesPermissions(res.roleList)
  226. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  227. this.hideLoading()
  228. notify('success', '用户信息刷新成功')
  229. }).catch((error) => {
  230. this.hideLoading()
  231. notify('error', '重新获取用户信息失败:' + error.data)
  232. })
  233. },
  234. updateAuthInfoFail (error) {
  235. this.hideLoading()
  236. notify('error', error.data)
  237. },
  238. //取消修改表单,表单进入不可编辑状态,不再使用
  239. cancelModify () {
  240. this.isModifyMode = false
  241. },
  242. //上传文件时移除文件的响应函数
  243. handleRemove (file, fileList) {
  244. console.log(file, fileList)
  245. },
  246. //添加文件时的响应函数
  247. handleExceed (files, fileList) {
  248. this.$message.warning(
  249. `当前限制选择 1 个文件,本次选择了 ${
  250. files.length
  251. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  252. )
  253. },
  254. //移除文件前的响应函数
  255. beforeRemove (file, fileList) {
  256. //return this.$confirm(`确定移除 ${file.name}?`)
  257. },
  258. //文件上传前的响应函数
  259. beforeFileUpload (file) {
  260. // 文件大小不能超过10M
  261. if (file.size > 10 * 1000 * 1000){
  262. notify('error', '单个文件大小不能超过10M')
  263. return false;
  264. }
  265. let fileName = file.name
  266. let index = fileName.lastIndexOf('.');
  267. // 文件不能没有后缀
  268. if (index <= 0){
  269. notify('error', '只能上传png/jpg格式的文件')
  270. return false;
  271. }
  272. let fileSuffix = fileName.substr(index)
  273. // 文件后缀必须是.png或者.jpg
  274. if (fileSuffix !== '.jpg' && fileSuffix !== '.png') {
  275. notify('error', '只能上传png/jpg格式的文件')
  276. return false;
  277. }
  278. },
  279. //上传文件,此处为上传图片
  280. uploadFile (param) {
  281. this.showLoading();
  282. const formData = new FormData()
  283. let config = {
  284. //添加请求头
  285. headers: {'Content-Type': 'multipart/form-data'},
  286. }
  287. formData.append('file', param.file)
  288. Http.upload(Apis.FILE.UPLOAD_IMAGE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  289. this.hideLoading();
  290. console.log('上传成功')
  291. this.authentication.businessLicensePhoto = res.data
  292. console.log(res.data)
  293. notify('success', '上传成功')
  294. }).catch(error => {
  295. this.hideLoading()
  296. try {
  297. if (error.response.status === 413){
  298. notify('error', '文件过大,请选择小于20M的图片')
  299. }else if (error.response.status === 500){
  300. notify('error', '上传文件发生错误,请稍后重试')
  301. }
  302. }catch (e) {
  303. notify('error', error.data)
  304. }
  305. })
  306. },
  307. //
  308. setUserInfo () {
  309. this.user = storageGet('user')
  310. },
  311. //测试用函数
  312. test () {
  313. },
  314. showLoading () {
  315. this.loading = true
  316. },
  317. hideLoading () {
  318. this.loading = false
  319. },
  320. sendBusMessage () {
  321. this.$root.$emit('user', this.user)
  322. },
  323. checkNumber(value){
  324. return /^\d+$/.test(value);
  325. },
  326. checkNumberAndWord(value){
  327. return /^[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/g.test(value) || /^[A-Za-z0-9]\w{14}$/g.test(value);
  328. }
  329. },
  330. }
  331. </script>
  332. <style scoped>
  333. .el-radio {
  334. margin: 10px 20px 10px 0;
  335. }
  336. .el-form-item /deep/ .el-tabs__content {
  337. max-height: 120px !important;
  338. overflow: auto;
  339. }
  340. .el-row {
  341. margin-bottom: 10px;
  342. }
  343. .el-input {
  344. width: 400px;
  345. }
  346. .avatar-uploader .el-upload {
  347. border: 1px dashed #d9d9d9;
  348. border-radius: 6px;
  349. cursor: pointer;
  350. position: relative;
  351. overflow: hidden;
  352. }
  353. .avatar-uploader .el-upload:hover {
  354. border-color: #409EFF;
  355. }
  356. .avatar-uploader-icon {
  357. border: 1px dashed #d9d9d9;
  358. border-radius: 6px;
  359. font-size: 28px;
  360. color: #8c939d;
  361. width: 176px;
  362. height: 178px;
  363. line-height: 178px;
  364. text-align: center;
  365. }
  366. .avatar-uploader-icon:hover {
  367. border-color: #409EFF;
  368. }
  369. .avatar {
  370. width: 178px;
  371. height: 178px;
  372. display: block;
  373. }
  374. </style>