
Ext.onReady(function() {
    var loadMask = new Ext.LoadMask(document.body, { msg: "正在加载数据，请等待..." });
    loadMask.show();

    Ext.BLANK_IMAGE_URL = "../ext/resources/images/default/s.gif";
    Ext.QuickTips.init();
    
    var store = new Ext.data.SimpleStore({	
		fields: ['departmentID', 'departmentName'],	
		data : [['ZONGBU','安溪总部'],['ZHANGZHOU','艾美百货漳州店']]	
	});
    //form
    var form = new Ext.form.FormPanel({
        defaultType: 'textfield',
        defaults: { msgTarget: 'side' },
        layout: 'form',
        labelWidth: 50,
        frame: true,
		shadow:true,
		iconCls:"lock",
        labelAlign: 'right',
        iconCls:"lock",
        items: [
        {
        
			fieldLabel: '店&nbsp;&nbsp;&nbsp;别',
			store: store,				
			displayField:'departmentName',
			valueField:'departmentID',
			xtype:'combo',
			mode: 'local',
			emptyText:'请选择一个店别',
			width:122,
			allowBlank:false,
			msgTarget: 'side',
			triggerAction:'all',
			hiddenName:'dianBie'			
				
    },
    {
        fieldLabel: '帐&nbsp;&nbsp;&nbsp;号',
        name: 'supNo',
        allowBlank: false,
        emptyText: '请输入供应商帐号',        
        msgTarget: 'side',
		iconCls:"lock"
    },
    {
        fieldLabel: '密&nbsp;&nbsp;&nbsp;码',
        name: 'password',
        inputType: 'password',
        allowBlank: false,
        emptyText: '密码不能为空'
    },
	{
        xtype: 'panel',
        layout: 'column',
        items: [
        {
            xtype: 'panel',
            columnWidth: 0.55,
            layout: 'form',
            items: [
                { fieldLabel: '验证码', name: 'code', xtype: 'textfield', width: 60, allowBlank: false, emptyText: '验证码', msgTarget: 'side' }
            ]
        },
            { html: '<img id="validate" src="vaidCode.jsp" ext:qtip="点击刷新验证码" />', columnWidth: 0.37 }
        ]
    },
	{
		xtype:'panel',
		html:'<a href="/study.html" target="_blank" >使用教程</a>'
	}
    ]
    });

    var win = new Ext.Window({
        title: '供应商管理系统-登录窗口',
        height: 200,
        width: 250,
        closable: false,
        buttonAlign: "center",
        resizable: false,
        items: [form],
        buttons: [
            {
                text: '登录',
                handler: function() {
					
                    if (form.getForm().isValid()) {
                        form.getForm().submit({
                            waitTitle: '请稍候',
                            waitMsg: '正在验证中……',
                            method: 'POST',
                            url: '/checkLogin.do',
                            success: function(form, action) {
                                if (action.result.success == true) {
                                    window.location = "main.jsp";
                                }

                            },
                            failure: function(form, action) {
								if (action.failureType == Ext.form.Action.CLIENT_INVALID) {                                     
                                     Ext.Msg.alert('登录失败!', '客户端发送数据失败!');
                                 } else if (action.failureType == Ext.form.Action.CONNECT_FAILURE) {
                                     Ext.Msg.alert('警告', '请求出错或连接的服务不存在! : ' + action.result.msg);
                                 }
                                 else {
                                     Ext.Msg.alert("错误", action.result.msg);                                     
                                 }
                                

                            }

                        });
                    }
                }
            },
            {
                text: '重置',
                handler: function() {
                    form.getForm().reset();
                }
            }
    ]
    });

    win.show();

    Ext.get("validate").on("click", function() {
        Ext.get("validate").dom.src = "vaidCode.jsp?" + Date();
    })

    var delay = new Ext.util.DelayedTask(function() {
        loadMask.hide();
    });
    delay.delay(500);
});

