doum
18 小时以前 5c3c04b9705db216d199053afc278324ed766f14
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
<template>
    <view class="login">
        <view class="login-image">
            <image src="/static/images/logo@2x.png" mode="widthFix"></image>
        </view>
        <view class="login-list">
            <view class="login-list-item">
                <view class="icon">
                    <image src="/static/icon/login_ic_phone@2x.png" mode="widthFix"></image>
                </view>
                <input :focus='focus' @blur="focus=false" type="text" v-model="form.userName" placeholder="请输入登录账号" />
            </view>
            <view class="login-list-item">
                <view class="icon">
                    <image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
                </view>
                <input :focus='focus1' @blur="focus1=false"    type="safe-password" v-model="form.password" placeholder="请输入密码" />
            </view>
        </view>
        <view class="login-btn" @click="submitDo">立即登录</view>
        <view class="login-info">
            <image src="/static/icon/ic_agree@2x.png" v-if="!radio" @click="changeRadio()" mode="widthFix"></image>
            <image src="/static/icon/ic_agree_sel@2x.png" v-if="radio" @click="changeRadio()"  mode="widthFix"></image>
            <view class="login-info-text">
                我已阅读并同意<text>《鼎元科技用户服务协议》</text>及<text>《鼎元科技用户隐私政策》</text>
            </view>
        </view>
    </view>
</template>
 
<script>
import { mapState } from 'vuex'
    export default {
        computed: {
            ...mapState(['shopInfo', 'shopToken','openid'])
        },
        data() {
            return {
                focus:false,
                focus1:false,
                loading:false,
                form:{
                    userName:'',
                    password:'',
                    openid:'',
                    memberId:''
                },
                radio:false
            };
        },
        onShow() {
            this.focus=false
            this.focus1=false
            this.form.openid=this.openid
             this.checkShopLogin()
        },
        methods:{
            async checkShopLogin(){
                var that =this
                console.log("shopInfo",this.shopInfo)
                console.log("shopToken",this.shopToken)
                
                console.log("openid",this.openid)
                if( this.shopInfo !=null && this.shopInfo.id!=null && (this.shopToken!=null &&this.shopToken!='')){
                    //验证token是否有效
                    let res = await that.$u.api.getShopInfo({tokenType:1  })
                    if (res.code === 200) {
                        await that.$store.commit('setShopInfo', res.data) 
                        that.jumpShopIndex()
                    }
                }else if( this.openid !=null && this.openid !=''){
                    //优先静默登陆
                    let res = await that.$u.api.shopOpenidLogin(this.form)
                    if (res.code === 200 && res.shop!=null && res.token!=null) {
                        await that.$store.commit('setShopInfo', res.data.shop)
                        await that.$store.commit('setShopToken', res.data.token)
                        that.jumpShopIndex()
                    }
                }
            },  
            changeRadio(){
                this.radio = !this.radio
            },
            submitDo(){
                if(!this.form.userName){
                    uni.showToast({
                        'title': '请输入登录账号',icon:'none'
                    })
                    this.focus=true
                    this.loading=false
                    return
                }
                if(!this.form.password){
                    uni.showToast({
                        'title': '请输入登录密码',icon:'none'
                    })
                    this.focus1=true
                    this.loading=false
                    return
                }
                if(!this.radio){
                    uni.showToast({
                        'title': '请先仔细阅读并同意用户协议和隐私政策',icon:'none'
                    })
                    this.loading=false
                    return
                }
                var that =this
                this.$u.api.shopPasswordLogin(this.form)
                    .then(res => {
                        if (res.code === 200) { 
                            that.$store.commit('setShopInfo', res.data.shop)
                            that.$store.commit('setShopToken', res.data.token)
                            that.jumpShopIndex()
                        }
                    })
            },
            jumpShopIndex() {
                uni.navigateTo({
                    url: '/pages/distributor/distributor'
                })
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .login {
        width: 100%;
        padding: 0 60rpx;
        box-sizing: border-box;
        .login-image {
            width: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 162rpx;
            image {
                width: 400rpx;
            }
        }
        .login-list {
            width: 100%;
            margin-top: 160rpx;
            .login-list-item {
                width: 100%;
                height: 100rpx;
                display: flex;
                align-items: center;
                justify-content: space-between;
                border-bottom: 1rpx solid #E5E5E5;
                .icon {
                    width: 40rpx;
                    height: 40rpx;
                    flex-shrink: 0;
                    margin-right: 20rpx;
                    image {
                        width: 100%;
                    }
                }
                input {
                    flex: 1;
                    height: 100%;
                    font-weight: 400;
                    font-size: 30rpx;
                    color: #111111;
                }
                text {
                    font-weight: 400;
                    font-size: 28rpx;
                    color: #004096;
                    margin-left: 20rpx;
                }
            }
        }
        .login-btn {
            width: 100%;
            height: 88rpx;
            line-height: 88rpx;
            text-align: center;
            background: #004096;
            border-radius: 44rpx;
            font-weight: 600;
            font-size: 32rpx;
            color: #FFFFFF;
            margin-top: 60rpx;
        }
        .login-info {
            width: 100%;
            display: flex;
            align-items: flex-start;
            margin-top: 60rpx;
            image {
                width: 36rpx;
                height: 36rpx;
                flex-shrink: 0;
                margin-right: 14rpx;
            }
            .login-info-text {
                flex: 1;
                font-weight: 400;
                font-size: 24rpx;
                color: #555555;
                text {
                    color: #2E68C4;
                }
            }
        }
    }
</style>