officialAuthentication.vue 4.2 KB

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