nameAuthentication.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <template>
  2. <uni-section title="实名认证" type="line">
  3. <view class="example">
  4. <!-- 自定义表单校验 -->
  5. <uni-forms ref="customForm" :rules="customRules" :modelValue="form">
  6. <uni-forms-item label="姓名" required name="name">
  7. <uni-easyinput v-model="form.name" placeholder="请输入姓名" maxlength="20"/>
  8. </uni-forms-item>
  9. <uni-forms-item label="电话" required name="phone">
  10. <uni-easyinput v-model="form.phone" placeholder="请输入电话" maxlength="13"/>
  11. </uni-forms-item>
  12. <uni-forms-item label="身份证号" required name="idCard">
  13. <uni-easyinput v-model="form.idCard" placeholder="请输入身份证号" maxlength="18"/>
  14. </uni-forms-item>
  15. <uni-forms-item label="身份证正反面" required class="onePic" v-if="form.id != null">
  16. <image :src="loadImgSrc(item)" v-for="(item, index1) in imageList" :key="index1">
  17. </image>
  18. </uni-forms-item>
  19. <uni-forms-item label="身份证正反面" required name="path" v-if="form.id == null">
  20. <upload :imgArr="imageList" name="path" v-model="form.path" :fileSize="1" :limit="2"
  21. @updateImg="updateImg"></upload>
  22. </uni-forms-item>
  23. </uni-forms>
  24. <button type="primary" @click="submitForm('customForm')" v-if="form.id==null">提交</button>
  25. </view>
  26. </uni-section>
  27. </template>
  28. <script>
  29. import upload from '../../components/upload/index.vue'
  30. import {appletAdd,getUserInfo} from '@/api/me/nameAuthentication.js'
  31. export default {
  32. components: {
  33. upload
  34. },
  35. onReady() {
  36. // 设置自定义表单校验规则,必须在节点渲染完毕后执行
  37. this.$refs.customForm.setRules(this.customRules)
  38. this.userId = getApp().globalData.userId
  39. this.getUserInfoByUserId(this.userId)
  40. },
  41. data() {
  42. return {
  43. form: {},
  44. // 表单校验
  45. customRules: {
  46. name: {
  47. rules: [{
  48. required: true,
  49. errorMessage: '姓名不能为空'
  50. }]
  51. },
  52. phone: {
  53. rules: [{
  54. required: true,
  55. errorMessage: '电话不能为空'
  56. },
  57. {
  58. pattern:'^1[3456789]\\d{9}$',
  59. errorMessage: '请填写正确的手机号'
  60. }]
  61. },
  62. idCard: {
  63. rules: [{
  64. required: true,
  65. errorMessage: '身份证号不能为空'
  66. },
  67. {
  68. pattern: '/(^\\d{15}$)|(^\\d{18}$)|(^\\d{17}(\\d|X|x)$)/',
  69. errorMessage: '请填写正确的身份号'
  70. }]
  71. },
  72. path: {
  73. rules: [{
  74. required: true,
  75. errorMessage: '身份证正反面不能为空'
  76. }]
  77. },
  78. },
  79. imageList: []
  80. }
  81. },
  82. methods: {
  83. // 取消按钮
  84. cancel() {
  85. this.open = false;
  86. this.reset();
  87. },
  88. /** 提交按钮 */
  89. submitForm(e) {
  90. this.$refs[e].validate().then(res => {
  91. if(this.imageList.length!=2){
  92. uni.showToast({
  93. title: "身份证正反面照片为两张!",
  94. icon: "none"
  95. })
  96. }else{
  97. appletAdd(this.form).then(res => {
  98. uni.navigateBack();
  99. });
  100. }
  101. })
  102. },
  103. //图片上传
  104. updateImg(imgList) {
  105. this.imageList = imgList;
  106. this.form.path = this.imageList.join(',');
  107. },
  108. //按userId查询实名认证信息
  109. getUserInfoByUserId(userId){
  110. getUserInfo(userId).then(res =>{
  111. if(res.data!=null){
  112. this.form = res.data;
  113. this.imageList = res.data.path.split(",")
  114. }
  115. })
  116. }
  117. }
  118. };
  119. </script>
  120. <style>
  121. </style>