phone.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. <template>
  2. <view class="all">
  3. <u-navbar title="修改手机号"></u-navbar>
  4. <view class="login-form">
  5. <view class="login-form-item">
  6. <view class="input">
  7. <u-input :customStyle="placeholderStyle" :placeholderStyle="placeholderStyle" v-model="form.telephone" type="number" placeholder="请输入手机号" placeholder-style="font-size:16px;color:#ccc;"/>
  8. </view>
  9. </view>
  10. <view class="login-form-item">
  11. <view class="input">
  12. <u-input :customStyle="placeholderStyle" :placeholderStyle="placeholderStyle" v-model="form.verifyCode" type="number" placeholder="请输入验证码" placeholder-style="font-size:16px;color:#ccc;"/>
  13. <view class="code" @click="getCode">{{codeTips}}</view>
  14. </view>
  15. </view>
  16. </view>
  17. <u-button class="login-btn" type="success" shape="circle" @click="sure">确定修改</u-button>
  18. <u-verification-code :seconds="sendMsgSecond" ref="uCode" @change="codeChange" @end="end" @start="start" change-text="已发送(Xs)">
  19. </u-verification-code>
  20. </view>
  21. </template>
  22. <script>
  23. import * as userApi from '@/apis/user.js'
  24. import * as loginApi from '@/apis/login.js'
  25. import {
  26. checkPhone
  27. } from '@/utils'
  28. export default {
  29. data() {
  30. return {
  31. elderMode:false,
  32. placeholderStyle:{
  33. 'font-size':'28rpx'
  34. },
  35. form: {
  36. telephone: '',
  37. verifyCode: '',
  38. },
  39. isSendMsgIng: false,
  40. sendMsgSecond: 60,
  41. codeTips: '',
  42. jpcode: 'toLogin',
  43. }
  44. },
  45. methods: {
  46. codeChange(text) {
  47. this.codeTips = text;
  48. },
  49. start() {
  50. if (!this.isSendMsgIng) {
  51. uni.showLoading({
  52. title: "加载中",
  53. mask: true,
  54. })
  55. loginApi.getVerifyCode(this.form.telephone).then((response) => {
  56. uni.hideLoading();
  57. this.carhelp.set("getvcodetime", new Date().getTime());
  58. if (!"") {
  59. //倒计时
  60. uni.showToast({
  61. title: "发送成功"
  62. })
  63. } else {
  64. uni.showToast({
  65. title: "您的验证码已经发送[5分钟有效],请勿重复点击"
  66. })
  67. }
  68. }).catch(error => {
  69. uni.showToast({
  70. title: error,
  71. icon: "none"
  72. })
  73. })
  74. }
  75. },
  76. //倒计时
  77. end() {
  78. this.sendMsgSecond = 60;
  79. this.isSendMsgIng = false;
  80. },
  81. // 获取验证码
  82. getCode() {
  83. if (this.$refs.uCode.canGetCode) {} else {
  84. uni.showToast({
  85. title: '倒计时结束后再发送',
  86. icon: "none"
  87. })
  88. return
  89. }
  90. var checkPhoneResult = checkPhone(this.form.telephone);
  91. if (checkPhoneResult !== true) {
  92. uni.showToast({
  93. title: checkPhoneResult,
  94. })
  95. return;
  96. }
  97. this.$refs.uCode.start();
  98. },
  99. sure() {
  100. var checkPhoneResult = checkPhone(this.form.telephone);
  101. if(!this.form.telephone || checkPhoneResult != true) {
  102. uni.showToast({
  103. title: checkPhoneResult,
  104. icon: "none"
  105. })
  106. return;
  107. }
  108. if(!this.form.verifyCode) {
  109. uni.showToast({
  110. title: "请输入验证码",
  111. icon: "none"
  112. })
  113. return
  114. }
  115. uni.showLoading({
  116. title: "加载中",
  117. mask: true,
  118. })
  119. userApi.changePhone(this.form).then((response) => {
  120. uni.hideLoading();
  121. uni.reLaunch({
  122. url: '/pages/index/index?jpcode=' + this.jpcode
  123. })
  124. }).catch(error => {
  125. uni.showToast({
  126. title: error,
  127. icon: "none"
  128. })
  129. })
  130. },
  131. theme(type) {
  132. if(type == 'elder')
  133. {
  134. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  135. let data = {
  136. "font-size":'32rpx',
  137. };
  138. this.placeholderStyle = data;
  139. }
  140. else
  141. {
  142. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  143. let data = {
  144. "font-size":'28rpx'
  145. };
  146. this.placeholderStyle = data;
  147. }
  148. }
  149. },
  150. onReady(){
  151. this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
  152. if(this.elderMode)
  153. this.theme('elder')
  154. else
  155. this.theme('standard')
  156. }
  157. }
  158. </script>
  159. <style>
  160. page{
  161. background-color: #fff;
  162. }
  163. </style>
  164. <style lang="scss" scoped>
  165. @import "@/_theme.scss";
  166. .all{
  167. @include themeify{
  168. font-size: themed('font-size2');
  169. }
  170. }
  171. .login-form{
  172. background-color: #fff;
  173. padding: 12px 28px;
  174. }
  175. .login-form-item{
  176. .title{
  177. margin-bottom: 8px;
  178. }
  179. .input {
  180. padding: 4px 0;
  181. border-bottom: 1px solid #f7f7f7;
  182. position: relative;
  183. }
  184. .code{
  185. position: absolute;
  186. right: 0;
  187. top:12px;
  188. color:#1677FF;
  189. }
  190. .tips {
  191. color: $u-type-info;
  192. margin-top: 12px;
  193. @include themeify{
  194. font-size: themed('font-size1');
  195. }
  196. /* font-size: 12px;*/
  197. span{
  198. color:#3fbd70;
  199. }
  200. }
  201. }
  202. .login-btn {
  203. margin: 28px ;
  204. background-color:#00B962!important;
  205. border-color: #00B962!important;
  206. color:#fff!important;
  207. }
  208. </style>