jialh
2025-08-20 2d2756dc0e61ed8cd38c2796daf5cacdfdd49bf2
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
<template>
    <view class="">
        <view class="flex justify-center logo">
            <view class="cu-avatar xl round margin-left logo-lage" :style="{backgroundImage: 'url(' + logoUrl + ')' }">
            </view>
        </view>
 
        <view class="margin-top padding-left padding-right radius" v-if="!loginByPhone">
            <view class="cu-form-group margin-top">
                <view class="title">用户名</view>
                <input placeholder="请输入姓名/手机号" name="input" v-model="username"></input>
            </view>
            <view class="cu-form-group border-bottom">
                <view class="title">密码</view>
                <input placeholder="请输入密码" type="password" name="input" v-model="password"></input>
            </view>
        </view>
        <view class="margin-top padding-left padding-right radius" v-else>
            <view class="cu-form-group margin-top">
                <view class="title">手机号</view>
                <input placeholder="请输入手机号" name="input" v-model="username"></input>
            </view>
            <view class="cu-form-group border-bottom">
                <view class="title">验证码</view>
                <input v-model="password" placeholder="请输入短信验证码" name="input"></input>
                <button class='cu-btn bg-blue shadow' :disabled="btnDisabled"
                    @click="sendMsgCode()">{{btnValue}}</button>
            </view>
        </view>
 
        <view class="padding flex flex-direction margin-top">
            <button class="cu-btn bg-blue lg" @click="_doLogin()">登录</button>
            <!-- #ifdef MP-WEIXIN -->
            <!-- <wechat-login ref="wechatLoginRef"></wechat-login> -->
            <!-- #endif -->
        </view>
        <!-- #ifdef H5 -->
        <view class="padding-lr flex justify-between">
            <view class="text-green" @click="_doLoginPhone()">{{phoneLoginName}}</view>
            <view class="text-green" @click="_doRegister()">注册</view>
        </view>
        <!-- #endif -->
 
    </view>
</template>
 
<script>
    var _this;
    import wInput from '../../components/watch-input.vue' //input
    import wButton from '../../components/watch-button.vue' //button
    import {
        sendSmsCode,
        ownerLogin,
    } from '../../api/user/userApi.js'
    import context from '../../lib/java110/Java110Context.js';
 
    import {
 
        getLoginCode
    } from '../../lib/java110/page/Page.js';
 
    import {
        saveOwnerStorage,
        saveUserLoginInfo,
        removeUserLoginInfo,
        getWAppId,
        saveWAppId,
        getLoginFlag
    } from '@/lib/java110/utils/StorageUtil.js';
    // import wechatLogin from '@/components/user/wechat-login.vue';
 
    const constant = context.constant;
    const factory = context.factory;
 
    const login = 1; //1标识登录页面 请下发code 不要下发key
    export default {
        data() {
            return {
                logoUrl: '',
                username: '',
                password: '',
                code: "",
                loginByPhone: false,
                msgCode: '',
                btnDisabled: false,
                btnValue: '验证码',
                phoneLoginName: '验证码登录'
 
            };
        },
        onLoad(option) {
            let that = this;
            this.logoUrl = constant.url.baseUrl + 'logo.png';
            let wAppId = uni.getStorageSync(constant.mapping.W_APP_ID);
            //todo 清除缓存内容,以防 业主后退,然后还显示他的东西 
            uni.clearStorageSync();
            if (wAppId) {
                uni.setStorageSync(constant.mapping.W_APP_ID, wAppId);
            }
            // #ifdef MP-WEIXIN
            setTimeout(function() {
                that.$refs.wechatLoginRef._initWechatLogin();
            }, 1000)
            // #endif
        },
        // components: {
        //     wechatLogin
        // },
        methods: {
            _doLogin: function() {
                let _that = this;
                if (this.username == '') {
                    wx.showToast({
                        title: '请填写用户名',
                        icon: "none"
                    });
                    return;
                }
                if (this.password == '') {
                    wx.showToast({
                        title: '请填写密码',
                        icon: "none"
                    });
                    return;
                }
                let _obj = {
                    username: this.username,
                    password: this.password,
                    code: _that.code,
                    appId: this.vc.getWAppId(),
                    loginByPhone: this.loginByPhone
                };
                ownerLogin(this, _obj)
                    .then((_user) => {
                        //todo 保存登录信息
                        if (_user.auditState == "11000") {
                            saveUserLoginInfo(_user.userId, _user.token, _user.key);
                            uni.navigateTo({
                                url: '/pages/index/authOwnerLog'
                            })
                        } else if (_user.auditState == "10000") {
                            uni.showToast({
                                icon: 'none',
                                title: '您提交的房屋认证审核中,请联系物业管理人员'
                            })
                        } else if (_user.auditState == "13000") {
                            uni.showToast({
                                icon: 'none',
                                title: '您提交的房屋认证审核失败,请联系物业管理人员'
                            })
                        } else {
                            saveUserLoginInfo(_user.userId, _user.token, _user.key);
                            uni.navigateTo({
                                url: '/pages/login/loginInitWechat?communityId=' + _user.communityId
                            })
                        }
                    }, err => {
                        wx.showToast({
                            icon: 'none',
                            title: err
                        })
                    });
            },
            _doRegister: function() {
                //let _url = '/pages/login/registerByWechat';
                let _url = '/pages/login/register';
                this.vc.navigateTo({
                    url: _url
                })
            },
            sendMsgCode: function() {
                sendSmsCode(this.username, this);
            },
            _doLoginPhone: function() {
                this.loginByPhone = !this.loginByPhone;
                if (this.loginByPhone) {
                    this.phoneLoginName = "密码登录"
                } else {
                    this.phoneLoginName = "验证码登录"
                }
                this.username = '';
                this.password = '';
            }
 
        }
    }
</script>
 
<style>
    page {
        background-color: #FFF;
    }
 
    .logo {
        margin-top: 160upx;
        margin-bottom: 140upx;
    }
 
    .logo .logo-lage {
        height: 180upx;
        width: 180upx;
    }
 
    .login-nav {
        background-color: #00AA00;
        height: 120upx;
    }
 
    .login-nav text {
        color: #FFFFFF;
        font-size: 30upx;
    }
</style>