效果图:
代码:
Ext.define('supplierModel', { extend: 'Ext.data.Model', fields: [{ name: 'id', type: 'string' }, { name: 'guaranteesupplier', type: 'string' }, { name: 'historysupplier', type: 'string' }] }); var supplierStore = Ext.create('Ext.data.Store', { model: 'supplierModel', proxy: { type: 'ajax', url: 'findSupplierManagementSupplier.action', reader: { // 数据格式为json type: 'json', root: 'root', totalProperty: 'total' } }, autoLoad: true }); var supplierGird = Ext.create('Ext.grid.Panel',{ store : supplierStore, forceFit : true, id : 'supplierGird', height : '100%', width : '100%', columns : [ new Ext.grid.RowNumberer({ header : "序号", align : 'center', width : 40, xtype : "rownumberer" }), { width : 493, text : "供应商名称", style : { textAlign : 'center' }, dataIndex : 'guaranteesupplier' } ], // listeners : { // 'selectionchange' : function(me, selected, options) { // findworkuser(); // } // }, bbar : Ext.create('Ext.PagingToolbar', { store : supplierStore, displayInfo : true, displayMsg : '共{2}条', emptyMsg : "没有数据" }) }); var addSupplierField = Ext.create("Ext.form.FieldSet", { height : 100, width : 350, border:false, layout : "column", items : [{ xtype:'textfield', columnWidth :1, fieldLabel : '维保供应商<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '路径不能为空', allowBlank: false, id:'guaranteeId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '历史供应商<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '路径不能为空', allowBlank: false, id:'historyId' }] }); var addSupplierPanel = Ext.create("Ext.form.Panel", { border:false, layout:'fit', id:'addSupplierPanel', items : [ addSupplierField ], buttons : [ { formBind : true, disabled : true, text : "添加", handler :function(){ var guaranteeSupplier = Ext.getCmp("guaranteeId").getValue(); var historySupplier = Ext.getCmp("historyId").getValue(); addSupplierPanel.submit({ url:'addSupplier.action', method:'post', params:{ 'suppliermnt.guaranteeSupplier':guaranteeSupplier, 'suppliermnt.historySupplier':historySupplier, }, success:function(form, action){ // var o = Ext.JSON.decode(action.response.responseText); addSupplierWindow.close(); supplierStore.load(); Ext.Msg.alert("提示", "添加成功!"); }, failure:function(){ addSupplierWindow.close(); Ext.Msg.alert("提示", "添加失败!"); } }); } } , { text : "重置", handler : function() { this.up('form').getForm().reset(); } }] }); var addSupplierWindow = Ext.create("Ext.window.Window", { title : "添加", layout:'fit', items : [ addSupplierPanel], closeAction : 'hide' }); var modifySupplierField = Ext.create("Ext.form.FieldSet", { height : 100, width : 350, border:false, layout : "column", items : [{ xtype:'textfield', columnWidth :1, fieldLabel : '维保供应商<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '路径不能为空', allowBlank: false, id:'modifyguaranteeId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '历史供应商<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '路径不能为空', allowBlank: false, id:'modifyhistoryId' }] }); var modifySupplierPanel = Ext.create("Ext.form.Panel", { border:false, items : [ modifySupplierField ], buttons : [ { formBind : true, disabled : true, text : "修改", handler :function(){ var supplierselection = Ext.getCmp('supplierGird').getSelectionModel().getSelection(); var supplierId = supplierselection[0].data.id; var guaranteeSupplier = Ext.getCmp("modifyguaranteeId").getValue(); var historySupplier = Ext.getCmp("modifyhistoryId").getValue(); modifySupplierPanel.submit({ url:'modifySupplier.action', method:'post', params:{ 'suppliermnt.guaranteeSupplier':guaranteeSupplier, 'suppliermnt.historySupplier':historySupplier, 'suppliermnt.id':supplierId, }, success:function(form, action){ // var o = Ext.JSON.decode(action.response.responseText); modifySupplierWindow.close(); supplierStore.load(); Ext.Msg.alert("提示", "修改成功!"); }, failure:function(){ modifySupplierWindow.close(); Ext.Msg.alert("提示", "修改失败!"); } }); } } , { text : "重置", handler : function() { this.up('form').getForm().reset(); } }] }); var modifySupplierWindow = Ext.create("Ext.window.Window", { title : "修改", layout:'fit', items : [ modifySupplierPanel], closeAction : 'hide' }); var organizationStore = Ext.create('Ext.data.Store', { fields : [ 'id','organization' ], data : [ { id: 1, organization : "管理人员" }, { id: 2, organization : "技术人员" }, { id: 3, organization : "驻场人员" } ] }); var organizationGird = Ext.create('Ext.grid.Panel', { store : organizationStore, forceFit : true, id : 'organizationGird', height : '100%', width : '100%', columns : [ new Ext.grid.RowNumberer({ header : "序号", align : 'center', width : 40, xtype : "rownumberer" }), { width : 493, text : "组织架构名称", style : { textAlign : 'center' }, dataIndex : 'organization' } ], listeners : { 'selectionchange' : function(me, selected, options) { findworkuser(); } } }); var officerDetailsField = Ext.create("Ext.form.FieldSet", { height : 300, width : 350, border:false, layout : "column", items : [{ xtype:'textfield', columnWidth :1, fieldLabel : '姓名', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'nameId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '出生日期', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'birthId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '电话', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'phoneId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '身份证', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'cardId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '邮箱', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'emailId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '供应商名称id', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'supplierId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '组织构架id', margin : '10 20 10 0', labelAlign:"right", allowBlank: false, id:'organizationId' }] }); var officerDetailsPanel = Ext.create("Ext.form.Panel", { border:false, items : [ officerDetailsField ], }); var officerDetailsWindow = Ext.create("Ext.window.Window", { title : "详情", layout:'fit', items : [ officerDetailsPanel], closeAction : 'hide' }); var addOfficerField = Ext.create("Ext.form.FieldSet", { height : 300, width : 350, border:false, layout : "column", items : [{ xtype:'textfield', columnWidth :1, fieldLabel : '姓名<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '姓名不能为空', maxLength : 20, maxLengthText : '姓名长度不得大于20个字符长度', allowBlank: false, id:'addnameId', },{ xtype:'textfield', columnWidth :1, fieldLabel : '出生日期<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '出生日期不能为空', allowBlank: false, id:'addbirthId', },{ xtype:'textfield', columnWidth :1, fieldLabel : '电话<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '电话不能为空', regex: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/ , regexText: '电话号码格式不正确', allowBlank: false, id:'addphoneId', },{ xtype:'textfield', columnWidth :1, fieldLabel : '身份证<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '身份证不能为空', regex: /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/, regexText: '身份证号码格式不正确', allowBlank: false, id:'addcardId', },{ xtype:'textfield', columnWidth :1, fieldLabel : '邮箱<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '邮箱不能为空', regex: /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/, regexText: '邮箱格式不正确', allowBlank: false, id:'addemailId', },{ xtype:'textfield', columnWidth :1, fieldLabel : '供应商id<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '供应商id不能为空', allowBlank: false, id:'addsupplierId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '组织构架id<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '组织构架id不能为空', allowBlank: false, id:'addorganizationId' }] }); var addOfficerPanel = Ext.create("Ext.form.Panel", { border:false, items : [ addOfficerField ], buttons : [ { formBind : true, disabled : true, text : "添加", handler :function(){ var addname = Ext.getCmp("addnameId").getValue(); var addbirth = Ext.getCmp("addbirthId").getValue(); var addphone = Ext.getCmp("addphoneId").getValue(); var addcard = Ext.getCmp("addcardId").getValue(); var addemail = Ext.getCmp("addemailId").getValue(); var addsupplier = Ext.getCmp("addsupplierId").getValue(); var addorganization = Ext.getCmp("addorganizationId").getValue(); addOfficerPanel.submit({ url:'addWorkUser.action', method:'post', params:{ 'workuser.name':addname, 'workuser.birth':addbirth, 'workuser.phone':addphone, 'workuser.card':addcard, 'workuser.email':addemail, 'workuser.supplier':addsupplier, 'workuser.organization':addorganization, }, success:function(form, action){ // var o = Ext.JSON.decode(action.response.responseText); addOfficerWindow.close(); userStore.load(); Ext.Msg.alert("提示", "添加成功!"); }, failure:function(){ addOfficerWindow.close(); Ext.Msg.alert("提示", "添加失败!"); } }); } } , { text : "重置", handler : function() { this.up('form').getForm().reset(); } }] }); var addOfficerWindow = Ext.create("Ext.window.Window", { title : "详情", layout:'fit', items : [ addOfficerPanel], closeAction : 'hide' }); var modifyOfficerField = Ext.create("Ext.form.FieldSet", { height : 300, width : 350, border:false, layout : "column", items : [{ xtype:'textfield', columnWidth :1, fieldLabel : '姓名<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '姓名不能为空', maxLength : 20, maxLengthText : '姓名长度不得大于20个字符长度', allowBlank: false, id:'modifynameId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '出生日期<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '出生日期不能为空', allowBlank: false, id:'modifybirthId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '电话<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '电话不能为空', regex: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,14}$/ , regexText: '电话号码格式不正确', allowBlank: false, id:'modifyphoneId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '身份证<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '身份证不能为空', regex: /^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/, regexText: '身份证号码格式不正确', allowBlank: false, id:'modifycardId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '邮箱<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '邮箱不能为空', regex: /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/, regexText: '邮箱格式不正确', allowBlank: false, id:'modifyemailId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '供应商id<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '供应商id', allowBlank: false, id:'modifysupplierId' },{ xtype:'textfield', columnWidth :1, fieldLabel : '组织构架id<span style="color:red">*</span>', margin : '10 20 10 0', labelAlign:"right", blankText: '组织构架id', allowBlank: false, id:'modifyorganizationId' }] }); var modifyOfficerPanel = Ext.create("Ext.form.Panel", { border:false, items : [ modifyOfficerField ], buttons : [ { formBind : true, disabled : true, text : "修改", handler :function(){ var userselection = Ext.getCmp('userGrid').getSelectionModel().getSelection(); var modifyId = userselection[0].data.id; var modifyname = Ext.getCmp("modifynameId").getValue(); var modifybirth = Ext.getCmp("modifybirthId").getValue(); var modifyphone = Ext.getCmp("modifyphoneId").getValue(); var modifycard = Ext.getCmp("modifycardId").getValue(); var modifyemail = Ext.getCmp("modifyemailId").getValue(); var modifysupplier = Ext.getCmp("modifysupplierId").getValue(); var modifyorganization = Ext.getCmp("modifyorganizationId").getValue(); modifyOfficerPanel.submit({ url:'modifyWorkUser.action', method:'post', params:{ 'workuser.id':modifyId, 'workuser.name':modifyname, 'workuser.birth':modifybirth, 'workuser.phone':modifyphone, 'workuser.card':modifycard, 'workuser.email':modifyemail, 'workuser.supplier':modifysupplier, 'workuser.organization':modifyorganization, }, success:function(form, action){ // var o = Ext.JSON.decode(action.response.responseText); modifyOfficerWindow.close(); userStore.load(); Ext.Msg.alert("提示", "添加成功!"); }, failure:function(){ modifyOfficerWindow.close(); Ext.Msg.alert("提示", "添加失败!"); } }); } } , { text : "重置", handler : function() { this.up('form').getForm().reset(); } }] }); var modifyOfficerWindow = Ext.create("Ext.window.Window", { title : "详情", layout:'fit', items : [ modifyOfficerPanel], closeAction : 'hide' }); Ext.define('userModel', { extend: 'Ext.data.Model', fields: [{ name: 'id', type: 'string' }, { name: 'name', type: 'string' }, { name: 'birth', type: 'string' }, { name: 'phone', type: 'string' }, { name: 'card', type: 'string' }, { name: 'email', type: 'string' }, { name: 'supplierid', type: 'string' }, { name: 'organizationid', type: 'string' }] }); var userStore = Ext.create('Ext.data.Store', { model: 'userModel', proxy: { type: 'ajax', url: 'findWorkUser.action', reader: { // 数据格式为json type: 'json', root: 'root', totalProperty: 'total' } }, autoLoad: false }); var userGrid = Ext.create('Ext.grid.Panel', { store: userStore, forceFit : true, id : 'userGrid', height : '100%', width : '100%', columns : [ new Ext.grid.RowNumberer({ header : "序号", align : 'center', width : 40, xtype : "rownumberer" }), { width : 452, text : "人员名称", style : { textAlign : 'center' }, dataIndex : 'name' }, { text : '详情', width : 40, flex : 1, dataIndex : 'id', sortable : true, renderer:function(value){ var param ="\'"+value+"\'"; return '<a style="text-decoration:none" href="javascript:void(0)" onclick="doClick('+param+')"> 详情</a>'; } } ] }); function initPanel() { supplierStore.load(); var supplierPanel = Ext.create('Ext.panel.Panel', { title : '服务人员管理', store : supplierStore, width : '100%', height : '100%', renderTo : Ext.getBody(), layout : 'border', defaults : { bodyStyle : "background-color: #FFFFFF;", frame : true }, items : [ { region : "west", width : '33%', height : '100%', // collapsible : true, // title : '供应商', hideTitle : false, layout : 'fit', tbar : [{ xtype : 'label', style:'font-size:12px;font-family:bold;', id : 'addLabel', text : '供应商' }, '->', // { xtype: 'tbfill' }, { xtype : 'button', text : '添加', handler : function() { addSupplierWindow.show(); } }, { xtype : 'button', text : '删除', handler : function() { var supplierselection = Ext.getCmp('supplierGird').getSelectionModel().getSelection(); if(supplierselection.length != 0){ var supplierId = supplierselection[0].data.id; Ext.Ajax.request({ url:'deleteSupplier.action', method:'post', params:{ 'suppliermnt.id':supplierId, }, success:function(form, action){ supplierStore.load(); Ext.Msg.alert("提示", "删除成功!"); }, failure:function(){ Ext.Msg.alert("提示", "删除失败!"); } }); }else { Ext.Msg.alert("提示", "请选择供应商!"); } } }, { xtype : 'button', text : '修改', handler : function() { var supplierselection = Ext.getCmp('supplierGird').getSelectionModel().getSelection(); if(supplierselection.length != 0){ modifySupplierWindow.show(); var supplierId = supplierselection[0].data.id; var guaranteesupplier = supplierselection[0].data.guaranteesupplier; var historysupplier = supplierselection[0].data.historysupplier; Ext.getCmp('modifyguaranteeId').setValue(guaranteesupplier); Ext.getCmp('modifyhistoryId').setValue(historysupplier); }else{ Ext.Msg.alert("提示", "请选择供应商!"); } } } ], items : [ supplierGird ], }, { region : "center", split : true, border : true, width : '34%', // title : '组织架构', layout : 'fit', tbar : [{ xtype : 'label', style:'font-size:15px;font-family:bold;', id : 'addLabel2', text : '组织架构' }], items : [ organizationGird ], }, { region : "east", // title : '人员', width : '34%', layout : 'fit', tbar : [ { xtype : 'label', style:'font-size:12px;font-family:bold;', id : 'addLabel1', text : '人员' }, '->', // { xtype: 'tbfill' }, { xtype : 'button', text : '添加', handler : function() { var supplierselection = Ext.getCmp('supplierGird').getSelectionModel().getSelection(); var organizationselection = Ext.getCmp('organizationGird').getSelectionModel().getSelection(); if(supplierselection.length != 0){ if(organizationselection.length != 0){ var organizationid = organizationselection[0].data.id; var guaranteesupplierid = supplierselection[0].data.id; Ext.getCmp('addsupplierId').setValue(guaranteesupplierid); Ext.getCmp('addorganizationId').setValue(organizationid); addOfficerWindow.show(); }else{ var guaranteesupplierid = supplierselection[0].data.id; Ext.getCmp('addsupplierId').setValue(guaranteesupplierid); addOfficerWindow.show(); } }else{ addOfficerWindow.show(); } } }, { xtype : 'button', text : '删除', handler : function() { var userselection = Ext.getCmp('userGrid').getSelectionModel().getSelection(); if(userselection.length != 0){ var userId = userselection[0].data.id; Ext.Ajax.request({ url:'deleteWorkUser.action', method:'post', params:{ 'work.id':userId, }, success:function(form, action){ userStore.load(); Ext.Msg.alert("提示", "删除成功!"); }, failure:function(){ Ext.Msg.alert("提示", "删除失败!"); } }); }else { Ext.Msg.alert("提示", "请选择人员!"); } } }, { xtype : 'button', text : '修改', handler : function(value) { var userselection = Ext.getCmp('userGrid').getSelectionModel().getSelection(); if(userselection.length != 0){ userStore.proxy.extraParams['id']=value; userStore.load(); Ext.getCmp('modifynameId').setValue(userStore.data.items[0].data.name); Ext.getCmp('modifybirthId').setValue(userStore.data.items[0].data.birth); Ext.getCmp('modifyphoneId').setValue(userStore.data.items[0].data.phone); Ext.getCmp('modifycardId').setValue(userStore.data.items[0].data.card); Ext.getCmp('modifyemailId').setValue(userStore.data.items[0].data.email); Ext.getCmp('modifysupplierId').setValue(userStore.data.items[0].data.supplierid); Ext.getCmp('modifyorganizationId').setValue(userStore.data.items[0].data.organizationid); modifyOfficerWindow.show(); }else{ Ext.Msg.alert("提示", "请选择人员!"); } } } ], items : [ userGrid ], } ] }); } function findworkuser(){ var supplierselection = Ext.getCmp('supplierGird').getSelectionModel().getSelection(); var organizationselection = Ext.getCmp('organizationGird').getSelectionModel().getSelection(); if(supplierselection.length !=0 && organizationselection.length != 0){ var supplierId = supplierselection[0].data.id; var organizationId = organizationselection[0].data.id; Ext.Ajax.request({ url : "findWorkUser.action", params : { "workuser.supplierid" : supplierId, "workuser.organizationid" : organizationId }, method : 'post', success : function(response, options) { var o = Ext.JSON.decode(response.responseText); userStore.load(); }, failure : function() { Ext.Msg.alert("提示", "加载错误!"); } }); }else{ Ext.Msg.alert("提示", "请选择供应商!"); } } function doClick(arg){ userStore.proxy.extraParams['id']=arg; userStore.load(); Ext.getCmp('nameId').setValue(userStore.data.items[0].data.name); Ext.getCmp('birthId').setValue(userStore.data.items[0].data.birth); Ext.getCmp('phoneId').setValue(userStore.data.items[0].data.phone); Ext.getCmp('cardId').setValue(userStore.data.items[0].data.card); Ext.getCmp('emailId').setValue(userStore.data.items[0].data.email); Ext.getCmp('supplierId').setValue(userStore.data.items[0].data.supplierid); Ext.getCmp('organizationId').setValue(userStore.data.items[0].data.organizationid); officerDetailsWindow.show(); }