Files
ebiz-h5/src/components/ebiz/question/ShortMessage.vue
2020-08-24 09:11:25 +08:00

236 lines
5.3 KiB
Vue

<template>
<div :class="{ message: 1, show }">
<div class="box">
<div class="title">短信验证</div>
<div class="content">
<p>{{ text }}</p>
<div class="enter" v-if="type === 'confirm'">
<input type="text" v-model="code" placeholder="请输入短信验证码" maxlength="6" />
<button type="button" @click="getMessage" v-no-more-click="3000">
{{ sendTime === 0 ? '获取验证码' : sendTime + 's后重新获取' }}
</button>
</div>
</div>
<div class="bottom">
<div @click="cancel" v-if="type === 'confirm'">取消</div>
<div @click="confirm" :style="{ width: type === 'alert' ? '100%' : '50%' }">确定</div>
</div>
</div>
</div>
</template>
<script>
import { getAuthCode, autchCodeCheck } from '@/api/ebiz/sale/sale'
export default {
name: 'shortMessage',
props: {
show: {
type: Boolean,
default: false
},
text: {
type: String,
default: ''
},
type: {
type: String,
default: 'confirm'
},
sendTime: {
type: Number,
default: 0
}
},
data() {
return {
code: '',
sid: '',
getCaptcha: false,
timer: null
}
},
watch: {
show(n) {
if (n)
return (document.body.style.cssText = `
overflow-y:hidden;
height:100vh;
`)
document.body.style.cssText = `
overflow-y:visible;
height:auto;
`
},
sendTime(nv) {
console.log('time change ... ', this.sendTime)
if (nv === 0) {
clearInterval(this.timer)
this.timer = null
}
if (!this.timer) {
this.timer = setInterval(() => {
if (this.sendTime === 0) {
console.log('clear timer...')
clearInterval(this.timer)
this.timer = null
} else {
this.$emit('update:sendTime', this.sendTime - 1)
}
}, 1000)
}
}
},
methods: {
cancel() {
clearInterval(this.timer)
this.timer = null
this.$emit('update:sendTime', 0)
this.code = ''
this.getCaptcha = false
this.$emit('update:show', false)
},
async confirm() {
if (!this.getCaptcha) {
return this.$toast('请先获取验证码')
}
if (!this.code.trim()) {
return this.$toast('请输入验证码')
}
let res = await autchCodeCheck({
smsId: this.sid,
code: this.code
})
console.log(res)
if (res.result === '0') {
this.$emit('getMessage', {
type: 'confirm',
data: true
})
clearInterval(this.timer)
this.timer = null
this.$emit('update:sendTime', 0)
} else {
this.$toast(res.resultMessage)
}
this.code = ''
},
async getMessage() {
if (this.sendTime !== 0) return
this.getCaptcha = true
let data = {
operateType: 'appntInfoEntry',
type: 'H5',
operateCode: 18222023301,
system: 'agentApp',
operateCodeType: '0'
}
//获取验证码
let res = await getAuthCode(data)
if (res.result === '0') {
this.$toast('获取验证码成功')
}
this.sid = res.sessionId
this.$emit('update:sendTime', 60)
}
}
}
</script>
<style lang="scss" scoped>
.message {
position: fixed;
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
top: 0;
left: 0;
z-index: -1;
visibility: hidden;
transition: all 0.2s ease 0.2s;
opacity: 0;
&.show {
z-index: 9;
visibility: visible;
opacity: 1;
transition: all 0.2s;
.box {
transform: translateY(0);
transition: all 0.2s ease 0.2s;
}
}
.box {
width: 300px;
// height: 200px;
background: #fff;
border-radius: 10px;
position: relative;
overflow: hidden;
transform: translateY(-10px);
transition: all 0.2s;
padding-bottom: 40px;
.title {
text-align: center;
font-size: 14px;
color: #e4393c;
padding: 10px 0;
}
.content {
padding: 0 10px 15px;
p {
font-size: 13px;
padding: 10px 0 15px 0;
}
.enter {
border-bottom: 1px solid #eee;
padding: 0 10px 5px;
display: flex;
justify-content: space-between;
input,
button {
border: 0;
height: 30px;
}
input {
width: 150px;
font-size: 14px;
}
button {
background: 0;
border: 1px solid #e4393c;
color: #e4393c;
font-size: 13px;
text-align: center;
width: 90px;
border-radius: 4px;
flex-shrink: 0;
}
}
}
.bottom {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
display: flex;
div {
width: 50%;
height: 40px;
box-sizing: border-box;
text-align: center;
line-height: 40px;
&:first-child {
border-radius: 0 0 0 10px;
border: 1px solid #e4393c;
color: #e4393c;
}
&:last-child {
color: #fff;
background: #e4393c;
}
}
}
}
}
</style>