123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748 |
- /**
- * 与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 = '明细表有必填字段未完成填写, 继续将不会保存未完成的数据,是否继续?<hr>' + 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<arguments.length; i++) { //兼容多参数
- if(arguments[i])
- params['param' + i] = unescape(arguments[i].toString());
- }
- var me = this;
- var form = Ext.getCmp('form'), url = form.saveUrl;
- if(url.indexOf('caller=') == -1){
- url = url + "?caller=" + caller;
- }
- me.setLoading(true);
- Ext.Ajax.request({
- url : basePath + url,
- params : params,
- method : 'post',
- callback : function(options,success,response){
- me.setLoading(false);
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- saveSuccess(function(){
- //add成功后刷新页面进入可编辑的页面
- var value =r[form.keyField];
- var formCondition = form.keyField + "IS" + value;
- var gridCondition = '';
- var grid = Ext.getCmp('grid');
- if(grid && grid.mainField){
- gridCondition = grid.mainField + "IS'" + value+"'";
- }
- if(me.contains(window.location.href, '?', true)){
- window.location.href = window.location.href + '&formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- } else {
- window.location.href = window.location.href + '?formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- }
- });
- } else if(localJson.exceptionInfo){
- var str = localJson.exceptionInfo;
- if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
- str = str.replace('AFTERSUCCESS', '');
- saveSuccess(function(){
- //add成功后刷新页面进入可编辑的页面
- var value = r[form.keyField];
- var formCondition = form.keyField + "IS" + value;
- var gridCondition = '';
- var grid = Ext.getCmp('grid');
- if(grid && grid.mainField){
- gridCondition = grid.mainField + "IS'" + value +"'";
- }
- if(me.contains(window.location.href, '?', true)){
- window.location.href = window.location.href + '&formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- } else {
- window.location.href = window.location.href + '?formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- }
- });
- showError(str);
- } else {
- showError(str);
- return;
- }
- } else{
- saveFailure();//@i18n/i18n.js
- }
- }
- });
- },
- /**
- * 检查form未完善的字段
- */
- checkForm: function(){
- var s = '';
- var form = Ext.getCmp('form');
- form.getForm().getFields().each(function (item, index, length){
- if(!item.isValid()){
- if(s != ''){
- s += ',';
- }
- if(item.fieldLabel || item.ownerCt.fieldLabel){
- s += item.fieldLabel || item.ownerCt.fieldLabel;
- }
- }
- });
- if(s == ''){
- return true;
- }
- showError($I18N.common.form.necessaryInfo1 + '(<font color=green>' + s.replace(/ /g,'') +
- '</font>)' + $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 + '<br/>' + msg;
- }
- }
- });
- }
- if(s1 == '' && (s2 == '' || s2 == '<br/>')){
- 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<arguments.length; i++) { //兼容多参数
- if (arguments[i] != null)
- params['param' + i] = unescape(arguments[i].toString());
- }
- var form = Ext.getCmp('form'), url = form.updateUrl;
- if(url.indexOf('caller=') == -1){
- url = url + "?caller=" + caller;
- }
- me.setLoading(true);//loading...
- Ext.Ajax.request({
- url : basePath + url,
- params: params,
- method : 'post',
- callback : function(options,success,response){
- me.setLoading(false);
- var localJson = new Ext.decode(response.responseText);
- if(localJson.success){
- showMessage('提示', '保存成功!', 1000);
- //update成功后刷新页面进入可编辑的页面
- var u = String(window.location.href);
- if (u.indexOf('formCondition') == -1) {
- var value = r[form.keyField];
- var formCondition = form.keyField + "IS" + value ;
- var gridCondition = '';
- var grid = Ext.getCmp('grid');
- if(grid && grid.mainField){
- gridCondition = grid.mainField + "IS" + value;
- }
- if(me.contains(window.location.href, '?', true)){
- window.location.href = window.location.href + '&formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- } else {
- window.location.href = window.location.href + '?formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- }
- } else {
- window.location.reload();
- }
- } else if(localJson.exceptionInfo){
- var str = localJson.exceptionInfo;
- if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
- str = str.replace('AFTERSUCCESS', '');
- //update成功后刷新页面进入可编辑的页面
- var u = String(window.location.href);
- if (u.indexOf('formCondition') == -1) {
- var value = r[form.keyField];
- var formCondition = form.keyField + "IS" + value ;
- var gridCondition = '';
- var grid = Ext.getCmp('grid');
- if(grid && grid.mainField){
- gridCondition = grid.mainField + "IS" + value;
- }
- if(me.contains(window.location.href, '?', true)){
- window.location.href = window.location.href + '&formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- } else {
- window.location.href = window.location.href + '?formCondition=' +
- formCondition + '&gridCondition=' + gridCondition;
- }
- } else {
- window.location.reload();
- }
- }
- showError(str);return;
- } else {
- updateFailure();
- }
- }
- });
- },
- /**
- * 关闭之前进行一些判断,根据用户选择或保存或关闭
- *
- */
- beforeClose: function(me){
- var mm = this;
- var s = '';
- var forms = Ext.ComponentQuery.query('formpanel');
- if(forms.length > 0 && !forms[0].ignore){//check所有form是否已修改
- Ext.each(forms, function(form, index){
- var msg = mm.checkFormDirty(form);
- if(msg.length > 0){
- s = s + '<br/>' + 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 + '<br/>' + msg;
- }
- });
- }
- if(s == '' || s == '<br/>'){
- mm.onClose();
- } else {
- if(!formCondition){//单据新增界面哦
- //关闭前保存新增的数据
- Ext.MessageBox.show({//关闭前保存修改的数据
- title:'保存新添加的数据?',
- msg: '详细:<br/>' + s + '<br/>离开前要保存吗?',
- 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: '该单据已被修改:<br/>' + s + '<br/>离开前要保存吗?',
- 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 : ('表单字段(<font color=green>'+s+'</font>)已修改');
- },
- /**
- * 关闭操作
- */
- 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 : '<iframe id="iframe_add_'+panelId+'" src="' + url+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>',
- 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("明细表有必填字段未完成填写<hr>" + 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 + '<br/>' + grid.GridUtil.checkGridDirty(grid);
- }
- }
- });
- }
- if(s == '' || s == '<br/>'){
- me.submit(id);
- } else {
- Ext.MessageBox.show({
- title:'保存修改?',
- msg: '该单据已被修改:<br/>' + s + '<br/>提交前要先保存吗?',
- 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('<h3>' + unSave + '</h3> 填写后未保存,请先执行更新操作');
- 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('<h3>还有待完善的必填信息:</h3><hr>' + invalid.join('<br>'));
- 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:'<div align="center">节点处理人</div>',
- 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;j<maxSize;j++){
- user=Ext.create('Ext.form.field.Radio',{
- name:jp_nodeid,
- boxLabel:jp_candidates[j],
- columnWidth: 0.33,
- fieldCls:'x-myradio',
- checked: j==0?true:false
- });
- personUsers.push(user);
- }
- panel.add(personUsers);
- panel.personUsers=personUsers;
- if(jp_candidates.length>maxSize){
- 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: '『<a href="#" class="terms">全部</a>』',
- 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;i<jp_candidates.length;i++){
- user=Ext.create('Ext.form.field.Radio',{
- name:jp_nodeid,
- boxLabel:jp_candidates[i],
- columnWidth: 0.33,
- fieldCls:'x-myradio',
- checked: i==0?true:false
- });
- personUsers.push(user);
- }
- panel.add(personUsers);
- panel.personUsers=personUsers;
- e.preventDefault();
- }
- }
- }
- }
- });
- }
- },
- setLoading : function(b) {// 原this.getActiveTab().setLoading()换成此方法,解决Window模式下无loading问题
- var mask = this.mask;
- if (!mask) {
- this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
- msg : "处理中,请稍后...",
- msgCls : 'z-index:10000;'
- });
- }
- if (b)
- mask.show();
- else
- mask.hide();
- },
- link: function(item,args){
- var me = this;
- if(item.xtype=='multifield'){
- item.listeners={
- afterrender:function(item){
- var f=item.firstField;
- if(f.value){
- f.setFieldStyle({ 'color': 'blue'});
- f.focusCls = 'mail-attach';
- var index = 0,url=args[0], length = url.length, s, e;
- while(index < length) {
- if((s = url.indexOf('{', index)) != -1 && (e = url.indexOf('}', s + 1)) != -1) {
- url = url.substring(0, s) + Ext.getCmp(url.substring(s+1, e)).value + url.substring(e+1);
- index = e + 1;
- } else {
- break;
- }
- }
- f.inputEl.addListener('click',function(evt,el){
- openUrl(url);
- });
- }
- }
- };
- }else {
- item.fieldStyle=item.fieldStyle?item.fieldStyle+';color:blue':'color:blue';
- item.focusCls = 'mail-attach';
- item.listeners={
- click: {
- element:'inputEl',
- buffer : 100,
- fn: function(e,el) {
- if(item.value){
- var index = 0,url=args[0], length = url.length, s, e;
- while(index < length) {
- if((s = url.indexOf('{', index)) != -1 && (e = url.indexOf('}', s + 1)) != -1) {
- url = url.substring(0, s) + Ext.getCmp(url.substring(s+1, e)).value + url.substring(e+1);
- index = e + 1;
- } else {
- break;
- }
- }
- var caller = me.getURLParameter('whoami');
- var condition = me.getURLParameter('formCondition');
- if(url.indexOf("whoami=Craft")>0 ){
- 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];
- }
- });
|