register.vue 5.6 KB

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