IndividualAuthenticationCreate.vue 10 KB

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