register.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <view>
  3. <u-navbar title="" autoBack placeholder></u-navbar>
  4. <view class="card_login">
  5. <view class="card_head_logo">
  6. <image class="mine_image" src="../static/logo.png" mode=""></image>
  7. <view class="welcome_title">欢迎注册宝智达气瓶</view>
  8. </view>
  9. <u--form labelPosition="left" :model="formList" :rules="rules" ref="uForm">
  10. <u-form-item label="类型" prop="type" labelWidth="80" borderBottom ref="item1">
  11. <u-radio-group v-model="formList.type" placement="row">
  12. <u-radio shape="circle" :customStyle="{marginRight: '20px'}" v-for="(item, index) in radiolist"
  13. :key="index" :label="item.name" :name="item.value"></u-radio>
  14. </u-radio-group>
  15. </u-form-item>
  16. <u-form-item label="手机号" prop="phone" labelWidth="80" borderBottom ref="item1">
  17. <u--input v-model="formList.phone" border="none" placeholder="请填写手机号"></u--input>
  18. </u-form-item>
  19. <u-form-item label="验证码" prop="verifyCode" labelWidth="80" borderBottom>
  20. <u--input v-model="formList.verifyCode" border="none" placeholder="请填写验证码"></u--input>
  21. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="mini"
  22. :disabled="disabled1"></u-button>
  23. </u-form-item>
  24. <u-form-item label="密码" prop="password" labelWidth="80" borderBottom ref="item1">
  25. <u--input v-model="formList.password" border="none" placeholder="请填写密码"></u--input>
  26. </u-form-item>
  27. </u--form>
  28. <u-code ref="uCode" @change="codeChange" seconds="90" @start="disabled1 = true"
  29. @end="disabled1 = false"></u-code>
  30. <view class="title_register" @click="goLogin">去登录</view>
  31. <view class="card_btn">
  32. <u-button type="primary" :disabled="disabled" text="注册" @click="getRegister"></u-button>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. data() {
  40. return {
  41. radiolist: [{
  42. name: '私人',
  43. value: 1,
  44. }, {
  45. name: '商户',
  46. value: 0,
  47. }],
  48. formList: {
  49. type: 1,
  50. phone: '',
  51. verifyCode: '',
  52. password: '',
  53. },
  54. tips: '',
  55. disabled1: false,
  56. rules: {
  57. type: {
  58. type: 'string',
  59. required: true,
  60. message: '请选择用户类型',
  61. trigger: ['blur']
  62. },
  63. phone: {
  64. type: 'string',
  65. required: true,
  66. message: '请填写手机号',
  67. trigger: ['blur']
  68. },
  69. verifyCode: {
  70. type: 'string',
  71. required: true,
  72. message: '请填写验证码',
  73. trigger: ['blur']
  74. },
  75. password: {
  76. type: 'string',
  77. required: true,
  78. message: '请填写密码',
  79. trigger: ['blur']
  80. },
  81. },
  82. }
  83. },
  84. computed: {
  85. disabled() {
  86. if (this.formList.phone == '' || this.formList.verifyCode == '' || this.formList.password == '') {
  87. return true;
  88. } else {
  89. return false;
  90. }
  91. }
  92. },
  93. methods: {
  94. // 注册
  95. getRegister() {
  96. this.$refs.uForm.validate().then(res => {
  97. uni.showLoading();
  98. this.$api.post('/api/applet/register', {
  99. phone: this.formList.phone,
  100. password: this.formList.password,
  101. verifyCode: this.formList.verifyCode
  102. }).then((res) => {
  103. if (res.code == 200) {
  104. uni.showToast({
  105. title: res.msg,
  106. icon: 'none'
  107. });
  108. } else {
  109. uni.showToast({
  110. title: res.data.msg,
  111. icon: 'none'
  112. });
  113. }
  114. uni.hideLoading();
  115. })
  116. }).catch(errors => {
  117. // uni.$u.toast('校验失败')
  118. })
  119. },
  120. getCode() {
  121. if (this.$refs.uCode.canGetCode) {
  122. // 模拟向后端请求验证码
  123. if (this.formList.phone) {
  124. uni.showLoading({
  125. title: '正在获取验证码'
  126. })
  127. // 通知验证码组件内部开始倒计时
  128. this.$refs.uCode.start();
  129. this.$api.get('/api/verify-code', {
  130. phone: this.formList.phone,
  131. }).then(res => {
  132. if (res.code == 200) {
  133. uni.hideLoading();
  134. // 这里此提示会被this.start()方法中的提示覆盖
  135. uni.$u.toast('验证码已发送');
  136. }
  137. })
  138. } else {
  139. uni.$u.toast('请先输入手机号');
  140. }
  141. } else {
  142. uni.$u.toast('倒计时结束后再发送');
  143. }
  144. },
  145. codeChange(text) {
  146. this.tips = text;
  147. },
  148. // 登录
  149. goLogin() {
  150. // uni.redirectTo({
  151. // url: '/pages/login'
  152. // })
  153. uni.navigateBack({
  154. delta: 1
  155. });
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="scss">
  161. .welcome_title {
  162. font-size: 46rpx;
  163. font-weight: 600;
  164. margin-bottom: 60rpx;
  165. margin-top: 10rpx;
  166. }
  167. .card_head_logo {
  168. margin-top: 50rpx;
  169. display: flex;
  170. flex-direction: column;
  171. justify-content: center;
  172. align-items: center;
  173. }
  174. .card_login {
  175. padding: 20rpx 40rpx;
  176. }
  177. .mine_image {
  178. width: 100rpx;
  179. height: 100rpx;
  180. }
  181. .title_register {
  182. margin-top: 20rpx;
  183. display: flex;
  184. justify-content: flex-end;
  185. font-size: 28rpx;
  186. color: #494949;
  187. }
  188. .card_hint {
  189. margin-top: 60rpx;
  190. display: flex;
  191. align-items: flex-start;
  192. }
  193. .agreement_title {
  194. font-size: 30rpx;
  195. color: #333;
  196. }
  197. .protocol_title {
  198. color: #1177ff;
  199. }
  200. .card_btn {
  201. margin-top: 50rpx;
  202. }
  203. .card_checkbox {
  204. margin-top: 5rpx;
  205. position: relative;
  206. cursor: pointer;
  207. }
  208. .message {
  209. display: none;
  210. position: absolute;
  211. padding: 5px 8px;
  212. border: 1px solid #494949;
  213. border-radius: 9px;
  214. top: -36px;
  215. font-size: 12px;
  216. width: 110px;
  217. background: #494949;
  218. color: #fff;
  219. left: -6px;
  220. }
  221. .message::after {
  222. content: '';
  223. position: absolute;
  224. left: 8px;
  225. top: 100%;
  226. border: 8px solid transparent;
  227. border-top: 6px solid #494949;
  228. margin-left: -2px;
  229. }
  230. </style>