open.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="container-open">
  3. <view class="form-layout">
  4. <view class="form-label">姓名</view>
  5. <input v-model="form.userName" maxlength="20" placeholder="请输入您的姓名" placeholder-class="form-input-placeholder"/>
  6. <view class="form-label" style="margin-top: 28rpx;">身份证号</view>
  7. <input v-model="form.idNumber" maxlength="18" type="idcard" placeholder="请输入您的身份证号" placeholder-class="form-input-placeholder"/>
  8. </view>
  9. <view style="flex: auto;"></view>
  10. <button class="btn black" type="primary" @click="zfbIotVsp">提 交</button>
  11. <view style="flex: none;height: 100rpx;"></view>
  12. </view>
  13. </template>
  14. <script>
  15. import _ from 'lodash'
  16. import {
  17. iotVspInit,
  18. iotVspUniqueId
  19. } from '@/utils/ioTVsp'
  20. export default {
  21. data() {
  22. return {
  23. form: {
  24. idNumber: null,
  25. userName: null
  26. }
  27. }
  28. },
  29. onLoad() {
  30. uni.onAppShow(this.onAppShowHandler)
  31. },
  32. onUnload: function() {
  33. my.offAppShow(this.onAppShowHandler)
  34. },
  35. onReady() {
  36. iotVspInit((res) => {
  37. my.navigateBack()
  38. if (res.success) {
  39. setTimeout(() => {
  40. my.navigateBack()
  41. uni.showModal({
  42. title: '提示',
  43. content: '恭喜您,已成功开通快速刷脸通行!',
  44. showCancel: false
  45. })
  46. this.form = {
  47. idNumber: null,
  48. userName: null
  49. }
  50. }, 1000)
  51. }
  52. })
  53. },
  54. methods: {
  55. zfbIotVsp: _.throttle(function() {
  56. if(!this.form.userName) {
  57. uni.showToast({
  58. title: '姓名不能为空',
  59. duration: 2000
  60. })
  61. return
  62. }
  63. if(!this.form.idNumber) {
  64. uni.showToast({
  65. title: '身份证号不能为空',
  66. duration: 2000
  67. })
  68. return
  69. }
  70. if(this.form.idNumber.length === 15) {
  71. const idreg = /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/
  72. if(!idreg.test(this.form.idNumber)) {
  73. uni.showToast({
  74. title: '身份证号格式错误',
  75. duration: 2000
  76. })
  77. return
  78. }
  79. } else if(this.form.idNumber.length === 18) {
  80. const idreg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/
  81. if(!idreg.test(this.form.idNumber)) {
  82. uni.showToast({
  83. title: '身份证号格式错误',
  84. duration: 2000
  85. })
  86. return
  87. }
  88. } else {
  89. uni.showToast({
  90. title: '身份证号位数错误',
  91. duration: 2000
  92. })
  93. return
  94. }
  95. iotVspUniqueId(this.form.idNumber, this.form.userName, null, null).then((res) => {
  96. if(res) {
  97. uni.showModal({
  98. title: "提示",
  99. content: '您已开通快速刷脸通行!',
  100. showCancel: false
  101. })
  102. this.form = {
  103. idNumber: null,
  104. userName: null
  105. }
  106. } else {
  107. // uni.showModal({
  108. // title: "提示",
  109. // content: '人脸已入库!',
  110. // showCancel: false
  111. // })
  112. }
  113. })
  114. }, 3000)
  115. }
  116. }
  117. </script>
  118. <style scoped>
  119. .container-open {
  120. display: flex;
  121. flex-direction: column;
  122. align-items: center;
  123. width: 100%;
  124. height: 100vh;
  125. }
  126. .form-layout {
  127. width: calc(100% - 144rpx);
  128. margin: 24rpx 32rpx 0;
  129. background-color: #fff;
  130. border-radius: 20rpx;
  131. padding: 50rpx 40rpx;
  132. }
  133. .form-layout .form-label {
  134. color: rgba(51, 51, 51, 1);
  135. font-size: 32rpx;
  136. font-weight: 500;
  137. }
  138. .form-layout input {
  139. padding: 0;
  140. margin: 0;
  141. border: 0;
  142. background-color: transparent;
  143. width: 100%;
  144. border-bottom: 1px solid rgba(238, 238, 238, 1);
  145. min-height: 80rpx;
  146. line-height: 80rpx;
  147. }
  148. .form-layout .form-input-placeholder {
  149. color: rgba(204, 204, 204, 1);
  150. font-size: 36rpx;
  151. font-weight: 400;
  152. }
  153. .container-open .btn {
  154. width: 82%;
  155. height: 112rpx;
  156. line-height: 112rpx;
  157. border: none;
  158. border-radius: 16rpx;
  159. overflow: hidden;
  160. font-size: 36rpx;
  161. font-weight: 500;
  162. }
  163. .container-open .black {
  164. background-color: rgba(35, 54, 59, 1);
  165. }
  166. </style>