bindForm.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view class="bind-form-container" style="width: 100%; overflow: hidden">
  3. <image class="bg-image" src="/static/formBg.png" mode="aspectFill"></image>
  4. <image class="form-title-image" src="/static/logo.png"></image>
  5. <view class="form-container">
  6. <view class="form-title">Hi~</view>
  7. <uni-forms
  8. style="width: 100%"
  9. label-position="top"
  10. ref="baseForm"
  11. :modelValue="formData"
  12. :rules="customRules"
  13. >
  14. <uni-forms-item label="姓名" required name="name">
  15. <uni-easyinput
  16. v-model="formData.name"
  17. placeholder="请输入姓名"
  18. ></uni-easyinput>
  19. </uni-forms-item>
  20. <uni-forms-item label="身份证号" required name="sfzh">
  21. <uni-easyinput
  22. v-model="formData.sfzh"
  23. placeholder="请输入身份证号"
  24. ></uni-easyinput>
  25. </uni-forms-item>
  26. </uni-forms>
  27. <view @click="handleBindCard" class="bind-button">登录</view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. baseUrl: getApp().globalData.baseUrl,
  36. customRules: {
  37. name: {
  38. rules: [
  39. {
  40. required: true,
  41. errorMessage: "姓名不能为空",
  42. },
  43. ],
  44. },
  45. sfzh: {
  46. rules: [
  47. {
  48. required: true,
  49. errorMessage: "身份证号不能为空",
  50. },
  51. ],
  52. },
  53. },
  54. formData: {
  55. name: "",
  56. sfzh: "",
  57. },
  58. };
  59. },
  60. onReady() {
  61. // 设置自定义表单校验规则,必须在节点渲染完毕后执行
  62. this.$refs.baseForm.setRules(this.customRules);
  63. },
  64. methods: {
  65. handleBindCard() {
  66. this.$refs.baseForm.validate().then((res) => {
  67. uni.showLoading({
  68. title: "加载中",
  69. });
  70. uni.request({
  71. url:
  72. this.baseUrl +
  73. "/wxsfrz/wxRegister?name=" +
  74. this.formData.name +
  75. "&sfzh=" +
  76. this.formData.sfzh +
  77. "&openid=" +
  78. getApp().globalData.openId,
  79. method: "POST",
  80. success: ({ data }) => {
  81. if (data.code == 200) {
  82. uni.hideLoading();
  83. setTimeout(() => {
  84. uni.reLaunch({
  85. url:
  86. "/pages/bindCard?name=" +
  87. this.formData.name +
  88. "&sfzh=" +
  89. this.formData.sfzh,
  90. });
  91. }, 500);
  92. } else {
  93. uni.hideLoading();
  94. uni.showToast({
  95. title: data.msg,
  96. icon: "none",
  97. });
  98. }
  99. },
  100. });
  101. });
  102. },
  103. },
  104. };
  105. </script>
  106. <style scoped lang="scss">
  107. .form-title-image {
  108. width: 200rpx;
  109. height: 200rpx;
  110. position: absolute;
  111. top: 50rpx;
  112. left: 50%;
  113. transform: translateX(-50%);
  114. }
  115. .form-title {
  116. font-size: 40rpx;
  117. font-weight: bold;
  118. text-align: center;
  119. margin-bottom: 40rpx;
  120. }
  121. .form-container {
  122. width: 70%;
  123. padding: 40rpx 60rpx 50rpx;
  124. border-radius: 70rpx;
  125. box-shadow: #64646f33 0px 7px 29px 0px;
  126. margin: 300rpx auto 0;
  127. background-color: #fff;
  128. }
  129. .bg-image {
  130. position: absolute;
  131. width: 100%;
  132. height: 100%;
  133. z-index: -1;
  134. }
  135. .bind-button {
  136. width: 400rpx;
  137. margin: 70rpx auto 0;
  138. color: #fff;
  139. background: linear-gradient(to right, #007aff, #5c97d6);
  140. padding: 15rpx 10rpx;
  141. border-radius: 60rpx;
  142. text-align: center;
  143. box-shadow: #90979e23 0px 8px 24px;
  144. }
  145. </style>