
/*!
 * 帐号管理模块
 * 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.sell.AccountMgr"); 

/*==========================================================================================*/
/**
 * 渠道注册(添加窗口)
 */
com.hnjowe.ext.sell.AccountMgr.SellRegisterWin = Ext.extend(Ext.Window,{

	/*属性参数*/
	id: 'SellRegisterWin',
	title: '渠道注册',
	layout:'fit',
	width:700,
	height:530,
	border: false,
	maximizable:true,
	plain: true,
	modal:true,
	buttonAlign:'center',

    /**
     * 初始化函数
     */
	initComponent : function() {
		this.items = this.buildForm();
		this.buttons = this.buildUI();
		com.hnjowe.ext.sell.AccountMgr.SellRegisterWin.superclass.initComponent.call(this);
	},
	
	/**
	 * 建立表单
     */		
	 buildForm : function() {
		return [
			{
				xtype: 'form',  
				id: 'SellRegisterForm',
				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: "platRegSell.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:'platRegSell.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:'platRegSell.SELL_NAME',
												allowBlank: false,
												anchor:'95%'
											},
											{ 
												fieldLabel:'渠道代码',
												xtype:'textfield',
												name: 'platRegSell.SELL_CODE',
												anchor:'95%'
											},
											{ 
												fieldLabel:'渠道地址',
												xtype:'textfield',
												name: 'platRegSell.SELL_ADDRESS',
												anchor:'95%'
											},
											{ 
												fieldLabel:'渠道网址',
												xtype:'textfield',
												name: 'platRegSell.SELL_WEBSITE',
												vtype:'url',
												anchor:'95%'
											}
										]
									},
									{ 
										defaults:{
											labelWidth:80,
											labelStyle : "text-align:right;"
										},
										items:[
											{
												fieldLabel : "<font color=red>*</font> 渠道类型",
												xtype: 'combo',
												hiddenName:'platRegSell.SELL_TYPE',
												store: new Ext.data.ArrayStore({
														fields: ['SELL_TYPE','SELL_TYPE_NAME'],
														data: com.hnjowe.ext.sell.data.selltype
												}),
												displayField: 'SELL_TYPE_NAME',
												valueField: 'SELL_TYPE',
												blankText:'请选择类型',
												emptyText:'请选择类型',
												mode: 'local',
												width: 100,
												forceSelection: true,
												selectOnFocus: true,
												triggerAction: 'all',
												allowBlank: false
											},
											{
												xtype: 'combo',
												id: 'prov',
												hiddenName:'platRegSell.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:'platRegSell.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:'platRegSell.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: 'platRegSell.SELL_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: "platRegSell.CONTACT_NAME",
												allowBlank: false,
												blankText: '联系人姓名不能为空',
												maxLength: 20,
												width: 140
											},
											{
												fieldLabel: "<font color=red>*</font> 联系手机",
												xtype: "textfield",
												name: "platRegSell.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: "platRegSell.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:'platRegSell.CONTACT_SEX',	//隐藏值
												store: new Ext.data.ArrayStore({
														fields: ['CONTACT_SEX','sexName'],
														data: com.hnjowe.ext.sell.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: "platRegSell.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: "platRegSell.CONTACT_EMAIL",
												allowBlank: false,
												blankText: '联系电邮不能为空',
												maxLength: 40,
												vtype:'email',
												anchor:'95%'
											}
										] 
									}
								]
							}
						]
					},
					{xtype : "fieldset",autoHeight : true, title : "<font color=red>渠道银行帐户(用于接受商家返佣金,请正确填写)</font>",
						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 : [
											{
												xtype: 'combo',
												id: 'prov1',
												hiddenName:'platRegSell.BANK_PROV',
												store: new Ext.data.ArrayStore({
														fields: ['PROV_CODE','PROV_NAME'],
														data: com.hnjowe.ext.data.provinces
												}),
												listeners:{   
													select:function(combo, record, index){   
														Ext.getCmp('city1').clearValue();   
														Ext.getCmp('city1').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: 'city1',
												hiddenName:'platRegSell.BANK_CITY',	//隐藏值
												store: new Ext.data.ArrayStore({
														fields: ['CITY_CODE','CITY_NAME'],
														data: []
												}),
												listeners:{   
													select:function(combo, record, index){   
														Ext.getCmp('country1').clearValue();   
														Ext.getCmp('country1').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: 'country1',
												hiddenName:'platRegSell.BANK_COUNTRY',	//隐藏值
												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
											}
										]
									},
									{ 
										defaults:{
											anchor:'100%',
											labelWidth:80,
											labelStyle : "text-align:right;"
										},
										items:[
											{
												fieldLabel: "<font color=red>*</font>开户银行名称",
												xtype: "textfield",
												name: "platRegSell.BANK_NAME",
												allowBlank: false,
												blankText: '开户银行名称不能为空',
												maxLength: 100,
												anchor:'95%'
											},{
												fieldLabel: "<font color=red>*</font>银行卡或存折号",
												xtype: "textfield",
												name: "platRegSell.ACCOUNT_NO",
												allowBlank: false,
												blankText: '银行卡或存折号不能为空',
												maxLength: 100,
												anchor:'95%'
											},{
												fieldLabel: "<font color=red>*</font>帐户名称(姓名)",
												xtype: "textfield",
												name: "platRegSell.ACCOUNT_NAME",
												allowBlank: false,
												blankText: '帐户名称(姓名)不能为空',
												maxLength: 40,
												anchor:'95%'
											}
										] 
									}
								]
							}
						]
					}
				]
			
			}
		];
	 },
	 
	/**
	 * 建立UI
     */
	buildUI : function(){
		return [{
				text: '注册',
				handler: this.onRegister,
				scope: this
			},
			{
				text: '关闭',
				handler: this.onClose,
				scope: this
			}
		];
	},
	
    /**
     * 事件：注册
     */
	onRegister : function() {

		Ext.getCmp('SellRegisterForm').getForm().submit({
			url:'/platform/sell/accountmgr/sellRegister.action',
			method: 'POST',
			waitMsg:'注册中,请稍后..',
			scope: this,
			success: function(form, action) { 
				if(typeof(action.result) != "undefined"){
					Ext.Msg.alert('提示', action.result.msg);
					Ext.getCmp('SellRegisterWin').close();
				}
			}, 
			failure: function(form, action) {
				if(typeof(action.result) != "undefined"){
					Ext.Msg.alert('提示', action.result.msg);
					Ext.getCmp('SellRegisterWin').close();
				}
			} 
		});
	},
	
    /**
     * 事件：关闭
     */
	onClose : function() {
		this.close();
		this.destroy();
	}
	
});


/*自定义验证帐号是否重复*/
Ext.apply(Ext.form.VTypes,{
	checkLoginName : function(val, field){
		var result;
		Ext.Ajax.request({
			url: '/platform/sell/accountmgr/checkLoginName.action?sellLoginName='+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:'确认密码不一致'
});






