RegisterByMobile.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view class="div container">
  3. <view class="div section-wrapper top-wrapper">
  4. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" v-model="username" placeholder="请输入手机号" type="number" :attr="{ oninput: 'if(value.length>11)value=value.slice(0,11)' }" /></view></flex-line>
  5. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" v-model="code" placeholder="请输入短信验证码" type="number" :attr="{ oninput: 'if(value.length>6)value=value.slice(0,6)' }" /><view @click="sendVerifyCodeMobile" class="div common-btn send-btn">{{sendStateTextMobile}}</view></view></flex-line>
  6. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="password" placeholder="设置密码" maxlength="20" /></view></flex-line>
  7. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="confirmPassword" placeholder="确认密码" maxlength="20" /><label v-if="!confirmPassword" class="tips">6-20位数字/字母/符号</label></view></flex-line>
  8. </view>
  9. <view class="div common-btn ds-button-large mt-10 mb-10" @click="onSubmit">注册</view>
  10. <view class="div link-wrapper">
  11. <text class="span left-text">点击注册表示同意</text>
  12. <text class="span right-text" @click="onAgreement">《用户协议》</text>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import { urlencode } from '@/util/common'
  18. import { mapState, mapMutations } from 'vuex'
  19. import { registerByMobile } from '../../../api/memberRegister'
  20. import { getSmsCaptcha } from '../../../api/common'
  21. import flexLine from '../../flexLine'
  22. export default {
  23. name: 'RegisterByMobile',
  24. data () {
  25. return {
  26. username: '',
  27. code: '',
  28. password: '',
  29. confirmPassword: '',
  30. aggrementUrl: '',
  31. verifyCodeMobile: '',
  32. canSendMobile: true,
  33. timeIntervalMobile: false,
  34. sendStateTextMobile: '发送'
  35. }
  36. },
  37. components: {
  38. flexLine
  39. },
  40. mounted () {
  41. },
  42. created: function () {
  43. },
  44. computed: {
  45. ...mapState({
  46. inviter_id: state => state.member.inviterId
  47. })
  48. },
  49. beforeDestroy: function () {
  50. clearInterval(this.timeIntervalMobile)
  51. },
  52. methods: {
  53. ...mapMutations({
  54. saveAuthInfo: 'memberLogin'
  55. }),
  56. goBack () {
  57. uni.navigateBack({delta:1})
  58. },
  59. goProfile () {
  60. uni.navigateBack({delta:2})
  61. },
  62. goProfileAdd () {
  63. uni.navigateTo({ url: 'profileAdd' })
  64. },
  65. sendVerifyCodeMobile () {
  66. if (!this.username) {
  67. uni.showToast({icon:'none',title: '请先输入手机号'})
  68. return
  69. }
  70. if (!this.canSendMobile) {
  71. return
  72. }
  73. getSmsCaptcha(1, this.username).then(res => {
  74. this.canSendMobile = false
  75. let second = 60
  76. uni.showToast({icon:'none',title: res.message})
  77. let _this = this
  78. this.timeIntervalMobile = setInterval(function () {
  79. if (second <= 0) {
  80. _this.canSendMobile = true
  81. _this.sendStateTextMobile = '发送'
  82. clearInterval(_this.timeIntervalMobile)
  83. } else {
  84. _this.sendStateTextMobile = second + 's'
  85. }
  86. second--
  87. }, 1000)
  88. }).catch(function (error) {
  89. uni.showToast({icon:'none',title: error.message})
  90. })
  91. },
  92. check () {
  93. let username = this.username
  94. let code = this.code
  95. let password = this.password
  96. let confirmPassword = this.confirmPassword
  97. if (username.length === 0) {
  98. uni.showToast({icon:'none',title: '请输入手机号'})
  99. return false
  100. }
  101. if (code.length === 0) {
  102. uni.showToast({icon:'none',title: '请输入验证码'})
  103. return false
  104. }
  105. if (code.length !== 6) {
  106. uni.showToast({icon:'none',title: '请输入6位验证码'})
  107. return false
  108. }
  109. if (password.length === 0) {
  110. uni.showToast({icon:'none',title: '请输入密码'})
  111. return false
  112. }
  113. if (password.length < 6 || password.length > 20) {
  114. uni.showToast({icon:'none',title: '请输入6-20个字符的密码'})
  115. return false
  116. }
  117. if (confirmPassword.length === 0) {
  118. uni.showToast({icon:'none',title: '请输入确认密码'})
  119. return false
  120. }
  121. if (password.length !== confirmPassword.length) {
  122. uni.showToast({icon:'none',title: '确认密码与输入密码不一致'})
  123. return false
  124. }
  125. if (password !== confirmPassword) {
  126. uni.showToast({icon:'none',title: '确认密码与输入密码不一致'})
  127. return false
  128. }
  129. return true
  130. },
  131. signup () {
  132. if (!this.check()) {
  133. return
  134. }
  135. uni.showLoading({ title: '加载中' })
  136. let inviterId = this.inviter_id // 获取邀请人id
  137. registerByMobile(this.username, this.password, this.confirmPassword, this.code, inviterId).then(
  138. response => {
  139. uni.hideLoading()
  140. this.saveAuthInfo({ token: response.result.token, info: response.result.info })
  141. uni.navigateTo({ url: '/pages/member/index/Index' })
  142. },
  143. error => {
  144. uni.hideLoading()
  145. uni.showToast({icon:'none',title: error.message})
  146. }
  147. )
  148. },
  149. onSubmit () {
  150. this.signup()
  151. },
  152. onAgreement () {
  153. uni.navigateTo({ url: '/pages/home/article/Document'+'?'+urlencode( { type: '' })})
  154. }
  155. }
  156. }
  157. </script>
  158. <style scoped lang="scss">
  159. .ds-button-large{margin:0 $pageSpace}
  160. .container {
  161. display: flex;
  162. flex-direction: column;
  163. justify-content: flex-start;
  164. align-items: stretch;
  165. //background-color: $primaryColor;
  166. .input-wrapper {
  167. font-size:$subFontSize;
  168. display: flex;
  169. flex-direction: row;
  170. align-content: flex-start;
  171. align-items: center;
  172. background-color: #fff;
  173. height:2.2rem;
  174. padding-left:0.5rem;
  175. input {
  176. flex: 1;
  177. }
  178. .bottom-input {
  179. border-bottom-width: 0;
  180. }
  181. .img{height:1.75rem}
  182. }
  183. .link-wrapper {
  184. display: flex;
  185. flex-direction: row;
  186. justify-content: center;
  187. align-items: stretch;
  188. .span {
  189. font-size:$subFontSize;
  190. display: flex;
  191. flex-direction: row;
  192. justify-content: center;
  193. align-items: center;
  194. }
  195. .left-text {
  196. color: $descTextColor;
  197. }
  198. .right-text {
  199. color: $primaryColor;
  200. }
  201. }
  202. }
  203. .top-wrapper {margin:0 $pageSpace;}
  204. .bottom-wrapper {margin-top:0.5rem;}
  205. .tips {
  206. color: $descTextColor;
  207. font-size:$fontSize;
  208. white-space: nowrap;
  209. position: absolute;
  210. right: 0;
  211. top:50%;
  212. margin-top:-.3rem;
  213. }
  214. .countdown {min-width:4rem;margin-right:0.5rem;}
  215. .send-btn{border:1px solid $primaryColor;color:$primaryColor;min-width: 2rem}
  216. .field-line-right{position: relative;
  217. .field-input{
  218. text-align: left !important;
  219. }
  220. }
  221. </style>