EnterpriseAuthenticationCreate.vue 12 KB

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