FormUtil.js 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748
  1. /**
  2. * 与formpanel操作相关的增删改查的操作方法都在这里哦
  3. * 如果formpanel作为主表,还有一些gridpanel等的信息作为附表,form操作时还包括了对gridpanel等的操作
  4. * @author yingp
  5. */
  6. Ext.define('erp.util.FormUtil',{
  7. /**
  8. * 从后台拿到formpanel配置
  9. * @param form formpanel表
  10. * @param url 提交的action名
  11. * @param param 传递回去的数据,比如{caller:Purchase,condition:pu_id=30001}
  12. */
  13. getMultiAssigns:'/common/getMultiNodeAssigns.action',
  14. takeoveraction:'common/takeOverTask.action',
  15. deleteProcess:'common/deleteProcessAfterAudit.action?_noc=1',
  16. getItemsAndButtons: function(form, url, param){
  17. var me = this, tab = me.getActiveTab();
  18. me.setLoading(true);
  19. Ext.Ajax.request({//拿到form的items
  20. url : basePath + url,
  21. params: param,
  22. method : 'post',
  23. callback : function(options, success, response){
  24. me.setLoading(false);
  25. if (!response) return;
  26. var res = new Ext.decode(response.responseText);
  27. if(res.exceptionInfo != null){
  28. showError(res.exceptionInfo);return;
  29. }
  30. form.fo_id = res.fo_id;
  31. form.fo_keyField = res.keyField;
  32. form.tablename = res.tablename;//表名
  33. if(res.keyField){//主键
  34. form.keyField = res.keyField;
  35. }
  36. if(res.statusField){//状态
  37. form.statusField = res.statusField;
  38. }
  39. if(res.statuscodeField){//状态码
  40. form.statuscodeField = res.statuscodeField;
  41. }
  42. if(res.codeField){//Code
  43. form.codeField = res.codeField;
  44. }
  45. if(res.dealUrl){
  46. form.dealUrl = res.dealUrl;
  47. }
  48. form.fo_detailMainKeyField = res.fo_detailMainKeyField;//从表外键字段
  49. var grids = Ext.ComponentQuery.query('gridpanel');
  50. //如果该页面只有一个form,而且form字段少于8个,则布局改变
  51. if(!form.fixedlayout && !form.minMode && grids.length == 0 && res.items.length <= 8){
  52. Ext.each(res.items, function(item){
  53. item.columnWidth = 0.5;
  54. });
  55. form.layout = 'column';
  56. }
  57. if((res.items.length>0.097*window.innerWidth && window.innerWidth<=1150)){
  58. Ext.each(res.items, function(item){
  59. form.layout='column';
  60. //若根据分辨率直接获取宽度会导致 有时不能占满整行
  61. item.width=window.innerWidth*(item.columnWidth)-item.columnWidth*4*10;
  62. });
  63. }
  64. //data&items
  65. var items = me.setItems(form, res.items, res.data, res.limits, {
  66. labelColor: res.necessaryFieldColor
  67. });
  68. form.add(items);
  69. //title
  70. if(res.title && res.title != ''){
  71. form.setTitle(res.title);
  72. var _tt = res.title;
  73. if(form.codeField) {
  74. var _c = form.down('#' + form.codeField);
  75. if( _c && !Ext.isEmpty(_c.value) )
  76. _tt += '(' + _c.value + ')';
  77. }
  78. tab && tab.setTitle(_tt);
  79. }
  80. me.setButtons(form, res.buttons);
  81. //form第一个可编辑框自动focus
  82. me.focusFirst(form);
  83. form.fireEvent('afterload', form);
  84. }
  85. });
  86. },
  87. focusFirst: function(form){
  88. var bool = true;
  89. if(!form.readOnly){
  90. Ext.each(form.items.items, function(){
  91. if(bool && this.hidden == false && this.readOnly == false && this.editable == true){
  92. this.focus(false, 200);
  93. bool = false;
  94. }
  95. });
  96. }
  97. },
  98. /**
  99. * @param necessaryCss 必填项样式
  100. */
  101. setItems: function(form, items, data, limits, necessaryCss){
  102. var me = this, edit = !form.readOnly,hasData = true,limitArr = new Array();
  103. if(limits != null && limits.length > 0) {//权限外字段
  104. limitArr = Ext.Array.pluck(limits, 'lf_field');
  105. }
  106. if (data) {
  107. data = Ext.decode(data);
  108. if(form.statuscodeField && data[form.statuscodeField] != null && data[form.statuscodeField] != '' &&
  109. ['ENTERING', 'UNAUDIT', 'UNPOST', 'CANUSE'].indexOf(data[form.statuscodeField]) == -1){//非在录入和已提交均设置为只读// && data[form.statuscodeField] != 'COMMITED'
  110. form.readOnly = true;
  111. edit = false;
  112. }
  113. if(form.statusCode && data[form.statusCode] == 'POSTED'){//存在单据状态 并且单据状态不等于空 并且 单据状态等于已过账
  114. form.readOnly = true;
  115. edit = false;
  116. }
  117. // statusCode
  118. } else {
  119. hasData = false;
  120. }
  121. var bool = 'a';
  122. if(items.length > 110&&items.length <=190){
  123. bool = 'b';
  124. }else if(items.length>190){
  125. bool = 'c';
  126. }
  127. Ext.each(items, function(item){
  128. if(screen.width < 1280){//根据屏幕宽度,调整列显示宽度
  129. if(item.columnWidth > 0 && item.columnWidth <= 0.25){
  130. item.columnWidth = 1/3;
  131. } else if(item.columnWidth > 0.25 && item.columnWidth <= 0.5){
  132. item.columnWidth = 2/3;
  133. } else if(item.columnWidth >= 1){
  134. item.columnWidth = 1;
  135. }
  136. } else {
  137. if(item.columnWidth > 0.25 && item.columnWidth < 0.5){
  138. item.columnWidth = 1/3;
  139. } else if(item.columnWidth > 0.5 && item.columnWidth < 0.75){
  140. item.columnWidth = 2/3;
  141. }
  142. }
  143. if(!item.allowBlank && item.fieldLabel && necessaryCss.labelColor) {
  144. item.labelStyle = 'color:#' + necessaryCss.labelColor;
  145. item.fieldStyle = 'background:#FFFAFA;color:#515151;'
  146. }
  147. if(item.readOnly) {
  148. item.fieldStyle = 'background:#e0e0e0;';
  149. }
  150. if(item.name != null) {
  151. if(item.name == form.statusField){//状态加特殊颜色
  152. item.fieldStyle = item.fieldStyle + ';font-weight:bold;';
  153. } else if(item.name == form.statuscodeField){//状态码字段强制隐藏
  154. item.xtype = 'hidden';
  155. }
  156. }
  157. if(item.xtype == 'hidden') {
  158. item.columnWidth = 0;
  159. item.margin = '0';
  160. }
  161. if(item.xtype == 'checkbox') {
  162. item.focusCls = '';
  163. }
  164. if(item.maskRe!=null){
  165. item.maskRe=new RegExp(item.regex);
  166. }
  167. if (hasData) {
  168. item.value = data[item.name];
  169. if(item.secondname){//针对合并型的字段MultiField
  170. item.secondvalue = data[item.secondname];
  171. }
  172. if(item.xtype=='multifield1'){
  173. if(item.logic){
  174. var logics = item.logic.split(",");
  175. item.secondvalue = data[logics[0]];
  176. if(logics[1]){
  177. item.thirdvalue = data[logics[1]];
  178. }
  179. }
  180. }
  181. if(!edit){
  182. form.readOnly = true;
  183. item.fieldStyle = item.fieldStyle + ';background:#f1f1f1;';
  184. item.readOnly = true;
  185. }
  186. if(item.xtype == 'checkbox'){
  187. item.checked = Math.abs(item.value || 0) == 1;
  188. item.fieldStyle = '';
  189. }
  190. }
  191. if(limitArr.length > 0 && Ext.Array.contains(limitArr, item.name)) {
  192. item.hidden = true;
  193. }
  194. if(item.html&&item.name == null&&item.value==''){
  195. }else{
  196. if(bool == 'b') {
  197. item.columnWidth = item.columnWidth*0.83;
  198. }
  199. if(bool == 'c') {
  200. // item.columnWidth = item.columnWidth*0.65;
  201. item.columnWidth = item.columnWidth*0.85;
  202. }
  203. }
  204. if(item.renderfn){
  205. var args = new Array();
  206. var arr = item.renderfn.split(':');
  207. //hey start 主表字段背景颜色
  208. if(arr&&arr[0]!='itemstyle'){//判断是否是itemstyle
  209. if(contains(item.renderfn, ':', true)){
  210. Ext.each(item.renderfn.split(':'), function(a, index){
  211. if(index == 0){
  212. renderName = a;
  213. } else {
  214. args.push(a);
  215. }
  216. });
  217. } else {renderName=item.renderfn;}
  218. if(renderName != 'F'){
  219. me[renderName](item, args, form);
  220. }
  221. }else{
  222. switch(arr.length)
  223. {
  224. case 2:
  225. if(data&&data[item.name]&&data[item.name]==arr[1]) item.fieldStyle = item.fieldStyle + ';background:#c0c0c0;';
  226. break;
  227. case 3:
  228. if(data&&data[item.name]&&data[item.name]==arr[1]) item.fieldStyle = item.fieldStyle + ';background:'+arr[2]+';';
  229. break;
  230. default:
  231. }
  232. }
  233. }
  234. });
  235. // 字段少的form
  236. if(form.minMode) {
  237. Ext.each(items, function(item){
  238. if(item.columnWidth >= 0 && item.columnWidth < 0.5){
  239. item.columnWidth = 0.5;
  240. } else if(item.columnWidth >= 0.5) {
  241. item.columnWidth = 1;
  242. }
  243. });
  244. }
  245. return items;
  246. },
  247. setButtons: function(form, buttonString){
  248. if(buttonString != null && buttonString.trim() != ''){
  249. var buttons = new Array();
  250. buttons.push('->');//->使buttons放在toolbar中间
  251. Ext.each(buttonString.split('#'), function(btn, index){
  252. var o = {};
  253. o.xtype = btn;
  254. o.height = 26;
  255. buttons.push(o);
  256. if((index + 1)%12 == 0){//每行显示12个button,超过12个就添加一个bbar
  257. buttons.push('->');
  258. form.addDocked({
  259. xtype: 'toolbar',
  260. dock: 'bottom',
  261. defaults: {
  262. style: {
  263. marginLeft: '10px'
  264. }
  265. },
  266. items: buttons//12个加进去
  267. });
  268. buttons = new Array();//清空
  269. buttons.push('->');
  270. }
  271. });
  272. buttons.push('->');
  273. form.addDocked({//未到12个的
  274. xtype: 'toolbar',
  275. dock: 'bottom',
  276. defaults: {
  277. style: {
  278. marginLeft: '10px'
  279. }
  280. },
  281. items: buttons
  282. });
  283. }
  284. },
  285. loadNewStore: function(form, param){
  286. var me = this;
  287. me.setLoading(true);
  288. Ext.Ajax.request({
  289. url : basePath + "common/loadNewFormStore.action",
  290. params: param,
  291. method : 'post',
  292. callback : function(options,success,response){
  293. me.setLoading(false);
  294. var res = new Ext.decode(response.responseText);
  295. if(res.exceptionInfo != null){
  296. showError(res.exceptionInfo);return;
  297. }
  298. if(res.data){
  299. var d = Ext.decode(res.data);
  300. form.getForm().setValues(d);
  301. var chs = form.query('checkbox');
  302. Ext.each(chs, function(){
  303. this.setValue(Math.abs(d[this.name] || 0) == 1);
  304. });
  305. form.getForm().getFields().each(function (item,index,length){
  306. item.originalValue = item.value;
  307. });
  308. }
  309. }
  310. });
  311. },
  312. getSeqId: function(form){
  313. if(!form){
  314. form = Ext.getCmp('form');
  315. }
  316. Ext.Ajax.request({
  317. url : basePath + form.getIdUrl,
  318. method : 'get',
  319. async: false,
  320. callback : function(options,success,response){
  321. var rs = new Ext.decode(response.responseText);
  322. if(rs.exceptionInfo){
  323. showError(rs.exceptionInfo);return;
  324. }
  325. if(rs.success){
  326. Ext.getCmp(form.keyField).setValue(rs.id);
  327. }
  328. }
  329. });
  330. },
  331. /**
  332. * 保存之前的判断
  333. * @param arg 额外参数
  334. */
  335. beforeSave: function(me, arg){
  336. var mm = this;
  337. var form = Ext.getCmp('form');
  338. if(! mm.checkForm()){
  339. return;
  340. }
  341. if(form.keyField){
  342. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  343. mm.getSeqId(form);
  344. }
  345. }
  346. var grids = Ext.ComponentQuery.query('gridpanel');
  347. var removea = new Array();
  348. Ext.each(grids,function(g,index){
  349. if(g.xtype=='itemgrid'){
  350. g.saveValue();
  351. removea.push(g);
  352. }
  353. });
  354. Ext.each(removea,function(r,index){
  355. Ext.Array.remove(grids,r);
  356. });
  357. if(grids.length > 0 && !grids[0].ignore){
  358. var param = me.GridUtil.getGridStore();
  359. if(grids[0].necessaryField&&grids[0].necessaryField.length > 0 && (param == null || param == '')){
  360. var errInfo = me.GridUtil.getUnFinish(grids[0]);
  361. if(errInfo.length > 0)
  362. errInfo = '明细表有必填字段未完成填写, 继续将不会保存未完成的数据,是否继续?<hr>' + errInfo;
  363. else
  364. errInfo = '明细表还未添加数据, 是否继续?';
  365. warnMsg(errInfo, function(btn){
  366. if(btn == 'yes'){
  367. mm.onSave(param, arg);
  368. } else {
  369. return;
  370. }
  371. });
  372. } else {
  373. mm.onSave(param, arg);
  374. }
  375. } else {
  376. mm.onSave([]);
  377. }
  378. },
  379. /**
  380. * 单据保存
  381. * @param param 传递过来的数据,比如gridpanel的数据
  382. */
  383. onSave: function(param, arg){
  384. var me = this;
  385. var form = Ext.getCmp('form');
  386. param = param == null ? [] : "[" + param.toString() + "]";
  387. if(form.getForm().isValid()){
  388. //form里面数据
  389. Ext.each(form.items.items, function(item){
  390. if(item.xtype == 'numberfield'){
  391. //number类型赋默认值,不然sql无法执行
  392. if(item.value == null || item.value == ''){
  393. item.setValue(0);
  394. }
  395. }
  396. });
  397. var r = form.getValues();
  398. Ext.each(form.items.items, function(item){
  399. if(item.xtype == 'itemgrid'){
  400. //number类型赋默认值,不然sql无法执行
  401. if(item.value != null && item.value != ''){
  402. r[item.name]=item.value;
  403. }
  404. }
  405. });
  406. //去除ignore字段
  407. var keys = Ext.Object.getKeys(r), f;
  408. var reg = /[!@#$%^&*()'":,\/?]/;
  409. Ext.each(keys, function(k){
  410. f = form.down('#' + k);
  411. if(f && f.logic == 'ignore') {
  412. delete r[k];
  413. }
  414. //codeField值强制大写,自动过滤特殊字符
  415. if(k == form.codeField && !Ext.isEmpty(r[k])) {
  416. r[k] = r[k].trim().toUpperCase().replace(reg, '');
  417. }
  418. });
  419. if(!me.contains(form.saveUrl, '?caller=', true)){
  420. form.saveUrl = form.saveUrl + "?caller=" + caller;
  421. }
  422. me.save(r, param, arg);
  423. }else{
  424. me.checkForm();
  425. }
  426. },
  427. save: function(){
  428. var params = new Object();
  429. var r = arguments[0];
  430. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  431. if(contains(k, 'ext-', true)){
  432. delete r[k];
  433. }
  434. });
  435. params.formStore = unescape(escape(Ext.JSON.encode(r)));
  436. params.param = unescape(arguments[1].toString());
  437. for(var i=2; i<arguments.length; i++) { //兼容多参数
  438. if(arguments[i])
  439. params['param' + i] = unescape(arguments[i].toString());
  440. }
  441. var me = this;
  442. var form = Ext.getCmp('form'), url = form.saveUrl;
  443. if(url.indexOf('caller=') == -1){
  444. url = url + "?caller=" + caller;
  445. }
  446. me.setLoading(true);
  447. Ext.Ajax.request({
  448. url : basePath + url,
  449. params : params,
  450. method : 'post',
  451. callback : function(options,success,response){
  452. me.setLoading(false);
  453. var localJson = new Ext.decode(response.responseText);
  454. if(localJson.success){
  455. saveSuccess(function(){
  456. //add成功后刷新页面进入可编辑的页面
  457. var value =r[form.keyField];
  458. var formCondition = form.keyField + "IS" + value;
  459. var gridCondition = '';
  460. var grid = Ext.getCmp('grid');
  461. if(grid && grid.mainField){
  462. gridCondition = grid.mainField + "IS'" + value+"'";
  463. }
  464. if(me.contains(window.location.href, '?', true)){
  465. window.location.href = window.location.href + '&formCondition=' +
  466. formCondition + '&gridCondition=' + gridCondition;
  467. } else {
  468. window.location.href = window.location.href + '?formCondition=' +
  469. formCondition + '&gridCondition=' + gridCondition;
  470. }
  471. });
  472. } else if(localJson.exceptionInfo){
  473. var str = localJson.exceptionInfo;
  474. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  475. str = str.replace('AFTERSUCCESS', '');
  476. saveSuccess(function(){
  477. //add成功后刷新页面进入可编辑的页面
  478. var value = r[form.keyField];
  479. var formCondition = form.keyField + "IS" + value;
  480. var gridCondition = '';
  481. var grid = Ext.getCmp('grid');
  482. if(grid && grid.mainField){
  483. gridCondition = grid.mainField + "IS'" + value +"'";
  484. }
  485. if(me.contains(window.location.href, '?', true)){
  486. window.location.href = window.location.href + '&formCondition=' +
  487. formCondition + '&gridCondition=' + gridCondition;
  488. } else {
  489. window.location.href = window.location.href + '?formCondition=' +
  490. formCondition + '&gridCondition=' + gridCondition;
  491. }
  492. });
  493. showError(str);
  494. } else {
  495. showError(str);
  496. return;
  497. }
  498. } else{
  499. saveFailure();//@i18n/i18n.js
  500. }
  501. }
  502. });
  503. },
  504. /**
  505. * 检查form未完善的字段
  506. */
  507. checkForm: function(){
  508. var s = '';
  509. var form = Ext.getCmp('form');
  510. form.getForm().getFields().each(function (item, index, length){
  511. if(!item.isValid()){
  512. if(s != ''){
  513. s += ',';
  514. }
  515. if(item.fieldLabel || item.ownerCt.fieldLabel){
  516. s += item.fieldLabel || item.ownerCt.fieldLabel;
  517. }
  518. }
  519. });
  520. if(s == ''){
  521. return true;
  522. }
  523. showError($I18N.common.form.necessaryInfo1 + '(<font color=green>' + s.replace(/&nbsp;/g,'') +
  524. '</font>)' + $I18N.common.form.necessaryInfo2);
  525. return false;
  526. },
  527. /**
  528. * 删除操作
  529. */
  530. onDelete: function(id){
  531. var me = this;
  532. warnMsg($I18N.common.msg.ask_del_main, function(btn){
  533. if(btn == 'yes'){
  534. var form = Ext.getCmp('form');
  535. if(!me.contains(form.deleteUrl, '?caller=', true)){
  536. form.deleteUrl = form.deleteUrl + "?caller=" + caller;
  537. }
  538. me.setLoading(true);
  539. Ext.Ajax.request({
  540. url : basePath + form.deleteUrl,
  541. params: {
  542. id: id
  543. },
  544. method : 'post',
  545. callback : function(options,success,response){
  546. me.setLoading(false);
  547. var localJson = new Ext.decode(response.responseText);
  548. if(localJson.exceptionInfo){
  549. showError(localJson.exceptionInfo);return;
  550. }
  551. if(localJson.success){
  552. delSuccess(function(){
  553. me.onClose();
  554. });//@i18n/i18n.js
  555. } else {
  556. delFailure();
  557. }
  558. }
  559. });
  560. }
  561. });
  562. },
  563. /**
  564. * 单据修改
  565. * @param
  566. * @param
  567. * @param opts 获取form数据的参数{asString, dirtyOnly, includeEmptyText, useDataValues}
  568. * @param extra 额外参数
  569. */
  570. onUpdate: function(me, ignoreWarn, opts, extra){
  571. var mm = this;
  572. var form = Ext.getCmp('form');
  573. var s1 = mm.checkFormDirty(form);
  574. var s2 = '';
  575. var grids = Ext.ComponentQuery.query('gridpanel');
  576. var removea = new Array();
  577. if(form.codeField && (Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == '')){
  578. showError('编号不能为空.');
  579. return;
  580. }
  581. Ext.each(grids,function(g,index){
  582. if(g.xtype=='itemgrid'){
  583. g.saveValue();
  584. removea.push(g);
  585. }
  586. });
  587. Ext.each(removea,function(r,index){
  588. Ext.Array.remove(grids,r);
  589. });
  590. if(grids.length > 0 && !grids[0].ignore){//check所有grid是否已修改
  591. Ext.each(grids, function(grid, index){
  592. if(grid.GridUtil){
  593. var msg = grid.GridUtil.checkGridDirty(grid);
  594. if(msg.length > 0){
  595. s2 = s2 + '<br/>' + msg;
  596. }
  597. }
  598. });
  599. }
  600. if(s1 == '' && (s2 == '' || s2 == '<br/>')){
  601. showError('还未添加或修改数据.');
  602. return;
  603. }
  604. if(form && form.getForm().isValid()){
  605. //form里面数据
  606. var r = (opts && opts.dirtyOnly) ? form.getForm().getValues(false, true) :
  607. form.getValues();
  608. //去除ignore字段
  609. var keys = Ext.Object.getKeys(r), f;
  610. Ext.each(keys, function(k){
  611. f = form.down('#' + k);
  612. if(f && f.logic == 'ignore') {
  613. delete r[k];
  614. }
  615. if(f && opts && opts.dirtyOnly) {
  616. extra = (extra || '') +
  617. '\n(' + f.fieldLabel + ') old: ' + f.originalValue + ' new: ' + r[k];
  618. }
  619. });
  620. if(opts && opts.dirtyOnly && form.keyField) {
  621. r[form.keyField] = form.down("#" + form.keyField).getValue();
  622. }
  623. if(!mm.contains(form.updateUrl, '?caller=', true)){
  624. form.updateUrl = form.updateUrl + "?caller=" + caller;
  625. }
  626. var params = [];
  627. if(grids.length > 0 && grids[0].columns.length > 0 && !grids[0].ignore){
  628. if(grids[0].GridUtil.isEmpty(grids[0])) {
  629. warnMsg('明细还未录入数据,是否继续保存?', function(btn){
  630. if(btn == 'yes' || btn == 'ok'){
  631. mm.update(r, '[]', extra);
  632. } else {
  633. return;
  634. }
  635. });
  636. } else if(grids[0].GridUtil.isDirty(grids[0])) {
  637. var param = grids[0].GridUtil.getGridStore();
  638. if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param.length == 0 || param == '') && !ignoreWarn){
  639. warnMsg('明细表有必填项未填写,是否继续保存?', function(btn){
  640. if(btn == 'yes' || btn == 'ok'){
  641. params = unescape("[" + param.toString() + "]");
  642. mm.update(r, params, extra);
  643. } else {
  644. return;
  645. }
  646. });
  647. } else {
  648. params = unescape("[" + param.toString() + "]");
  649. mm.update(r, params, extra);
  650. }
  651. } else {
  652. mm.update(r, '[]', extra);
  653. }
  654. } else {
  655. mm.update(r, params, extra);
  656. }
  657. }else{
  658. mm.checkForm(form);
  659. }
  660. },
  661. update: function(){
  662. var me = this, params = new Object();
  663. var r = arguments[0];
  664. Ext.each(Ext.Object.getKeys(r), function(k){//去掉页面非表单定义字段
  665. if(contains(k, 'ext-', true)){
  666. delete r[k];
  667. }
  668. });
  669. params.formStore = unescape(escape(Ext.JSON.encode(r)));
  670. params.param = unescape(arguments[1].toString());
  671. for(var i=2; i<arguments.length; i++) { //兼容多参数
  672. if (arguments[i] != null)
  673. params['param' + i] = unescape(arguments[i].toString());
  674. }
  675. var form = Ext.getCmp('form'), url = form.updateUrl;
  676. if(url.indexOf('caller=') == -1){
  677. url = url + "?caller=" + caller;
  678. }
  679. me.setLoading(true);//loading...
  680. Ext.Ajax.request({
  681. url : basePath + url,
  682. params: params,
  683. method : 'post',
  684. callback : function(options,success,response){
  685. me.setLoading(false);
  686. var localJson = new Ext.decode(response.responseText);
  687. if(localJson.success){
  688. showMessage('提示', '保存成功!', 1000);
  689. //update成功后刷新页面进入可编辑的页面
  690. var u = String(window.location.href);
  691. if (u.indexOf('formCondition') == -1) {
  692. var value = r[form.keyField];
  693. var formCondition = form.keyField + "IS" + value ;
  694. var gridCondition = '';
  695. var grid = Ext.getCmp('grid');
  696. if(grid && grid.mainField){
  697. gridCondition = grid.mainField + "IS" + value;
  698. }
  699. if(me.contains(window.location.href, '?', true)){
  700. window.location.href = window.location.href + '&formCondition=' +
  701. formCondition + '&gridCondition=' + gridCondition;
  702. } else {
  703. window.location.href = window.location.href + '?formCondition=' +
  704. formCondition + '&gridCondition=' + gridCondition;
  705. }
  706. } else {
  707. window.location.reload();
  708. }
  709. } else if(localJson.exceptionInfo){
  710. var str = localJson.exceptionInfo;
  711. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  712. str = str.replace('AFTERSUCCESS', '');
  713. //update成功后刷新页面进入可编辑的页面
  714. var u = String(window.location.href);
  715. if (u.indexOf('formCondition') == -1) {
  716. var value = r[form.keyField];
  717. var formCondition = form.keyField + "IS" + value ;
  718. var gridCondition = '';
  719. var grid = Ext.getCmp('grid');
  720. if(grid && grid.mainField){
  721. gridCondition = grid.mainField + "IS" + value;
  722. }
  723. if(me.contains(window.location.href, '?', true)){
  724. window.location.href = window.location.href + '&formCondition=' +
  725. formCondition + '&gridCondition=' + gridCondition;
  726. } else {
  727. window.location.href = window.location.href + '?formCondition=' +
  728. formCondition + '&gridCondition=' + gridCondition;
  729. }
  730. } else {
  731. window.location.reload();
  732. }
  733. }
  734. showError(str);return;
  735. } else {
  736. updateFailure();
  737. }
  738. }
  739. });
  740. },
  741. /**
  742. * 关闭之前进行一些判断,根据用户选择或保存或关闭
  743. *
  744. */
  745. beforeClose: function(me){
  746. var mm = this;
  747. var s = '';
  748. var forms = Ext.ComponentQuery.query('formpanel');
  749. if(forms.length > 0 && !forms[0].ignore){//check所有form是否已修改
  750. Ext.each(forms, function(form, index){
  751. var msg = mm.checkFormDirty(form);
  752. if(msg.length > 0){
  753. s = s + '<br/>' + msg;
  754. }
  755. });
  756. }
  757. var grids = Ext.ComponentQuery.query('gridpanel');
  758. if(grids.length > 0 && !grids[0].ignore && me.GridUtil){//check所有grid是否已修改
  759. Ext.each(grids, function(grid, index){
  760. var msg = me.GridUtil.checkGridDirty(grid);
  761. if(msg.length > 0){
  762. s = s + '<br/>' + msg;
  763. }
  764. });
  765. }
  766. if(s == '' || s == '<br/>'){
  767. mm.onClose();
  768. } else {
  769. if(!formCondition){//单据新增界面哦
  770. //关闭前保存新增的数据
  771. Ext.MessageBox.show({//关闭前保存修改的数据
  772. title:'保存新添加的数据?',
  773. msg: '详细:<br/>' + s + '<br/>离开前要保存吗?',
  774. buttons: Ext.Msg.YESNOCANCEL,
  775. icon: Ext.Msg.WARNING,
  776. fn: function(btn){
  777. if(btn == 'yes'){
  778. mm.beforeSave(me);
  779. } else if(btn == 'no'){
  780. mm.onClose();
  781. } else {
  782. return;
  783. }
  784. }
  785. });
  786. } else {//单据查看界面哦
  787. Ext.MessageBox.show({
  788. title:'保存修改?',
  789. msg: '该单据已被修改:<br/>' + s + '<br/>离开前要保存吗?',
  790. buttons: Ext.Msg.YESNOCANCEL,
  791. icon: Ext.Msg.WARNING,
  792. fn: function(btn){
  793. if(btn == 'yes'){
  794. mm.onUpdate(form, []);
  795. } else if(btn == 'no'){
  796. mm.onClose();
  797. } else {
  798. return;
  799. }
  800. }
  801. });
  802. }
  803. }
  804. },
  805. /**
  806. * 检查表单是否被修改,并返回被修改的内容
  807. */
  808. checkFormDirty: function(){
  809. var form = Ext.getCmp('form');
  810. var s = '';
  811. form.getForm().getFields().each(function (item,index, length){
  812. if(item.logic!='ignore'){
  813. var value = item.value == null ? "" : item.value;
  814. if(item.xtype == 'htmleditor') {
  815. value = item.getValue();
  816. }
  817. item.originalValue = item.originalValue == null ? "" : item.originalValue;
  818. if(Ext.typeOf(item.originalValue) != 'object'){
  819. if(item.originalValue.toString() != value.toString()){//isDirty、wasDirty、dirty一直都是true,没办法判断,所以直接用item.originalValue,原理是一样的
  820. var label = item.fieldLabel || item.ownerCt.fieldLabel ||
  821. item.boxLabel || item.ownerCt.title;//针对fieldContainer、radio、fieldset等
  822. if(label){
  823. s = s + '&nbsp;' + label.replace(/&nbsp;/g,'');
  824. }
  825. }
  826. }
  827. }
  828. });
  829. return (s == '') ? s : ('表单字段(<font color=green>'+s+'</font>)已修改');
  830. },
  831. /**
  832. * 关闭操作
  833. */
  834. onClose: function(){
  835. var modal=parent.Ext.getCmp('modalwindow');
  836. if(modal){
  837. var history=modal.historyMaster;
  838. Ext.Ajax.request({
  839. url: basePath + 'common/changeMaster.action',
  840. params: {
  841. to: history
  842. },
  843. callback: function(opt, s, r) {
  844. if (s) {
  845. modal.close();
  846. } else {
  847. alert('切换到原账套失败!');
  848. }
  849. }
  850. });
  851. }else{
  852. var main = parent.Ext.getCmp("content-panel"),bool = false;
  853. if(main){
  854. bool = true;
  855. main.getActiveTab().close();
  856. } else {
  857. var win = parent.Ext.ComponentQuery.query('window');
  858. if(win){
  859. Ext.each(win, function(){
  860. this.close();
  861. });
  862. } else {
  863. bool = true;
  864. window.close();
  865. }
  866. }
  867. var p = Ext.ComponentQuery.query('erpCloseButton');
  868. if(!bool && p){//如果还是没关闭tab,直接关闭页面
  869. window.close();
  870. }
  871. }
  872. },
  873. /**
  874. * 跳转到add页面
  875. */
  876. onAdd: function(panelId, title, url){
  877. var main = parent.Ext.getCmp("content-panel");
  878. if(main){
  879. panelId = (panelId == main.getActiveTab().id || panelId == null)
  880. ? Math.random() : panelId;
  881. var panel = Ext.getCmp(panelId);
  882. if(!panel){
  883. var value = "";
  884. if (title.toString().length>5) {
  885. value = title.toString().substring(0,5);
  886. } else {
  887. value = title;
  888. }
  889. if(!contains(url, 'http://', true) && !contains(url, basePath, true)){
  890. url = basePath + url;
  891. }
  892. panel = {
  893. title : value,
  894. tag : 'iframe',
  895. tabConfig:{tooltip:title},
  896. border : false,
  897. layout : 'fit',
  898. iconCls : 'x-tree-icon-tab-tab',
  899. html : '<iframe id="iframe_add_'+panelId+'" src="' + url+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>',
  900. closable : true
  901. };
  902. this.openTab(panel, panelId);
  903. } else {
  904. main.setActiveTab(panel);
  905. }
  906. } else {
  907. if(!contains(url, basePath, true)){
  908. url = basePath + url;
  909. }
  910. window.open(url);
  911. }
  912. },
  913. /**
  914. * 取{field}值,自动赋值给{tField}
  915. * @param caller 表名
  916. * @param tField 待赋值的字段
  917. * @param [record 待赋值的明细行]
  918. */
  919. getFieldValue: function(caller, field, condition, tField, record){
  920. Ext.Ajax.request({
  921. url : basePath + 'common/getFieldData.action',
  922. async: false,
  923. params: {
  924. caller: caller,
  925. field: field,
  926. condition: condition
  927. },
  928. method : 'post',
  929. callback : function(options,success,response){
  930. var localJson = new Ext.decode(response.responseText);
  931. if(localJson.exceptionInfo){
  932. showError(localJson.exceptionInfo);return;
  933. }
  934. if(localJson.success){
  935. if(localJson.data != null){
  936. if(record){
  937. record.set(tField, localJson.data);
  938. } else {
  939. var ff = Ext.getCmp(tField);
  940. if(ff)
  941. ff.setValue(localJson.data);
  942. }
  943. }
  944. }
  945. }
  946. });
  947. },
  948. /**
  949. * 取{fields}值,自动赋值给{tFields},field用','隔开
  950. * @param caller 表名
  951. * @param tFields 待赋值的字段
  952. * @param [record 待赋值的明细行]
  953. */
  954. getFieldsValue: function(caller, fields, condition, tFields, record){
  955. Ext.Ajax.request({
  956. url : basePath + 'common/getFieldsData.action',
  957. async: false,
  958. params: {
  959. caller: caller,
  960. fields: fields,
  961. condition: condition
  962. },
  963. method : 'post',
  964. callback : function(options,success,response){
  965. var localJson = new Ext.decode(response.responseText);
  966. if(localJson.exceptionInfo){
  967. showError(localJson.exceptionInfo);return;
  968. }
  969. if(localJson.success){
  970. if(record){
  971. if(localJson.data != null){
  972. var fis = fields.split(',');
  973. Ext.each(tFields.split(','), function(f, index){
  974. if( localJson.data[fis[index]] != null){
  975. record.set(f, localJson.data[fis[index]]);
  976. }
  977. });
  978. }
  979. } else {
  980. if(localJson.data != null){
  981. var fis = fields.split(',');
  982. Ext.each(tFields.split(','), function(f, index){
  983. if(localJson.data[fis[index]] != null){
  984. var fi = Ext.getCmp(f);
  985. if (fi)
  986. fi.setValue(localJson.data[fis[index]]);
  987. }
  988. });
  989. }
  990. }
  991. }
  992. }
  993. });
  994. },
  995. /**
  996. * 取{fields}值
  997. * @param caller 表名
  998. */
  999. getFieldsValues: function(caller, fields, condition, data, fn){
  1000. Ext.Ajax.request({
  1001. url : basePath + 'common/getFieldsDatas.action',
  1002. async: false,
  1003. params: {
  1004. caller: caller,
  1005. fields: fields,
  1006. condition: condition
  1007. },
  1008. method : 'post',
  1009. callback : function(options,success,response){
  1010. var localJson = new Ext.decode(response.responseText);
  1011. if(localJson.exceptionInfo){
  1012. showError(localJson.exceptionInfo);return;
  1013. }
  1014. if(localJson.success){
  1015. data = localJson.data;
  1016. fn && fn.call(null, localJson.data);
  1017. }
  1018. }
  1019. });
  1020. },
  1021. /**
  1022. * 取{field}值
  1023. * @param caller 表名
  1024. */
  1025. _getFieldValue: function(caller, field, condition){
  1026. Ext.Ajax.request({
  1027. url : basePath + 'common/getFieldData.action',
  1028. async: false,
  1029. params: {
  1030. caller: caller,
  1031. field: field,
  1032. condition: condition
  1033. },
  1034. method : 'post',
  1035. callback : function(options,success,response){
  1036. var localJson = new Ext.decode(response.responseText);
  1037. if(localJson.exceptionInfo){
  1038. showError(localJson.exceptionInfo);return null;
  1039. }
  1040. if(localJson.success){
  1041. if(localJson.data != null){
  1042. return localJson.data;
  1043. } else {
  1044. return null;
  1045. }
  1046. } else {
  1047. return null;
  1048. }
  1049. }
  1050. });
  1051. },
  1052. /**
  1053. * 取{field}值
  1054. * @param caller 表名
  1055. */
  1056. _getFieldValues: function(caller, field, condition, tfield, record){
  1057. Ext.Ajax.request({
  1058. url : basePath + 'common/getFieldDatas.action',
  1059. async: false,
  1060. params: {
  1061. caller: caller,
  1062. field: field,
  1063. condition: condition
  1064. },
  1065. method : 'post',
  1066. callback : function(options,success,response){
  1067. var localJson = new Ext.decode(response.responseText);
  1068. if(localJson.exceptionInfo){
  1069. showError(localJson.exceptionInfo);return null;
  1070. }
  1071. if(localJson.success){
  1072. if(localJson.data != null){
  1073. if(record){
  1074. record.set(tfield, localJson.data);
  1075. } else {
  1076. Ext.getCmp(tfield).setValue(localJson.data);
  1077. }
  1078. }
  1079. } else {
  1080. return;
  1081. }
  1082. }
  1083. });
  1084. },
  1085. /**
  1086. * 取{fields}值,field用','隔开
  1087. * @param caller 表名
  1088. */
  1089. _getFieldsValue: function(caller, fields, condition){
  1090. Ext.Ajax.request({
  1091. url : basePath + 'common/getFieldsData.action',
  1092. async: false,
  1093. params: {
  1094. caller: caller,
  1095. fields: fields,
  1096. condition: condition
  1097. },
  1098. method : 'post',
  1099. callback : function(options,success,response){
  1100. var localJson = new Ext.decode(response.responseText);
  1101. if(localJson.exceptionInfo){
  1102. showError(localJson.exceptionInfo);return;
  1103. }
  1104. if(localJson.success){
  1105. return localJson.data;
  1106. }
  1107. }
  1108. });
  1109. },
  1110. checkFieldValue: function(caller, condition){
  1111. Ext.Ajax.request({
  1112. url : basePath + 'common/checkFieldData.action',
  1113. params: {
  1114. caller: caller,
  1115. condition: condition
  1116. },
  1117. method : 'post',
  1118. callback : function(options,success,response){
  1119. var localJson = new Ext.decode(response.responseText);
  1120. if(localJson.exceptionInfo){
  1121. showError(localJson.exceptionInfo);
  1122. return false;
  1123. }
  1124. if(localJson.success){
  1125. return localJson.data;
  1126. }
  1127. }
  1128. });
  1129. },
  1130. onAudit: function(id){
  1131. var me = this;
  1132. var form = Ext.getCmp('form');
  1133. if(form && form.getForm().isValid()){
  1134. if(!me.contains(form.auditUrl, '?caller=', true)){
  1135. form.auditUrl = form.auditUrl + "?caller=" + caller;
  1136. }
  1137. me.setLoading(true);//loading...
  1138. //清除流程
  1139. Ext.Ajax.request({
  1140. url : basePath + me.deleteProcess,
  1141. params: {
  1142. keyValue:id,
  1143. caller:caller,
  1144. _noc:1
  1145. },
  1146. method:'post',
  1147. async:false,
  1148. callback : function(options,success,response){
  1149. }
  1150. });
  1151. Ext.Ajax.request({
  1152. url : basePath + form.auditUrl,
  1153. params: {
  1154. id: id
  1155. },
  1156. method : 'post',
  1157. callback : function(options,success,response){
  1158. me.setLoading(false);
  1159. var localJson = new Ext.decode(response.responseText);
  1160. if(localJson.success){
  1161. //audit成功后刷新页面进入可编辑的页面
  1162. showMessage('提示', '审核成功!', 1000);
  1163. window.location.reload();
  1164. } else {
  1165. if(localJson.exceptionInfo){
  1166. var str = localJson.exceptionInfo;
  1167. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1168. str = str.replace('AFTERSUCCESS', '');
  1169. showMessage("提示", str);
  1170. auditSuccess(function(){
  1171. window.location.reload();
  1172. });
  1173. } else {
  1174. showError(str);return;
  1175. }
  1176. }
  1177. }
  1178. }
  1179. });
  1180. } else {
  1181. me.checkForm();
  1182. }
  1183. },
  1184. onB2b: function(id){
  1185. var me = this;
  1186. var form = Ext.getCmp('form');
  1187. if(!me.contains(form.b2bUrl, '?caller=', true)){
  1188. form.b2bUrl = form.b2bUrl + "?caller=" + caller;
  1189. }
  1190. me.setLoading(true);//loading...
  1191. Ext.Ajax.request({
  1192. url : basePath + form.b2bUrl,
  1193. params: {
  1194. id: id
  1195. },
  1196. method : 'post',
  1197. callback : function(options,success,response){
  1198. me.setLoading(false);
  1199. var localJson = new Ext.decode(response.responseText);
  1200. if(localJson.success){
  1201. //audit成功后刷新页面进入可编辑的页面
  1202. showMessage('提示', '同步成功!', 1000);
  1203. window.location.reload();
  1204. } else {
  1205. if(localJson.exceptionInfo){
  1206. var str = localJson.exceptionInfo;
  1207. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1208. str = str.replace('AFTERSUCCESS', '');
  1209. showMessage("提示", str);
  1210. auditSuccess(function(){
  1211. window.location.reload();
  1212. });
  1213. } else {
  1214. showError(str);return;
  1215. }
  1216. }
  1217. }
  1218. }
  1219. });
  1220. },
  1221. onAuditWithManAndTime: function(id,auditerFieldName,auditdateFieldName){
  1222. var me = this;
  1223. var form = Ext.getCmp('form');
  1224. if(!me.contains(form.auditUrl, '?caller=', true)){
  1225. form.auditUrl = form.auditUrl + "?caller=" + caller;
  1226. }
  1227. me.setLoading(true);//loading...
  1228. //清除流程
  1229. Ext.Ajax.request({
  1230. url : basePath + me.deleteProcess,
  1231. params: {
  1232. keyValue:id,
  1233. caller:caller,
  1234. _noc:1
  1235. },
  1236. method:'post',
  1237. async:false,
  1238. callback : function(options,success,response){
  1239. }
  1240. });
  1241. Ext.Ajax.request({
  1242. url : basePath + form.auditUrl,
  1243. params: {
  1244. id: id,
  1245. auditerFieldName:auditerFieldName,
  1246. auditdateFieldName:auditdateFieldName
  1247. },
  1248. method : 'post',
  1249. callback : function(options,success,response){
  1250. me.setLoading(false);
  1251. var localJson = new Ext.decode(response.responseText);
  1252. if(localJson.success){
  1253. //audit成功后刷新页面进入可编辑的页面
  1254. showMessage('提示', '审核成功!', 1000);
  1255. window.location.reload();
  1256. } else {
  1257. if(localJson.exceptionInfo){
  1258. var str = localJson.exceptionInfo;
  1259. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1260. str = str.replace('AFTERSUCCESS', '');
  1261. showMessage("提示", str);
  1262. auditSuccess(function(){
  1263. window.location.reload();
  1264. });
  1265. } else {
  1266. showError(str);return;
  1267. }
  1268. }
  1269. }
  1270. }
  1271. });
  1272. },
  1273. onResAuditWithManAndTime: function(id,auditerFieldName,auditdateFieldName){
  1274. var me = this;
  1275. var form = Ext.getCmp('form');
  1276. if(!me.contains(form.resAuditUrl, '?caller=', true)){
  1277. form.resAuditUrl = form.resAuditUrl + "?caller=" + caller;
  1278. }
  1279. me.setLoading(true);//loading...
  1280. Ext.Ajax.request({
  1281. url : basePath + form.resAuditUrl,
  1282. params: {
  1283. id: id,
  1284. auditerFieldName:auditerFieldName,
  1285. auditdateFieldName:auditdateFieldName
  1286. },
  1287. method : 'post',
  1288. callback : function(options,success,response){
  1289. me.setLoading(false);
  1290. var localJson = new Ext.decode(response.responseText);
  1291. if(localJson.exceptionInfo){
  1292. showError(localJson.exceptionInfo);
  1293. }
  1294. if(localJson.success){
  1295. //resAudit成功后刷新页面进入可编辑的页面
  1296. showMessage('提示', '反审核成功!', 1000);
  1297. window.location.reload();
  1298. }
  1299. }
  1300. });
  1301. },
  1302. onResAudit: function(id){
  1303. var me = this;
  1304. var form = Ext.getCmp('form');
  1305. if(!me.contains(form.resAuditUrl, '?caller=', true)){
  1306. form.resAuditUrl = form.resAuditUrl + "?caller=" + caller;
  1307. }
  1308. me.setLoading(true);//loading...
  1309. Ext.Ajax.request({
  1310. url : basePath + form.resAuditUrl,
  1311. params: {
  1312. id: id
  1313. },
  1314. method : 'post',
  1315. callback : function(options,success,response){
  1316. me.setLoading(false);
  1317. var localJson = new Ext.decode(response.responseText);
  1318. if(localJson.exceptionInfo){
  1319. showError(localJson.exceptionInfo);
  1320. }
  1321. if(localJson.success){
  1322. //resAudit成功后刷新页面进入可编辑的页面
  1323. showMessage('提示', '反审核成功!', 1000);
  1324. window.location.reload();
  1325. }
  1326. }
  1327. });
  1328. },
  1329. onAccounted: function(id){
  1330. var me = this;
  1331. var form = Ext.getCmp('form');
  1332. if(!me.contains(form.accountedUrl, '?caller=', true)){
  1333. form.accountedUrl = form.accountedUrl + "?caller=" + caller;
  1334. }
  1335. me.setLoading(true);//loading...
  1336. Ext.Ajax.request({
  1337. url : basePath + form.accountedUrl,
  1338. params: {
  1339. id: id
  1340. },
  1341. method : 'post',
  1342. callback : function(options,success,response){
  1343. me.setLoading(false);
  1344. var localJson = new Ext.decode(response.responseText);
  1345. if(localJson.success){
  1346. //记账成功后刷新页面进入不可编辑的页面
  1347. accountedSuccess(function(){
  1348. window.location.reload();
  1349. });
  1350. } else {
  1351. if(localJson.exceptionInfo){
  1352. var str = localJson.exceptionInfo;
  1353. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1354. str = str.replace('AFTERSUCCESS', '');
  1355. showMessage("提示", str);
  1356. accountedSuccess(function(){
  1357. window.location.reload();
  1358. });
  1359. } else {
  1360. showError(str);return;
  1361. }
  1362. }
  1363. }
  1364. }
  1365. });
  1366. },
  1367. onResAccounted: function(id){
  1368. var me = this;
  1369. var form = Ext.getCmp('form');
  1370. if(!me.contains(form.resAccountedUrl, '?caller=', true)){
  1371. form.resAccountedUrl = form.resAccountedUrl + "?caller=" + caller;
  1372. }
  1373. me.setLoading(true);//loading...
  1374. Ext.Ajax.request({
  1375. url : basePath + form.resAccountedUrl,
  1376. params: {
  1377. id: id
  1378. },
  1379. method : 'post',
  1380. callback : function(options,success,response){
  1381. me.setLoading(false);
  1382. var localJson = new Ext.decode(response.responseText);
  1383. if(localJson.exceptionInfo){
  1384. showError(localJson.exceptionInfo);
  1385. }
  1386. if(localJson.success){
  1387. //resAudit成功后刷新页面进入可编辑的页面
  1388. resAccountedSuccess();
  1389. window.location.reload();
  1390. }
  1391. }
  1392. });
  1393. },
  1394. /**
  1395. * @param allowEmpty 是否允许Grid为空
  1396. */
  1397. onSubmit: function(id, allowEmpty, errFn, scope){
  1398. var me = this;
  1399. var form = Ext.getCmp('form');
  1400. if(form && form.getForm().isValid()){
  1401. var s = me.checkFormDirty(form);
  1402. var grids = Ext.ComponentQuery.query('gridpanel');
  1403. if(grids.length > 0 && !grids[0].ignore){//check所有grid是否已修改
  1404. var param = grids[0].GridUtil.getAllGridStore(grids[0]);
  1405. if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param == '') && (allowEmpty !== true)){
  1406. var errInfo = grids[0].GridUtil.getUnFinish(grids[0]);
  1407. if(errInfo.length > 0)
  1408. showError("明细表有必填字段未完成填写<hr>" + errInfo);
  1409. else
  1410. showError("明细表还未添加数据,无法提交!");
  1411. return;
  1412. }
  1413. Ext.each(grids, function(grid, index){
  1414. if(grid.GridUtil){
  1415. var msg = grid.GridUtil.checkGridDirty(grid);
  1416. if(msg.length > 0){
  1417. s = s + '<br/>' + grid.GridUtil.checkGridDirty(grid);
  1418. }
  1419. }
  1420. });
  1421. }
  1422. if(s == '' || s == '<br/>'){
  1423. me.submit(id);
  1424. } else {
  1425. Ext.MessageBox.show({
  1426. title:'保存修改?',
  1427. msg: '该单据已被修改:<br/>' + s + '<br/>提交前要先保存吗?',
  1428. buttons: Ext.Msg.YESNOCANCEL,
  1429. icon: Ext.Msg.WARNING,
  1430. fn: function(btn){
  1431. if(btn == 'yes'){
  1432. if(typeof errFn === 'function')
  1433. errFn.call(scope);
  1434. else
  1435. me.onUpdate(form, true);
  1436. } else if(btn == 'no'){
  1437. me.submit(id);
  1438. } else {
  1439. return;
  1440. }
  1441. }
  1442. });
  1443. }
  1444. } else {
  1445. me.checkForm();
  1446. }
  1447. },
  1448. submit: function(id){
  1449. var me = this;
  1450. var form = Ext.getCmp('form');
  1451. if(!me.contains(form.submitUrl, '?caller=', true)){
  1452. form.submitUrl = form.submitUrl + "?caller=" + caller;
  1453. }
  1454. me.setLoading(true);//loading...
  1455. Ext.Ajax.request({
  1456. url : basePath + form.submitUrl,
  1457. params: {
  1458. id: id
  1459. },
  1460. method : 'post',
  1461. callback : function(options,success,response){
  1462. me.setLoading(false);
  1463. var localJson = new Ext.decode(response.responseText);
  1464. if(localJson.success){
  1465. //跳转之前 若节点指定多人则指定候选人
  1466. Ext.Ajax.request({
  1467. url : basePath + me.getMultiAssigns,
  1468. params: {
  1469. id: id,
  1470. caller:caller
  1471. },
  1472. method : 'post',
  1473. callback : function(){
  1474. var localJson = new Ext.decode(arguments[2].responseText);
  1475. if(localJson.exceptionInfo){
  1476. var str = localJson.exceptionInfo;
  1477. showError(str);
  1478. }else {
  1479. if(localJson.MultiAssign){
  1480. if(localJson.autoSetJnode){
  1481. form.SetNodeDealMan(id);
  1482. }else me.showAssignWin(localJson.assigns);
  1483. }else {
  1484. showMessage('提示', '提交成功!', 1000);
  1485. window.location.reload();
  1486. if(form.onSumitSuccess){
  1487. form.onSumitSuccess();
  1488. }
  1489. }
  1490. }
  1491. }
  1492. });
  1493. //submit成功后刷新页面进入可编辑的页面
  1494. } else {
  1495. if(localJson.exceptionInfo){
  1496. var str = localJson.exceptionInfo;
  1497. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1498. str = str.replace('AFTERSUCCESS', '');
  1499. Ext.Ajax.request({
  1500. url : basePath + me.getMultiAssigns,
  1501. params: {
  1502. id: id,
  1503. caller:caller
  1504. },
  1505. method : 'post',
  1506. callback : function(){
  1507. var localJson = new Ext.decode(arguments[2].responseText);
  1508. if(localJson.exceptionInfo){
  1509. var str = localJson.exceptionInfo;
  1510. showError(str);
  1511. }else {
  1512. if(localJson.MultiAssign){
  1513. me.showAssignWin(localJson.assigns);
  1514. }else {
  1515. showMessage('提示', '提交成功!', 1000);
  1516. window.location.reload();
  1517. }
  1518. }
  1519. }
  1520. });
  1521. }
  1522. showMessage("提示", str);
  1523. }
  1524. }
  1525. }
  1526. });
  1527. },
  1528. onResSubmit: function(id){
  1529. var me = this;
  1530. var form = Ext.getCmp('form');
  1531. if(!me.contains(form.resSubmitUrl, '?caller=', true)){
  1532. form.resSubmitUrl = form.resSubmitUrl + "?caller=" + caller;
  1533. }
  1534. me.setLoading(true);//loading...
  1535. Ext.Ajax.request({
  1536. url : basePath + form.resSubmitUrl,
  1537. params: {
  1538. id: id
  1539. },
  1540. method : 'post',
  1541. callback : function(options,success,response){
  1542. me.setLoading(false);
  1543. var localJson = new Ext.decode(response.responseText);
  1544. if(localJson.exceptionInfo){
  1545. showError(localJson.exceptionInfo);
  1546. }
  1547. if(localJson.success){
  1548. //resSubmit成功后刷新页面进入可编辑的页面
  1549. showMessage('提示', '反提交成功!', 1000);
  1550. window.location.reload();
  1551. }
  1552. }
  1553. });
  1554. },
  1555. onBanned: function(id){
  1556. var me = this;
  1557. var form = Ext.getCmp('form');
  1558. if(!me.contains(form.bannedUrl, '?caller=', true)){
  1559. form.bannedUrl = form.bannedUrl + "?caller=" + caller;
  1560. }
  1561. me.setLoading(true);//loading...
  1562. Ext.Ajax.request({
  1563. url : basePath + form.bannedUrl,
  1564. params: {
  1565. id: id
  1566. },
  1567. method : 'post',
  1568. callback : function(options,success,response){
  1569. me.setLoading(false);
  1570. var localJson = new Ext.decode(response.responseText);
  1571. if(localJson.success){
  1572. //banned成功后刷新页面进入可编辑的页面
  1573. window.location.href = window.location.href;
  1574. bannedSuccess();
  1575. } else {
  1576. if(localJson.exceptionInfo){
  1577. var str = localJson.exceptionInfo;
  1578. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1579. str = str.replace('AFTERSUCCESS', '');
  1580. showError(str);
  1581. bannedSuccess();
  1582. window.location.reload();
  1583. } else {
  1584. showError(str);return;
  1585. }
  1586. }
  1587. }
  1588. }
  1589. });
  1590. },
  1591. onResBanned: function(id){
  1592. var me = this;
  1593. var form = Ext.getCmp('form');
  1594. if(!me.contains(form.resBannedUrl, '?caller=', true)){
  1595. form.resBannedUrl = form.resBannedUrl + "?caller=" + caller;
  1596. }
  1597. me.setLoading(true);//loading...
  1598. Ext.Ajax.request({
  1599. url : basePath + form.resBannedUrl,
  1600. params: {
  1601. id: id
  1602. },
  1603. method : 'post',
  1604. callback : function(options,success,response){
  1605. me.setLoading(false);
  1606. var localJson = new Ext.decode(response.responseText);
  1607. if(localJson.exceptionInfo){
  1608. showError(localJson.exceptionInfo);
  1609. }
  1610. if(localJson.success){
  1611. //resBanned成功后刷新页面进入可编辑的页面
  1612. resBannedSuccess();
  1613. window.location.reload();
  1614. }
  1615. }
  1616. });
  1617. },
  1618. onPrint: function(id){
  1619. var me = this;
  1620. var form = Ext.getCmp('form');
  1621. if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){
  1622. form.printUrl = form.printUrl + "?caller=" + caller;
  1623. }
  1624. me.setLoading(true);//loading...
  1625. Ext.Ajax.request({
  1626. url : basePath + form.printUrl,
  1627. params: {
  1628. id: id
  1629. },
  1630. method : 'post',
  1631. callback : function(options,success,response){
  1632. me.setLoading(false);
  1633. var localJson = new Ext.decode(response.responseText);
  1634. if(localJson.success){
  1635. window.location.href = window.location.href;
  1636. printSuccess();
  1637. } else {
  1638. if(localJson.exceptionInfo){
  1639. var str = localJson.exceptionInfo;
  1640. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1641. str = str.replace('AFTERSUCCESS', '');
  1642. showError(str);
  1643. printSuccess();
  1644. window.location.reload();
  1645. } else {
  1646. showError(str);return;
  1647. }
  1648. }
  1649. }
  1650. }
  1651. });
  1652. },
  1653. onEnd: function(id){
  1654. var me = this;
  1655. var form = Ext.getCmp('form');
  1656. if(form.endUrl && !me.contains(form.endUrl, '?caller=', true)){
  1657. form.endUrl = form.endUrl + "?caller=" + caller;
  1658. }
  1659. me.setLoading(true);//loading...
  1660. Ext.Ajax.request({
  1661. url : basePath + form.endUrl,
  1662. params: {
  1663. id: id
  1664. },
  1665. method : 'post',
  1666. callback : function(options,success,response){
  1667. me.setLoading(false);
  1668. var localJson = new Ext.decode(response.responseText);
  1669. if(localJson.success){
  1670. endSuccess(function(){
  1671. window.location.reload();
  1672. });
  1673. } else {
  1674. if(localJson.exceptionInfo){
  1675. var str = localJson.exceptionInfo;
  1676. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1677. str = str.replace('AFTERSUCCESS', '');
  1678. showError(str);
  1679. endSuccess(function(){
  1680. window.location.reload();
  1681. });
  1682. } else {
  1683. showError(str);return;
  1684. }
  1685. }
  1686. }
  1687. }
  1688. });
  1689. },
  1690. onResEnd: function(id, f){
  1691. var me = this;
  1692. var form = f || Ext.getCmp('form');
  1693. if(form.endUrl && !me.contains(form.endUrl, '?caller=', true)){
  1694. form.endUrl = form.endUrl + "?caller=" + caller;
  1695. }
  1696. me.setLoading(true);//loading...
  1697. Ext.Ajax.request({
  1698. url : basePath + form.resEndUrl,
  1699. params: {
  1700. id: id
  1701. },
  1702. method : 'post',
  1703. callback : function(options,success,response){
  1704. me.setLoading(false);
  1705. var localJson = new Ext.decode(response.responseText);
  1706. if(localJson.success){
  1707. resEndSuccess(function(){
  1708. window.location.reload();
  1709. });
  1710. } else {
  1711. if(localJson.exceptionInfo){
  1712. var str = localJson.exceptionInfo;
  1713. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){
  1714. str = str.replace('AFTERSUCCESS', '');
  1715. showError(str);
  1716. resEndSuccess(function(){
  1717. window.location.reload();
  1718. });
  1719. } else {
  1720. showError(str);return;
  1721. }
  1722. }
  1723. }
  1724. }
  1725. });
  1726. },
  1727. onNullify: function(id){
  1728. var me = this;
  1729. var form = Ext.getCmp('form');
  1730. if(form.nullifyUrl && !me.contains(form.nullifyUrl, '?caller=', true)){
  1731. form.nullifyUrl = form.nullifyUrl + "?caller=" + caller;
  1732. }
  1733. me.setLoading(true);//loading...
  1734. Ext.Ajax.request({
  1735. url : basePath + form.nullifyUrl,
  1736. params: {
  1737. id: id
  1738. },
  1739. method : 'post',
  1740. callback : function(options,success,response){
  1741. me.setLoading(false);
  1742. var localJson = new Ext.decode(response.responseText);
  1743. if(localJson.success){
  1744. nullifySuccess(function(){
  1745. window.location.reload();
  1746. });
  1747. } else {
  1748. if(localJson.exceptionInfo){
  1749. var str = localJson.exceptionInfo;
  1750. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1751. str = str.replace('AFTERSUCCESS', '');
  1752. showError(str);
  1753. nullifySuccess(function(){
  1754. window.location.reload();
  1755. });
  1756. } else {
  1757. showError(str);return;
  1758. }
  1759. }
  1760. }
  1761. }
  1762. });
  1763. },
  1764. batchPrint:function(idS,reportName,condition,title,todate,dateFW,fromdate,enddate,urladdress,whichsystem){
  1765. var printUrl = 'common/BatchPrintController/batchPrint.action';
  1766. var me = this;
  1767. var form = Ext.getCmp('form');
  1768. if(printUrl && !me.contains(printUrl, '?caller=', true)){
  1769. printUrl = printUrl + "?caller=" + caller;
  1770. }
  1771. me.setLoading(true);//loading...
  1772. Ext.Ajax.request({
  1773. url : basePath + printUrl,
  1774. params: {
  1775. idS: idS,
  1776. reportName:reportName,
  1777. condition:condition,
  1778. title:title,
  1779. todate:todate,
  1780. dateFW:dateFW,
  1781. fromdate:fromdate,
  1782. enddate:enddate
  1783. },
  1784. method : 'post',
  1785. timeout: 360000,
  1786. callback : function(options,success,response){
  1787. me.setLoading(false);//loading...
  1788. var res = new Ext.decode(response.responseText);
  1789. var url = urladdress + '?reportfile=' +
  1790. res.keyData[0]+'&&fdate='+fromdate+'&&tdate='+todate+'&&assifall=have'+'&&asscatecode='+'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+'';
  1791. window.open(url, (form == null ? '' : form.title) + '-批量打印', 'width=' + (window.screen.width-10) +
  1792. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1793. /*
  1794. var url = urladdress + '/common/reportviewer.aspx?reportfile=' +
  1795. res.keyData[0]+'&&fdate='+fromdate+'&&tdate='+todate+'&&assifall=have'+'&&asscatecode='+'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+'';
  1796. window.open(url, (form == null ? '' : form.title) + '-批量打印', 'width=' + (window.screen.width-10) +
  1797. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1798. */
  1799. }
  1800. });
  1801. },
  1802. onwindowsPrint2: function(id, reportName, condition, callback){
  1803. var me = this;
  1804. var form = Ext.getCmp('form');
  1805. if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){
  1806. form.printUrl = form.printUrl + "?caller=" + caller;
  1807. }
  1808. me.setLoading(true);//loading...
  1809. Ext.Ajax.request({
  1810. url : basePath + form.printUrl,
  1811. params: {
  1812. id: id,
  1813. reportName:reportName,
  1814. condition:condition
  1815. },
  1816. method : 'post',
  1817. timeout: 360000,
  1818. callback : function(options,success,response){
  1819. var res = new Ext.decode(response.responseText);
  1820. if(res.exceptionInfo) {
  1821. me.setLoading(false);
  1822. showError(res.exceptionInfo);
  1823. return;
  1824. }
  1825. Ext.Ajax.request({
  1826. url: basePath + 'common/report/print.action',
  1827. method: 'post',
  1828. params: {
  1829. id: id,
  1830. caller:caller,
  1831. reportName:reportName,
  1832. condition:condition
  1833. },
  1834. callback : function(options, success, response){
  1835. var res = new Ext.decode(response.responseText);
  1836. me.setLoading(false);
  1837. if(res.success){
  1838. if(res.info.isbz=='pdf'){
  1839. window.location.href=res.info.printUrl+'/print?reportname='+res.info.reportname+'&condition='+res.info.condition+'&whichsystem='+res.info.whichsystem+"&"+'defaultCondition='+res.info.defaultCondition;
  1840. }else{
  1841. //var whichsystem = re.whichsystem;
  1842. var url = res.info.printUrl + '?reportfile=' + res.info.reportname + '&&rcondition='+res.info.condition+'&&company=&&sysdate=373FAE331D06E956870163DCB2A96EC7&&key=3D7595A98BFF809D5EEEA9668B47F4A5&&whichsystem='+res.info.whichsystem+'';
  1843. window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) +
  1844. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1845. }
  1846. }
  1847. }
  1848. });
  1849. }
  1850. });
  1851. /* Ext.Ajax.request({
  1852. url : basePath + form.printUrl,
  1853. params: {
  1854. id: id,
  1855. reportName:reportName,
  1856. condition:condition
  1857. },
  1858. method : 'post',
  1859. callback : function(options,success,response){
  1860. var res = new Ext.decode(response.responseText);
  1861. if(res.exceptionInfo) {
  1862. me.setLoading(false);
  1863. showError(res.exceptionInfo);
  1864. return;
  1865. }
  1866. Ext.Ajax.request({
  1867. url : basePath + 'common/enterprise/getprinturl.action',
  1868. params: {
  1869. caller: caller,
  1870. reportName: reportName
  1871. },
  1872. callback: function(opt, s, r) {
  1873. me.setLoading(false);
  1874. var re = Ext.decode(r.responseText);
  1875. if(re.exceptionInfo) {
  1876. showError(re.exceptionInfo);
  1877. return;
  1878. }
  1879. if(re.printurl) {
  1880. var whichsystem = re.whichsystem;
  1881. var url = re.printurl + '?reportfile=' +
  1882. ( res.keyData[0]||re.report) + '&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+'';
  1883. window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) +
  1884. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1885. //(re.report || res.keyData[0])
  1886. var whichsystem=re.whichsystem;
  1887. var url = re.printurl + '/common/reportviewer.aspx?reportfile=' +
  1888. res.keyData[0]+'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+'';
  1889. window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) +
  1890. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1891. }
  1892. callback && callback.call(null);
  1893. }
  1894. });
  1895. }
  1896. });*/
  1897. },
  1898. onwindowsPrint: function(id, reportName, condition, callback){
  1899. var me = this;
  1900. var form = Ext.getCmp('form');
  1901. if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){
  1902. form.printUrl = form.printUrl + "?caller=" + caller;
  1903. }
  1904. me.setLoading(true);//loading...
  1905. Ext.Ajax.request({
  1906. url : basePath + form.printUrl,
  1907. params: {
  1908. id: id,
  1909. reportName:reportName,
  1910. condition:condition
  1911. },
  1912. method : 'post',
  1913. timeout: 360000,
  1914. callback : function(options,success,response){
  1915. var res = new Ext.decode(response.responseText);
  1916. if(res.exceptionInfo) {
  1917. me.setLoading(false);
  1918. showError(res.exceptionInfo);
  1919. return;
  1920. }
  1921. Ext.Ajax.request({
  1922. url: basePath + 'common/report/print.action',
  1923. method: 'post',
  1924. params: {
  1925. id: id,
  1926. caller:caller,
  1927. reportName:reportName,
  1928. condition:condition
  1929. },
  1930. callback : function(options, success, response){
  1931. var res = new Ext.decode(response.responseText);
  1932. me.setLoading(false);
  1933. if(res.success){
  1934. //var whichsystem = re.whichsystem;
  1935. var url = res.info.printUrl + '?reportfile=' + res.info.reportname + '&&rcondition='+res.info.condition+'&&company=&&sysdate=373FAE331D06E956870163DCB2A96EC7&&key=3D7595A98BFF809D5EEEA9668B47F4A5&&whichsystem='+res.info.whichsystem+'';
  1936. window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) +
  1937. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1938. }
  1939. }
  1940. });
  1941. }
  1942. });
  1943. },
  1944. //====================BOM打印方法
  1945. onwindowsPrintBom: function(id, reportName, condition,prodcode){
  1946. var me = this;
  1947. var form = Ext.getCmp('form');
  1948. if(form.printUrl && !me.contains(form.printUrl, '?caller=', true)){
  1949. form.printUrl = form.printUrl + "?caller=" + caller;
  1950. }
  1951. me.setLoading(true);//loading...
  1952. Ext.Ajax.request({
  1953. url : basePath + form.printUrl,
  1954. params: {
  1955. id: id,
  1956. reportName:reportName,
  1957. condition:condition,
  1958. prodcode:prodcode
  1959. },
  1960. method : 'post',
  1961. callback : function(options,success,response){
  1962. var res = new Ext.decode(response.responseText);
  1963. if(res.exceptionInfo) {
  1964. me.setLoading(false);
  1965. showError(res.exceptionInfo);
  1966. return;
  1967. }
  1968. Ext.Ajax.request({
  1969. url : basePath + 'common/enterprise/getprinturl.action',
  1970. params: {
  1971. caller: caller,
  1972. reportName: reportName
  1973. },
  1974. callback: function(opt, s, r) {
  1975. me.setLoading(false);
  1976. var re = Ext.decode(r.responseText);
  1977. if(re.exceptionInfo) {
  1978. showError(re.exceptionInfo);
  1979. return;
  1980. }
  1981. if(re.printurl) {
  1982. var whichsystem=re.whichsystem;
  1983. //var whichsystem = re.whichsystem;
  1984. /*var url = re.printurl + '/common/reportviewer.aspx?reportfile=' +
  1985. (re.report || res.keyData[0]) +'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+'';
  1986. window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) +
  1987. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');*/
  1988. var url = re.printurl + '?reportfile=' +
  1989. (re.report || res.keyData[0]) +'&&rcondition='+condition+'&&company=&&sysdate='+res.keyData[3]+'&&key='+res.keyData[1]+'&&whichsystem='+whichsystem+'';
  1990. window.open(url, form.title + '-打印', 'width=' + (window.screen.width-10) +
  1991. ',height=' + (window.screen.height*0.87) + ',top=0,left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  1992. }
  1993. // window.location.reload();
  1994. }
  1995. });
  1996. }
  1997. });
  1998. },
  1999. //========================
  2000. onPost: function(id){
  2001. var me = this;
  2002. var form = Ext.getCmp('form');
  2003. if(form && form.getForm().isValid()){
  2004. var unSave = me.getUnSave(form);
  2005. if(unSave.length > 0) {
  2006. showError('<h3>' + unSave + '</h3> 填写后未保存,请先执行更新操作');
  2007. return;
  2008. }
  2009. var grids = Ext.ComponentQuery.query('gridpanel');
  2010. if(grids.length > 0){
  2011. var invalid = [];
  2012. Ext.each(grids, function(grid, index){
  2013. if(!grid.ignore && grid.GridUtil){
  2014. var msg = grid.GridUtil.getInvalid(grid);
  2015. if(msg.length > 0){
  2016. invalid.push((grids.length > 1 ? ('从表' + (index + 1) + ' ') : '') + msg);
  2017. }
  2018. }
  2019. });
  2020. if(invalid.length > 0) {
  2021. showError('<h3>还有待完善的必填信息:</h3><hr>' + invalid.join('<br>'));
  2022. return;
  2023. }
  2024. }
  2025. if(form.postUrl && !me.contains(form.postUrl, '?caller=', true)){
  2026. form.postUrl = form.postUrl + "?caller=" + caller;
  2027. }
  2028. warnMsg('确定过账?', function(btn){
  2029. if(btn == 'yes'){
  2030. me.setLoading(true);//loading...
  2031. Ext.Ajax.request({
  2032. url : basePath + form.postUrl,
  2033. params: {
  2034. id: id
  2035. },
  2036. method : 'post',
  2037. callback : function(options,success,response){
  2038. me.setLoading(false);
  2039. var localJson = new Ext.decode(response.responseText);
  2040. if(localJson.success){
  2041. postSuccess(function(){
  2042. window.location.reload();
  2043. });
  2044. } else {
  2045. if(localJson.exceptionInfo){
  2046. var str = localJson.exceptionInfo;
  2047. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  2048. str = str.replace('AFTERSUCCESS', '');
  2049. showError(str);
  2050. postSuccess(function(){
  2051. window.location.reload();
  2052. });
  2053. } else {
  2054. showError(str);return;
  2055. }
  2056. }
  2057. }
  2058. }
  2059. });
  2060. }
  2061. });
  2062. } else {
  2063. me.checkForm();
  2064. }
  2065. },
  2066. /**
  2067. * 获取form修改但未保存的字段,并提示
  2068. */
  2069. getUnSave: function(form) {
  2070. var unSave = [];
  2071. Ext.Array.each(form.items.items, function(item){
  2072. var text = item.fieldLabel || item.boxLabel;
  2073. if(item.firstField)
  2074. item = item.firstField;
  2075. if(typeof item.getValue == 'function' && !item.allowBlank &&
  2076. Ext.isEmpty(item.originalValue) && !Ext.isEmpty(item.value)) {
  2077. text && (unSave.push(text));
  2078. }
  2079. });
  2080. return unSave.join(' ');
  2081. },
  2082. onResPost: function(id){
  2083. var me = this;
  2084. var form = Ext.getCmp('form');
  2085. if(form.resPostUrl && !me.contains(form.resPostUrl, '?caller=', true)){
  2086. form.resPostUrl = form.resPostUrl + "?caller=" + caller;
  2087. }
  2088. me.setLoading(true);//loading...
  2089. Ext.Ajax.request({
  2090. url : basePath + form.resPostUrl,
  2091. params: {
  2092. id: id
  2093. },
  2094. method : 'post',
  2095. callback : function(options,success,response){
  2096. me.setLoading(false);
  2097. var localJson = new Ext.decode(response.responseText);
  2098. if(localJson.success){
  2099. resPostSuccess(function(){
  2100. window.location.reload();
  2101. });
  2102. } else {
  2103. if(localJson.exceptionInfo){
  2104. var str = localJson.exceptionInfo;
  2105. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  2106. str = str.replace('AFTERSUCCESS', '');
  2107. showError(str);
  2108. resPostSuccess(function(){
  2109. window.location.reload();
  2110. });
  2111. } else {
  2112. showError(str);return;
  2113. }
  2114. }
  2115. }
  2116. }
  2117. });
  2118. },
  2119. onHung: function(id){
  2120. var me = this;
  2121. var form = Ext.getCmp('form');
  2122. if(!me.contains(form.resAuditUrl, '?caller=', true)){
  2123. form.resAuditUrl = form.resAuditUrl + "?caller=" + caller;
  2124. }
  2125. me.setLoading(true);//loading...
  2126. Ext.Ajax.request({
  2127. url : basePath + form.hungUrl,
  2128. params: {
  2129. id: id
  2130. },
  2131. method : 'post',
  2132. callback : function(options,success,response){
  2133. me.setLoading(false);
  2134. var localJson = new Ext.decode(response.responseText);
  2135. if(localJson.exceptionInfo){
  2136. showError(localJson.exceptionInfo);
  2137. }
  2138. if(localJson.success){
  2139. //resAudit成功后刷新页面进入可编辑的页面
  2140. resAuditSuccess();
  2141. window.location.reload();
  2142. }
  2143. }
  2144. });
  2145. },
  2146. onResHung: function(id){
  2147. var me = this;
  2148. var form = Ext.getCmp('form');
  2149. if(!me.contains(form.resAuditUrl, '?caller=', true)){
  2150. form.resAuditUrl = form.resAuditUrl + "?caller=" + caller;
  2151. }
  2152. me.setLoading(true);//loading...
  2153. Ext.Ajax.request({
  2154. url : basePath + form.resHungUrl,
  2155. params: {
  2156. id: id
  2157. },
  2158. method : 'post',
  2159. callback : function(options,success,response){
  2160. me.setLoading(false);
  2161. var localJson = new Ext.decode(response.responseText);
  2162. if(localJson.exceptionInfo){
  2163. showError(localJson.exceptionInfo);
  2164. }
  2165. if(localJson.success){
  2166. //resAudit成功后刷新页面进入可编辑的页面
  2167. resAuditSuccess();
  2168. window.location.reload();
  2169. }
  2170. }
  2171. });
  2172. },
  2173. onCheck: function(id){
  2174. var me = this;
  2175. var form = Ext.getCmp('form');
  2176. if(form.checkUrl && !me.contains(form.checkUrl, '?caller=', true)){
  2177. form.checkUrl = form.checkUrl + "?caller=" + caller;
  2178. }
  2179. me.setLoading(true);//loading...
  2180. Ext.Ajax.request({
  2181. url : basePath + form.checkUrl,
  2182. params: {
  2183. id: id
  2184. },
  2185. method : 'post',
  2186. callback : function(options,success,response){
  2187. me.setLoading(false);
  2188. var localJson = new Ext.decode(response.responseText);
  2189. if(localJson.success){
  2190. checkSuccess(function(){
  2191. window.location.reload();
  2192. });
  2193. } else {
  2194. if(localJson.exceptionInfo){
  2195. var str = localJson.exceptionInfo;
  2196. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  2197. str = str.replace('AFTERSUCCESS', '');
  2198. showError(str);
  2199. checkSuccess(function(){
  2200. vwindow.location.reload();
  2201. });
  2202. } else {
  2203. showError(str);return;
  2204. }
  2205. }
  2206. }
  2207. }
  2208. });
  2209. },
  2210. onConfirm: function(id){
  2211. var me=this;
  2212. var form=Ext.getCmp('form');
  2213. if(form.onConfirmUrl && !me.contains(form.onConfirmUrl, '?caller=', true)){
  2214. form.onConfirmUrl = form.onConfirmUrl + "?caller=" + caller;
  2215. }
  2216. me.setLoading(true);//loading...
  2217. Ext.Ajax.request({
  2218. url : basePath + form.onConfirmUrl,
  2219. params: {
  2220. id: id
  2221. },
  2222. method : 'post',
  2223. callback : function(options,success,response){
  2224. me.setLoading(false);
  2225. var localJson = new Ext.decode(response.responseText);
  2226. if(localJson.success){
  2227. Ext.Msg.alert('提示', '确认成功', function(){
  2228. window.location.reload();
  2229. });
  2230. } else {
  2231. if(localJson.exceptionInfo){
  2232. var str = localJson.exceptionInfo;
  2233. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  2234. str = str.replace('AFTERSUCCESS', '');
  2235. showError(str);
  2236. Ext.Msg.alert('提示', '确认成功', function(){
  2237. window.location.reload();
  2238. });
  2239. } else {
  2240. showError(str);return;
  2241. }
  2242. }
  2243. }
  2244. }
  2245. });
  2246. },
  2247. onResCheck: function(id){
  2248. var me = this;
  2249. var form = Ext.getCmp('form');
  2250. if(form.resCheckUrl && !me.contains(form.resCheckUrl, '?caller=', true)){
  2251. form.resCheckUrl = form.resCheckUrl + "?caller=" + caller;
  2252. }
  2253. me.setLoading(true);//loading...
  2254. Ext.Ajax.request({
  2255. url : basePath + form.resCheckUrl,
  2256. params: {
  2257. id: id
  2258. },
  2259. method : 'post',
  2260. callback : function(options,success,response){
  2261. me.setLoading(false);
  2262. var localJson = new Ext.decode(response.responseText);
  2263. if(localJson.success){
  2264. resCheckSuccess(function(){
  2265. window.location.reload();
  2266. });
  2267. } else {
  2268. if(localJson.exceptionInfo){
  2269. var str = localJson.exceptionInfo;
  2270. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  2271. str = str.replace('AFTERSUCCESS', '');
  2272. showError(str);
  2273. resCheckSuccess(function(){
  2274. window.location.reload();
  2275. });
  2276. } else {
  2277. showError(str);return;
  2278. }
  2279. }
  2280. }
  2281. }
  2282. });
  2283. },
  2284. openTab : function (panel,id){
  2285. var o = (typeof panel == "string" ? panel : id || panel.id);
  2286. var main = this.getMain();
  2287. var tab = main.getComponent(o);
  2288. if (tab) {
  2289. main.setActiveTab(tab);
  2290. } else if(typeof panel!="string"){
  2291. panel.id = o;
  2292. var p = main.add(panel);
  2293. main.setActiveTab(p);
  2294. }
  2295. },
  2296. getMain: function(){
  2297. var main = Ext.getCmp("content-panel");
  2298. if(!main)
  2299. main = parent.Ext.getCmp("content-panel");
  2300. if(!main)
  2301. main = parent.parent.Ext.getCmp("content-panel");
  2302. return main;
  2303. },
  2304. getActiveTab: function(){
  2305. var tab = null;
  2306. if(Ext.getCmp("content-panel")){
  2307. tab = Ext.getCmp("content-panel").getActiveTab();
  2308. }
  2309. if(!tab && parent.Ext && parent.Ext.getCmp("content-panel"))
  2310. tab = parent.Ext.getCmp("content-panel").getActiveTab();
  2311. if(!tab && parent.parent.Ext && parent.parent.Ext.getCmp("content-panel"))
  2312. tab = parent.parent.Ext.getCmp("content-panel").getActiveTab();
  2313. if(!tab && parent.Ext){
  2314. var win = parent.Ext.ComponentQuery.query('window');
  2315. if(win.length > 0){
  2316. tab = win[win.length-1];
  2317. }
  2318. }
  2319. return tab;
  2320. },
  2321. /**
  2322. * string:原始字符串
  2323. * substr:子字符串
  2324. * isIgnoreCase:忽略大小写
  2325. */
  2326. contains: function(string, substr, isIgnoreCase){
  2327. if (string == null || substr == null) return false;
  2328. if (isIgnoreCase === undefined || isIgnoreCase === true) {
  2329. string = string.toLowerCase();
  2330. substr = substr.toLowerCase();
  2331. }
  2332. return string.indexOf(substr) > -1;
  2333. },
  2334. showAssignWin :function(persons){
  2335. var me=this;
  2336. var confirm = new Ext.button.Button({
  2337. text:$I18N.common.button.erpConfirmButton,
  2338. handler:function(btn){
  2339. var items = Ext.ComponentQuery.query('window >tabpanel>panel>radio');
  2340. var params = new Array();
  2341. Ext.each(items,function(item){
  2342. if(item.getValue()){
  2343. var param = new Object();
  2344. var label = item.boxLabel;//em_name(em_code) 2013-3-8 10:18:11
  2345. var em_code = label.substring(label.lastIndexOf('(')+1,label.length-1);
  2346. param.em_code = em_code;
  2347. param.nodeId=item.name;
  2348. params.push(JSON.stringify(param));
  2349. }
  2350. });
  2351. Ext.Ajax.request({
  2352. url: basePath + 'common/takeOverTask.action',
  2353. async: false,
  2354. params: {
  2355. params:unescape(params),
  2356. _noc: 1
  2357. },
  2358. callback: function(options,success,response){
  2359. var text = response.responseText;
  2360. jsonData = Ext.decode(text);
  2361. //再发送请求
  2362. if(jsonData.success){
  2363. Ext.Msg.alert('提示' ,"指派成功!");
  2364. Ext.Ajax.request({
  2365. url: basePath + 'common/processpaging.action',
  2366. params: {
  2367. params:unescape(params),
  2368. _noc: 1
  2369. }
  2370. });
  2371. win.close();
  2372. }else{
  2373. Ext.Msg.alert('提示' ,"指派失败!");
  2374. win.close();
  2375. }
  2376. window.location.reload();
  2377. }
  2378. });
  2379. }
  2380. });
  2381. var cancel = new Ext.button.Button({
  2382. text:$I18N.common.button.erpCancelButton,
  2383. handler:function(){
  2384. var params = new Array();
  2385. for (var i = 0; i < persons.length; i++){
  2386. var param = new Object();
  2387. param.em_code = persons[i].JP_CANDIDATES;
  2388. param.nodeId=persons[i].JP_NODEID;
  2389. params.push(JSON.stringify(param));
  2390. }
  2391. Ext.Ajax.request({
  2392. url: basePath + 'common/processpaging.action',
  2393. params: {
  2394. params:unescape(params),
  2395. _noc: 1
  2396. },
  2397. callback: function(options,success,response){
  2398. win.close();
  2399. window.location.reload();
  2400. }
  2401. });
  2402. }
  2403. });
  2404. var searchKey = new Object();
  2405. var win = Ext.create('Ext.window.Window', {
  2406. title:'<div align="center">节点处理人</div>',
  2407. height: 350,
  2408. width: 500,
  2409. layout: {
  2410. type: 'vbox',
  2411. align : 'stretch'
  2412. },
  2413. closable:false,
  2414. id:'win',
  2415. autoScroll:true,
  2416. buttonAlign:'center',
  2417. buttons: [confirm,cancel],
  2418. items: []
  2419. });
  2420. win.add([{
  2421. xtype:'textfield',
  2422. margin:'10 20 10 20',
  2423. fieldLabel:'快速搜索',
  2424. labelStyle:'font-weight:bold;',
  2425. id:'searchtextfield',
  2426. //columnWidth:0.8,
  2427. flex:1,
  2428. enableKeyEvents:true,
  2429. listeners:{
  2430. keydown:function(field,e){
  2431. if(e.getKey()==Ext.EventObject.ENTER){
  2432. searchKey[Ext.getCmp('processTab').getActiveTab().id]=field.value;
  2433. var results=Ext.Array.filter(persons[Ext.getCmp('processTab').getActiveTab().id].JP_CANDIDATES,function(JP_CANDIDATE){
  2434. if(field.value==undefined || JP_CANDIDATE.indexOf(field.value)!=-1) return JP_CANDIDATE;
  2435. });
  2436. Ext.Array.each(Ext.getCmp('processTab').getActiveTab().personUsers,function(item){
  2437. Ext.getCmp('processTab').getActiveTab().remove(item);
  2438. });
  2439. me.addUserItems(Ext.getCmp('processTab').getActiveTab(),persons[Ext.getCmp('processTab').getActiveTab().id].JP_NODEID,results);
  2440. }
  2441. }
  2442. }
  2443. }]);
  2444. this.addAssignItems(win,persons,searchKey);
  2445. win.show();
  2446. },
  2447. addAssignItems:function(win,persons,searchKey){
  2448. var me=this;
  2449. var tab = new Ext.TabPanel({
  2450. id : 'processTab',
  2451. enableTabScroll : true,
  2452. closeAll : true,
  2453. //activeTab : 0,
  2454. tabWidth : 480,
  2455. flex:9,
  2456. minTabWidth :80,
  2457. autoHeight:true,
  2458. resizeTabs : true,
  2459. listeners:{
  2460. 'tabchange':function(tabPanel,newCard,oldCard,eOpts){
  2461. Ext.getCmp('searchtextfield').setValue(searchKey[newCard.id]);
  2462. }
  2463. }
  2464. });
  2465. win.add(tab);
  2466. for (var i = 0; i < persons.length; i++){
  2467. var panel=new Ext.Panel({
  2468. id:i.toString(),
  2469. width: 480,
  2470. autoHeight:true,
  2471. autoScroll:true,
  2472. layout:'column',
  2473. bodyStyle: 'background:#e0e0e0',
  2474. title:persons[i].JP_NODENAME
  2475. });
  2476. tab.add(panel);
  2477. me.addUserItems(panel,persons[i].JP_NODEID,persons[i].JP_CANDIDATES);
  2478. }
  2479. tab.setActiveTab(0);
  2480. },
  2481. addUserItems:function(panel,jp_nodeid,jp_candidates){
  2482. var me=this;
  2483. var maxSize=jp_candidates.length>24?24:jp_candidates.length,personUsers=new Array(),user=null,more=Ext.getCmp('more'+panel.id);
  2484. if(more)more.destroy();
  2485. for(var j=0;j<maxSize;j++){
  2486. user=Ext.create('Ext.form.field.Radio',{
  2487. name:jp_nodeid,
  2488. boxLabel:jp_candidates[j],
  2489. columnWidth: 0.33,
  2490. fieldCls:'x-myradio',
  2491. checked: j==0?true:false
  2492. });
  2493. personUsers.push(user);
  2494. }
  2495. panel.add(personUsers);
  2496. panel.personUsers=personUsers;
  2497. if(jp_candidates.length>maxSize){
  2498. panel.add({ xtype: 'textfield',
  2499. readOnly:true,
  2500. labelSeparator:'',
  2501. columnWidth:1,
  2502. id:'more'+panel.id,
  2503. fieldStyle : 'background:#e0e0e0;border-bottom:none;vertical-align:middle;border-top:none;border-right:none;border-bottom:none;border-left:none;',
  2504. fieldLabel: '『<a href="#" class="terms">全部</a>』',
  2505. listeners: {
  2506. click: {
  2507. element: 'labelEl',
  2508. fn: function(e,el) {
  2509. var target = e.getTarget('.terms');
  2510. Ext.getCmp('more'+panel.id).destroy();
  2511. if (target) {
  2512. Ext.Array.each(panel.personUsers,function(item){
  2513. panel.remove(item);
  2514. });
  2515. var personUsers=new Array();
  2516. for(var i=0;i<jp_candidates.length;i++){
  2517. user=Ext.create('Ext.form.field.Radio',{
  2518. name:jp_nodeid,
  2519. boxLabel:jp_candidates[i],
  2520. columnWidth: 0.33,
  2521. fieldCls:'x-myradio',
  2522. checked: i==0?true:false
  2523. });
  2524. personUsers.push(user);
  2525. }
  2526. panel.add(personUsers);
  2527. panel.personUsers=personUsers;
  2528. e.preventDefault();
  2529. }
  2530. }
  2531. }
  2532. }
  2533. });
  2534. }
  2535. },
  2536. setLoading : function(b) {// 原this.getActiveTab().setLoading()换成此方法,解决Window模式下无loading问题
  2537. var mask = this.mask;
  2538. if (!mask) {
  2539. this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
  2540. msg : "处理中,请稍后...",
  2541. msgCls : 'z-index:10000;'
  2542. });
  2543. }
  2544. if (b)
  2545. mask.show();
  2546. else
  2547. mask.hide();
  2548. },
  2549. link: function(item,args){
  2550. var me = this;
  2551. if(item.xtype=='multifield'){
  2552. item.listeners={
  2553. afterrender:function(item){
  2554. var f=item.firstField;
  2555. if(f.value){
  2556. f.setFieldStyle({ 'color': 'blue'});
  2557. f.focusCls = 'mail-attach';
  2558. var index = 0,url=args[0], length = url.length, s, e;
  2559. while(index < length) {
  2560. if((s = url.indexOf('{', index)) != -1 && (e = url.indexOf('}', s + 1)) != -1) {
  2561. url = url.substring(0, s) + Ext.getCmp(url.substring(s+1, e)).value + url.substring(e+1);
  2562. index = e + 1;
  2563. } else {
  2564. break;
  2565. }
  2566. }
  2567. f.inputEl.addListener('click',function(evt,el){
  2568. openUrl(url);
  2569. });
  2570. }
  2571. }
  2572. };
  2573. }else {
  2574. item.fieldStyle=item.fieldStyle?item.fieldStyle+';color:blue':'color:blue';
  2575. item.focusCls = 'mail-attach';
  2576. item.listeners={
  2577. click: {
  2578. element:'inputEl',
  2579. buffer : 100,
  2580. fn: function(e,el) {
  2581. if(item.value){
  2582. var index = 0,url=args[0], length = url.length, s, e;
  2583. while(index < length) {
  2584. if((s = url.indexOf('{', index)) != -1 && (e = url.indexOf('}', s + 1)) != -1) {
  2585. url = url.substring(0, s) + Ext.getCmp(url.substring(s+1, e)).value + url.substring(e+1);
  2586. index = e + 1;
  2587. } else {
  2588. break;
  2589. }
  2590. }
  2591. var caller = me.getURLParameter('whoami');
  2592. var condition = me.getURLParameter('formCondition');
  2593. if(url.indexOf("whoami=Craft")>0 ){
  2594. condition=condition.replace(/%27/g,'');
  2595. var cr_id ;
  2596. Ext.Ajax.request({
  2597. url : basePath + 'common/getFieldData.action',
  2598. async: false,
  2599. params: {
  2600. caller: 'Craft left join make on ma_prodcode = cr_prodcode and cr_code=ma_craftcode',
  2601. field: 'cr_id',
  2602. condition: condition.replace(/IS/g, "=")
  2603. },
  2604. method : 'post',
  2605. callback : function(opt, s, res){
  2606. var r = new Ext.decode(res.responseText);
  2607. if(r.exceptionInfo){
  2608. showError(r.exceptionInfo);return;
  2609. } else if(r.success){
  2610. cr_id = r.data;
  2611. if( cr_id && cr_id != 0 && cr_id != null){
  2612. openUrl('jsps/pm/mes/craft.jsp?formCondition=cr_idIS '+cr_id+
  2613. '&gridCondition=cd_cridIS'+cr_id);
  2614. }else{
  2615. showError('请选择有效的途程');
  2616. }
  2617. }
  2618. }
  2619. });
  2620. }else if(url.indexOf("whoami=BOMStep") > 0 ){
  2621. condition=condition.replace(/%27/g,'');
  2622. Ext.Ajax.request({
  2623. url: basePath + 'pm/mes/getBomVersion.action',
  2624. params: {
  2625. caller: caller,
  2626. condition: condition.replace(/IS/g, "=")
  2627. },
  2628. method: 'post',
  2629. callback: function(options, success, response) {
  2630. var res = new Ext.decode(response.responseText);
  2631. if (res.exceptionInfo) {
  2632. showError(res.exceptionInfo);
  2633. } else {
  2634. var prodcode = res.data['sb_prodcode'];
  2635. var craftcode = res.data['sb_craftcode'];
  2636. var bomversion = res.data['sb_bomversion'];
  2637. var sp_sbid = res.data['sb_id'];
  2638. var formCondition = "sb_prodcodeIS'" +prodcode+"' and sb_craftcodeIS'"+craftcode+"' and" +
  2639. " sb_bomversionIS'"+bomversion+"'";
  2640. var gridCondition = "sp_sbidIS"+sp_sbid;
  2641. if(sp_sbid && sp_sbid != 0 && sp_sbid != null){
  2642. openUrl('jsps/pm/mes/BOMStep.jsp?whoami=BOMStep&formCondition=' + formCondition+
  2643. '&gridCondition=' +gridCondition);
  2644. }else{
  2645. showError('请选择有效的BOM版本编号');
  2646. }
  2647. }
  2648. }
  2649. });
  2650. }else{
  2651. openUrl(url);
  2652. }
  2653. }
  2654. }
  2655. }
  2656. };
  2657. }
  2658. },
  2659. Highlight:function(item,args){
  2660. if(args&&args[0].indexOf('{')==0&&args[0].indexOf('}')==(args[0].length-1)){
  2661. var str = args[0].substring(1,args[0].length-1),color;
  2662. if(args[0].indexOf(',')>0){
  2663. //配置方式3
  2664. var Arr = str.split(',');
  2665. Ext.Array.each(Arr, function(a) {
  2666. var file = a.split('=');
  2667. if(file[1]==item.value){
  2668. color = file[0];
  2669. }
  2670. });
  2671. }else{
  2672. //配置方式2
  2673. var file = str.split('=');
  2674. if(file[1]==item.value){
  2675. color = file[0];
  2676. }
  2677. }
  2678. var style='font-weight:bold;color:';
  2679. style+=color+";";
  2680. item.fieldStyle=item.fieldStyle?item.fieldStyle+style:style;
  2681. }else{
  2682. //配置方式1
  2683. var style='font-weight:bold;color:';
  2684. style+=(args && args[0])?args[0]+";":'red;';
  2685. item.fieldStyle=item.fieldStyle?item.fieldStyle+style:style;
  2686. }
  2687. },
  2688. formula: function(item, args, form){
  2689. Ext.defer(function(){
  2690. var mm = this, field = form.down('#' + item.name), vals = {};
  2691. if(field != null && !form.readOnly) {
  2692. field.addEvents({'formula': true});
  2693. field.addListener('formula', function(f, changedField, changedFieldVal){
  2694. if(changedField) {
  2695. vals[changedField] = changedFieldVal || 0;
  2696. }
  2697. // eg: eval("var a = 1, b = 2, c = 3;a + b / c")
  2698. var exp = 'var ' + Ext.Object.toQueryString(vals).replace(/&/gi, ",") + ";" + args[0];
  2699. field.setValue(eval(exp) || 0);
  2700. });
  2701. var fields = args[0].split(/\+|-|\*|\(|\)|\//g);
  2702. Ext.Array.each(fields, function(f){
  2703. if(f) {
  2704. var ff = form.down('#' + f);
  2705. if(ff) {
  2706. vals[f] = ff.getValue() || 0;
  2707. ff.on('change', function(_f, newVal){
  2708. field.fireEvent('formula', field, _f.getName(), _f.getValue());
  2709. });
  2710. }
  2711. }
  2712. });
  2713. field.fireEvent('formula');
  2714. }
  2715. }, 500);
  2716. },
  2717. getURLParameter:function(name){
  2718. return (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [,null])[1];
  2719. }
  2720. });