replacePhone.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="forget-pass">
  3. <navbar ref="navbar" :config="config" backColor="#666"></navbar>
  4. <form @submit="formSubmit">
  5. <view class="used-phone">
  6. <view class="user-phone-item">
  7. 旧手机号
  8. </view>
  9. <input type="text" name="usedPhone" value="" v-model="userPhone" disabled="true" placeholder-style="color:#cccccc; font-size:28rpx;" maxlength="11" @input="onUsedPhone" placeholder="请输入您以前的手机号"/>
  10. </view>
  11. <view class="background">
  12. </view>
  13. <view class="phone">
  14. <view class="phone-item">
  15. 新手机号
  16. </view>
  17. <input type="number" name="phone" value="" placeholder-style="color:#cccccc; font-size:28rpx;" maxlength="11" @input="onPhone" placeholder="请输入您的新的手机号码"/>
  18. </view>
  19. <view class="verification-code">
  20. <view class="verification-item">
  21. 验证码
  22. </view>
  23. <input type="text" name="code" value="" placeholder-style="color:#cccccc; font-size:28rpx;" maxlength="6" @input="onCode" placeholder="请输入您的验证码"/>
  24. <button class="verification-right" :disabled="disabled" @click="obtainCode" :class="isPhone?'active':''">
  25. {{verificationCode}}
  26. </button>
  27. </view>
  28. <view class="button">
  29. <button form-type="submit">确认提交</button>
  30. </view>
  31. </form>
  32. </view>
  33. </template>
  34. <script>
  35. import {getVerfityCode,changeMobile} from "@/api/login.js"
  36. export default{
  37. data(){
  38. return{
  39. config: {
  40. back: true, //false是tolbar页面 是则不写
  41. title: '更换手机号',
  42. color: '#1A1A1A',
  43. //背景颜色;参数一:透明度(0-1);参数二:背景颜色(array则为线性渐变,string为单色背景)
  44. backgroundColor: [1, "#fff"],
  45. statusBarFontColor: '#1A1A1A',
  46. // backTabPage: "/pages/index/my"
  47. },
  48. phone:"", //手机号
  49. usedPhone:"",//旧手机号
  50. usedIsPhone:false,
  51. isPhone:false,//手机号正则
  52. code:"", //验证码
  53. disabled:false,
  54. time:60,
  55. verificationCode:"发送验证码",
  56. userPhone:null
  57. }
  58. },
  59. onLoad() {
  60. this.getUserInfo()
  61. },
  62. methods:{
  63. getUserInfo() {
  64. this.$http.get("/account/app-info").then(res => {
  65. if(res&&res.code==200){
  66. console.log(res.data.mobile)
  67. this.userPhone = res.data.mobile
  68. }
  69. })
  70. },
  71. //获取验证码
  72. obtainCode(){
  73. console.log(666)
  74. if(this.isPhone){
  75. this.$http.get("/account/verify-mobile/"+this.phone).then(res=>{
  76. if(res&&res.code==200){
  77. if(res.data==true){
  78. this.$mUtil.toast("该手机号已被注册")
  79. }else{
  80. this.$http.post(getVerfityCode,this.phone).then(res=>{
  81. if(res&&res.code==200){
  82. this.disabled=false;
  83. this.isPhone=false;
  84. this.verificationCode=this.time+"s";
  85. this.clear=setInterval(this.countDown,1000);
  86. }
  87. })
  88. }
  89. }
  90. })
  91. }
  92. },
  93. countDown(){
  94. if(this.time<=0){
  95. this.disabled=false;
  96. this.verificationCode="重新获取";
  97. this.isPhone=true;
  98. this.time=60;
  99. clearInterval(this.clear)
  100. }else{
  101. --this.time;
  102. this.verificationCode=this.time+'s'
  103. }
  104. },
  105. //清楚计时器
  106. beforeDestroy(){
  107. clearInterval(this.clear)
  108. },
  109. //手机号
  110. onPhone(e){
  111. this.phone=e.detail.value
  112. if(this.phone.match(this.$mConfig.telRegex)){
  113. if(this.verificationCode=='发送验证码'||this.verificationCode=='重新获取'){
  114. this.isPhone=true
  115. }
  116. }else{
  117. this.isPhone=false
  118. }
  119. },
  120. //旧手机号
  121. onUsedPhone(e){
  122. this.usedPhone= e.detail.value
  123. if(this.usedPhone.match(this.$mConfig.telRegex)){
  124. this.usedIsPhone=true
  125. }else{
  126. this.usedIsPhone=false
  127. }
  128. },
  129. //验证码
  130. onCode(e){
  131. this.code=e.detail.value
  132. },
  133. //提交信息
  134. formSubmit(e){
  135. let target = e.detail.value;
  136. if(!target.usedPhone){
  137. this.$mUtil.toast('请输入旧手机号')
  138. return false
  139. }
  140. if(!target.phone){
  141. this.$mUtil.toast("请输入新手机号")
  142. return false
  143. }
  144. if(target.phone==target.usedPhone){
  145. this.$mUtil.toast('新手机号和旧手机号相同')
  146. return false
  147. }
  148. if(!(target.phone.match(this.$mConfig.telRegex))){
  149. this.$mUtil.toast("请输入正确的手机号")
  150. return false
  151. }
  152. if(!target.code){
  153. this.$mUtil.toast("请输入验证码")
  154. return false
  155. }
  156. let param= {
  157. mobile:target.usedPhone,
  158. new_mobile:target.phone,
  159. captcha:target.code
  160. }
  161. this.$http.get("/account/verify-mobile/"+param.new_mobile).then(res=>{
  162. if(res &&res.code==200){
  163. if(res.data==true){
  164. this.$mUtil.toast("该手机号已被注册")
  165. }else{
  166. this.$http.post(changeMobile,param)
  167. .then(res=>{
  168. if(res.code==200){
  169. this.$mUtil.toast("修改成功")
  170. setTimeout(()=>{
  171. uni.reLaunch({
  172. url:"../register/login"
  173. })
  174. },2000)
  175. this.$mUtil.toast("修改成功")
  176. }
  177. })
  178. }
  179. }
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. .used-phone{
  187. display: flex;
  188. align-items: center;
  189. align-items: center;
  190. margin: 0 30rpx;
  191. padding: 30rpx 0;
  192. .user-phone-item{
  193. font-size: 28rpx;
  194. color: #1A1A1A;
  195. font-weight: 400;
  196. }
  197. input{
  198. flex: 1;
  199. margin-left: 60rpx;
  200. }
  201. }
  202. .button{
  203. margin: 700rpx 30rpx 0 30rpx;
  204. button{
  205. font-size: 36rpx;
  206. color: #ffffff;
  207. font-weight: 400;
  208. background-color: #FA6138;
  209. border-radius: 43rpx;
  210. }
  211. }
  212. .phone{
  213. margin: 0 30rpx;
  214. display: flex;
  215. padding: 27rpx 0 30rpx 0;
  216. align-items: center;
  217. border-bottom: 1rpx solid #E6E6E6;
  218. .phone-item{
  219. font-size: 28rpx;
  220. font-weight: 400;
  221. color: #1A1A1A;
  222. }
  223. input{
  224. flex: 1;
  225. margin-left: 60rpx;
  226. }
  227. }
  228. .verification-code{
  229. margin: 0 30rpx;
  230. display: flex;
  231. align-items: center;
  232. padding: 12rpx 0;
  233. border-bottom: 1rpx solid #E6E6E6;
  234. .verification-item{
  235. font-size: 28rpx;
  236. font-weight: 400;
  237. color: #1A1A1A;
  238. }
  239. input{
  240. flex: 1;
  241. margin-left: 88rpx;
  242. }
  243. .verification-right{
  244. font-size: 28rpx;
  245. color: #999999;
  246. background-color: #F5F5F5;
  247. font-weight: 400;
  248. border: 1rpx solid #b3b3b3;
  249. border-radius: 36rpx;
  250. padding: 0 30rpx;
  251. }
  252. .active{
  253. background-color: #FA6138;
  254. color: #FFFFFF;
  255. }
  256. }
  257. .background{
  258. height: 10rpx;
  259. background-color: #F5F5F5;
  260. }
  261. .new-pass{
  262. margin: 0 30rpx;
  263. display: flex;
  264. align-items: center;
  265. padding: 23rpx 0 30rpx 0;
  266. border-bottom: 1rpx solid #E6E6E6;
  267. .new-pass-item{
  268. font-size: 28rpx;
  269. color: #1A1A1A;
  270. font-weight: 400;
  271. }
  272. input{
  273. flex: 1;
  274. margin-left: 88rpx;
  275. }
  276. }
  277. .confirm-pass{
  278. margin: 0 30rpx;
  279. display: flex;
  280. padding: 34rpx 0 30rpx 0 ;
  281. border-bottom: 1rpx solid #E6E6E6;
  282. .confirm-pass-item{
  283. font-size: 28rpx ;
  284. font-weight: 400;
  285. color: #1A1A1A;
  286. }
  287. input{
  288. flex: 1;
  289. margin-left: 60rpx;
  290. }
  291. }
  292. </style>