﻿
/*!
 * 帐号管理模块
 * Account Manager Model
 * Copyright(c) 20010-2012 hainan jowe technology ltd
 * author: wangxiuwu
 * create in 2010-01-14
 */

/*
 * 定义命名空间 define namespace
 */
Ext.namespace("com.hnjowe.ext.corp.AccountMgr"); 

/*==========================================================================================*/
/**
 * 商家注册(添加窗口)
 */
com.hnjowe.ext.corp.AccountMgr.CorpRegisterWin = Ext.extend(Ext.Window,{

	/*属性参数*/
	id: 'CorpRegisterWin',
	title: '商家注册',
	layout:'fit',
	width:700,
	height:480,//530
	border: false,
	maximizable:true,
	plain: true,
	modal:true,
	buttonAlign:'center',

    /**
     * 初始化函数
     */
	initComponent : function() {
		this.items = this.buildForm();
		this.buttons = this.buildUI();
		com.hnjowe.ext.corp.AccountMgr.CorpRegisterWin.superclass.initComponent.call(this);
	},
	
	/**
	 * 建立表单
     */		
	 buildForm : function() {
		return [
			{
				xtype: 'form',  
				id: 'CorpRegisterForm',
				bodyStyle:'padding:10px 10px 10px 10px',
				autoScroll:true,
				frame: true,
				items:[
					{xtype : "fieldset", autoHeight : true, title : "商家基本信息",
						items : [

							//行(分两列)
							{ 
								layout:'column',
								defaults:{ 
									columnWidth:0.5,
									layout:'form',
									border:false,
									bodyStyle:'padding:0 10px 0 0' 
								},
								items:[
									{ 
										defaults:{
											labelWidth:80,
											labelStyle: "text-align:right;"
										},
										items:[
											{
												fieldLabel: "<font color=red>*</font> <font color=blue>管理帐号</font>",
												xtype: "textfield",
												name: "platRegCorp.LOGIN_NAME",
												allowBlank: false,
												blankText: '管理帐号不能为空',
												minLength: 6,
												maxLength: 15,
												regex:/^[_a-zA-Z0-9]*$/,
												regexText: '管理帐号必须是由下划线或字母或数字组成,不分大小写',
												//vtype:'checkLoginName',
												width: 140
											},
											{
												fieldLabel:'<font color=red>*</font> <font color=blue>管理密码</font>',
												xtype: "textfield",
												id:'newLoginPwd',
												name:'platRegCorp.LOGIN_PWD',
												allowBlank:false,
												minLength:6,
												maxLength:15,
												inputType:'password',
												width: 140
											},
											{
												fieldLabel:'<font color=red>*</font> <font color=blue>确认密码</font>',
												xtype: "textfield",
												name:"newLoginPwd_confirm",
												inputType:'password',
												vtype:'password',
												initialPassField:'newLoginPwd',
												width:140
											},
											{ 
												fieldLabel:'<font color=red>*</font> 商家名称',
												xtype:'textfield',
												name:'platRegCorp.CORP_NAME',
												allowBlank: false,
												anchor:'95%'
											},
											{ 
												fieldLabel:'工商代码',
												xtype:'textfield',
												name: 'platRegCorp.CORP_CODE',
												anchor:'95%'
											},
											{ 
												fieldLabel:'商家地址',
												xtype:'textfield',
												name: 'platRegCorp.CORP_ADDRESS',
												anchor:'95%'
											},
											{ 
												fieldLabel:'商家网址',
												xtype:'textfield',
												name: 'platRegCorp.CORP_WEBSITE',
												vtype:'url',
												anchor:'95%'
											}
										]
									},
									{ 
										defaults:{
											labelWidth:80,
											labelStyle : "text-align:right;"
										},
										items:[
											{
												fieldLabel : "<font color=red>*</font> 商家类型",
												xtype: 'combo',
												hiddenName:'platRegCorp.BUSINESS_CLASS_ID',
												store: new Ext.data.ArrayStore({
														fields: ['BUSINESS_CLASS_ID','BUSINESS_CLASS_NAME'],
														data: com.hnjowe.ext.corp.data.businessclass
												}),
												displayField: 'BUSINESS_CLASS_NAME',
												valueField: 'BUSINESS_CLASS_ID',
												blankText:'请选择类型',
												emptyText:'请选择类型',
												mode: 'local',
												width: 100,
												forceSelection: true,
												selectOnFocus: true,
												triggerAction: 'all',
												allowBlank: false
											},
											{
												xtype: 'combo',
												id: 'prov',
												hiddenName:'platRegCorp.PROV_NAME',
												store: new Ext.data.ArrayStore({
														fields: ['PROV_CODE','PROV_NAME'],
														data: com.hnjowe.ext.data.provinces
												}),
												listeners:{   
													select:function(combo, record, index){   
														Ext.getCmp('city').clearValue();   
														Ext.getCmp('city').store.loadData(com.hnjowe.ext.data.cities[record.data.PROV_CODE]);   
													}   
												},
												fieldLabel : "<font color=red>*</font> 所属省份",
												displayField: 'PROV_NAME',
												valueField: 'PROV_NAME',
												blankText:'请选择省份',
												emptyText:'请选择省份',
												mode: 'local',
												width: 100,
												forceSelection: true,
												selectOnFocus: true,
												triggerAction: 'all',
												allowBlank: false
											},
											
											{
												xtype: 'combo',
												id: 'city',
												hiddenName:'platRegCorp.CITY_NAME',
												store: new Ext.data.ArrayStore({
														fields: ['CITY_CODE','CITY_NAME'],
														data: []
												}),
												listeners:{
													select:function(combo, record, index){   
														Ext.getCmp('country').clearValue();   
														Ext.getCmp('country').store.loadData(com.hnjowe.ext.data.countries[record.data.CITY_CODE]);   
													}   
												},									
												fieldLabel : "<font color=red>*</font> 所属城市",
												displayField: 'CITY_NAME',
												valueField: 'CITY_NAME',
												blankText:'请选择城市',
												emptyText:'请选择城市',
												mode: 'local',
												width: 100,
												forceSelection: true,
												selectOnFocus: true,
												triggerAction: 'all',
												allowBlank: false
											},
											{
												xtype: 'combo',
												id: 'country',
												hiddenName:'platRegCorp.COUNTRY_NAME',	//隐藏值
												store: new Ext.data.ArrayStore({
														fields: ['COUNTRY_CODE','COUNTRY_NAME'],
														data: []
												}),
												fieldLabel : "<font color=red>*</font> 所属地区",
												displayField: 'COUNTRY_NAME',
												valueField: 'COUNTRY_NAME',
												blankText:'请选择地区',   
												emptyText:'请选择地区', 
												mode: 'local',
												width: 100,
												forceSelection: true,
												selectOnFocus: true,
												triggerAction: 'all',
												allowBlank: false
											},
											{ 
												fieldLabel:'商家简介',
												xtype:'textarea',
												height: 75,
												anchor:'95%',
												name: 'platRegCorp.CORP_INFO'
											}
										] 
									}
								]
							}
						]
					},
					{xtype : "fieldset",autoHeight : true, title : "商家联系信息",
						items : [
							//行(分两列)
							{ 
								layout:'column',
								defaults:{ 
									columnWidth:0.5,
									layout:'form',
									border:false,
									bodyStyle:'padding:0 10px 0 0' 
								},
								items:[
									{ 
										defaults:{
											labelWidth:80,
											labelStyle: "text-align:right;"
										},
										items : [
											{
												fieldLabel: "<font color=red>*</font> 联系人姓名",
												xtype: "textfield",
												name: "platRegCorp.CONTACT_NAME",
												allowBlank: false,
												blankText: '联系人姓名不能为空',
												maxLength: 20,
												width: 140
											},
											{
												fieldLabel: "<font color=red>*</font> 联系手机",
												xtype: "textfield",
												name: "platRegCorp.CONTACT_MOBILE",
												allowBlank: false,
												blankText: '联系手机不能为空',
												maxLength: 11,
												regex:/^1(3|4|5|8)[0-9]{9}$/,
												regexText: '手机号码非法',
												width: 140
											},
											{
												fieldLabel: "<font color=red>*</font> 联系固话",
												xtype: "textfield",
												name: "platRegCorp.CONTACT_TEL",
												allowBlank: false,
												blankText: '联系固话不能为空',
												maxLength: 20,
												regex:/^((0\d{2,3})-)(\d{7,8})(-(\d{2,}))?$/,
												regexText: '固定号码非法,正式格式为: 区号-电话号码-分机号',
												width: 140
											}
										]
									},
									{ 
										defaults:{
											labelWidth:80,
											labelStyle : "text-align:right;"
										},
										items:[
											{
												xtype: 'combo',
												hiddenName:'platRegCorp.CONTACT_SEX',	//隐藏值
												store: new Ext.data.ArrayStore({
														fields: ['CONTACT_SEX','sexName'],
														data: com.hnjowe.ext.corp.data.sex
												}),
												fieldLabel : "<font color=red>*</font> 联系人性别",
												displayField: 'sexName',
												valueField: 'CONTACT_SEX',
												allowBlank: false,
												blankText:'请选择性别',
												emptyText:'请选择性别',
												mode: 'local',
												width: 100,
												forceSelection: true,
												selectOnFocus: true,
												triggerAction: 'all'
											},
											{
												fieldLabel: "<font color=red>*</font> 联系传真",
												xtype: "textfield",
												name: "platRegCorp.CONTACT_FAX",
												allowBlank: false,
												blankText: '联系传真不能为空',
												maxLength: 20,
												regex:/^((0\d{2,3})-)(\d{7,8})(-(\d{2,}))?$/,
												regexText: '传真号码非法,正式格式为: 区号-电话号码-分机号',
												width: 140
											},
											{
												fieldLabel: "<font color=red>*</font> 联系电邮",
												xtype: "textfield",
												name: "platRegCorp.CONTACT_EMAIL",
												allowBlank: false,
												blankText: '联系电邮不能为空',
												maxLength: 40,
												vtype:'email',
												anchor:'95%'
											}
										] 
									}
								]
							}
						]
					}
				]
			
			}
		];
	 },
	 
	/**
	 * 建立UI
     */
	buildUI : function(){
		return [{
				text: '注册',
				handler: this.onRegister,
				scope: this
			},
			{
				text: '关闭',
				handler: this.onClose,
				scope: this
			}
		];
	},
	
    /**
     * 事件：注册
     */
	onRegister : function() {

		Ext.getCmp('CorpRegisterForm').getForm().submit({
			url:'/platform/corp/accountmgr/corpRegister.action',
			method: 'POST',
			waitMsg:'注册中,请稍后..',
			scope: this,
			success: function(form, action) { 
				if(typeof(action.result) != "undefined"){
					Ext.Msg.alert('提示', action.result.msg);
					Ext.getCmp('CorpRegisterWin').close();
				}
			}, 
			failure: function(form, action) {
				if(typeof(action.result) != "undefined"){
					Ext.Msg.alert('提示', action.result.msg);
					Ext.getCmp('CorpRegisterWin').close();
				}
			} 
		});
	},
	
    /**
     * 事件：关闭
     */
	onClose : function() {
		this.close();
		this.destroy();
	}
	
});


/*自定义验证帐号是否重复*/
Ext.apply(Ext.form.VTypes,{
	checkLoginName : function(val, field){
		var result;
		Ext.Ajax.request({
			url: '/platform/corp/accountmgr/checkLoginName.action?corpLoginName='+val,
			method: 'GET',
			success: function(response, opts){
				var obj = Ext.decode(response.responseText);
				if(null!=obj.checkResult) {
					//Ext.Msg.alert('提示11', obj.checkResult);
					if(obj.checkResult=="1"){
						result = true;
						//Ext.Msg.alert('提示11', obj.checkResult);
					}else{
						result = false;
						//Ext.Msg.alert('提示12', obj.checkResult);
					}
				}
			}
		});
		return result;
	},
	checkLoginNameText:'帐号已经存在，不能重复注册'
});


/*自定义验证vtype:'password'*/
Ext.apply(Ext.form.VTypes,{
	password : function(val, field){
		if(field.initialPassField){
			var pwd = Ext.getCmp(field.initialPassField);
			return (val == pwd.getValue());
		}
		return true;
	},
	passwordText:'确认密码不一致'
});






