register.vue 6.4 KB

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