jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<template>
    <div class="password">
        <div class="password_tip">
            <img src="@/assets/icon/password_ic_tip@2x.png" alt="" />
            <span>绑定手机号可以更好地保护您的账户安全,保护个人信息不被侵害。</span>
        </div>
        <div class="password_list">
            <div class="password_list_item">
                <span>当前绑定</span>
                <div class="password_list_item_box">
                    <input type="number" disabled v-model="form.currentPhone" maxlength="11">
                </div>
            </div>
            <div class="password_list_item">
                <span>新手机号</span>
                <div class="password_list_item_box">
                    <input type="text" v-model="form.newPhone" maxlength="11" placeholder="请输入新手机号">
                </div>
            </div>
            <div class="password_list_item">
                <span>验证码</span>
                <div class="password_list_item_box">
                    <input type="text" v-model="form.verificationCode" maxlength="4" placeholder="请输入手机验证码">
                    <p @click="getVerificationCode" v-if="!code.isOpen">获取验证码</p>
                    <p @click="getVerificationCode" v-else>{{code.num}}</p>
                </div>
            </div>
        </div>
        <div class="password_footer">
            <button v-preventReClick class="password_footer_submit" @click="submit">
                <span>完成</span>
            </button>
        </div>
    </div>
</template>
 
<script setup lang="ts">
    import { reactive, onBeforeUnmount } from 'vue'
    import { Toast } from 'vant'
    import { useStore } from "vuex"
    import { useRouter } from "vue-router"
    import { REGULAR } from '@/utils/utils'
    import { updatePhoneVerification } from '@/interface'
 
    const router = useRouter()
 
    const store = useStore()
 
    // 表单相关
    let form = reactive<updatePhoneVerification>({
        currentPhone: store.state.userInfo.companyUser.phone,
        newPhone: '',
        verificationCode: ''
    })
 
    // 验证码相关
    let code = reactive<{ num: number, isOpen: boolean, timer: number }>({
        num: 60,
        isOpen: false,
        timer: 0
    })
 
    // 获取验证码
    const getVerificationCode = (): void => {
        code.isOpen = true
        code.timer = setInterval(() => {
            if (code.num === 0) {
                clearInterval(code.timer)
                code.isOpen = false
                code.num = 60
            }
            code.num = code.num - 1
        }, 1000)
    }
 
    const submit = (): void => {
        if (!form.newPhone) {
            Toast({ message: '新手机号不能为空' })
        } else if (!REGULAR.phoneRegular.test(form.newPhone)) {
            Toast({ message: '手机号不合法' })
        } else if (!form.verificationCode) {
            Toast({ message: '验证码不能为空' })
        } else {
            console.log('可以提交')
        }
    }
 
    onBeforeUnmount(() => {
        clearInterval(code.timer)
    })
</script>
 
<style lang="scss" scoped>
    .password {
        position: absolute;
        width: 100%;
        height: 100%;
        background: white;
        .password_tip {
            padding: 20px 30px;
            display: flex;
            background: #F7F7F7;
            box-sizing: border-box;
            img {
                width: 24px;
                height: 24px;
                margin-right: 10px;
                margin-top: 8px;
            }
            span {
                font-size: 24px;
                font-weight: 400;
                color: #666666;
            }
        }
        .password_list {
            padding: 0 30px;
            .password_list_item {
                display: flex;
                align-items: center;
                height: 90px;
                border-bottom: 1PX solid #E5E5E5;
                span {
                    width: 150px;
                    flex-shrink: 0;
                    font-size: 30px;
                    font-weight: 400;
                    color: #222222;
                }
                .password_list_item_box {
                    display: flex;
                    justify-content: space-between;
                    flex: 1;
                    input {
                        border: none;
                        font-size: 30px;
                    }
                    input::-webkit-input-placeholder {
                        font-size: 28px;
                        font-weight: 400;
                        color: #B2B2B2;
                    }
                    p {
                        font-size: 26px;
                        font-weight: 400;
                        color: $nav-color;
                    }
                }
            }
        }
        .password_footer {
            margin-top: 80px;
            padding: 0 30px;
            .password_footer_submit {
                width: 100%;
                height: 88px;
                border: none;
                background: #4275FC;
                box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
                border-radius: 8px;
                display: flex;
                align-items: center;
                justify-content: center;
                span {
                    font-size: 30px;
                    font-weight: 500;
                    color: #FFFFFF;
                }
            }
        }
    }
</style>