<template>
|
<GlobalWindow
|
:title="title"
|
width="40%"
|
:visible.sync="visible"
|
:confirm-working="isWorking"
|
@confirm="confirm"
|
>
|
<el-form :model="form" ref="form" :rules="rules">
|
<el-form-item label="手机号" prop="phone">
|
<el-input v-model="form.phone" placeholder="请输入" disabled v-trim/>
|
</el-form-item>
|
<el-form-item label="验证码" prop="code">
|
<div style="width: 100%; display: flex; align-items: center;">
|
<el-input v-model="form.code" placeholder="请输入" v-trim/>
|
<el-button type="primary" style="margin-left: 15px;" @click="send" v-if="num === 0">发送验证码</el-button>
|
<el-button type="primary" style="margin-left: 15px;" v-else>{{num}}</el-button>
|
</div>
|
</el-form-item>
|
</el-form>
|
</GlobalWindow>
|
</template>
|
|
<script>
|
import BaseOpera from '@/components/base/BaseOpera'
|
import GlobalWindow from '@/components/common/GlobalWindow'
|
import { sendSms, validateCode } from '@/api/business/smsEmail'
|
import { mapState } from 'vuex'
|
export default {
|
name: 'operaverifyPhoneNumberWindew',
|
extends: BaseOpera,
|
components: { GlobalWindow },
|
data () {
|
return {
|
form: {
|
phone: this.$store.state.userInfo.company.phone,
|
code: ''
|
},
|
rules: {
|
code: [
|
{ required: true, message: '请输入验证码' }
|
]
|
},
|
num: 0,
|
timer: null
|
}
|
},
|
computed: {
|
...mapState(['userInfo'])
|
},
|
methods: {
|
open (title) {
|
this.title = title
|
this.num = 0
|
clearInterval(this.timer)
|
this.timer = null
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.form.resetFields()
|
})
|
},
|
send () {
|
sendSms({
|
phone: this.form.phone
|
}).then(res => {
|
this.num = 60
|
this.setTime()
|
})
|
},
|
setTime () {
|
this.timer = setInterval(() => {
|
if (this.num === 0) {
|
clearInterval(this.timer)
|
this.timer = null
|
return
|
}
|
this.num = this.num - 1
|
}, 1000)
|
},
|
confirm () {
|
this.$refs.form.validate((valid) => {
|
if (!valid) {
|
return
|
}
|
this.isWorking = true
|
validateCode({
|
code: this.form.code
|
}).then(res => {
|
this.visible = false
|
this.$tip.apiSuccess('操作成功')
|
this.$emit('success')
|
}).catch(e => {
|
this.$tip.apiFailed(e)
|
}).finally(() => {
|
this.isWorking = false
|
})
|
})
|
}
|
}
|
}
|
</script>
|