function startSearch(a){var b=document.search.text.value.trim();if(b===""||b==="请输入商品名称或型号"){alert("请输入商品名称或型号")}else{if(b.length<2){alert("搜索关键词长度至少为2个字符")}else{if(a==="sub"){return true}else{document.search.submit()}}}return false}function resizeImage(g,b,e){var c,a,d,f;c=new Image();c.src=g.src;a=c.width;d=c.height;f=Math.min(e/d,b/a);g.width=a*f;g.height=d*f}function fullToHalf(c){var a="";for(var b=0;b<c.length;b++){code=c.charCodeAt(b);if(code>=65281&&code<=65373){a+=String.fromCharCode(code-65248)}else{if(code===12288){a+=" "}else{a+=c.charAt(b)}}}return a}var win;function helpdesk(){if(win===undefined||win.closed){win=window.open("","helpdesk","toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=yes,width=600,height=500");if(win.location.href==="about:blank"){win.location.href="/helpdesk"}}win.focus()}Ext.BLANK_IMAGE_URL="/css/images/default/s.gif";Ext.namespace("Ext.app","Ext.app.RT");Ext.app.RT.ShippingAddress=Ext.data.Record.create([{name:"shipping_address_id",type:"int"},{name:"party_name",type:"string"},{name:"region_code",type:"string"},{name:"street",type:"string"},{name:"postal_code",type:"string"},{name:"mobile",type:"string"},{name:"phone",type:"string"}]);Ext.app.RT.Order=Ext.data.Record.create([{name:"order_id",type:"int"},{name:"customer_id",type:"int"},{name:"customer_login",type:"string"},{name:"creation_date",type:"date",dateFormat:"Y-m-d"},{name:"shipping_date",type:"date",dateFormat:"Y-m-d"},{name:"amount",type:"float"},{name:"freight",type:"float"},{name:"shipper_type",type:"int"},{name:"discount",type:"float"},{name:"rebate",type:"float"},{name:"order_status",type:"int"},{name:"shipping_address_region_code",type:"string"},{name:"shipping_address_party_name",type:"string"},{name:"shipping_address_street",type:"string"},{name:"shipping_address_postal_code",type:"string"},{name:"shipping_address_mobile",type:"string"},{name:"shipping_address_phone",type:"string"},{name:"memo",type:"string"}]);Ext.app.RT.OrderItem=Ext.data.Record.create([{name:"order_item_seq_id",type:"int"},{name:"item_id",type:"int"},{name:"item_name"},{name:"specification"},{name:"model_no"},{name:"quantity",type:"float"},{name:"unit_name"},{name:"sales_price",type:"float"},{name:"amount",type:"float"}]);Ext.app.OrderStatus=new Ext.data.SimpleStore({fields:["code","text"],data:[[1,"等待大管家确认"],[2,"大管家已确认，请您付款"],[3,"已部分发货"],[4,"订单已完成"],[5,"订单已取消"],[6,"订单已付款，等待发货"]]});Ext.app.ShipperType=new Ext.data.SimpleStore({fields:["code","text"],data:[[1,"大管家送货"],[2,"物流公司"],[3,"快递"],[4,"自己提货"]]});Ext.app.LoginWindow=function(){this.loginForm=new Ext.FormPanel({id:"login-form",baseCls:"x-plain",labelAlign:"right",labelWidth:60,url:"/login",defaults:{msgTarget:"under",validationDelay:500},plugins:new Ext.ux.plugins.InfoPlugin(),items:[{xtype:"textfield",name:"login",fieldLabel:"用户名",allowBlank:false,emptyText:"请输入用户名",regex:/^[_a-zA-Z0-9\u4e00-\u9fa5]{2,20}$/,regexText:"用户名只能由字母、数字以及中文字符构成",minLength:2,minLengthText:"用户名长度为2-20个字符",maxLength:20,maxLengthText:"用户名长度为2-20个字符"},{xtype:"textfield",name:"password",fieldLabel:"密码",allowBlank:false,inputType:"password",minLength:6,minLengthText:"密码长度为6-12个字符",maxLength:12,maxLengthText:"密码长度为6-12个字符"},{xtype:"box",id:"forgot-passwd",style:"margin-top: 5px;",autoEl:{cn:"<p>尚未注册的用户请先注册。</p><p>忘记密码或用户名？点击下面的“忘记密码”按钮，可以通过邮件取回您的密码或用户名。<p>"}}],buttonAlign:"center",buttons:[{iconCls:"x-alipay_icon",width:"107px",tooltip:"如果您是支付宝用户，可无须注册，直接用支付宝账号登录",handler:function(){location=alipayLoginUrl},scope:this},{iconCls:"x-icon-login",text:"登录",tooltip:"使用大管家网站用户登录",handler:function(){this.login()},scope:this},{text:"取消",iconCls:"btn-cancel",handler:function(){this.loginForm.getForm().reset();this.loginForm.hideInfo();this.hide()},scope:this},{text:"免费注册",iconCls:"x-icon-signup",tooltip:"还没有用户名？立即注册。",handler:function(){this.getLayout().setActiveItem("signup-form")},scope:this},{text:"忘记密码",iconCls:"x-icon-help",handler:function(){this.getLayout().setActiveItem("password-form")},scope:this}],listeners:{render:{fn:function(){this.loginForm.el.addKeyListener(Ext.EventObject.ENTER,this.login,this)},scope:this}}});this.passwordForm=new Ext.FormPanel({id:"password-form",baseCls:"x-plain",labelWidth:60,url:"/login",defaults:{msgTarget:"under",validationDelay:500},items:[{xtype:"box",autoEl:{cn:"<p>填写说明：</p><ul><li>如果遗忘登录用户名，请填写邮件地址取回用户名。</li><li>如果遗忘登录密码，可填写用户名或邮件地址，我们会将您的登录密码发送到您的邮箱。</li><li>为了确保密码安全，请在收到密码后进入用户管理，更改您的密码。</li></ul>"}},{xtype:"textfield",name:"login",fieldLabel:"用户名",emptyText:"请输入用户名",regex:/^[_a-z0-9\u4e00-\u9fa5]{2,20}$/,regexText:"用户名只能由字母、数字以及中文字符构成",minLength:2,minLengthText:"用户名长度为2-20个字符",maxLength:20,maxLengthText:"用户名长度为2-20个字符"},{xtype:"textfield",name:"email",width:200,emptyText:"请输入注册时输入的电子邮件地址",fieldLabel:"E-Mail",vtype:"email"}],buttonAlign:"center",buttons:[{text:"取回密码",handler:this.retrievePassword,scope:this},{text:"取回用户名",handler:this.retrieveLogin,scope:this},{text:"返回登录",iconCls:"x-icon-previous",handler:function(){this.getLayout().setActiveItem("login-form")},scope:this},{text:"取消",iconCls:"btn-cancel",handler:function(){this.passwordForm.getForm().reset();this.hide()},scope:this}]});this.signupForm=new Ext.FormPanel({id:"signup-form",frame:true,baseCls:"x-plain",labelWidth:80,title:"请输入注册信息",bodyStyle:"padding:5px 5px 0",defaults:{xtype:"textfield",msgTarget:"side",width:200},items:[{fieldLabel:"用户名*",name:"login",itemCls:"required",allowBlank:false,emptyText:"请输入用户名",regex:/^[_a-zA-Z0-9\u4e00-\u9fa5]{2,20}$/,regexText:"用户名只能由字母、数字以及中文字符构成",minLength:2,minLengthText:"用户名长度为2-20个字符",maxLength:20,maxLengthText:"用户名长度为2-20个字符",listeners:{blur:function(){if(!this.isValid()){return}Ext.Ajax.request({url:"/auth",jsonData:{version:"1.1",method:"checkUnique",params:{login:this.getValue()}},success:function(a){var b=Ext.decode(a.responseText);if(!b.result){this.markInvalid("该用户名已存在，请选择其他用户名!")}},nocache:true,scope:this})}}},{fieldLabel:"姓名*",name:"party_name",itemCls:"required",allowBlank:false,emptyText:"请输入您的真实姓名"},{name:"password",fieldLabel:"密码*",allowBlank:false,itemCls:"required",inputType:"password",listeners:{blur:function(){var a=this.ownerCt;a.validatePassword(a.getForm())}},minLength:6,minLengthText:"密码长度为6-12个字符",maxLength:12,maxLengthText:"密码长度为6-12个字符"},{name:"verify",fieldLabel:"重复密码*",submitValue:false,allowBlank:false,itemCls:"required",inputType:"password",listeners:{blur:function(){var a=this.ownerCt;a.validatePassword(a.getForm())}},minLength:6,minLengthText:"密码长度为6-12个字符",maxLength:12,maxLengthText:"密码长度为6-12个字符"},{xtype:"textfield",name:"email",itemCls:"required",fieldLabel:"E-Mail*",emptyText:"请输入您的常用电子邮件地址",allowBlank:false,vtype:"email",listeners:{blur:function(){if(!this.isValid()){return}Ext.Ajax.request({url:"/auth",jsonData:{version:"1.1",method:"checkUnique",params:{email:this.getValue()}},success:function(a){var b=Ext.decode(a.responseText);if(!b.result){this.markInvalid("已有用户使用了该邮件地址，请核实!")}},nocache:true,scope:this})}}},{xtype:"numberfield",minLength:11,maxLength:11,fieldLabel:"手机",name:"mobile"},{xtype:"box",autoEl:{style:"margin-top: 10px;",cn:"* 以上带星号的为必须输入的项目。"}}],plugins:new Ext.ux.plugins.InfoPlugin({width:"auto"}),buttonAlign:"center",buttons:[{text:"注册",iconCls:"x-icon-signup",handler:function(){var a=this.signupForm;var b=a.getForm();if(!b.isValid()||!a.validatePassword(b)){a.showInfo({icon:Ext.ux.InfoPanel.ERROR,msg:"输入数据仍有错误，请更正后重新提交。请将鼠标移动到出错字段右侧图标上查看具体出错原因。",autoHide:5000});return}b.doAction("jsonsubmit",{url:"/auth",jsonmethod:"signup",asSingleArgs:true,success:function(c,d){if(d.result.success){this.afterLogin()}},scope:this})},scope:this},{text:"取消",iconCls:"btn-cancel",handler:function(){this.signupForm.getForm().reset();this.hide()},scope:this}],validatePassword:function(a){var c=a.findField("password");var b=a.findField("verify");if(c.isValid()&&b.isValid()){if(c.getValue()!==b.getValue()){a.markInvalid({password:"密码和重复输入的密码不一致",verify:"密码和重复输入的密码不一致"})}else{c.clearInvalid();b.clearInvalid();return true}}}});Ext.app.LoginWindow.superclass.constructor.call(this,{width:500,height:300,closable:false,closeAction:"hide",bodyStyle:"padding:5px;",iconCls:"x-icon-login",title:"用户登录",layout:"card",activeItem:0,modal:true,renderTo:Ext.getBody(),tools:[{id:"help",handler:helpdesk}],items:[this.loginForm,this.passwordForm,this.signupForm]})};Ext.extend(Ext.app.LoginWindow,Ext.Window,{login:function(){this.loginForm.getForm().doAction("jsonsubmit",{url:"/auth",jsonmethod:"login",success:function(){this.afterLogin()},failure:function(){this.loginForm.showInfo({icon:Ext.ux.InfoPanel.ERROR,msg:"登录错误，请核实用户名和密码！"})},scope:this})},show:function(b,a){if(typeof b==="function"){this.successAction=b}else{this.successAction="reload"}this.successActionScope=a||this;this.getLayout().setActiveItem("login-form");Ext.app.LoginWindow.superclass.show.call(this);this.loginForm.getForm().findField("login").focus(false,true)},showSignup:function(){this.getLayout().setActiveItem("signup-form");Ext.app.LoginWindow.superclass.show.call(this)},afterLogin:function(){Ext.app.loggedIn=true;this.hide();if(this.successAction==="reload"){location.reload()}else{if(typeof this.successAction==="function"){this.successAction.call(this.successActionScope)}else{if(typeof this.successAction==="string"){location=this.successAction}else{location="/"}}}},retrievePassword:function(){var a=this.passwordForm.getForm();if(!a.isValid()){return}if(!a.findField("login").getValue()&&!a.findField("email").getValue()){a.markInvalid({login:"必须输入用户名或邮件",email:"必须输入用户名或邮件"});return}a.doAction("jsonsubmit",{url:"/auth",jsonmethod:"retrievePassword",success:function(b,c){if(c.result.success){Ext.Msg.show({title:"成功取回密码",msg:"密码已通过邮件发送给您，请查收。",buttons:Ext.Msg.OK,icon:Ext.Msg.INFO})}},scope:this})},retrieveLogin:function(){var a=this.passwordForm.getForm();if(!a.isValid()){return}if(!a.findField("email").getValue()){a.markInvalid({email:"必须输入邮件地址才能取回登录名"});return}a.doAction("jsonsubmit",{url:"/auth",jsonmethod:"retrieveLogin",success:function(b,c){if(c.result.success){Ext.Msg.show({title:"成功取回用户名",msg:"用户名已通过邮件发送给您，请查收。",buttons:Ext.Msg.OK,icon:Ext.Msg.INFO})}},scope:this})}});Ext.app.logout=function(){Ext.Ajax.request({url:"/auth",jsonData:{version:"1.1",method:"logout",params:{}},success:function(a){window.location="/"},scope:this,nocache:true})};Ext.app.Region=(function(){var c,b;function d(){var e=[],g=c;e["1"]={name:"root",code:"1",children:[]};for(var h in g){if(g.hasOwnProperty(h)){if(isNaN(parseInt(h,10))){continue}var f=g[h],i=f[1]||"1";e[h]={name:f[0],code:h,parent:f[1]};if(e[i]){if(!e[i].children){e[i].children=[]}e[i].children.push(h)}}}c=e}function a(){if(!b){Ext.Ajax.request({url:"/scripts/regiondata.json",method:"get",success:function(e){c=Ext.decode(e.responseText);d();b=true},async:false,scope:this})}}return{getData:function(){if(!b){a()}return c},getRegionName:function(g){var e="",f,h=this.getData();do{f=h[g];e=f.name+e;g=f.parent}while(g!==1);return e}}}());Ext.app.RegionLoader=(function(){return{load:function(d,k){var e=Ext.app.Region.getData();var b=e[d.id==="root"?1:d.id].children;d.beginUpdate();for(var f=0,g=b.length;f<g;f++){var a=e[b[f]];var j=(a.children===undefined);var h={id:a.code,text:a.name,leaf:j};var c=j?new Ext.tree.TreeNode(h):new Ext.tree.AsyncTreeNode(h);d.appendChild(c)}d.endUpdate();if(typeof k==="function"){k(this,d)}}}}());Ext.app.RegionSelector=Ext.extend(Ext.ux.form.TreeComboBox,{allowBlank:false,width:200,minListWidth:200,resizable:true,displayField:"text",valueField:"id",lazyInit:true,constructor:function(a){this.treeConfig={singleExpand:true,loader:Ext.app.RegionLoader,root:new Ext.tree.AsyncTreeNode({id:"root",text:"Root",expanded:false})};Ext.apply(this,a);Ext.app.RegionSelector.superclass.constructor.call(this,a)},renderer:function(a){if(a.attributes){var b=a[this.displayField]||a.attributes[this.displayField];while(a.getDepth()>1){a=a.parentNode;b=(a[this.displayField]||a.attributes[this.displayField])+b}return b}else{return Ext.app.Region.getRegionName(a)}},validateValue:function(b){var a=Ext.app.Region.getData();var c=this.rawValue;if(!c){this.markInvalid(this.blankText);return false}if(a[c].parent===1&&c!=="500100"&&c!=="110100"&&c!=="120100"&&c!=="310100"&&c!=="810000"&&c!=="820000"){this.markInvalid("区域选择必须至少选择到城市一级");return false}return true}});Ext.reg("regionselector",Ext.app.RegionSelector);Ext.app.AddressForm=function(a){Ext.apply(this,{labelWidth:70,defaultType:"textfield",defaults:{msgTarget:"under",validationDelay:500},bodyStyle:"padding: 5px",items:[{xtype:"hidden",name:"shipping_address_id"},{fieldLabel:"收货人*",name:"party_name",emptyText:"请输入收货人姓名",allowBlank:false,itemCls:"required"},{xtype:"regionselector",name:"region_code",fieldLabel:"地区*",emptyText:"请从下拉框中选择一个地区",itemCls:"required"},{xtype:"textarea",name:"street",fieldLabel:"住址*",height:35,allowBlank:false,emptyText:"请仅输入街道地址，无须重复输入省市等地区信息",itemCls:"required",width:400},{xtype:"numberfield",name:"postal_code",width:70,minLength:6,maxLength:6,fieldLabel:"邮编"},{xtype:"fieldset",title:"收货联系电话*(需至少输入一个)",layout:"column",labelWidth:40,autoHeight:true,items:[{layout:"form",width:240,border:false,items:{xtype:"numberfield",name:"mobile",minLength:11,maxLength:11,fieldLabel:"手机",msgTarget:"under",validationDelay:500}},{layout:"form",columnWidth:1,border:false,items:{xtype:"textfield",name:"phone",fieldLabel:"电话",emptyText:"格式:区号-电话*分机",minLength:8,vtype:"phone",msgTarget:"under",validationDelay:500,listeners:{blur:function(b){b.setValue(fullToHalf(b.getValue()))}}}}]}],plugins:new Ext.ux.plugins.InfoPlugin()});Ext.apply(this,a);Ext.app.AddressForm.superclass.constructor.call(this)};Ext.extend(Ext.app.AddressForm,Ext.form.FormPanel,{isValid:function(){var a=this.getForm();if(!a.isValid()){return false}if(!a.findField("phone").getValue()&&!a.findField("mobile").getValue()){a.markInvalid({mobile:"必须输入手机或电话",phone:"必须输入手机或电话"});return false}return true}});Ext.app.AddressGrid=function(b){Ext.apply(this,b);var a=[new Ext.grid.RowNumberer(),new Ext.grid.CheckboxSelectionModel({singleSelect:true}),{header:"收货人",width:100,dataIndex:"party_name"},{id:"address-col",header:"地址",width:250,dataIndex:"street",renderer:function(e,f,d){return Ext.app.Region.getRegionName(d.data.region_code)+d.data.street}},{header:"邮编",width:80,dataIndex:"postal_code"},{header:"手机",width:100,dataIndex:"mobile"},{header:"电话",width:100,dataIndex:"phone"}];if(this.actions){for(var c=0;c<this.actions.length;c++){a.push(this.actions[c])}}this.cm=new Ext.grid.ColumnModel(a);Ext.app.AddressGrid.superclass.constructor.call(this)};Ext.extend(Ext.app.AddressGrid,Ext.grid.GridPanel,{stripeRows:true,enableColumnMove:false,trackMouseOver:true,autoExpandColumn:"address-col"});function resizePopupImage(a){resizeImage(a,230,230);Ext.get("loading").addClass("x-hidden");Ext.get("pop_img").child("a").next().removeClass("x-hidden")}function initImagePopup(){Ext.DomHelper.createTemplate('<div id="pop_img" class="x-hidden"><img id="pointer" src="/img/pointer.gif"/><a id="loading"><img src="/img/loading_img.gif" /></a><a id="popup-img" href="#" class="x-hidden"><img  onload="javascript:resizePopupImage(this)"/></a></div>').append(Ext.getBody(),false);var a=Ext.get("pop_img");var b=Ext.get("popup-img");Ext.select(".item-cell table div").on({mouseover:function(){var c=Ext.get(this).child("img").dom.src.split("/").last();if(c!=="nopic_small.png"){b.dom.href=Ext.get(this).child("a").dom.href;b.child("img").dom.src="/imglib/thumba/"+c;a.removeClass("x-hidden");a.alignTo(this,"l-tr",[-8,0]);a.first().alignTo(this,"c-tr?",[0,34])}},mouseout:function(f,c){var d=f.getRelatedTarget();if(a.dom!==d&&!a.contains(d)){a.addClass("x-hidden");Ext.get("loading").removeClass("x-hidden");b.addClass("x-hidden")}}});a.hover(Ext.emptyFn,function(d,c){a.addClass("x-hidden");Ext.get("loading").removeClass("x-hidden");b.addClass("x-hidden")})}function initHelpDesk(){var a=function(){Ext.get("helpdesk").dom.style.top=document.documentElement.scrollTop+parseInt(document.documentElement.clientHeight,10)-111+"px"};if(Ext.fly("helpdesk")){window.onresize=a;window.onscroll=a;a()}}function initNav(){Ext.select("#nav .item").addClassOnOver("item-hover");if(Ext.isIE&&Ext.get("small_img")!==null){Ext.select("#nav .item").hover(function(){Ext.get("small_img").setStyle("z-index","-1")},function(){Ext.get("small_img").setStyle("z-index","0")})}}function closeHelpDesk(){Ext.get("helpdesk").hide()}Ext.onReady(function(){Ext.QuickTips.init();initHelpDesk()});
