EnterpriseAuthentication.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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="12%" 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="file">
  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. legalPersonName: [
  107. {required: true, message: '请输入公司法人姓名', trigger: 'blur'}
  108. ],
  109. bankAccount: [
  110. {required: true, message: '请输入对公账户', trigger: 'blur'},
  111. {
  112. validator: (rule, value, callback) => {
  113. if (!this.checkNumber(value)) {
  114. callback(new Error('对公账户输入有误'))
  115. } else {
  116. callback()
  117. }
  118. }, trigger: 'blur'
  119. },
  120. ],
  121. unifiedSocialCreditCode: [
  122. {required: true, message: '请输入统一社会信用代码', trigger: 'blur'},
  123. {
  124. validator: (rule, value, callback) => {
  125. if (!this.checkNumberAndWord(value)) {
  126. callback(new Error('统一社会信用代码输入有误'))
  127. } else {
  128. callback()
  129. }
  130. }, trigger: 'blur'
  131. },
  132. ],
  133. address: [
  134. {required: true, message: '请输入公司地址', trigger: 'blur'}
  135. ]
  136. }
  137. }
  138. },
  139. mounted () {
  140. this.$nextTick(() => {
  141. this.init()
  142. })
  143. },
  144. methods: {
  145. //初始化数据
  146. init () {
  147. this.setUserInfo()
  148. this.getAuthInfo()
  149. },
  150. //加载数据
  151. getAuthInfo () {
  152. this.showLoading()
  153. getCurrentEnterpriseAuthInfo(this.user.userVO.id, this.getAuthInfoSuccess, this.getAuthInfoFail)
  154. },
  155. getAuthInfoSuccess (res) {
  156. this.hideLoading()
  157. this.authentication.enterpriseName = res.enterpriseName == null ? '暂未填写' : res.enterpriseName
  158. this.authentication.legalPersonName = res.legalPersonName == null ? '暂未填写' : res.legalPersonName
  159. this.authentication.businessLicensePhoto = res.businessLicensePhoto == null ? defaultValue.image : res.businessLicensePhoto
  160. this.authentication.unifiedSocialCreditCode = res.unifiedSocialCreditCode == null ? '暂未填写' : res.unifiedSocialCreditCode
  161. this.authentication.bankAccount = res.bankAccount == null ? '暂未填写' : res.bankAccount
  162. this.authentication.address = res.address == null ? '暂未填写' : res.address
  163. this.authentication.authStatus = res.authStatus
  164. this.authentication.explain = res.explain
  165. console.log(this.authentication)
  166. },
  167. getAuthInfoFail (error) {
  168. this.hideLoading()
  169. notify('error', '加载认证信息失败:' + error.data)
  170. },
  171. //表单进入可编辑状态,可修改表单,不再使用
  172. modifyInfo () {
  173. this.isModifyMode = true
  174. },
  175. //提交认证信息
  176. updateAuthInfo () {
  177. //this.isModifyMode = false
  178. this.$refs['authentication'].validate(valid => {
  179. if (valid) {
  180. this.showLoading()
  181. const newAuthentication = {
  182. userId: this.user.userVO.id,
  183. enterpriseName: this.authentication.enterpriseName,
  184. legalPersonName: this.authentication.legalPersonName,
  185. businessLicensePhoto: this.authentication.businessLicensePhoto,
  186. unifiedSocialCreditCode: this.authentication.unifiedSocialCreditCode,
  187. bankAccount: this.authentication.bankAccount,
  188. address: this.authentication.address,
  189. }
  190. updateEnterpriseAuthInfo(this.user.userVO.id, newAuthentication, this.updateAuthInfoSuccess, this.updateAuthInfoFail)
  191. } else {
  192. notify('error', '表单填写错误!')
  193. return false
  194. }
  195. })
  196. },
  197. updateAuthInfoSuccess (res) {
  198. this.hideLoading()
  199. this.cancelModify()
  200. console.log(res)
  201. this.authentication.enterpriseName = res.enterpriseName == null ? '暂未填写' : res.enterpriseName
  202. this.authentication.legalPersonName = res.legalPersonName == null ? '暂未填写' : res.legalPersonName
  203. this.authentication.businessLicensePhoto = res.businessLicensePhoto == null ? defaultValue.image : res.businessLicensePhoto
  204. this.authentication.unifiedSocialCreditCode = res.unifiedSocialCreditCode == null ? '暂未填写' : res.unifiedSocialCreditCode
  205. this.authentication.bankAccount = res.bankAccount == null ? '暂未填写' : res.bankAccount
  206. this.authentication.address = res.address == null ? '暂未填写' : res.address
  207. notify('success', '认证信息修改成功,正在为您刷新用户信息')
  208. getCurrentUser().then(res => {
  209. storageSave('user', res)
  210. this.user = res
  211. this.sendBusMessage()
  212. //this.rolesPermissions = getRolesPermissions(res.roleList)
  213. storageSave('rolesPermissions', getRolesPermissions(res.roleList))
  214. this.hideLoading()
  215. notify('success', '用户信息刷新成功')
  216. }).catch((error) => {
  217. this.hideLoading()
  218. notify('error', '重新获取用户信息失败:' + error.data)
  219. })
  220. },
  221. updateAuthInfoFail (error) {
  222. this.hideLoading()
  223. notify('error', error.data)
  224. },
  225. //取消修改表单,表单进入不可编辑状态,不再使用
  226. cancelModify () {
  227. this.isModifyMode = false
  228. },
  229. //上传文件时移除文件的响应函数
  230. handleRemove (file, fileList) {
  231. console.log(file, fileList)
  232. },
  233. //添加文件时的响应函数
  234. handleExceed (files, fileList) {
  235. this.$message.warning(
  236. `当前限制选择 1 个文件,本次选择了 ${
  237. files.length
  238. } 个文件,共选择了 ${files.length + fileList.length} 个文件`
  239. )
  240. },
  241. //移除文件前的响应函数
  242. beforeRemove (file, fileList) {
  243. //return this.$confirm(`确定移除 ${file.name}?`)
  244. },
  245. //文件上传前的响应函数
  246. beforeFileUpload () {
  247. },
  248. //上传文件,此处为上传图片
  249. uploadFile (param) {
  250. const formData = new FormData()
  251. let config = {
  252. //添加请求头
  253. headers: {'Content-Type': 'multipart/form-data'},
  254. }
  255. formData.append('file', param.file)
  256. Http.upload(Apis.FILE.UPLOAD_IMAGE.replace('{userId}', this.user.userVO.id), formData, config).then((res) => {
  257. console.log('上传成功')
  258. this.authentication.photoUrl = res.data
  259. console.log(res.data)
  260. notify('success', '上传成功')
  261. }).catch(error => {
  262. notify('error', error.data.msg)
  263. })
  264. },
  265. //
  266. setUserInfo () {
  267. this.user = storageGet('user')
  268. },
  269. //测试用函数
  270. test () {
  271. },
  272. showLoading () {
  273. this.loading = true
  274. },
  275. hideLoading () {
  276. this.loading = false
  277. },
  278. sendBusMessage () {
  279. this.$root.$emit('user', this.user)
  280. },
  281. checkNumber(value){
  282. return /^\d+$/.test(value);
  283. },
  284. checkNumberAndWord(value){
  285. return /^[^_IOZSVa-z\W]{2}\d{6}[^_IOZSVa-z\W]{10}$/g.test(value) || /^[A-Za-z0-9]\w{14}$/g.test(value);
  286. }
  287. },
  288. }
  289. </script>
  290. <style scoped>
  291. .el-radio {
  292. margin: 10px 20px 10px 0;
  293. }
  294. .el-form-item /deep/ .el-tabs__content {
  295. max-height: 120px !important;
  296. overflow: auto;
  297. }
  298. .el-row {
  299. margin-bottom: 10px;
  300. }
  301. .el-input {
  302. width: 400px;
  303. }
  304. .avatar-uploader .el-upload {
  305. border: 1px dashed #d9d9d9;
  306. border-radius: 6px;
  307. cursor: pointer;
  308. position: relative;
  309. overflow: hidden;
  310. }
  311. .avatar-uploader .el-upload:hover {
  312. border-color: #409EFF;
  313. }
  314. .avatar-uploader-icon {
  315. border: 1px dashed #d9d9d9;
  316. border-radius: 6px;
  317. font-size: 28px;
  318. color: #8c939d;
  319. width: 176px;
  320. height: 178px;
  321. line-height: 178px;
  322. text-align: center;
  323. }
  324. .avatar-uploader-icon:hover {
  325. border-color: #409EFF;
  326. }
  327. .avatar {
  328. width: 178px;
  329. height: 178px;
  330. display: block;
  331. }
  332. </style>