nameAuthentication.vue 4.1 KB

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