bind.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <view class="container">
  3. <view class="body">
  4. <!-- 输入框区域 -->
  5. <view class="body_row mt-40">
  6. <view class="row_text">姓名</view>
  7. <input class="row_input" type="text" placeholder="请输入姓名" placeholder-style="color:#CCCCCC" v-model="name" />
  8. </view>
  9. <view class="body_row mt-30">
  10. <view class="row_text">编号</view>
  11. <input class="row_input" type="number" placeholder="请输入编号" placeholder-style="color:#CCCCCC" v-model="number" />
  12. </view>
  13. <view class="body_row mt-30">
  14. <view class="row_text">身份证</view>
  15. <input class="row_input" type="number" placeholder="请输入身份证" placeholder-style="color:#CCCCCC" v-model="identity" />
  16. </view>
  17. <!-- 确定按钮区域 -->
  18. <view class="body_btn" @click="handleConfirm">确认</view>
  19. </view>
  20. </view>
  21. </template>
  22. <script setup>
  23. import { ref } from 'vue'
  24. import { onLoad } from '@dcloudio/uni-app'
  25. import { myRequest } from '@/utils/api.js'
  26. // 姓名
  27. const name = ref('')
  28. // 编号
  29. const number = ref('')
  30. // 身份证号码
  31. const identity = ref('')
  32. onLoad(() => {})
  33. // 点击确认按钮回调
  34. const handleConfirm = () => {
  35. const flag = verifyValue()
  36. if (flag) {
  37. bindReq()
  38. }
  39. }
  40. // 绑定请求
  41. const bindReq = async () => {
  42. const res = await myRequest({
  43. url: '/wanzai/api/smartUser/bindStudent',
  44. method: 'post',
  45. data: {
  46. userId: uni.getStorageSync('userInfo').id,
  47. name: name.value,
  48. cardNo: number.value,
  49. idCard: identity.value
  50. }
  51. })
  52. // console.log(res)
  53. uni.showToast({
  54. title: res.message,
  55. icon: 'none',
  56. duration: 2000
  57. })
  58. if (res.code == 200) {
  59. setTimeout(() => {
  60. uni.redirectTo({
  61. url: '/pages/home/home'
  62. })
  63. }, 2000)
  64. }
  65. }
  66. // 验证表格数据是否符合规范
  67. const verifyValue = () => {
  68. // 姓名验证规则
  69. const regName = /^[\u4e00-\u9fa5]{2,4}$/
  70. // 身份证号码验证规则
  71. const regIdentity = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
  72. if (!name.value) {
  73. uni.showToast({
  74. title: '请输入姓名',
  75. icon: 'none'
  76. })
  77. return false
  78. }
  79. if (!regName.test(name.value)) {
  80. uni.showToast({
  81. title: '姓名格式错误',
  82. icon: 'none'
  83. })
  84. return false
  85. }
  86. if (!number.value) {
  87. uni.showToast({
  88. title: '请输入编号',
  89. icon: 'none'
  90. })
  91. return false
  92. }
  93. if (!identity.value) {
  94. uni.showToast({
  95. title: '请输入身份证',
  96. icon: 'none'
  97. })
  98. return false
  99. }
  100. if (!regIdentity.test(identity.value)) {
  101. uni.showToast({
  102. title: '证件号格式错误',
  103. icon: 'none'
  104. })
  105. return false
  106. }
  107. return true
  108. }
  109. </script>
  110. <style lang="scss" scoped>
  111. .container {
  112. display: flex;
  113. flex-direction: column;
  114. min-height: 100vh;
  115. background-color: #f1f6fe;
  116. .body {
  117. position: relative;
  118. padding: 0 20rpx;
  119. margin-top: 20rpx;
  120. height: calc(100vh - 20rpx);
  121. background-color: #fff;
  122. .body_row {
  123. display: flex;
  124. justify-content: space-between;
  125. align-items: center;
  126. height: 90rpx;
  127. font-size: 28rpx;
  128. .row_text {
  129. flex: 1;
  130. padding-right: 30rpx;
  131. text-align-last: justify;
  132. }
  133. .row_input {
  134. box-sizing: border-box;
  135. padding: 0 30rpx;
  136. width: 590rpx;
  137. height: 90rpx;
  138. border-radius: 15rpx;
  139. background-color: #f2f2f2;
  140. }
  141. }
  142. .mt-40 {
  143. margin-top: 40rpx;
  144. }
  145. .mt-30 {
  146. margin-top: 30rpx;
  147. }
  148. .body_btn {
  149. position: absolute;
  150. bottom: 150rpx;
  151. left: 227rpx;
  152. display: flex;
  153. justify-content: center;
  154. align-items: center;
  155. width: 297rpx;
  156. height: 100rpx;
  157. color: #fff;
  158. font-size: 32rpx;
  159. border-radius: 8rpx;
  160. background-color: #1e7dfb;
  161. }
  162. }
  163. }
  164. </style>