index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <!-- @format -->
  2. <template>
  3. <view class="app-container">
  4. <view class="setps">
  5. <u-steps :current="current">
  6. <u-steps-item title="第一步"> </u-steps-item>
  7. <u-steps-item title="第二步"></u-steps-item>
  8. <u-steps-item title="注册完成"></u-steps-item>
  9. </u-steps>
  10. </view>
  11. <view class="component">
  12. <component
  13. :formdData.sync="formdData"
  14. v-if="componentsKey[current] == 'uploadLicense'"
  15. :is="'uploadLicense'"
  16. ></component>
  17. <component
  18. :formdData.sync="formdData"
  19. :authorizerRef.sync="authorizerRef"
  20. v-if="componentsKey[current] == 'authorizer'"
  21. :is="'authorizer'"
  22. ></component>
  23. <component
  24. :formdData.sync="formdData"
  25. v-if="componentsKey[current] == 'recognition'"
  26. :is="'recognition'"
  27. >
  28. </component>
  29. </view>
  30. <view class="btn">
  31. <u-button
  32. class="custom-style"
  33. @click="handlePre"
  34. :plain="true"
  35. shape="circle"
  36. type="primary"
  37. >{{ current == 0 ? "退出注册" : "上一步" }}</u-button
  38. >
  39. <u-button
  40. class="custom-style"
  41. @click="handleNext"
  42. shape="circle"
  43. type="primary"
  44. >{{
  45. formdData.isPass && current == 2 ? "完成注册" : "下一步"
  46. }}</u-button
  47. >
  48. </view>
  49. <view style="height: 100rpx"></view>
  50. </view>
  51. </template>
  52. <script>
  53. import { idcardOCR } from "@/api/companiesRegistered";
  54. import { submitMiUser } from "@/api/personRegistered";
  55. import uploadLicense from "@/components/personRegistered/uploadLicense";
  56. import authorizer from "@/components/personRegistered/authorizer";
  57. import recognition from "@/components/personRegistered/recognition";
  58. export default {
  59. components: {
  60. uploadLicense,
  61. authorizer,
  62. recognition,
  63. },
  64. data() {
  65. return {
  66. authorizerRef: null,
  67. formdData: {
  68. cardFrontImg: null, //身份证正面
  69. cardBackImg: null, //身份证背面
  70. isPass: false, //是否通过
  71. personCardOrcResult: {
  72. name: "", //用户名
  73. idNum: "", //身份证号
  74. phone: "", //联系人手机号
  75. pwd: "", //单位联系电话
  76. pwdReset: "",
  77. }, //申请人信息
  78. recognition: {},
  79. },
  80. componentsKey: {
  81. 0: "uploadLicense",
  82. 1: "authorizer",
  83. 2: "recognition",
  84. },
  85. current: 0,
  86. };
  87. },
  88. created() {
  89. // this.handlefinish();
  90. },
  91. methods: {
  92. //ocr识别
  93. async handleOcr() {
  94. if (!(this.formdData.cardBackImg && this.formdData.cardFrontImg)) {
  95. uni.showToast({
  96. title: "请先上传身份证正反面照片",
  97. //将值设置为 success 或者直接不用写icon这个参数
  98. icon: "none",
  99. //显示持续时间为 2秒
  100. duration: 2000,
  101. });
  102. return;
  103. }
  104. uni.showLoading({
  105. title: "智能识别中...",
  106. });
  107. try {
  108. let {
  109. data: { idcardDownOcrResult, idcardUpOcrResult },
  110. } = await idcardOCR([
  111. this.formdData.cardBackImg,
  112. this.formdData.cardFrontImg,
  113. ]);
  114. this.formdData.personCardOrcResult.name = idcardUpOcrResult.name;
  115. this.formdData.personCardOrcResult.idNum = idcardUpOcrResult.idNum;
  116. this.current++;
  117. setTimeout(() => {
  118. uni.hideLoading();
  119. }, 2000);
  120. } catch (error) {
  121. uni.showLoading({
  122. title: "识别错误",
  123. });
  124. setTimeout(() => {
  125. uni.hideLoading();
  126. }, 2000);
  127. } finally {
  128. }
  129. },
  130. //个人信息校验
  131. handlePerson() {
  132. this.authorizerRef.validate().then((res) => {
  133. this.current++;
  134. });
  135. },
  136. //下一步
  137. handleNext() {
  138. if (this.componentsKey[this.current] == "uploadLicense") {
  139. this.handleOcr();
  140. } else if (this.componentsKey[this.current] == "authorizer") {
  141. this.handlePerson();
  142. } else if (this.componentsKey[this.current] == "recognition") {
  143. if (this.formdData.isPass) {
  144. this.handlefinish();
  145. }
  146. }
  147. },
  148. //完成注册
  149. async handlefinish() {
  150. try {
  151. uni.showLoading({
  152. title: "提交中...",
  153. });
  154. await submitMiUser({
  155. idCardUp: this.formdData.cardFrontImg,
  156. idCardDown: this.formdData.cardBackImg,
  157. idCard: this.formdData.personCardOrcResult.idNum,
  158. name: this.formdData.personCardOrcResult.name,
  159. pwd: this.formdData.personCardOrcResult.pwd,
  160. phone: this.formdData.personCardOrcResult.phone,
  161. });
  162. uni.showToast({
  163. title: "提交成功",
  164. //显示持续时间为 2秒
  165. duration: 2000,
  166. });
  167. setTimeout(() => {
  168. uni.navigateTo({
  169. url: `/pages/personRegistered/bindCompanies?name=${this.formdData.personCardOrcResult.name}&idNum=${this.formdData.personCardOrcResult.idNum}&password=${this.formdData.personCardOrcResult.pwd}`,
  170. success: (res) => {},
  171. fail: () => {},
  172. complete: () => {},
  173. });
  174. }, 2000);
  175. } catch (error) {
  176. } finally {
  177. uni.hideLoading();
  178. }
  179. },
  180. //上一步
  181. handlePre() {
  182. if (this.current == 0) {
  183. uni.navigateBack({
  184. delta: 1,
  185. });
  186. return;
  187. }
  188. this.current--;
  189. },
  190. },
  191. };
  192. </script>
  193. <style>
  194. .component {
  195. width: 95%;
  196. margin: 40rpx auto;
  197. }
  198. ::v-deep .u-button {
  199. width: 280rpx !important;
  200. height: 70rpx !important;
  201. font-size: 30rpx !important;
  202. }
  203. .btn {
  204. z-index: 99;
  205. display: flex;
  206. justify-content: space-between;
  207. align-items: center;
  208. background: #fff;
  209. padding: 20rpx;
  210. position: fixed;
  211. bottom: 0;
  212. left: 0;
  213. width: 100%;
  214. }
  215. .app-container {
  216. height: 100vh;
  217. background: rgb(248, 249, 250);
  218. }
  219. .setps {
  220. width: 95%;
  221. margin: 10rpx auto;
  222. background: #fff;
  223. padding: 20rpx;
  224. border-radius: 6px;
  225. }
  226. </style>