updateMobile.js
2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import userApi from '@/api/user'
import {Button, Cell, CellGroup, Col, Field, NavBar, Row, Toast} from 'vant'
import store from '@/store'
import util from '@/utils/util'
import storage from '@/utils/storage'
export default {
components: {
[Row.name]: Row,
[Col.name]: Col,
[Button.name]: Button,
[Cell.name]: Cell,
[CellGroup.name]: CellGroup,
[NavBar.name]: NavBar,
[Field.name]: Field,
[Toast.name]: Toast
},
data() {
return {
oldMobile: '',
oldMobileSmsCode: '',
showOldMobileSmsCode: false,
hasSendSms: false,
second: 60,
showSendBtn: true,
showConfirmBtn: false
}
},
mounted() {
this.init()
},
methods: {
init() {
const user = storage.getUser()
this.oldMobile = util.formatMobile(user.mobile)
},
onClickLeft() {
this.$router.go(-1)
},
sendSmsCode() {
this.showSendBtn = false
this.showConfirmBtn = true
this.hasSendSms = true
this.showOldMobileSmsCode = true
userApi.sendSmsCode(this.oldMobile).then( response => {
this.setTimeOut()
const smsCode = response.data
Toast('提示:测试阶段不发送短信验证码:'+smsCode)
})
},
setTimeOut() {
let timer = setTimeout(() => {
this.setTimeOut()
if (this.second > 0) {
this.second--
}
}, 1000)
if (this.second <= 0) {
this.hasSendSms = false
this.second = 60
clearTimeout(timer)
}
},
confirmOldMobileSmsCode() {
Toast('敬请期待')
},
submit() {
Toast('敬请期待')
return
if (!this.userName || this.userName === '') {
Toast('请输入姓名')
return
}
userApi.updateUserName(this.userName).then(response => {
store.dispatch('app/toggleUser', response.data)
this.$router.go(-1)
})
}
}
}