SendSmsCode.vue 1.4 KB
Newer Older
1
<template>
2
    <el-button @click="send" :disabled="leftTime > 0 && leftTime < 60">{{text}}</el-button>
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
</template>
<script>
import {sendSmsCode} from '@/api/ecw/orderCargoControl'
const timeout = null
export default {
    props:{
        orderId: [String, Number],
        scene: [String, Number]
    },
    data(){
        return {
            leftTime: 60,
            loading: false
        }
    },
    computed:{
        text(){
            if(this.leftTime === 60){
21
                return this.$t('发送验证码')
22 23 24 25
            }
            if(this.leftTime > 0){
                return this.leftTime + ''
            }
26
            return this.$t('重新发送')
27 28 29 30 31 32 33 34 35 36 37 38 39
        }
    },
    destroyed(){
        if(timeout)clearTimeout(timeout)
    },
    methods:{
        send(){
            if(this.loading || (this.leftTime > 0 && this.leftTime < 60)) return false
            this.loading = true
            sendSmsCode({
                orderId: this.orderId,
                scene: this.scene
            }).then(res => {
40
                this.$message.success(this.$t('发送成功'))
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
                this.countDown()
            }).finally(res => {
                this.loading = false
            })
        },
        countDown(){
            this.leftTime --
            if(this.leftTime <= 0){
                return false 
            }
            timeout = setTimeout(this.countDown, 1000)
        }
    }
}
</script>