register.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <view class="page">
  3. <uni-nav-bar :fixed="true" background-color="#FFE05C" :border="false" :statusBar="true" title="注册" />
  4. <view :style="{'marginTop':'10rpx'}">
  5. <u--form labelPosition="left" :model="form" :rules="rules" ref="uForm">
  6. <u-form-item :labelWidth="80" label="姓名:" borderBottom prop="name" ref="item1">
  7. <u--input v-model="form.username" placeholder="请输入姓名" border="none"></u--input>
  8. </u-form-item>
  9. <u-form-item :labelWidth="80" label="性别:" borderBottom prop="sex" ref="item1" @click="showSex = true">
  10. <u--input v-model="form.sex" disabled disabledColor="#ffffff" placeholder="请选择性别" border="none"></u--input>
  11. <u-icon slot="right" name="arrow-right"></u-icon>
  12. </u-form-item>
  13. <u-form-item :labelWidth="80" label="生日:" borderBottom prop="sex" ref="item1" @click="showBirthday = true">
  14. <u--input v-model="form.sex" disabled disabledColor="#ffffff" placeholder="请选择生日" border="none"></u--input>
  15. <u-icon slot="right" name="arrow-right"></u-icon>
  16. </u-form-item>
  17. <u-form-item :labelWidth="80" label="手机号:" borderBottom prop="username" ref="item1">
  18. <u--input v-model="form.username" placeholder="请输入手机号" border="none"></u--input>
  19. </u-form-item>
  20. <u-form-item :labelWidth="80" label="验证码:" borderBottom prop="code" ref="item1">
  21. <view class="inputCode">
  22. <u--input v-model="form.code" placeholder="请输入验证码" border="none"></u--input>
  23. </view>
  24. <u-button slot="right" @tap="getCode" :text="tips" type="success" size="small" :disabled="disabled1"></u-button>
  25. </u-form-item>
  26. <u-form-item :labelWidth="80" label="密码:" borderBottom prop="newPassword" ref="item1">
  27. <u--input v-model="form.newPassword" placeholder="请输入密码" type="password" border="none"></u--input>
  28. </u-form-item>
  29. <u-form-item :labelWidth="80" label="确认密码:" borderBottom prop="againPassword" ref="item1">
  30. <u--input v-model="form.againPassword" placeholder="再次确认密码" type="password" border="none"></u--input>
  31. </u-form-item>
  32. </u--form>
  33. <view :style="{'marginTop':'100rpx'}">
  34. <button class="customStyle" @click="retrievePassword">提交</button>
  35. </view>
  36. <view class="flex-row justify-center register">
  37. <text>已有账号!</text>
  38. <text @click="gologin" :style="{color:'#FFE05C'}">切换登录</text>
  39. </view>
  40. </view>
  41. <u-code ref="uCode" @change="codeChange" seconds="60" @start="disabled1 = true" @end="disabled1 = false"></u-code>
  42. <u-action-sheet
  43. :show="showSex"
  44. :actions="actions"
  45. title="请选择性别"
  46. @close="showSex = false"
  47. @select="sexSelect">
  48. </u-action-sheet>
  49. <u-datetime-picker
  50. :show="showBirthday"
  51. :value="birthday"
  52. mode="date"
  53. closeOnClickOverlay
  54. @confirm="birthdayConfirm"
  55. @cancel="birthdayClose"
  56. @close="birthdayClose"
  57. ></u-datetime-picker>
  58. </view>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. showBirthday:false,
  65. showSex:false,
  66. birthday: Number(new Date()),
  67. actions: [{
  68. name: '男',
  69. value:'1'
  70. },
  71. {
  72. name: '女',
  73. value:'0'
  74. },{
  75. name: '保密',
  76. value:'2'
  77. }
  78. ],
  79. tips:'',
  80. form:{
  81. username:'',
  82. code:'',
  83. newPassword:'',
  84. againPassword:''
  85. },
  86. rules: {
  87. 'username': {
  88. type: 'string',
  89. required: true,
  90. min:11,
  91. max: 11,
  92. pattern:this.$phonePattern,
  93. message: '请输入正确的电话号码',
  94. trigger: ['blur', 'change']
  95. },
  96. 'code': {
  97. type: 'string',
  98. required: true,
  99. min:4,
  100. max: 6,
  101. message: '请输入验证码',
  102. trigger: ['blur', 'change']
  103. },
  104. 'newPassword': {
  105. type: 'string',
  106. min:6,
  107. max: 16,
  108. required: true,
  109. message: '请输入6-18位密码',
  110. trigger: ['blur', 'change']
  111. },
  112. 'againPassword': {
  113. type: 'string',
  114. min:6,
  115. max: 16,
  116. required: true,
  117. message: '请输入6-18位密码',
  118. trigger: ['blur', 'change']
  119. }
  120. },
  121. }
  122. },
  123. methods: {
  124. gologin(){
  125. uni.redirectTo({
  126. url:'/pages/login/login'
  127. })
  128. },
  129. birthdayClose() {
  130. this.showBirthday = false
  131. // this.$refs.form1.validateField('userInfo.birthday')
  132. },
  133. birthdayConfirm(e) {
  134. console.log(e)
  135. this.showBirthday = false
  136. this.form.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  137. // this.$refs.form1.validateField('userInfo.birthday')
  138. },
  139. sexSelect(e) {
  140. console.log(e)
  141. },
  142. retrievePassword(){
  143. this.$refs.uForm.validate().then(res => {
  144. this.$api.login.retrievePassword(this.form).then(res=>{
  145. uni.showToast({
  146. icon: 'success',
  147. duration: 2000,
  148. title: '修改成功,即将跳转登录页'
  149. });
  150. setTimeout(()=>{
  151. this.logout()
  152. },2000)
  153. })
  154. })
  155. },
  156. logout(){
  157. this.$api.login.logout().then(res=>{
  158. uni.clearStorageSync();
  159. uni.navigateTo({
  160. url:'/pages/login/login'
  161. })
  162. })
  163. },
  164. back(){
  165. uni.navigateBack({
  166. delta: 1
  167. });
  168. },
  169. codeChange(text) {
  170. this.tips = text;
  171. },
  172. getCode() {
  173. if (this.$refs.uCode.canGetCode) {
  174. // 模拟向后端请求验证码
  175. uni.showLoading({
  176. title: '正在获取验证码'
  177. })
  178. this.$api.service.getSmsCode({phonenumber: this.form.username}).then(res=>{
  179. uni.hideLoading();
  180. // 这里此提示会被this.start()方法中的提示覆盖
  181. uni.$u.toast('验证码已发送');
  182. // 通知验证码组件内部开始倒计时
  183. this.$refs.uCode.start();
  184. })
  185. } else {
  186. uni.$u.toast('倒计时结束后再发送');
  187. }
  188. },
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. @import './index.rpx.css';
  194. </style>