IndividualAuthentication.vue 12 KB

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