nameAuthentication.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <uni-section title="实名认证" type="line">
  3. <view class="example">
  4. <uni-forms ref="customForm" :rules="customRules" :modelValue="form" class="form">
  5. <uni-forms-item label="姓名" required name="name">
  6. <uni-easyinput v-model="form.name" placeholder="请输入姓名" maxlength="20" :disabled="disabled"/>
  7. </uni-forms-item>
  8. <uni-forms-item label="电话" required name="phone">
  9. <uni-easyinput v-model="form.phone" placeholder="请输入电话" maxlength="13" :disabled="disabled"/>
  10. </uni-forms-item>
  11. <uni-forms-item label="身份证号" required name="idCard">
  12. <uni-easyinput v-model="form.idCard" placeholder="请输入身份证号" maxlength="18" :disabled="disabled"/>
  13. </uni-forms-item>
  14. <uni-forms-item label="身份证正反面" required v-if="form.id != null" class="onePic">
  15. <image :src="loadImgSrcLocalhost(item)" v-for="(item, index1) in imageList" :key="index1" class="cardPic">
  16. </image>
  17. </uni-forms-item>
  18. <uni-forms-item label="身份证正反面" required name="path" v-if="form.id == null" label-width="320">
  19. <upload :imgArr="imageList" name="path" v-model="form.path" :fileSize="1" :limit="2"
  20. style="position: relative;left: 3%;top: -10%;"
  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. disabled: false,
  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.disabled = true;
  115. this.imageList = res.data.path.split(",")
  116. }
  117. })
  118. }
  119. }
  120. };
  121. </script>
  122. <style scoped>
  123. .form {
  124. width: 100%;
  125. padding-left: 3%;
  126. }
  127. ::v-deep .item--uni-forms-item__label {
  128. width: 19% !important;
  129. }
  130. ::v-deep .item--uni-forms-item__label text{
  131. width: fit-content;
  132. white-space: nowrap;
  133. }
  134. ::v-deep .uni-section-content {
  135. padding: 0 2%;
  136. }
  137. ::v-deep .uni-forms .uni-forms-item__label:nth-child(4) {
  138. width: 26% !important;
  139. }
  140. /* ::v-deep .easyinput--uni-easyinput{
  141. margin-left: 10%;
  142. } */
  143. .cardPic{
  144. display: inline-block;
  145. width: 120px;
  146. height: 85px;
  147. }
  148. .cardPic:nth-child(1){
  149. margin-left: 10%;
  150. }
  151. </style>