/** * 与formpanel操作相关的增删改查的操作方法都在这里哦 * 如果formpanel作为主表,还有一些gridpanel等的信息作为附表,form操作时还包括了对gridpanel等的操作 * @author yingp */ Ext.define('erp.util.FormUtil',{ /** * 从后台拿到formpanel配置 * @param form formpanel表 * @param url 提交的action名 * @param param 传递回去的数据,比如{caller:Purchase,condition:pu_id=30001} */ getMultiAssigns:'/common/getMultiNodeAssigns.action', takeoveraction:'common/takeOverTask.action', deleteProcess:'common/deleteProcessAfterAudit.action?_noc=1', getItemsAndButtons: function(form, url, param){ var me = this, tab = me.getActiveTab(); me.setLoading(true); Ext.Ajax.request({//拿到form的items url : basePath + url, params: param, method : 'post', callback : function(options, success, response){ me.setLoading(false); if (!response) return; var res = new Ext.decode(response.responseText); if(res.exceptionInfo != null){ showError(res.exceptionInfo);return; } form.fo_id = res.fo_id; form.fo_keyField = res.keyField; form.tablename = res.tablename;//表名 if(res.keyField){//主键 form.keyField = res.keyField; } if(res.statusField){//状态 form.statusField = res.statusField; } if(res.statuscodeField){//状态码 form.statuscodeField = res.statuscodeField; } if(res.codeField){//Code form.codeField = res.codeField; } if(res.dealUrl){ form.dealUrl = res.dealUrl; } form.fo_detailMainKeyField = res.fo_detailMainKeyField;//从表外键字段 var grids = Ext.ComponentQuery.query('gridpanel'); //如果该页面只有一个form,而且form字段少于8个,则布局改变 if(!form.fixedlayout && !form.minMode && grids.length == 0 && res.items.length <= 8){ Ext.each(res.items, function(item){ item.columnWidth = 0.5; }); form.layout = 'column'; } if((res.items.length>0.097*window.innerWidth && window.innerWidth<=1150)){ Ext.each(res.items, function(item){ form.layout='column'; //若根据分辨率直接获取宽度会导致 有时不能占满整行 item.width=window.innerWidth*(item.columnWidth)-item.columnWidth*4*10; }); } //data&items var items = me.setItems(form, res.items, res.data, res.limits, { labelColor: res.necessaryFieldColor }); form.add(items); //title if(res.title && res.title != ''){ form.setTitle(res.title); var _tt = res.title; if(form.codeField) { var _c = form.down('#' + form.codeField); if( _c && !Ext.isEmpty(_c.value) ) _tt += '(' + _c.value + ')'; } tab && tab.setTitle(_tt); } me.setButtons(form, res.buttons); //form第一个可编辑框自动focus me.focusFirst(form); form.fireEvent('afterload', form); } }); }, focusFirst: function(form){ var bool = true; if(!form.readOnly){ Ext.each(form.items.items, function(){ if(bool && this.hidden == false && this.readOnly == false && this.editable == true){ this.focus(false, 200); bool = false; } }); } }, /** * @param necessaryCss 必填项样式 */ setItems: function(form, items, data, limits, necessaryCss){ var me = this, edit = !form.readOnly,hasData = true,limitArr = new Array(); if(limits != null && limits.length > 0) {//权限外字段 limitArr = Ext.Array.pluck(limits, 'lf_field'); } if (data) { data = Ext.decode(data); if(form.statuscodeField && data[form.statuscodeField] != null && data[form.statuscodeField] != '' && ['ENTERING', 'UNAUDIT', 'UNPOST', 'CANUSE'].indexOf(data[form.statuscodeField]) == -1){//非在录入和已提交均设置为只读// && data[form.statuscodeField] != 'COMMITED' form.readOnly = true; edit = false; } if(form.statusCode && data[form.statusCode] == 'POSTED'){//存在单据状态 并且单据状态不等于空 并且 单据状态等于已过账 form.readOnly = true; edit = false; } // statusCode } else { hasData = false; } var bool = 'a'; if(items.length > 110&&items.length <=190){ bool = 'b'; }else if(items.length>190){ bool = 'c'; } Ext.each(items, function(item){ if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度 if(item.columnWidth > 0 && item.columnWidth <= 0.25){ item.columnWidth = 1/3; } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){ item.columnWidth = 2/3; } else if(item.columnWidth >= 1){ item.columnWidth = 1; } } else { if(item.columnWidth > 0.25 && item.columnWidth < 0.5){ item.columnWidth = 1/3; } else if(item.columnWidth > 0.5 && item.columnWidth < 0.75){ item.columnWidth = 2/3; } } if(!item.allowBlank && item.fieldLabel && necessaryCss.labelColor) { item.labelStyle = 'color:#' + necessaryCss.labelColor; item.fieldStyle = 'background:#FFFAFA;color:#515151;' } if(item.readOnly) { item.fieldStyle = 'background:#e0e0e0;'; } if(item.name != null) { if(item.name == form.statusField){//状态加特殊颜色 item.fieldStyle = item.fieldStyle + ';font-weight:bold;'; } else if(item.name == form.statuscodeField){//状态码字段强制隐藏 item.xtype = 'hidden'; } } if(item.xtype == 'hidden') { item.columnWidth = 0; item.margin = '0'; } if(item.xtype == 'checkbox') { item.focusCls = ''; } if(item.maskRe!=null){ item.maskRe=new RegExp(item.regex); } if (hasData) { item.value = data[item.name]; if(item.secondname){//针对合并型的字段MultiField item.secondvalue = data[item.secondname]; } if(item.xtype=='multifield1'){ if(item.logic){ var logics = item.logic.split(","); item.secondvalue = data[logics[0]]; if(logics[1]){ item.thirdvalue = data[logics[1]]; } } } if(!edit){ form.readOnly = true; item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;'; item.readOnly = true; } if(item.xtype == 'checkbox'){ item.checked = Math.abs(item.value || 0) == 1; item.fieldStyle = ''; } } if(limitArr.length > 0 && Ext.Array.contains(limitArr, item.name)) { item.hidden = true; } if(item.html&&item.name == null&&item.value==''){ }else{ if(bool == 'b') { item.columnWidth = item.columnWidth*0.83; } if(bool == 'c') { // item.columnWidth = item.columnWidth*0.65; item.columnWidth = item.columnWidth*0.85; } } if(item.renderfn){ var args = new Array(); var arr = item.renderfn.split(':'); //hey start 主表字段背景颜色 if(arr&&arr[0]!='itemstyle'){//判断是否是itemstyle if(contains(item.renderfn, ':', true)){ Ext.each(item.renderfn.split(':'), function(a, index){ if(index == 0){ renderName = a; } else { args.push(a); } }); } else {renderName=item.renderfn;} if(renderName != 'F'){ me[renderName](item, args, form); } }else{ switch(arr.length) { case 2: if(data&&data[item.name]&&data[item.name]==arr[1]) item.fieldStyle = item.fieldStyle + ';background:#c0c0c0;'; break; case 3: if(data&&data[item.name]&&data[item.name]==arr[1]) item.fieldStyle = item.fieldStyle + ';background:'+arr[2]+';'; break; default: } } } }); // 字段少的form if(form.minMode) { Ext.each(items, function(item){ if(item.columnWidth >= 0 && item.columnWidth < 0.5){ item.columnWidth = 0.5; } else if(item.columnWidth >= 0.5) { item.columnWidth = 1; } }); } return items; }, setButtons: function(form, buttonString){ if(buttonString != null && buttonString.trim() != ''){ var buttons = new Array(); buttons.push('->');//->使buttons放在toolbar中间 Ext.each(buttonString.split('#'), function(btn, index){ var o = {}; o.xtype = btn; o.height = 26; buttons.push(o); if((index + 1)%12 == 0){//每行显示12个button,超过12个就添加一个bbar buttons.push('->'); form.addDocked({ xtype: 'toolbar', dock: 'bottom', defaults: { style: { marginLeft: '10px' } }, items: buttons//12个加进去 }); buttons = new Array();//清空 buttons.push('->'); } }); buttons.push('->'); form.addDocked({//未到12个的 xtype: 'toolbar', dock: 'bottom', defaults: { style: { marginLeft: '10px' } }, items: buttons }); } }, loadNewStore: function(form, param){ var me = this; me.setLoading(true); Ext.Ajax.request({ url : basePath + "common/loadNewFormStore.action", params: param, method : 'post', callback : function(options,success,response){ me.setLoading(false); var res = new Ext.decode(response.responseText); if(res.exceptionInfo != null){ showError(res.exceptionInfo);return; } if(res.data){ var d = Ext.decode(res.data); form.getForm().setValues(d); var chs = form.query('checkbox'); Ext.each(chs, function(){ this.setValue(Math.abs(d[this.name] || 0) == 1); }); form.getForm().getFields().each(function (item,index,length){ item.originalValue = item.value; }); } } }); }, getSeqId: function(form){ if(!form){ form = Ext.getCmp('form'); } Ext.Ajax.request({ url : basePath + form.getIdUrl, method : 'get', async: false, callback : function(options,success,response){ var rs = new Ext.decode(response.responseText); if(rs.exceptionInfo){ showError(rs.exceptionInfo);return; } if(rs.success){ Ext.getCmp(form.keyField).setValue(rs.id); } } }); }, /** * 保存之前的判断 * @param arg 额外参数 */ beforeSave: function(me, arg){ var mm = this; var form = Ext.getCmp('form'); if(! mm.checkForm()){ return; } if(form.keyField){ if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){ mm.getSeqId(form); } } var grids = Ext.ComponentQuery.query('gridpanel'); var removea = new Array(); Ext.each(grids,function(g,index){ if(g.xtype=='itemgrid'){ g.saveValue(); removea.push(g); } }); Ext.each(removea,function(r,index){ Ext.Array.remove(grids,r); }); if(grids.length > 0 && !grids[0].ignore){ var param = me.GridUtil.getGridStore(); if(grids[0].necessaryField&&grids[0].necessaryField.length > 0 && (param == null || param == '')){ var errInfo = me.GridUtil.getUnFinish(grids[0]); if(errInfo.length > 0) errInfo = '明细表有必填字段未完成填写, 继续将不会保存未完成的数据,是否继续?
' + errInfo; else errInfo = '明细表还未添加数据, 是否继续?'; warnMsg(errInfo, function(btn){ if(btn == 'yes'){ mm.onSave(param, arg); } else { return; } }); } else { mm.onSave(param, arg); } } else { mm.onSave([]); } }, /** * 单据保存 * @param param 传递过来的数据,比如gridpanel的数据 */ onSave: function(param, arg){ var me = this; var form = Ext.getCmp('form'); param = param == null ? [] : "[" + param.toString() + "]"; if(form.getForm().isValid()){ //form里面数据 Ext.each(form.items.items, function(item){ if(item.xtype == 'numberfield'){ //number类型赋默认值,不然sql无法执行 if(item.value == null || item.value == ''){ item.setValue(0); } } }); var r = form.getValues(); Ext.each(form.items.items, function(item){ if(item.xtype == 'itemgrid'){ //number类型赋默认值,不然sql无法执行 if(item.value != null && item.value != ''){ r[item.name]=item.value; } } }); //去除ignore字段 var keys = Ext.Object.getKeys(r), f; var reg = /[!@#$%^&*()'":,\/?]/; Ext.each(keys, function(k){ f = form.down('#' + k); if(f && f.logic == 'ignore') { delete r[k]; } //codeField值强制大写,自动过滤特殊字符 if(k == form.codeField && !Ext.isEmpty(r[k])) { r[k] = r[k].trim().toUpperCase().replace(reg, ''); } }); if(!me.contains(form.saveUrl, '?caller=', true)){ form.saveUrl = form.saveUrl + "?caller=" + caller; } me.save(r, param, arg); }else{ me.checkForm(); } }, save: function(){ var params = new Object(); var r = arguments[0]; Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段 if(contains(k, 'ext-', true)){ delete r[k]; } }); params.formStore = unescape(escape(Ext.JSON.encode(r))); params.param = unescape(arguments[1].toString()); for(var i=2; i' + s.replace(/ /g,'') + ')' + $I18N.common.form.necessaryInfo2); return false; }, /** * 删除操作 */ onDelete: function(id){ var me = this; warnMsg($I18N.common.msg.ask_del_main, function(btn){ if(btn == 'yes'){ var form = Ext.getCmp('form'); if(!me.contains(form.deleteUrl, '?caller=', true)){ form.deleteUrl = form.deleteUrl + "?caller=" + caller; } me.setLoading(true); Ext.Ajax.request({ url : basePath + form.deleteUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return; } if(localJson.success){ delSuccess(function(){ me.onClose(); });//@i18n/i18n.js } else { delFailure(); } } }); } }); }, /** * 单据修改 * @param * @param * @param opts 获取form数据的参数{asString, dirtyOnly, includeEmptyText, useDataValues} * @param extra 额外参数 */ onUpdate: function(me, ignoreWarn, opts, extra){ var mm = this; var form = Ext.getCmp('form'); var s1 = mm.checkFormDirty(form); var s2 = ''; var grids = Ext.ComponentQuery.query('gridpanel'); var removea = new Array(); if(form.codeField && (Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == '')){ showError('编号不能为空.'); return; } Ext.each(grids,function(g,index){ if(g.xtype=='itemgrid'){ g.saveValue(); removea.push(g); } }); Ext.each(removea,function(r,index){ Ext.Array.remove(grids,r); }); if(grids.length > 0 && !grids[0].ignore){//check所有grid是否已修改 Ext.each(grids, function(grid, index){ if(grid.GridUtil){ var msg = grid.GridUtil.checkGridDirty(grid); if(msg.length > 0){ s2 = s2 + '
' + msg; } } }); } if(s1 == '' && (s2 == '' || s2 == '
')){ showError('还未添加或修改数据.'); return; } if(form && form.getForm().isValid()){ //form里面数据 var r = (opts && opts.dirtyOnly) ? form.getForm().getValues(false, true) : form.getValues(); //去除ignore字段 var keys = Ext.Object.getKeys(r), f; Ext.each(keys, function(k){ f = form.down('#' + k); if(f && f.logic == 'ignore') { delete r[k]; } if(f && opts && opts.dirtyOnly) { extra = (extra || '') + '\n(' + f.fieldLabel + ') old: ' + f.originalValue + ' new: ' + r[k]; } }); if(opts && opts.dirtyOnly && form.keyField) { r[form.keyField] = form.down("#" + form.keyField).getValue(); } if(!mm.contains(form.updateUrl, '?caller=', true)){ form.updateUrl = form.updateUrl + "?caller=" + caller; } var params = []; if(grids.length > 0 && grids[0].columns.length > 0 && !grids[0].ignore){ if(grids[0].GridUtil.isEmpty(grids[0])) { warnMsg('明细还未录入数据,是否继续保存?', function(btn){ if(btn == 'yes' || btn == 'ok'){ mm.update(r, '[]', extra); } else { return; } }); } else if(grids[0].GridUtil.isDirty(grids[0])) { var param = grids[0].GridUtil.getGridStore(); if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param.length == 0 || param == '') && !ignoreWarn){ warnMsg('明细表有必填项未填写,是否继续保存?', function(btn){ if(btn == 'yes' || btn == 'ok'){ params = unescape("[" + param.toString() + "]"); mm.update(r, params, extra); } else { return; } }); } else { params = unescape("[" + param.toString() + "]"); mm.update(r, params, extra); } } else { mm.update(r, '[]', extra); } } else { mm.update(r, params, extra); } }else{ mm.checkForm(form); } }, update: function(){ var me = this, params = new Object(); var r = arguments[0]; Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段 if(contains(k, 'ext-', true)){ delete r[k]; } }); params.formStore = unescape(escape(Ext.JSON.encode(r))); params.param = unescape(arguments[1].toString()); for(var i=2; i 0 && !forms[0].ignore){//check所有form是否已修改 Ext.each(forms, function(form, index){ var msg = mm.checkFormDirty(form); if(msg.length > 0){ s = s + '
' + msg; } }); } var grids = Ext.ComponentQuery.query('gridpanel'); if(grids.length > 0 && !grids[0].ignore && me.GridUtil){//check所有grid是否已修改 Ext.each(grids, function(grid, index){ var msg = me.GridUtil.checkGridDirty(grid); if(msg.length > 0){ s = s + '
' + msg; } }); } if(s == '' || s == '
'){ mm.onClose(); } else { if(!formCondition){//单据新增界面哦 //关闭前保存新增的数据 Ext.MessageBox.show({//关闭前保存修改的数据 title:'保存新添加的数据?', msg: '详细:
' + s + '
离开前要保存吗?', buttons: Ext.Msg.YESNOCANCEL, icon: Ext.Msg.WARNING, fn: function(btn){ if(btn == 'yes'){ mm.beforeSave(me); } else if(btn == 'no'){ mm.onClose(); } else { return; } } }); } else {//单据查看界面哦 Ext.MessageBox.show({ title:'保存修改?', msg: '该单据已被修改:
' + s + '
离开前要保存吗?', buttons: Ext.Msg.YESNOCANCEL, icon: Ext.Msg.WARNING, fn: function(btn){ if(btn == 'yes'){ mm.onUpdate(form, []); } else if(btn == 'no'){ mm.onClose(); } else { return; } } }); } } }, /** * 检查表单是否被修改,并返回被修改的内容 */ checkFormDirty: function(){ var form = Ext.getCmp('form'); var s = ''; form.getForm().getFields().each(function (item,index, length){ if(item.logic!='ignore'){ var value = item.value == null ? "" : item.value; if(item.xtype == 'htmleditor') { value = item.getValue(); } item.originalValue = item.originalValue == null ? "" : item.originalValue; if(Ext.typeOf(item.originalValue) != 'object'){ if(item.originalValue.toString() != value.toString()){//isDirty、wasDirty、dirty一直都是true,没办法判断,所以直接用item.originalValue,原理是一样的 var label = item.fieldLabel || item.ownerCt.fieldLabel || item.boxLabel || item.ownerCt.title;//针对fieldContainer、radio、fieldset等 if(label){ s = s + ' ' + label.replace(/ /g,''); } } } } }); return (s == '') ? s : ('表单字段('+s+')已修改'); }, /** * 关闭操作 */ onClose: function(){ var modal=parent.Ext.getCmp('modalwindow'); if(modal){ var history=modal.historyMaster; Ext.Ajax.request({ url: basePath + 'common/changeMaster.action', params: { to: history }, callback: function(opt, s, r) { if (s) { modal.close(); } else { alert('切换到原账套失败!'); } } }); }else{ var main = parent.Ext.getCmp("content-panel"),bool = false; if(main){ bool = true; main.getActiveTab().close(); } else { var win = parent.Ext.ComponentQuery.query('window'); if(win){ Ext.each(win, function(){ this.close(); }); } else { bool = true; window.close(); } } var p = Ext.ComponentQuery.query('erpCloseButton'); if(!bool && p){//如果还是没关闭tab,直接关闭页面 window.close(); } } }, /** * 跳转到add页面 */ onAdd: function(panelId, title, url){ var main = parent.Ext.getCmp("content-panel"); if(main){ panelId = (panelId == main.getActiveTab().id || panelId == null) ? Math.random() : panelId; var panel = Ext.getCmp(panelId); if(!panel){ var value = ""; if (title.toString().length>5) { value = title.toString().substring(0,5); } else { value = title; } if(!contains(url, 'http://', true) && !contains(url, basePath, true)){ url = basePath + url; } panel = { title : value, tag : 'iframe', tabConfig:{tooltip:title}, border : false, layout : 'fit', iconCls : 'x-tree-icon-tab-tab', html : '', closable : true }; this.openTab(panel, panelId); } else { main.setActiveTab(panel); } } else { if(!contains(url, basePath, true)){ url = basePath + url; } window.open(url); } }, /** * 取{field}值,自动赋值给{tField} * @param caller 表名 * @param tField 待赋值的字段 * @param [record 待赋值的明细行] */ getFieldValue: function(caller, field, condition, tField, record){ Ext.Ajax.request({ url : basePath + 'common/getFieldData.action', async: false, params: { caller: caller, field: field, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return; } if(localJson.success){ if(localJson.data != null){ if(record){ record.set(tField, localJson.data); } else { var ff = Ext.getCmp(tField); if(ff) ff.setValue(localJson.data); } } } } }); }, /** * 取{fields}值,自动赋值给{tFields},field用','隔开 * @param caller 表名 * @param tFields 待赋值的字段 * @param [record 待赋值的明细行] */ getFieldsValue: function(caller, fields, condition, tFields, record){ Ext.Ajax.request({ url : basePath + 'common/getFieldsData.action', async: false, params: { caller: caller, fields: fields, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return; } if(localJson.success){ if(record){ if(localJson.data != null){ var fis = fields.split(','); Ext.each(tFields.split(','), function(f, index){ if( localJson.data[fis[index]] != null){ record.set(f, localJson.data[fis[index]]); } }); } } else { if(localJson.data != null){ var fis = fields.split(','); Ext.each(tFields.split(','), function(f, index){ if(localJson.data[fis[index]] != null){ var fi = Ext.getCmp(f); if (fi) fi.setValue(localJson.data[fis[index]]); } }); } } } } }); }, /** * 取{fields}值 * @param caller 表名 */ getFieldsValues: function(caller, fields, condition, data, fn){ Ext.Ajax.request({ url : basePath + 'common/getFieldsDatas.action', async: false, params: { caller: caller, fields: fields, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return; } if(localJson.success){ data = localJson.data; fn && fn.call(null, localJson.data); } } }); }, /** * 取{field}值 * @param caller 表名 */ _getFieldValue: function(caller, field, condition){ Ext.Ajax.request({ url : basePath + 'common/getFieldData.action', async: false, params: { caller: caller, field: field, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return null; } if(localJson.success){ if(localJson.data != null){ return localJson.data; } else { return null; } } else { return null; } } }); }, /** * 取{field}值 * @param caller 表名 */ _getFieldValues: function(caller, field, condition, tfield, record){ Ext.Ajax.request({ url : basePath + 'common/getFieldDatas.action', async: false, params: { caller: caller, field: field, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return null; } if(localJson.success){ if(localJson.data != null){ if(record){ record.set(tfield, localJson.data); } else { Ext.getCmp(tfield).setValue(localJson.data); } } } else { return; } } }); }, /** * 取{fields}值,field用','隔开 * @param caller 表名 */ _getFieldsValue: function(caller, fields, condition){ Ext.Ajax.request({ url : basePath + 'common/getFieldsData.action', async: false, params: { caller: caller, fields: fields, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo);return; } if(localJson.success){ return localJson.data; } } }); }, checkFieldValue: function(caller, condition){ Ext.Ajax.request({ url : basePath + 'common/checkFieldData.action', params: { caller: caller, condition: condition }, method : 'post', callback : function(options,success,response){ var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); return false; } if(localJson.success){ return localJson.data; } } }); }, onAudit: function(id){ var me = this; var form = Ext.getCmp('form'); if(form && form.getForm().isValid()){ if(!me.contains(form.auditUrl, '?caller=', true)){ form.auditUrl = form.auditUrl + "?caller=" + caller; } me.setLoading(true);//loading... //清除流程 Ext.Ajax.request({ url : basePath + me.deleteProcess, params: { keyValue:id, caller:caller, _noc:1 }, method:'post', async:false, callback : function(options,success,response){ } }); Ext.Ajax.request({ url : basePath + form.auditUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //audit成功后刷新页面进入可编辑的页面 showMessage('提示', '审核成功!', 1000); window.location.reload(); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage("提示", str); auditSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); } else { me.checkForm(); } }, onB2b: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.b2bUrl, '?caller=', true)){ form.b2bUrl = form.b2bUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.b2bUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //audit成功后刷新页面进入可编辑的页面 showMessage('提示', '同步成功!', 1000); window.location.reload(); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage("提示", str); auditSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onAuditWithManAndTime: function(id,auditerFieldName,auditdateFieldName){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.auditUrl, '?caller=', true)){ form.auditUrl = form.auditUrl + "?caller=" + caller; } me.setLoading(true);//loading... //清除流程 Ext.Ajax.request({ url : basePath + me.deleteProcess, params: { keyValue:id, caller:caller, _noc:1 }, method:'post', async:false, callback : function(options,success,response){ } }); Ext.Ajax.request({ url : basePath + form.auditUrl, params: { id: id, auditerFieldName:auditerFieldName, auditdateFieldName:auditdateFieldName }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //audit成功后刷新页面进入可编辑的页面 showMessage('提示', '审核成功!', 1000); window.location.reload(); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage("提示", str); auditSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onResAuditWithManAndTime: function(id,auditerFieldName,auditdateFieldName){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resAuditUrl, '?caller=', true)){ form.resAuditUrl = form.resAuditUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resAuditUrl, params: { id: id, auditerFieldName:auditerFieldName, auditdateFieldName:auditdateFieldName }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resAudit成功后刷新页面进入可编辑的页面 showMessage('提示', '反审核成功!', 1000); window.location.reload(); } } }); }, onResAudit: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resAuditUrl, '?caller=', true)){ form.resAuditUrl = form.resAuditUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resAuditUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resAudit成功后刷新页面进入可编辑的页面 showMessage('提示', '反审核成功!', 1000); window.location.reload(); } } }); }, onAccounted: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.accountedUrl, '?caller=', true)){ form.accountedUrl = form.accountedUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.accountedUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //记账成功后刷新页面进入不可编辑的页面 accountedSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showMessage("提示", str); accountedSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onResAccounted: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resAccountedUrl, '?caller=', true)){ form.resAccountedUrl = form.resAccountedUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resAccountedUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resAudit成功后刷新页面进入可编辑的页面 resAccountedSuccess(); window.location.reload(); } } }); }, /** * @param allowEmpty 是否允许Grid为空 */ onSubmit: function(id, allowEmpty, errFn, scope){ var me = this; var form = Ext.getCmp('form'); if(form && form.getForm().isValid()){ var s = me.checkFormDirty(form); var grids = Ext.ComponentQuery.query('gridpanel'); if(grids.length > 0 && !grids[0].ignore){//check所有grid是否已修改 var param = grids[0].GridUtil.getAllGridStore(grids[0]); if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param == '') && (allowEmpty !== true)){ var errInfo = grids[0].GridUtil.getUnFinish(grids[0]); if(errInfo.length > 0) showError("明细表有必填字段未完成填写
" + errInfo); else showError("明细表还未添加数据,无法提交!"); return; } Ext.each(grids, function(grid, index){ if(grid.GridUtil){ var msg = grid.GridUtil.checkGridDirty(grid); if(msg.length > 0){ s = s + '
' + grid.GridUtil.checkGridDirty(grid); } } }); } if(s == '' || s == '
'){ me.submit(id); } else { Ext.MessageBox.show({ title:'保存修改?', msg: '该单据已被修改:
' + s + '
提交前要先保存吗?', buttons: Ext.Msg.YESNOCANCEL, icon: Ext.Msg.WARNING, fn: function(btn){ if(btn == 'yes'){ if(typeof errFn === 'function') errFn.call(scope); else me.onUpdate(form, true); } else if(btn == 'no'){ me.submit(id); } else { return; } } }); } } else { me.checkForm(); } }, submit: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.submitUrl, '?caller=', true)){ form.submitUrl = form.submitUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.submitUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //跳转之前 若节点指定多人则指定候选人 Ext.Ajax.request({ url : basePath + me.getMultiAssigns, params: { id: id, caller:caller }, method : 'post', callback : function(){ var localJson = new Ext.decode(arguments[2].responseText); if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; showError(str); }else { if(localJson.MultiAssign){ if(localJson.autoSetJnode){ form.SetNodeDealMan(id); }else me.showAssignWin(localJson.assigns); }else { showMessage('提示', '提交成功!', 1000); window.location.reload(); if(form.onSumitSuccess){ form.onSumitSuccess(); } } } } }); //submit成功后刷新页面进入可编辑的页面 } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); Ext.Ajax.request({ url : basePath + me.getMultiAssigns, params: { id: id, caller:caller }, method : 'post', callback : function(){ var localJson = new Ext.decode(arguments[2].responseText); if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; showError(str); }else { if(localJson.MultiAssign){ me.showAssignWin(localJson.assigns); }else { showMessage('提示', '提交成功!', 1000); window.location.reload(); } } } }); } showMessage("提示", str); } } } }); }, onResSubmit: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resSubmitUrl, '?caller=', true)){ form.resSubmitUrl = form.resSubmitUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resSubmitUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resSubmit成功后刷新页面进入可编辑的页面 showMessage('提示', '反提交成功!', 1000); window.location.reload(); } } }); }, onBanned: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.bannedUrl, '?caller=', true)){ form.bannedUrl = form.bannedUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.bannedUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ //banned成功后刷新页面进入可编辑的页面 window.location.href = window.location.href; bannedSuccess(); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); bannedSuccess(); window.location.reload(); } else { showError(str);return; } } } } }); }, onResBanned: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resBannedUrl, '?caller=', true)){ form.resBannedUrl = form.resBannedUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resBannedUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resBanned成功后刷新页面进入可编辑的页面 resBannedSuccess(); window.location.reload(); } } }); }, onPrint: function(id){ var me = this; var form = Ext.getCmp('form'); if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){ form.printUrl = form.printUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.printUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ window.location.href = window.location.href; printSuccess(); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); printSuccess(); window.location.reload(); } else { showError(str);return; } } } } }); }, onEnd: function(id){ var me = this; var form = Ext.getCmp('form'); if(form.endUrl && !me.contains(form.endUrl, '?caller=', true)){ form.endUrl = form.endUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.endUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ endSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); endSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onResEnd: function(id, f){ var me = this; var form = f || Ext.getCmp('form'); if(form.endUrl && !me.contains(form.endUrl, '?caller=', true)){ form.endUrl = form.endUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resEndUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ resEndSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){ str = str.replace('AFTERSUCCESS', ''); showError(str); resEndSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onNullify: function(id){ var me = this; var form = Ext.getCmp('form'); if(form.nullifyUrl && !me.contains(form.nullifyUrl, '?caller=', true)){ form.nullifyUrl = form.nullifyUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.nullifyUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ nullifySuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); nullifySuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, batchPrint:function(idS,reportName,condition,title,todate,dateFW,fromdate,enddate,urladdress,whichsystem){ var printUrl = 'common/BatchPrintController/batchPrint.action'; var me = this; var form = Ext.getCmp('form'); if(printUrl && !me.contains(printUrl, '?caller=', true)){ printUrl = printUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + printUrl, params: { idS: idS, reportName:reportName, condition:condition, title:title, todate:todate, dateFW:dateFW, fromdate:fromdate, enddate:enddate }, method : 'post', timeout: 360000, callback : function(options,success,response){ me.setLoading(false);//loading... var res = new Ext.decode(response.responseText); var url = urladdress + '?reportfile=' + res.keyData[0]+'&&fdate='+fromdate+'&&tdate='+todate+'&&assifall=have'+'&&asscatecode='+'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+''; window.open(url, (form == null ? '' : form.title) + '-批量打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); /* var url = urladdress + '/common/reportviewer.aspx?reportfile=' + res.keyData[0]+'&&fdate='+fromdate+'&&tdate='+todate+'&&assifall=have'+'&&asscatecode='+'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+''; window.open(url, (form == null ? '' : form.title) + '-批量打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); */ } }); }, onwindowsPrint2: function(id, reportName, condition, callback){ var me = this; var form = Ext.getCmp('form'); if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){ form.printUrl = form.printUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.printUrl, params: { id: id, reportName:reportName, condition:condition }, method : 'post', timeout: 360000, callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo) { me.setLoading(false); showError(res.exceptionInfo); return; } Ext.Ajax.request({ url: basePath + 'common/report/print.action', method: 'post', params: { id: id, caller:caller, reportName:reportName, condition:condition }, callback : function(options, success, response){ var res = new Ext.decode(response.responseText); me.setLoading(false); if(res.success){ if(res.info.isbz=='pdf'){ window.location.href=res.info.printUrl+'/print?reportname='+res.info.reportname+'&condition='+res.info.condition+'&whichsystem='+res.info.whichsystem+"&"+'defaultCondition='+res.info.defaultCondition; }else{ //var whichsystem = re.whichsystem; var url = res.info.printUrl + '?reportfile=' + res.info.reportname + '&&rcondition='+res.info.condition+'&&company=&&sysdate=373FAE331D06E956870163DCB2A96EC7&&key=3D7595A98BFF809D5EEEA9668B47F4A5&&whichsystem='+res.info.whichsystem+''; window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); } } } }); } }); /* Ext.Ajax.request({ url : basePath + form.printUrl, params: { id: id, reportName:reportName, condition:condition }, method : 'post', callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo) { me.setLoading(false); showError(res.exceptionInfo); return; } Ext.Ajax.request({ url : basePath + 'common/enterprise/getprinturl.action', params: { caller: caller, reportName: reportName }, callback: function(opt, s, r) { me.setLoading(false); var re = Ext.decode(r.responseText); if(re.exceptionInfo) { showError(re.exceptionInfo); return; } if(re.printurl) { var whichsystem = re.whichsystem; var url = re.printurl + '?reportfile=' + ( res.keyData[0]||re.report) + '&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+''; window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); //(re.report || res.keyData[0]) var whichsystem=re.whichsystem; var url = re.printurl + '/common/reportviewer.aspx?reportfile=' + res.keyData[0]+'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+''; window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); } callback && callback.call(null); } }); } });*/ }, onwindowsPrint: function(id, reportName, condition, callback){ var me = this; var form = Ext.getCmp('form'); if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){ form.printUrl = form.printUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.printUrl, params: { id: id, reportName:reportName, condition:condition }, method : 'post', timeout: 360000, callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo) { me.setLoading(false); showError(res.exceptionInfo); return; } Ext.Ajax.request({ url: basePath + 'common/report/print.action', method: 'post', params: { id: id, caller:caller, reportName:reportName, condition:condition }, callback : function(options, success, response){ var res = new Ext.decode(response.responseText); me.setLoading(false); if(res.success){ //var whichsystem = re.whichsystem; var url = res.info.printUrl + '?reportfile=' + res.info.reportname + '&&rcondition='+res.info.condition+'&&company=&&sysdate=373FAE331D06E956870163DCB2A96EC7&&key=3D7595A98BFF809D5EEEA9668B47F4A5&&whichsystem='+res.info.whichsystem+''; window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); } } }); } }); }, //====================BOM打印方法 onwindowsPrintBom: function(id, reportName, condition,prodcode){ var me = this; var form = Ext.getCmp('form'); if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){ form.printUrl = form.printUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.printUrl, params: { id: id, reportName:reportName, condition:condition, prodcode:prodcode }, method : 'post', callback : function(options,success,response){ var res = new Ext.decode(response.responseText); if(res.exceptionInfo) { me.setLoading(false); showError(res.exceptionInfo); return; } Ext.Ajax.request({ url : basePath + 'common/enterprise/getprinturl.action', params: { caller: caller, reportName: reportName }, callback: function(opt, s, r) { me.setLoading(false); var re = Ext.decode(r.responseText); if(re.exceptionInfo) { showError(re.exceptionInfo); return; } if(re.printurl) { var whichsystem=re.whichsystem; //var whichsystem = re.whichsystem; /*var url = re.printurl + '/common/reportviewer.aspx?reportfile=' + (re.report || res.keyData[0]) +'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+''; window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');*/ var url = re.printurl + '?reportfile=' + (re.report || res.keyData[0]) +'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+''; window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) + ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); } // window.location.reload(); } }); } }); }, //======================== onPost: function(id){ var me = this; var form = Ext.getCmp('form'); if(form && form.getForm().isValid()){ var unSave = me.getUnSave(form); if(unSave.length > 0) { showError('

' + unSave + '

填写后未保存,请先执行更新操作'); return; } var grids = Ext.ComponentQuery.query('gridpanel'); if(grids.length > 0){ var invalid = []; Ext.each(grids, function(grid, index){ if(!grid.ignore && grid.GridUtil){ var msg = grid.GridUtil.getInvalid(grid); if(msg.length > 0){ invalid.push((grids.length > 1 ? ('从表' + (index + 1) + ' ') : '') + msg); } } }); if(invalid.length > 0) { showError('

还有待完善的必填信息:


' + invalid.join('
')); return; } } if(form.postUrl && !me.contains(form.postUrl, '?caller=', true)){ form.postUrl = form.postUrl + "?caller=" + caller; } warnMsg('确定过账?', function(btn){ if(btn == 'yes'){ me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.postUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ postSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); postSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); } }); } else { me.checkForm(); } }, /** * 获取form修改但未保存的字段,并提示 */ getUnSave: function(form) { var unSave = []; Ext.Array.each(form.items.items, function(item){ var text = item.fieldLabel || item.boxLabel; if(item.firstField) item = item.firstField; if(typeof item.getValue == 'function' && !item.allowBlank && Ext.isEmpty(item.originalValue) && !Ext.isEmpty(item.value)) { text && (unSave.push(text)); } }); return unSave.join(' '); }, onResPost: function(id){ var me = this; var form = Ext.getCmp('form'); if(form.resPostUrl && !me.contains(form.resPostUrl, '?caller=', true)){ form.resPostUrl = form.resPostUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resPostUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ resPostSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); resPostSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onHung: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resAuditUrl, '?caller=', true)){ form.resAuditUrl = form.resAuditUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.hungUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resAudit成功后刷新页面进入可编辑的页面 resAuditSuccess(); window.location.reload(); } } }); }, onResHung: function(id){ var me = this; var form = Ext.getCmp('form'); if(!me.contains(form.resAuditUrl, '?caller=', true)){ form.resAuditUrl = form.resAuditUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resHungUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.exceptionInfo){ showError(localJson.exceptionInfo); } if(localJson.success){ //resAudit成功后刷新页面进入可编辑的页面 resAuditSuccess(); window.location.reload(); } } }); }, onCheck: function(id){ var me = this; var form = Ext.getCmp('form'); if(form.checkUrl && !me.contains(form.checkUrl, '?caller=', true)){ form.checkUrl = form.checkUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.checkUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ checkSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); checkSuccess(function(){ vwindow.location.reload(); }); } else { showError(str);return; } } } } }); }, onConfirm: function(id){ var me=this; var form=Ext.getCmp('form'); if(form.onConfirmUrl && !me.contains(form.onConfirmUrl, '?caller=', true)){ form.onConfirmUrl = form.onConfirmUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.onConfirmUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ Ext.Msg.alert('提示', '确认成功', function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); Ext.Msg.alert('提示', '确认成功', function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, onResCheck: function(id){ var me = this; var form = Ext.getCmp('form'); if(form.resCheckUrl && !me.contains(form.resCheckUrl, '?caller=', true)){ form.resCheckUrl = form.resCheckUrl + "?caller=" + caller; } me.setLoading(true);//loading... Ext.Ajax.request({ url : basePath + form.resCheckUrl, params: { id: id }, method : 'post', callback : function(options,success,response){ me.setLoading(false); var localJson = new Ext.decode(response.responseText); if(localJson.success){ resCheckSuccess(function(){ window.location.reload(); }); } else { if(localJson.exceptionInfo){ var str = localJson.exceptionInfo; if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面 str = str.replace('AFTERSUCCESS', ''); showError(str); resCheckSuccess(function(){ window.location.reload(); }); } else { showError(str);return; } } } } }); }, openTab : function (panel,id){ var o = (typeof panel == "string" ? panel : id || panel.id); var main = this.getMain(); var tab = main.getComponent(o); if (tab) { main.setActiveTab(tab); } else if(typeof panel!="string"){ panel.id = o; var p = main.add(panel); main.setActiveTab(p); } }, getMain: function(){ var main = Ext.getCmp("content-panel"); if(!main) main = parent.Ext.getCmp("content-panel"); if(!main) main = parent.parent.Ext.getCmp("content-panel"); return main; }, getActiveTab: function(){ var tab = null; if(Ext.getCmp("content-panel")){ tab = Ext.getCmp("content-panel").getActiveTab(); } if(!tab && parent.Ext && parent.Ext.getCmp("content-panel")) tab = parent.Ext.getCmp("content-panel").getActiveTab(); if(!tab && parent.parent.Ext && parent.parent.Ext.getCmp("content-panel")) tab = parent.parent.Ext.getCmp("content-panel").getActiveTab(); if(!tab && parent.Ext){ var win = parent.Ext.ComponentQuery.query('window'); if(win.length > 0){ tab = win[win.length-1]; } } return tab; }, /** * string:原始字符串 * substr:子字符串 * isIgnoreCase:忽略大小写 */ contains: function(string, substr, isIgnoreCase){ if (string == null || substr == null) return false; if (isIgnoreCase === undefined || isIgnoreCase === true) { string = string.toLowerCase(); substr = substr.toLowerCase(); } return string.indexOf(substr) > -1; }, showAssignWin :function(persons){ var me=this; var confirm = new Ext.button.Button({ text:$I18N.common.button.erpConfirmButton, handler:function(btn){ var items = Ext.ComponentQuery.query('window >tabpanel>panel>radio'); var params = new Array(); Ext.each(items,function(item){ if(item.getValue()){ var param = new Object(); var label = item.boxLabel;//em_name(em_code) 2013-3-8 10:18:11 var em_code = label.substring(label.lastIndexOf('(')+1,label.length-1); param.em_code = em_code; param.nodeId=item.name; params.push(JSON.stringify(param)); } }); Ext.Ajax.request({ url: basePath + 'common/takeOverTask.action', async: false, params: { params:unescape(params), _noc: 1 }, callback: function(options,success,response){ var text = response.responseText; jsonData = Ext.decode(text); //再发送请求 if(jsonData.success){ Ext.Msg.alert('提示' ,"指派成功!"); Ext.Ajax.request({ url: basePath + 'common/processpaging.action', params: { params:unescape(params), _noc: 1 } }); win.close(); }else{ Ext.Msg.alert('提示' ,"指派失败!"); win.close(); } window.location.reload(); } }); } }); var cancel = new Ext.button.Button({ text:$I18N.common.button.erpCancelButton, handler:function(){ var params = new Array(); for (var i = 0; i < persons.length; i++){ var param = new Object(); param.em_code = persons[i].JP_CANDIDATES; param.nodeId=persons[i].JP_NODEID; params.push(JSON.stringify(param)); } Ext.Ajax.request({ url: basePath + 'common/processpaging.action', params: { params:unescape(params), _noc: 1 }, callback: function(options,success,response){ win.close(); window.location.reload(); } }); } }); var searchKey = new Object(); var win = Ext.create('Ext.window.Window', { title:'
节点处理人
', height: 350, width: 500, layout: { type: 'vbox', align : 'stretch' }, closable:false, id:'win', autoScroll:true, buttonAlign:'center', buttons: [confirm,cancel], items: [] }); win.add([{ xtype:'textfield', margin:'10 20 10 20', fieldLabel:'快速搜索', labelStyle:'font-weight:bold;', id:'searchtextfield', //columnWidth:0.8, flex:1, enableKeyEvents:true, listeners:{ keydown:function(field,e){ if(e.getKey()==Ext.EventObject.ENTER){ searchKey[Ext.getCmp('processTab').getActiveTab().id]=field.value; var results=Ext.Array.filter(persons[Ext.getCmp('processTab').getActiveTab().id].JP_CANDIDATES,function(JP_CANDIDATE){ if(field.value==undefined || JP_CANDIDATE.indexOf(field.value)!=-1) return JP_CANDIDATE; }); Ext.Array.each(Ext.getCmp('processTab').getActiveTab().personUsers,function(item){ Ext.getCmp('processTab').getActiveTab().remove(item); }); me.addUserItems(Ext.getCmp('processTab').getActiveTab(),persons[Ext.getCmp('processTab').getActiveTab().id].JP_NODEID,results); } } } }]); this.addAssignItems(win,persons,searchKey); win.show(); }, addAssignItems:function(win,persons,searchKey){ var me=this; var tab = new Ext.TabPanel({ id : 'processTab', enableTabScroll : true, closeAll : true, //activeTab : 0, tabWidth : 480, flex:9, minTabWidth :80, autoHeight:true, resizeTabs : true, listeners:{ 'tabchange':function(tabPanel,newCard,oldCard,eOpts){ Ext.getCmp('searchtextfield').setValue(searchKey[newCard.id]); } } }); win.add(tab); for (var i = 0; i < persons.length; i++){ var panel=new Ext.Panel({ id:i.toString(), width: 480, autoHeight:true, autoScroll:true, layout:'column', bodyStyle: 'background:#e0e0e0', title:persons[i].JP_NODENAME }); tab.add(panel); me.addUserItems(panel,persons[i].JP_NODEID,persons[i].JP_CANDIDATES); } tab.setActiveTab(0); }, addUserItems:function(panel,jp_nodeid,jp_candidates){ var me=this; var maxSize=jp_candidates.length>24?24:jp_candidates.length,personUsers=new Array(),user=null,more=Ext.getCmp('more'+panel.id); if(more)more.destroy(); for(var j=0;jmaxSize){ panel.add({ xtype: 'textfield', readOnly:true, labelSeparator:'', columnWidth:1, id:'more'+panel.id, fieldStyle : 'background:#e0e0e0;border-bottom:none;vertical-align:middle;border-top:none;border-right:none;border-bottom:none;border-left:none;', fieldLabel: '『全部』', listeners: { click: { element: 'labelEl', fn: function(e,el) { var target = e.getTarget('.terms'); Ext.getCmp('more'+panel.id).destroy(); if (target) { Ext.Array.each(panel.personUsers,function(item){ panel.remove(item); }); var personUsers=new Array(); for(var i=0;i0 ){ condition=condition.replace(/%27/g,''); var cr_id ; Ext.Ajax.request({ url : basePath + 'common/getFieldData.action', async: false, params: { caller: 'Craft left join make on ma_prodcode = cr_prodcode and cr_code=ma_craftcode', field: 'cr_id', condition: condition.replace(/IS/g, "=") }, method : 'post', callback : function(opt, s, res){ var r = new Ext.decode(res.responseText); if(r.exceptionInfo){ showError(r.exceptionInfo);return; } else if(r.success){ cr_id = r.data; if( cr_id && cr_id != 0 && cr_id != null){ openUrl('jsps/pm/mes/craft.jsp?formCondition=cr_idIS '+cr_id+ '&gridCondition=cd_cridIS'+cr_id); }else{ showError('请选择有效的途程'); } } } }); }else if(url.indexOf("whoami=BOMStep") > 0 ){ condition=condition.replace(/%27/g,''); Ext.Ajax.request({ url: basePath + 'pm/mes/getBomVersion.action', params: { caller: caller, condition: condition.replace(/IS/g, "=") }, method: 'post', callback: function(options, success, response) { var res = new Ext.decode(response.responseText); if (res.exceptionInfo) { showError(res.exceptionInfo); } else { var prodcode = res.data['sb_prodcode']; var craftcode = res.data['sb_craftcode']; var bomversion = res.data['sb_bomversion']; var sp_sbid = res.data['sb_id']; var formCondition = "sb_prodcodeIS'" +prodcode+"' and sb_craftcodeIS'"+craftcode+"' and" + " sb_bomversionIS'"+bomversion+"'"; var gridCondition = "sp_sbidIS"+sp_sbid; if(sp_sbid && sp_sbid != 0 && sp_sbid != null){ openUrl('jsps/pm/mes/BOMStep.jsp?whoami=BOMStep&formCondition=' + formCondition+ '&gridCondition=' +gridCondition); }else{ showError('请选择有效的BOM版本编号'); } } } }); }else{ openUrl(url); } } } } }; } }, Highlight:function(item,args){ if(args&&args[0].indexOf('{')==0&&args[0].indexOf('}')==(args[0].length-1)){ var str = args[0].substring(1,args[0].length-1),color; if(args[0].indexOf(',')>0){ //配置方式3 var Arr = str.split(','); Ext.Array.each(Arr, function(a) { var file = a.split('='); if(file[1]==item.value){ color = file[0]; } }); }else{ //配置方式2 var file = str.split('='); if(file[1]==item.value){ color = file[0]; } } var style='font-weight:bold;color:'; style+=color+";"; item.fieldStyle=item.fieldStyle?item.fieldStyle+style:style; }else{ //配置方式1 var style='font-weight:bold;color:'; style+=(args && args[0])?args[0]+";":'red;'; item.fieldStyle=item.fieldStyle?item.fieldStyle+style:style; } }, formula: function(item, args, form){ Ext.defer(function(){ var mm = this, field = form.down('#' + item.name), vals = {}; if(field != null && !form.readOnly) { field.addEvents({'formula': true}); field.addListener('formula', function(f, changedField, changedFieldVal){ if(changedField) { vals[changedField] = changedFieldVal || 0; } // eg: eval("var a = 1, b = 2, c = 3;a + b / c") var exp = 'var ' + Ext.Object.toQueryString(vals).replace(/&/gi, ",") + ";" + args[0]; field.setValue(eval(exp) || 0); }); var fields = args[0].split(/\+|-|\*|\(|\)|\//g); Ext.Array.each(fields, function(f){ if(f) { var ff = form.down('#' + f); if(ff) { vals[f] = ff.getValue() || 0; ff.on('change', function(_f, newVal){ field.fireEvent('formula', field, _f.getName(), _f.getValue()); }); } } }); field.fireEvent('formula'); } }, 500); }, getURLParameter:function(name){ return (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [,null])[1]; } });