officialAuthentication.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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="enterpriseName">
  7. <uni-easyinput v-model="form.enterpriseName" placeholder="请输入企业名称" maxlength="20" style="width: 40%;" :disabled="disabled"/>
  8. </uni-forms-item>
  9. <uni-forms-item label="法人姓名" required name="legalName">
  10. <uni-easyinput v-model="form.legalName" placeholder="请输入法人姓名" maxlength="20" :disabled="disabled"/>
  11. </uni-forms-item>
  12. <uni-forms-item label="联系电话" required name="phone">
  13. <uni-easyinput v-model="form.phone" placeholder="请输入联系电话" maxlength="13" :disabled="disabled"/>
  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">
  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/officialAuthentication.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. disabled: false,
  46. // 表单校验
  47. customRules: {
  48. enterpriseName: {
  49. rules: [{
  50. required: true,
  51. errorMessage: '企业名称不能为空'
  52. }]
  53. },
  54. legalName: {
  55. rules: [{
  56. required: true,
  57. errorMessage: '法人姓名不能为空'
  58. }]
  59. },
  60. phone: {
  61. rules: [{
  62. required: true,
  63. errorMessage: '联系电话不能为空'
  64. },
  65. {
  66. pattern:'^1[3456789]\\d{9}$',
  67. errorMessage: '请填写正确的手机号'
  68. }]
  69. },
  70. path: {
  71. rules: [{
  72. required: true,
  73. errorMessage: '证照信息不能为空'
  74. }]
  75. },
  76. },
  77. imageList: []
  78. }
  79. },
  80. methods: {
  81. // 取消按钮
  82. cancel() {
  83. this.open = false;
  84. this.reset();
  85. },
  86. /** 提交按钮 */
  87. submitForm(e) {
  88. this.$refs[e].validate().then(res => {
  89. if(this.imageList.length!=2){
  90. uni.showToast({
  91. title: "证照信息照片为两张!",
  92. icon: "none"
  93. })
  94. }else{
  95. appletAdd(this.form).then(res => {
  96. uni.navigateBack();
  97. });
  98. }
  99. })
  100. },
  101. //图片上传
  102. updateImg(imgList) {
  103. this.imageList = imgList;
  104. this.form.path = this.imageList.join(',');
  105. },
  106. //按userId查询实名认证信息
  107. getUserInfoByUserId(userId){
  108. getUserInfo(userId).then(res =>{
  109. if(res.data!=null){
  110. this.form = res.data;
  111. this.disabled = true;
  112. this.imageList = res.data.path.split(",")
  113. }
  114. })
  115. }
  116. }
  117. };
  118. </script>
  119. <style scoped>
  120. .form{
  121. width: 100%;
  122. padding-left: 3%;
  123. }
  124. ::v-deep .item--uni-forms-item__label{
  125. width: 19% !important;
  126. }
  127. ::v-deep .item--uni-forms-item__label text{
  128. width: fit-content;
  129. white-space: nowrap;
  130. }
  131. ::v-deep .uni-section-content{
  132. padding: 0 2%;
  133. }
  134. </style>