wjt
2024-06-22 b668b85e312acc4cfaecc423ff53cf7d919b7cf1
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<!-- 企业登录 -->
<template>
    <view class="companylogin">
        <u-navbar title="" :autoBack="true" bgColor="transparent"> 
            <template slot="center">
                
            </template>
        </u-navbar>
        <view class="image-box">
            <image src="/static/policy/loginHeader.png" mode="widthFix" ></image>
        </view>
        <view class="content-box">
            <!-- <u-form label-width="60" labelAlign="right" >
                <u-form-item label="手机号">
                    <u-input style="width: 80%;" v-model="form.phone" placeholder="请输入"></u-input>
                </u-form-item>
                <u-form-item label="验证码">
                    <u-input style="width: 80%;" v-model="form.code" placeholder="请输入">
                        <template slot="suffix">
                            <u-code ref="uCode" @change="codeChange" seconds="20" changeText="X秒重新获取"></u-code>
                            <u-button @tap="getCode" :text="tips" type="success" size="mini"></u-button>
                        </template>
                    </u-input>
                </u-form-item>
            </u-form> -->
            <view class="form">
                <view class="form-item margin-bottom">
                    <view class="form-label">
                        手机号
                    </view>
                    <view class="form-input">
                        <input type="number"  v-model="form.phone"  placeholder="请输入11位手机号"/>
                    </view>
                </view>
                <view class="form-item">
                    <view class="form-label">
                        验证码
                    </view>
                    <view class="form-input set-flex set-flex-content-between">
                        <input type="number" v-model="form.code"  placeholder="请输入验证码"/>
                        <view @click="getCode">
                            <text class="driver"></text>
                            <text class="getcode">{{tips}}</text>
                        </view>
                    </view>
                </view>
            </view>
            <view style="margin-top: 56rpx;">
                <view class="per-button" @click="loging">登录</view>
            </view>
             <view @click="goRegister" class="company-register" v-if="form.userType == '02'">
                 企业注册
             </view>
            <!-- <u--text text="企业注册" type="primary" @click="goRegister"></u--text> -->
        </view>
    </view>
</template>
 
<script>
    // 00营商办,01执法,02企业 区分不同的登陆页面
    import { getCode, codeLogin, getInfo } from '@/api/auth.js'
    export default {
        data() {
            return {
                tips: '获取验证码',
                form: {
                    phone: '',
                    code: '',
                    userType: '01'
                },
                loginToken: '',
                isSendCode: false,
                countdownTime: 20,
                timer: ''
            }
        },
        onLoad(options) {
            if(options.code) {
                this.form.userType = options.code
            }
        },
        onUnload() {
            if(this.timer) {
                clearTimeout(this.timer)
                this.timer = null
            }
        },
        methods: {
            getCode() {
                if(!this.form.phone){
                    uni.showToast({
                        title: '请输入手机号',
                        icon: 'none'
                    })
                    return
                }
                if(!this.$u.test.mobile(this.form.phone)){
                    uni.showToast({
                        title: '请输入正确的手机号',
                        icon: 'none'
                    })
                    return
                }
                if (!this.isSendCode) {
                    this.isSendCode = true
                    uni.showLoading({
                        title: '正在获取验证码'
                    })
                    getCode({phone: this.form.phone }).then(val => {
                            this.startCountdown()
                            uni.hideLoading();
                            this.tips = `${this.countdownTime}s后重新获取`
                            uni.$u.toast('验证码已发送');
                    })
                } else {
                    uni.$u.toast('倒计时结束后再发送');
                }
            },
            startCountdown() {
                if(this.timer) {
                    clearTimeout(this.timer)
                    this.timer = null
                }
                if(this.countdownTime <= 0) {
                    this.tips = "重新获取"
                    this.isSendCode = false
                    this.countdownTime = 20
                    return
                }
                this.timer = setTimeout(() => {
                    this.countdownTime--
                    this.tips = `${this.countdownTime}s后重新获取`
                    this.startCountdown()
                }, 1000)
            },
            loging() {
                codeLogin(this.form).then(val => {
                    if(val.data.token) {
                        this.loginToken = val.data.token
                        uni.setStorageSync('sessionToken', this.loginToken)
                        this.getInfo()
                    }
                })
            },
            getInfo() {
                getInfo().then(val => {
                    uni.setStorageSync('userInfo',  val.data.data)
                    if(this.form.userType == '02') {
                        uni.redirectTo({
                            url:`/qiye/qiyeIndex/qiyeIndex`
                        })
                    } else if(this.form.userType == '01'){
                        uni.redirectTo({
                            url:`/policy/policyIndex/policyIndex`
                        })
                    } else {
                        uni.redirectTo({
                            url:`/policy/policyIndex/policyIndex`
                        })
                    }
                })
            },
            goRegister() {
                uni.navigateTo({
                    url: `/pages/registerCompany/registerCompany`
                })
            }
        }
    }
</script>
 
<style scoped lang="scss">
    .companylogin {
        &>.image-box {
            width: 100%;
            height: 345rpx;
            text-align: center;
            background-color: #111;
            &>image{
                width: 100%;
                height: 345rpx;
            }
        }
        .content-box{
            border-radius: 40rpx 40rpx 0 0;
            padding: 40rpx 32rpx;
            position: relative;
            top: 80rpx;
            background-color: white;
            .form {
                .form-item{
                    .form-label{
                        font-size: 34rpx;
                        margin: 0 0 24rpx 16rpx;
                    }
                    .form-input{
                        background-color: #F7F7F7;
                        padding: 20rpx;
                        border-radius: 20rpx;
                    }
                }
            }
            .margin-bottom{
                margin-bottom: 36rpx;
            }
            .getcode{
                color: #1171E0;
                font-size: 34rpx;
                font-weight: 500;
                width: 20%;
            }
            .driver{
                display: inline-block;
                vertical-align: middle;
                margin-right: 20rpx;
                width: 2rpx;
                height: 48rpx;
                background-color: #C3C6CD;
            }
        }
        .company-register{
            position: fixed;
            bottom: 32rpx;
            left: 50%;
            transform: translateX(-50%);
            padding: 16rpx 46rpx;
            color: #1171E0;
            display: inline-block;
            border-radius: 12rpx;
            border: 2rpx solid #ABD2FF;
            background: #F0F8FF;
        }
    }
</style>