FormUtil.js 65 KB

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