<template>
    <div>
        <lj-win-common body-class="login-body" :show-back="false" hideAppBar >
            <mu-button v-if="isRelogin" icon slot="header_left" @click="closeWin"><i class="iconfont icon-left"></i>
            </mu-button>
            <div slot="body">
                <div style="margin: 0 auto;width: 80%; margin-bottom: 24px;">
                    <div class="flx-start" style="margin-left: -16px; margin-bottom: -24px;">
                        <img style="width: 128px;height: 128px;" :src="logoSrc" />
                    </div>
                    <div style="display: flex; font-size: 24px;font-weight: bold; text-align: left;">欢迎登录</div>
                    <div style="display: flex; font-size: 24px;font-weight: bold; text-align: left;">金龙恒核价系统</div>
                     <!-- <div style="font-size: 15px;color: #888;">一切尽在掌握中</div> -->
                </div>

                <div style="margin: 0 auto; width: 80%; display: flex; flex-direction: column;">
                    <!-- <div class="input_class">
                        <van-tag class="mode-flag" round v-if="isConnectModeTitle">
                            {{ isConnectModeTitle }}
                        </van-tag>
                        <mu-select label="账套" v-model="currentAccount" @change="accountChange" solo style="min-height: 0px;min-width: 0px;" placeholder="请选择账套" @click="handleSelectAccount">
                            <mu-option v-for="(account, index) in accounts" :key="index" :label="account" :value="account"/>
                            <template slot="append">
                                <i class="iconfont icon-settings" @click.stop="openSettingDialog"></i>
                            </template>
                        </mu-select>
                    </div> -->
                    <!-- <div class="input_class"> -->
                        <mu-auto-complete
                            v-model="usercode"
                            :placeholder="'请输入用户名'"
                            label="账号"
                            ref="usercodeField"
                            :data="usercodeList"
                            openOnFocus
                            @select="usercodeSelected"
                            style="width: 100%;min-height: 0px;min-width: 0px; margin-bottom: 16px;"
                            @keyup.enter.native="handleFocusPW"
                            >
                            <!-- v-if="!isPhoneNumberLogin" -->
                            <!-- <template slot="prepend">
                                <i class="iconfont icon-account" style="margin-right:5px"></i>
                            </template> -->
                            <template slot="append" v-if="usercode">
                                <i class="iconfont icon-close" style="font-size: 18px;margin-right:5px;" @click="handleRemoveUsercode"></i>
                            </template>
                        </mu-auto-complete>
                        <!-- <mu-text-field 
                            v-model="usercode" 
                            type="number" 
                            placeholder="请输入电话号码"
                            solo
                            style="min-height: 0px;min-width: 0px;" 
                            v-else
                        >
                            <template slot="prepend">
                                <i class="iconfont icon-tel" style="margin-right:5px"></i>
                            </template>
                            <template slot="append" v-if="usercode">
                                <i class="iconfont icon-close" style="font-size: 18px;margin-right:5px;" @click="handleRemoveUsercode"></i>
                            </template>
                        </mu-text-field> -->
                    <!-- </div> -->
                    <!-- <div class="input_class"> -->
                        <mu-text-field
                            ref="password"
                            v-model="password"
                            label="密码"
                            placeholder="请输入密码"
                            style="width: 100%;min-height: 0px;min-width: 0px;"
                            :type="visibility ? 'text' : 'password'"
                            @keyup.enter.native="login"
                        >
                            <template slot="append">
                                <i class="iconfont" :class="visibility ? 'icon-yanjing_kai' : 'icon-yanjing_bi'" style="font-size: 18px;margin-right:5px;" @click="() => (visibility = !visibility)"></i>
                            </template>
                            <!-- <template slot="prepend">
                                <i class="iconfont icon-xiugaimima" style="margin-right:5px"></i>
                            </template> -->
                        </mu-text-field>
                        <!-- <mu-text-field
                            ref="password"
                            v-model="password"
                            placeholder="请输入验证码"
                            solo
                            style="min-height: 0px;min-width: 0px;"
                            type="text"
                            @keyup.enter.native="login"
                            v-else
                        >
                            <template slot="append">
                                <mu-button 
                                    color="primary" 
                                    @click="handleSendSMSCode" 
                                    :disabled="smsSendCd > 0"
                                >
                                    {{ smsSendCd == 0 ? "获取验证码" : smsSendCd + "秒后重试" }}
                                </mu-button>
                            </template>
                            <template slot="prepend">
                                <i class="iconfont icon-xiugaimima" style="margin-right:5px"></i>
                            </template>
                        </mu-text-field> -->
                    <!-- </div> -->
                    <div style="padding: 20px 0;">
                        <mu-button full-width large round color="primary" @click="login">登录</mu-button>
                    </div>
                    <div style="padding: 10px 0; margin: 0 auto;">
                        <!-- <div style="color: #46a4da; font-size: 14px;" @click="openSettingDialog">连接参数设置</div> -->
                        <!-- <div style="color: #46a4da; font-size: 14px;" @click="isPhoneNumberLogin = false" v-if="isPhoneNumberLogin">用户名登录</div>
                        <div style="color: #46a4da; font-size: 14px;" @click="isPhoneNumberLogin = true" v-else>手机登录</div> -->
                        <!-- <div style="color: #46a4da; font-size: 14px;" @click="openAccounts">账号管理</div> -->
                        <mu-button full-width large round flat @click="openAccounts">账号管理</mu-button>
                    </div>
                    
                </div>

            </div>
            <!-- <template slot="footer">
                <mu-button large color="primary" @click="login" style="width:100%">登陆</mu-button>
            </template> -->
        </lj-win-common>
        <!-- <mu-dialog :open.sync="settingDialogOpen" :overlay-close="false" title="连接参数设置">
            <mu-text-field v-model="cusid" label="中转码"
                action-icon=":iconfont icon-qrcode-scan"
                @input.native="handleConnectParamsChange"
                @focus="fnFocusSelect($event)"
                :action-click="handleCusidScan"
                :error-text="checkTransitMode"
                @keyup.enter.native="handleSettingConfirmButton('cusid')" label-float full-width/>
            <van-divider dashed>
                {{ isDividerText }}
            </van-divider>
            <mu-text-field v-model="ip" label="IP"
                @input.native="handleConnectParamsChange"
                @keyup.enter.native="$refs.dialogPort.focus()"
                @focus="fnFocusSelect($event)"
                :error-text="checkIpMode"
                label-float
                full-width>
                <template slot="append" v-if="ip">
                    <i class="iconfont icon-close" style="font-size: 18px;margin-right:5px;" @click="handleRemoveIP"></i>
                </template>
            </mu-text-field>
            <mu-text-field v-model="port" label="IP端口"
                ref="dialogPort"
                @input.native="handleConnectParamsChange"
                @keyup.enter.native="handleSettingConfirmButton('ip')"
                @focus="fnFocusSelect($event)"
                :error-text="checkPortInput"
                label-float
                full-width>
                <template slot="append" v-if="port">
                    <i class="iconfont icon-close" style="font-size: 18px;margin-right:5px;" @click="handleRemovePort"></i>
                </template>
            </mu-text-field>
            <div class="flex" style="text-align: center">
                <mu-button class="flex-1" @click="handleSettingCancelButton">取消
                </mu-button>
                <mu-button class="btn-confirm flex-1" color="primary" @click="handleCheckAndSetting">
                    {{ isConfirmText }}
                </mu-button>
            </div>
        </mu-dialog> -->
    </div>

</template>

<script>
    import $lj from 'components/lj-public'
    import LjWinCommon from "components/lj-win-common";

    export default {
        components: {
            LjWinCommon
        },
        data() {
            return {
                isRelogin: false,
                rememberUser: true,
                menuOpen: false,
                sureLogin:false,
                ifFirstLogin: false,
                ipAccounts: [],
                transitAccounts: [],
                tempParams: {},
                currentAccount: "金龙恒核价",
                usercode: "",
                password: "",
                userHistory: {},
                userHistoryAccount: [],
                settingDialogOpen: false,
                connectMode: '',
                transitMode: "transit",
                ipMode: "ip",
                ipAndTransitMode: "ip&transit",
                ip: '',
                port: '',
                // ip: '223.4.178.191',
                // port: '30032',
                cusid: "",
                logoSrc: '../../../assets/image/jlhapp-logo.png',
                ifOpenMng: false,
                connectTrue:false,
                visibility: false, // 密码可视
                checkTransitMode: "", // 中转码错误提示
                checkPortInput: "", // prot错误提示
                checkIpMode: "", // ip错误提示
                tempserverConnectParams: "", //
                ipAndPort: {}, // 暂存ip信息
                loginType: 0, // 登录方式，0-账号密码，1-手机号码
                timer: null,
                isPhoneNumberLogin: false,
                smsSendCd: 0,
            }
        },
        computed: {
            isDividerText() {
                if (this.cusid && this.ip) {
                    return '中转与IP，自动切换'
                }
                return '或'
            },
            isConfirmText() {
                if (this.cusid && this.ip) {
                    return '择优连接'
                }
                if (this.cusid) {
                    return '中转连接'
                }
                if (this.ip || this.port) {
                    return 'IP连接'
                }
                return '连接'
            },
            maxUserHistoryAccount() {
                let maxList = {};
                let userHistoryAccount = {};
                let userHistory = this.userHistory || {};
                if (this.userHistoryAccount.length > 0) {
                    let index = -1;
                    for (let i = 0; i < this.userHistoryAccount.length; i++) {
                        if (this.userHistoryAccount[i].name == this.currentAccount) {
                            index = i;
                            break;
                        }
                    }
                    if (index > -1) {
                        userHistoryAccount = this.userHistoryAccount[index].account;
                    }
                }
                Object.assign(maxList, userHistory, userHistoryAccount);
                return maxList
            },
            usercodeList: function () {
                const list = [];
                if (this.rememberUser) {
                    for (let usercode in this.maxUserHistoryAccount) {
                        list.push(usercode);
                    }
                }
                return list;
            },
            accounts() {
                if (this.connectMode === this.transitMode) {
                    return this.transitAccounts;
                } else {
                    return this.ipAccounts;
                }
            },
			isConnectModeTitle() {
                let title = '';
                switch (this.connectMode) {
                    case this.ipMode:
                        title = 'IP连接';
                        break;
                    case this.transitMode:
                        title = '中转连接';
                        break;
                    case this.ipAndTransitMode:
                        title = '择优连接';
                        break;
                    default:
                        break;
                }
                return title;
			}
        },
        created() {
            let pageParam = $lj.getPageParam();
            if (pageParam) {
                this.ifFirstLogin = pageParam.ifFirstLogin;
                this.isRelogin = pageParam.isRelogin;
                this.ifOpenMng = pageParam.ifOpenMng;
                this.sureLogin = pageParam.sureLogin;
            }
            if (typeof this.ifOpenMng === 'undefined') {
                this.ifOpenMng = false;
            }
            if (!this.isRelogin) {
                $lj.setKeybackClose();
            }
            if (this.ifFirstLogin !== true) {
                // this.loadHistorySetting();
            } else {
               this.connectMode =  this.transitMode;
            }
        },
        mounted() {
            this.initUserHistory();
            if (this.ifFirstLogin !== true) {
                let lastUser = $lj.getStorage("loginRememberUser");
                console.log('lastUser :>> ', JSON.stringify(lastUser));
                // this.currentAccount = $lj.getStorage("lastLoginAccount");
                if (lastUser) {
                    this.rememberUser = true;
                    this.usercode = lastUser;
                    this._initAccoutMsg();
                    this.usercodeSelected(this.usercode);
                }
            }
            // if (!this.currentAccount) {
            //     if (!this.ip && !this.port && !this.cusid) {
            //         // 初始化，未设置
            //         this.settingDialogOpen = true;
            //         $lj.toast("请先设置连接属性");
            //     } else {
            //         this.openSettingDialog();
            //         // this.handleConnectButton();
            //     }
            // } else {
            //     this.handleConnectButton();
            // }
        },
        methods: {
            // handleSendSMSCode() {
            //     if (!this.currentAccount) {
            //         $lj.toast("请先选择帐套");
            //         this.openSettingDialog();
            //         return false;
            //     }
            //     if (!this.usercode) {
            //         $lj.toast("请先输入手机号码");
            //         return false;
            //     }
            //     let self = this;
            //     $lj.postLJRequest("SendSMSToLogin", {
            //         account: this.currentAccount,
            //         phoneNumber: this.usercode
            //     }, function (ret) {
            //         // 表示发送成功
            //         $lj.toast("发送成功!");
            //         // alert("验证码:" + ret.code);
            //         self.getCode();
            //     })
            // },
            getCode(){      
                const TIME_COUNT = 60;
                if (!this.timer) {
                    this.smsSendCd = TIME_COUNT;
                    this.timer = setInterval(() => {
                        if (this.smsSendCd > 0 && this.smsSendCd <= TIME_COUNT) {
                            this.smsSendCd--;         
                        } else {
                            clearInterval(this.timer);
                            this.timer = null;
                        }
                    }, 1000)       
                }
            },
            fnFocusSelect(ev) {
                ev.currentTarget.select();
            },
            // handleSelectAccount() {
            //     if (!this.accounts.length) {
            //         this.openSettingDialog();
            //     }
            // },
            handleRemoveUsercode() {
                this.usercode = "";
                this.$refs.usercodeField.focus();
                console.log('this.$refs.usercodeField.focus() :>> ', this.$refs.usercodeField);
            },
            handleRemoveIP() {
                this.ip = "";
            },
            handleRemovePort() {
                this.port = "";
            },
            handleFocusPW() {
                this.$refs.usercodeField.blur();
                this.$refs.password.focus();
                console.log('_setUserHistory this.MaxxxxxxuserHistoryAccount :>> ', JSON.stringify(this.maxUserHistoryAccount));
            },
            // handleSettingCancelButton() {
            //     $lj.setStorage("serverConnectParams", this.tempserverConnectParams);
            //     // this.tempserverConnectParams = $lj.getStorage("serverConnectParams");
            //     this.currentAccount = this.tempAccount;
            //     this.connectMode = '';
            //     this.loadHistorySetting();
            //     // this.tempAccount = this.currentAccount;
            //     // this.loadHistorySetting();
            //     // this.settingDialogOpen = false;
            //     this.closeSettingDialog();
            // },
            // handleConnectParamsChange() {
            //     if (this.accounts.length > 0) {
            //         this.accounts.length = [];
            //         this.currentAccount = "";
            //     }
            //     this._autoResetCheck();
            // },
            // loadHistorySetting() {
            //     let serverConnectParams = $lj.getStorage("serverConnectParams");
            //     console.log('loadHistorySetting  serverConnectParams:>> ', JSON.stringify(serverConnectParams));
            //     if ($lj.isIPad()){
            //         // ios审核连接测试
            //         if (!serverConnectParams || (!serverConnectParams.ip && !serverConnectParams.port && !serverConnectParams.cusid)) {
            //             serverConnectParams = {
            //                 ip: "47.107.226.255",
            //                 port: 30043
            //             }
            //         }
            //     }
            //     if (serverConnectParams) {
            //         this.ip = serverConnectParams.ip;
            //         this.port = serverConnectParams.port;
            //         this.cusid = serverConnectParams.cusid;
            //     }
            //     if (this.ip && this.port && this.cusid) {
            //         this.connectMode =  this.ipAndTransitMode;
            //     } else if (this.ip && this.port) {
            //         this.connectMode =  this.ipMode;
            //     } else {
            //         this.connectMode = this.ip && this.port ? this.ipMode : this.transitMode;
            //     }
            // },
            // handleCheckAndSetting() {
            //     // 验证中转服务和IP服务的一致性
            //     if (this.cusid && this.ip) {
            //         this.handleSettingConfirmButton('all', () => {
            //             if (this.ipAndPort.ip != this.ip || this.ipAndPort.port != this.port) {
            //                 this.checkIpMode = '中转码与IP连接的后台不一致，请检查'
            //             } else {
            //                 this.closeSettingDialog();
            //             }
            //         });
            //     } else {
            //         this.handleSettingConfirmButton('all', () => {
            //              this.closeSettingDialog();
            //         });
            //     }
            // },
            // handleSettingConfirmButton(connect, callback) {
            //     if (!this.checkConnectParmsValid(connect)) {
            //         return;
            //     }
            //     let self = this;
			// 	$lj.initServerConnect();
            //     this.getAccounts(function() {
                    
            //         if (self.accounts.length === 0 || !self.currentAccount) {
            //             $lj.toast("请先选择帐套");
            //             return;
            //         }
            //         if (connect == 'cusid') {
            //             self.ip = self.ipAndPort.ip;
            //             self.port = self.ipAndPort.port;
            //         }
            //         callback && callback();
            //     });
            // },
            closeSettingDialog() {
                // let serverConnectParams =  $lj.getStorage("serverConnectParams");
                if (this.ipAccounts !== this.accounts) {
                    this.ipAccounts.length = 0;
                } else {
                    this.transitAccounts.length = 0;
                }
                this.settingDialogOpen = false;
            },
            // openSettingDialog() {
            //     this.tempserverConnectParams = $lj.getStorage("serverConnectParams");
            //     this.tempAccount = this.currentAccount;
            //     this.loadHistorySetting();
            //     this.settingDialogOpen = true;
            //     this.getAccounts();
            //     // this.handleConnectButton();
            //     // if (!this.accounts || this.accounts.length === 0) {
            //     //     this.getAccounts();
            //     // }
            // },
            //账套管理
            openAccounts(){
                let self = this;
				$lj.openWin('login-mng',{isRelogin:true})
            },
            // 登录历史
            initUserHistory() {
                this.userHistory = $lj.getStorage("userHistory");
                if (typeof this.userHistory !== "object") {
                    this.userHistory = {};
                }
                this.userHistoryAccount = $lj.getStorage("userHistoryAccount") || [];
                console.log('$lj.getStorage("userHistoryAccount")>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> :>> ', JSON.stringify($lj.getStorage("userHistoryAccount")));
                console.log('$lj.this.userHistoryAccount("userHistoryAccount")>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> :>> ', JSON.stringify(this.userHistoryAccount));
            },
            _initAccoutMsg() {
                // 缓存本地登录账号
                let accountList = $lj.getStorage('cacheAccount') || [];
                let length = accountList.length;
                for (let i = 0; i < length; i++) {
                    if (accountList[i].account == this.currentAccount && accountList[i].usercode == this.usercode) {
                        this.ip = accountList[i].ip;
                        this.port = accountList[i].port;
                        this.cusid = accountList[i].cusid;
                        this.connectMode = accountList[i].connectMode || '';
                        this.isPhoneNumberLogin = accountList[i].isPhoneNumberLogin || '';
                        break;
                    }
                }
            },
            _setUserHistory(currentAccount, username, password) {
                if (!this.rememberUser) return false;
                console.log('_setUserHistory this.userHistoryAccount :>> ', JSON.stringify(this.userHistoryAccount));
                if(this.isPhoneNumberLogin) {
                    password = ''
                }
                let index = -1;
                if (this.userHistoryAccount.length > 0) {
                    for (let i = 0; i < this.userHistoryAccount.length; i++) {
                        if (this.userHistoryAccount[i].name == currentAccount) {
                            index = i;
                            break;
                        }
                    }
                    if (index > -1) {
                        this.userHistoryAccount[index].account[username] = password;
                    }
                }
                if (index == -1) {
                    let obj = {};
                    obj.name = currentAccount;
                    obj.account = {};
                    obj.account[username] = password;
                    this.userHistoryAccount.push(obj);
                }
                console.log('_setUserHistory this.userHistoryAccount :>> ', JSON.stringify(this.userHistoryAccount));
                console.log('_setUserHistory this.MaxxxxxxuserHistoryAccount :>> ', JSON.stringify(this.maxUserHistoryAccount));
                if (this.rememberUser) {
                    $lj.setStorage('userHistoryAccount', this.userHistoryAccount);
                }
            },
            // getAccounts(callback) {
            //     let self = this;
            //     $lj.postLJRequest("GetToken", {}, function (ret) {
            //         if (ret) {
            //             // self.accounts.length = 0;
            //             if (ret.accounts && ret.accounts.length > 0) {
            //                 self._autoResetCheck();
            //                 let getFirstAccount = false;
            //                 ret.accounts.forEach((item) => {
            //                     if (item === self.currentAccount) {
            //                         getFirstAccount = true;
            //                     }
            //                 });
            //                 console.log('self.connectMode :>> ', JSON.stringify(self.connectMode));
            //                 if (self.connectMode === self.transitMode) {
            //                     self.ipAccounts.length = 0;
            //                     self.transitAccounts = ret.accounts;
            //                 } else {
            //                     self.ipAccounts = ret.accounts;
            //                     self.transitAccounts.length = 0;
            //                 }
            //                 if (!getFirstAccount) {
            //                     self.currentAccount = self.accounts[0];
            //                 }
            //                 if (self.connectMode != self.ipMode && ret.hasOwnProperty('ip')) {
            //                     self.ipAndPort = {
            //                         ip: ret.ip,
            //                         port: ret.port
            //                     }
            //                     if (!self.ip) {
            //                         self.ip = ret.ip;
            //                         self.port = ret.port;
            //                     }
            //                 }
            //                 // if (self.accounts.length === 1 && ifAutoConfirm) {
            //                     // self.handleSettingConfirmButton();
            //                 //     $lj.toast("连接成功");
            //                 //     callback && callback();
            //                 // } else {
            //                 // if (self.sureLogin) {
            //                 //     self.login();
            //                 // } else {
            //                 $lj.toast("连接成功", 1500);
            //                 callback && callback();
            //                 // }
            //                 // }
            //                 return;
            //             } else {
            //                 self.currentAccount = "";
            //             }
            //         }
            //         alert("连接失败，请重试");
            //     }, function(err) {
            //         $lj.toast(err.errCode || err.ErrMsg);
            //         if (self.connectMode == self.transitMode) {
            //             // 中转
            //             self.checkTransitMode = err.errCode
            //         } else {
            //             self.checkIpMode = err.errCode
            //         }
            //         $lj.setStorage("serverConnectParams", self.tempserverConnectParams);
            //         // this.tempserverConnectParams = $lj.getStorage("serverConnectParams");
            //         self.currentAccount = self.tempAccount;
            //     }, false, false)
            // },
            _autoResetCheck() {
                this.checkTransitMode = "";
                this.checkIpMode = "";
                this.checkPortInput = "";
            },
            usercodeSelected(item, index) {
                console.log('usercodeSelected this.maxUserHistoryAccount :>> ', JSON.stringify(this.maxUserHistoryAccount));
                this.password = this.maxUserHistoryAccount[item];
                this.$refs.usercodeField.blur();
            },
            checkLoginParams() {
                // if (!this.currentAccount) {
                //     $lj.toast("请先选择帐套");
                //     this.openSettingDialog();
                //     return false;
                // }
                if (!this.usercode) {
                    $lj.toast("请先输入用户名");
                    return false;
                }
                // if (!this.password) {
                //     $lj.toast("请先输入密码");
                //     return false
                // }
                return true;
            },
            // handleCusidScan() {
            //     let self = this;
            //     $lj.openScanner((ret) => {
            //         setTimeout(() => {
            //             let content = ret.content.trim();
            //             self.cusid = content;
            //             self.handleSettingConfirmButton('cusid');
            //         }, 200);
            //     })
            // },
            checkConnectParmsValid(connect) {
                switch (connect) {
                    case 'cusid':
                        if (!this.cusid) {
                            this.checkTransitMode = "请扫描或输入中转码"
                            return false;
                        }
                        this.connectMode = this.transitMode;
                        break;
                    case 'ip':
                        if (!this.ip) {
                            this.checkIpMode = "请先输入IP"
                            return false;
                        }
                        if (!$lj.isValidIP(this.ip)) {
                            this.checkIpMode = "请输入正确的IP地址"
                            return false;
                        }
                        if (!this.port) {
                            this.checkPortInput = "请先输入端口"
                            return false;
                        }
                        this.connectMode = this.ipMode
                        break;
                    default:
                        if (!this.cusid && !this.ip) {
                            $lj.toast("请选择中转或IP连接方式");
                            return false;
                        }
                        if (this.ip) {
                            if (!$lj.isValidIP(this.ip)) {
                                this.checkIpMode = "请输入正确的IP地址"
                                return false;
                            }
                            if (!this.port) {
                                this.checkPortInput = "请先输入端口"
                                return false;
                            }
                        }
                        if (this.cusid && this.ip) {
                            this.connectMode = this.ipAndTransitMode;
                        } else if (!this.cusid && this.ip) {
                            this.connectMode = this.ipMode;
                        } else {
                            this.connectMode = this.transitMode;
                        }
                        break;
                }
                $lj.setStorage("serverConnectParams", {
                    ip: this.ip,
                    port: this.port,
                    cusid: this.cusid
                });
                return true;
            },
            // handleConnectButton() {
            //     if (!this.checkConnectParmsValid()) {
            //         return;
            //     }
            //     $lj.initServerConnect(()=>this.getAccounts());
            //     // if(this.connectTrue && this.sureLogin){
            //     //     this.login();
            //     // }
            // },
            login() {
                if (!this.checkLoginParams()) {
                    return;
                }
                // var requestData = {
                //     account: this.currentAccount,
                //     userid: this.usercode,
                //     password: this.password,
                //     clientType: this.isPhoneNumberLogin ? 11 : 10,
                //     phoneUUID: $lj.deviceId,
                //     typeName:'L1APP'
                // };
                var requestData = {
                    usercode: this.usercode,
                    psw: this.password,
                };

                var self = this;
                $lj.postLJRequest("Login", requestData, function (ret) {
                    if (ret) {
                        let oldToken = $lj.getStorage("token");
                        let token = ret.token;
                        $lj.setStorage("token", token);
                        $lj.token = token;
                        let reportHabit = $lj.getStorage("reportHabit");
                        if (!reportHabit) {
                            $lj.setStorage("reportHabit", {});
                        }
                        $lj.setStorage("lastLoginAccount", self.currentAccount);
                        $lj.setStorage("user", ret);
                        $lj.setStorage("loginRememberUser", self.rememberUser ? ret.usercode : "");
                        self._setUserHistory(self.currentAccount, ret.usercode, self.password);
                        // self.userHistory[self.usercode] = self.password;
                        // $lj.setStorage('userHistory', self.rememberUser ? self.userHistory : {});

                        // 缓存本地登录账号
                        let accountList = $lj.getStorage('cacheAccount');
                        console.log(' accountList :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(accountList), );
                        let ifexist = false;
                        if (!accountList) {
                            accountList = [];
                        }
                        console.log(' accountList after:>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(accountList));
                        accountList.forEach((acc) => {
                            acc.checked = false;
                            if (acc.account == self.currentAccount && acc.usercode == ret.usercode) {
                                acc.token = ret.token;
                                acc.ip = self.ip;
                                acc.port = self.port;
                                acc.cusid = self.cusid;
                                acc.username = ret.username;
                                acc.checked = true;
                                acc.connectMode = self.connectMode;
                                acc.isPhoneNumberLogin = self.isPhoneNumberLogin
                                ifexist = true;
                            }
                        })
                        if (!ifexist) {
                            accountList.push({
                                token: ret.token,
                                ip: self.ip,
                                port: self.port,
                                cusid: self.cusid,
                                account: self.currentAccount,
                                usercode: ret.usercode,
                                username: ret.username,
                                connectMode: self.connectMode,
                                isPhoneNumberLogin: self.isPhoneNumberLogin,
                                checked: true
                            });
                        }
                        $lj.setStorage('cacheAccount', accountList);

                        console.log('$lj.getStorage(cacheAccount) :>> ', JSON.stringify($lj.getStorage('cacheAccount')));

                        // if(oldToken){
                        //     $lj.postLJRequest("NotifyUsersKicked", {tokens: [oldToken], fromClient: 1},function(ret) {
                        //         self.handleLoginSuccess();
                        //     });
                        // } else {
                            self.handleLoginSuccess();
                        // }

                        if(ret.WarnMsg && ret.WarnMsg.length > 0) {
                            $lj.toast(ret.WarnMsg, 2000, "middle");
                        }
                    }
                },function(ret){
                    $lj.setStorage("token", "");

                    if(ret.ErrMsg.indexOf("修改密码") != -1) {
                        $lj.selectDialog("操作提示", ret.ErrMsg, ["修改密码", "取消"], function(btnIndex) {
                            if(btnIndex == 1) {
                                self.gotoPasswordEdit();
                            }
                        })
                    } else {
                        alert(ret.ErrMsg)
                    }
                },false,false);
            },
            handleLoginSuccess(){
                if (this.ifOpenMng) {
                    $lj.sendEvent("login_byaccount");
                } else {
                    // this.tableInit();
                    $lj.toast("登录成功");
                    $lj.sendEvent("login_success", {reload: true});
                }
                $lj.closeWin();
            },
            gotoPasswordEdit() {
                $lj.openWin("password-edit",{account: this.currentAccount, usercode: this.usercode});
            },
            closeWin() {
                $lj.closeWin();
            },
            accountChange() {
                this.usercode = "";
                this.password = "";
            },
            // tableInit(){
            //     let token =  $lj.getStorage('token');
            //     var requestData = {
            //         token:token
            //     };
            //     $lj.postLJRequest("RpTimeOperateAppInit", requestData, function (ret) {
                    
            //     },function(ret){
            //         if (ret.ErrMsg) {
            //             $lj.toast("初始化数据仓库基础资料失败!");
            //         }
            //     })
            // }
        }
    }
</script>
<style>
    .login-body {
        text-align: center;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-box-pack: center;
        background-size: cover;
        background: radial-gradient(44.42% 20.49% at -7.209302325581396% 100%, rgba(255, 235, 59, 0.18) 0%, rgba(255, 235, 59, 0) 100%), radial-gradient(107.91% 49.79% at 100% -5.901287553648069%, rgba(33, 150, 243, 0.46) 0%, rgba(33, 144, 235, 0) 100%), rgba(255, 255, 255, 1);
    }
    .input_class {
        position: relative;
        background-color: #f6f6f6;
        padding: 5px;
        border-radius: 10px;
        margin: 10px 0;
    }
    .input_class .mode-flag {
        position: absolute;
        top: -8px;
        left: 10px;
        padding-left: 6px;
        padding-right: 6px;
        background-color: #0084FF;
        border: none!important;
        color: #f6f6f6;
    }
    .mu-dialog-wrapper {
        z-index: 100!important;
    }
    .mu-overlay {
        z-index: 99!important;
    }
    .mu-dialog-body {
        padding: 16px;
        padding-bottom: 20px;
    }
    .mu-dialog-body .van-divider{
        color: #1989fa;
        border-color: #1989fa;
        margin: 8px 0;
        padding: 0 16px;
    }
    .mu-dialog-body .btn-confirm{
        position: relative;
        margin-left: 8px;
    }
    .mu-dialog-body .btn-confirm .van-loading{
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
        background-color: rgba(255, 255, 255, 0.2);
    }
    .mu-ripple-wrapper {
        font-size: 12px;
    }
</style>