IndividualAuthentication.vue 10 KB

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