BOMStep.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mes.BOMStep', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. GridUtil: Ext.create('erp.util.GridUtil'),
  7. views:[
  8. 'pm.mes.BOMStep','core.form.Panel','core.grid.Panel2','core.button.Query','core.button.Load',
  9. 'core.button.Add','core.button.Save','core.button.Close','core.button.Update','core.trigger.SearchField',
  10. 'core.form.YnField','core.grid.YnColumn', 'core.grid.TfColumn','pm.mes.BOMStepTree','core.button.LoadMake',
  11. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.trigger.MultiDbfindTrigger','core.button.CopyByConfigs',
  12. 'core.button.CleanDetail'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpFormPanel': {
  18. afterload: function(form) {
  19. var items = form.items.items;
  20. Ext.each(items, function() {
  21. var val = getUrlParam(this.name);
  22. if(!Ext.isEmpty(val)) {
  23. this.setValue(val);
  24. //autoQuery = true;
  25. /*if(this.xtype == 'dbfindtrigger') {
  26. this.autoDbfind('form', caller, this.name, this.name + " like '%" + val + "%'");
  27. }*/
  28. }
  29. });
  30. },
  31. },
  32. 'erpGridPanel2': {
  33. itemclick: function(view,record){
  34. me.itemclick(view,record,me);
  35. }
  36. },
  37. 'erpAddButton': {
  38. click: function(){
  39. var code = Ext.getCmp("pr_code").value;
  40. var cr_code = Ext.getCmp("cr_code").value;
  41. me.FormUtil.onAdd('addMakeBase', '新增工序BOM', 'jsps/pm/mes/BOMStep.jsp?whoami=' + caller + '&pr_code='+code+'&cr_code='+cr_code );
  42. }
  43. },
  44. 'bomsteptree': {
  45. itemmousedown: function(selModel, record){
  46. me.loadTab(selModel, record);
  47. me.lastSelected = record;
  48. }
  49. },
  50. 'dbfindtrigger[name=sb_bomversion]': {
  51. afterrender: function(f){
  52. var sb_id = Ext.getCmp('sb_id');
  53. if(sb_id && sb_id.value!=null && sb_id.value!='' &&sb_id.value!=0){
  54. f.setEditable(false);
  55. f.setReadOnly(true);
  56. }
  57. },
  58. beforetrigger: function(t) {
  59. t.autoDbfind = true;
  60. t.setHideTrigger(false);
  61. t.setReadOnly(false);
  62. var cr_code = Ext.getCmp('cr_code');
  63. var pr_code = Ext.getCmp('pr_code');
  64. if(cr_code){
  65. t.dbBaseCondition = "sb_craftcode='"+cr_code.value+"' and sb_prodcode='"+ pr_code.value+"'";
  66. }
  67. },
  68. change: function(t){
  69. var prodcode = Ext.getCmp('pr_code').value;
  70. var cr_code = Ext.getCmp('cr_code').value;
  71. if(t.value!=''){
  72. me.FormUtil.getFieldValue('stepBom', 'sb_id', "sb_bomversion='" + t.value + "' and sb_prodcode = '"+prodcode+"' and sb_craftcode = '"+cr_code+"'", 'sb_id');
  73. var sb_id = Ext.getCmp('sb_id');
  74. if(sb_id && sb_id.value!=null && sb_id.value!='' &&sb_id.value!=0){
  75. t.setEditable(false);
  76. t.setReadOnly(true);
  77. this.query();
  78. }
  79. }
  80. t.autoDbfind = false;
  81. t.setHideTrigger(false);
  82. t.setReadOnly(false);
  83. var cr_code = Ext.getCmp('cr_code');
  84. var pr_code = Ext.getCmp('pr_code');
  85. if(cr_code){
  86. t.dbBaseCondition = "sb_craftcode='"+cr_code.value+"' and sb_prodcode='"+ pr_code.value+"'";
  87. }
  88. },
  89. focus: function(t){
  90. t.autoDbfind = false;
  91. t.setHideTrigger(false);
  92. t.setReadOnly(false);
  93. },
  94. /*aftertrigger: function(t){
  95. if(t.value!=''){
  96. this.query();
  97. }
  98. }*/
  99. },
  100. 'dbfindtrigger[name=cr_code]': {
  101. beforetrigger: function(t){
  102. var pr_code = Ext.getCmp('pr_code');
  103. if(cr_code){
  104. t.dbBaseCondition = " cr_prodcode='"+ pr_code.value+"'";
  105. }
  106. }
  107. },
  108. 'dbfindtrigger[name=sp_stepcode]': {
  109. beforetrigger: function(t) {
  110. t.autoDbfind = false;
  111. t.setHideTrigger(false);
  112. t.setReadOnly(false);
  113. var cr_code = Ext.getCmp('cr_code');
  114. var pr_code = Ext.getCmp('pr_code');
  115. t.dbBaseCondition = "cr_code='"+cr_code.value+"' and cr_prodcode='"+ pr_code.value+"'";
  116. }
  117. },
  118. 'erpQueryButton': {
  119. click: function(btn){
  120. this.query();
  121. }
  122. },
  123. 'erpCleanDetailButton':{
  124. click : function(btn) {
  125. me.cleanDetail();
  126. }
  127. },
  128. 'erpLoadButton': {
  129. afterrender: function(btn){
  130. btn.setWidth(130);
  131. btn.setText('载入标准BOM');
  132. },
  133. click: function(btn){
  134. var pr_code = Ext.getCmp("pr_code").value;
  135. var dbwin = new Ext.window.Window({
  136. id : 'ddbwin',
  137. title: 'BOM载入',
  138. height: "90%",
  139. width: "75%",
  140. maximizable : true,
  141. buttonAlign : 'center',
  142. layout : 'anchor',
  143. items: []
  144. });
  145. dbwin.show();
  146. var iframe = dbwin.getEl().down('iframe');
  147. if(!iframe) {
  148. dbwin.add({
  149. tag : 'iframe',
  150. frame : true,
  151. anchor : '100% 100%',
  152. layout : 'fit',
  153. html : '<iframe src="#" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  154. });
  155. iframe = dbwin.getEl().down('iframe');
  156. }
  157. iframe.dom.src = basePath+'jsps/pm/mes/BOMStepLoad.jsp?whoami=BOMStep!load&gridCondition=bo_mothercodeIS'+"'"+pr_code+"'";
  158. }
  159. },
  160. 'erpLoadMakeButton': {
  161. afterrender: function(btn){
  162. btn.setText('载入工单BOM');
  163. btn.setWidth(120);
  164. },
  165. click: function(btn){
  166. var sp_bomversion = Ext.getCmp("sb_bomversion").value;
  167. var sb_prodcode = Ext.getCmp("pr_code").value;
  168. /*if(sp_bomversion == ''){
  169. showError('请先选择BOM版本编号!');
  170. return;
  171. }*/
  172. var dbwin = new Ext.window.Window({
  173. id : 'adbwin',
  174. title: '工单BOM载入',
  175. height: "90%",
  176. width: "75%",
  177. maximizable : true,
  178. buttonAlign : 'center',
  179. layout : 'anchor',
  180. items: []
  181. });
  182. dbwin.show();
  183. var iframe = dbwin.getEl().down('iframe');
  184. if(!iframe) {
  185. dbwin.add({
  186. tag : 'iframe',
  187. frame : true,
  188. anchor : '100% 100%',
  189. layout : 'fit',
  190. html : '<iframe src="#" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  191. });
  192. iframe = dbwin.getEl().down('iframe');
  193. }
  194. iframe.dom.src = basePath+'jsps/pm/mes/BOMStepLoadMake.jsp?whoami=BOMStep!loadmake&gridCondition=ma_codeIS'+"'"+sp_bomversion+"' and ma_prodcodeIS'"+sb_prodcode+"'";
  195. }
  196. },
  197. 'erpUpdateButton': {
  198. afterrender: function(btn){
  199. btn.setText('保存');
  200. },
  201. click: function(btn){
  202. var cr_code = Ext.getCmp('cr_code').value;
  203. /*var st_code = Ext.getCmp('cr_name').value;*/
  204. var sp_bomversion = Ext.getCmp('sb_bomversion').value;
  205. if(cr_code == ''){
  206. showError("未填写途程!");
  207. return;
  208. }else if(sp_bomversion == ''){
  209. showError("未填写BOM版本编号!");
  210. return;
  211. }
  212. this.onUpdate();
  213. }
  214. }
  215. });
  216. },
  217. query: function(cr_value, st_value){
  218. var pr_code = Ext.getCmp('pr_code').value;
  219. var cr_code = Ext.getCmp('cr_code');
  220. var st_code = Ext.getCmp('cr_name');
  221. var sp_bomversion = Ext.getCmp('sb_bomversion');
  222. var grid = Ext.getCmp('grid');
  223. var condition = "sb_prodcode='"+pr_code+"'";
  224. if(cr_code&&cr_code.value != ""&&cr_code.value != null){
  225. condition += "and sb_craftcode='"+cr_code.value+"'";
  226. }else{
  227. showError("未填写途程!");
  228. return;
  229. }
  230. if(sp_bomversion&&sp_bomversion.value != ""&&sp_bomversion.value != null){
  231. condition += "and sb_bomversion='"+sp_bomversion.value+"'";
  232. }else{
  233. showError("未填写BOM版本编号!");
  234. return;
  235. }
  236. var param = {
  237. caller : caller,
  238. condition : condition
  239. };
  240. grid.GridUtil.loadNewStore(grid, param);
  241. },
  242. getForm: function(btn){
  243. return btn.ownerCt.ownerCt;
  244. },
  245. onUpdate: function(){
  246. var form = Ext.getCmp('form');
  247. var me = this, params = new Object();
  248. if(form.codeField && (Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == '')){
  249. showError('编号不能为空.');
  250. return;
  251. }
  252. var s1 = me.checkFormDirty(form);
  253. var s2 = '';
  254. var grids = Ext.ComponentQuery.query('gridpanel');
  255. if(grids.length > 0 && !grids[0].ignore){//check所有grid是否已修改
  256. Ext.each(grids, function(grid, index){
  257. if(grid.GridUtil){
  258. var msg = grid.GridUtil.checkGridDirty(grid);
  259. if(msg.length > 0){
  260. s2 = s2 + '<br/>' + msg;
  261. }
  262. }
  263. });
  264. }
  265. if(s1 == '' && (s2 == '' || s2 == '<br/>')){
  266. showError('还未添加或修改数据.');
  267. return;
  268. }
  269. if(form && form.getForm().isValid()){
  270. //form里面数据
  271. var r = form.getValues();
  272. //去除ignore字段
  273. var keys = Ext.Object.getKeys(r), f;
  274. Ext.each(keys, function(k){
  275. f = form.down('#' + k);
  276. if(f && f.logic == 'ignore') {
  277. delete r[k];
  278. }
  279. });
  280. if(!me.contains(form.updateUrl, '?caller=', true)){
  281. form.updateUrl = form.updateUrl + "?caller=" + caller;
  282. }
  283. var params = [];
  284. var grid = Ext.getCmp("grid");
  285. var count = 0;
  286. var count1 = 0;
  287. Ext.Array.each(grid.getStore().data.items,function(item){
  288. if(item.data['sp_tracekind'] != null && item.data['sp_tracekind'] != '' ){
  289. count++;
  290. }
  291. if(item.data['sp_soncode'] != null && item.data['sp_soncode'] != '' ){
  292. count1++;
  293. }
  294. });
  295. if(count != count1){
  296. showError('管控类型不允许为空');
  297. return;
  298. }
  299. if(grids.length > 0 && grids[0].columns.length > 0 && !grids[0].ignore){
  300. if(grids[0].GridUtil.isEmpty(grids[0])) {
  301. showError("明细还未录入数据,请添加明细行数据!");
  302. return;
  303. } else if(grids[0].GridUtil.isDirty(grids[0])) {
  304. var param = grids[0].GridUtil.getGridStore();
  305. if(grids[0].necessaryField && grids[0].necessaryField.length > 0 && (param == null || param.length == 0 || param == '')){
  306. warnMsg('明细表有必填项未填写,是否继续保存?', function(btn){
  307. if(btn == 'yes' || btn == 'ok'){
  308. params = unescape("[" + param.toString() + "]");
  309. me.update();
  310. } else {
  311. return;
  312. }
  313. });
  314. }else{
  315. me.update();
  316. }
  317. }else{
  318. me.update();
  319. }
  320. }else{
  321. me.update();
  322. }
  323. }
  324. },
  325. update: function(){
  326. var me =this,form = Ext.getCmp('form'), url = form.updateUrl;
  327. var r = form.getValues();
  328. var formStore = unescape(escape(Ext.JSON.encode(r)));
  329. var grids = Ext.ComponentQuery.query('gridpanel');
  330. var cr_code = Ext.getCmp('cr_code');
  331. var pr_code = Ext.getCmp('pr_code');
  332. var sb_bomversion = Ext.getCmp('sb_bomversion');
  333. /*var st_code = Ext.getCmp('cr_name');*/
  334. var cr_value = cr_code.value;
  335. /*var st_value = st_code.value;*/
  336. if(url.indexOf('caller=') == -1){
  337. url = url + "?caller=" + caller;
  338. }
  339. var gridStore = unescape("[" + grids[0].GridUtil.getGridStore() + "]");
  340. me.setLoading(true);//loading...
  341. Ext.Ajax.request({
  342. url : basePath + url,
  343. params: {
  344. formStore : formStore,
  345. gridStore : gridStore
  346. },
  347. method : 'post',
  348. callback : function(options,success,response){
  349. me.setLoading(false);
  350. var localJson = new Ext.decode(response.responseText);
  351. if(localJson.success){
  352. /*me.query();*/
  353. var formCondition = 'sb_bomversionIS'+"'"+sb_bomversion.value+"'"+'and pr_codeIS'+"'"+pr_code.value+"'"+'and cr_codeIS'+"'"+cr_code.value+"'";
  354. var sb_id = Ext.getCmp('sb_id');
  355. if(sb_id.value == '' || sb_id.value == null || sb_id.value == 0){
  356. me.FormUtil.getFieldValue('stepBom', 'sb_id', "sb_bomversion='" + sb_bomversion.value + "' and sb_prodcode = '"+pr_code.value+"' and sb_craftcode = '"+cr_code.value+"'", 'sb_id');
  357. }
  358. if(sb_id != '' && sb_id != null && sb_id != 0){
  359. window.location.href=basePath+'jsps/pm/mes/BOMStep.jsp?whoami=BOMStep&formCondition='+formCondition+'&gridCondition=sp_sbidIS'+sb_id.value;
  360. }
  361. } else if(localJson.exceptionInfo){
  362. var str = localJson.exceptionInfo;
  363. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  364. me.query();
  365. }
  366. showError(str);return;
  367. } else {
  368. updateFailure();
  369. }
  370. }
  371. });
  372. },
  373. /**
  374. * 检查表单是否被修改,并返回被修改的内容
  375. */
  376. checkFormDirty: function(){
  377. var form = Ext.getCmp('form');
  378. var s = '';
  379. form.getForm().getFields().each(function (item,index, length){
  380. if(item.logic!='ignore'){
  381. var value = item.value == null ? "" : item.value;
  382. if(item.xtype == 'htmleditor') {
  383. value = item.getValue();
  384. }
  385. item.originalValue = item.originalValue == null ? "" : item.originalValue;
  386. if(Ext.typeOf(item.originalValue) != 'object'){
  387. if(item.originalValue.toString() != value.toString()){//isDirty、wasDirty、dirty一直都是true,没办法判断,所以直接用item.originalValue,原理是一样的
  388. var label = item.fieldLabel || item.ownerCt.fieldLabel ||
  389. item.boxLabel || item.ownerCt.title;//针对fieldContainer、radio、fieldset等
  390. if(label){
  391. s = s + '&nbsp;' + label.replace(/&nbsp;/g,'');
  392. }
  393. }
  394. }
  395. }
  396. });
  397. return (s == '') ? s : ('表单字段(<font color=green>'+s+'</font>)已修改');
  398. },
  399. /**
  400. * string:原始字符串
  401. * substr:子字符串
  402. * isIgnoreCase:忽略大小写
  403. */
  404. contains: function(string, substr, isIgnoreCase){
  405. if (string == null || substr == null) return false;
  406. if (isIgnoreCase === undefined || isIgnoreCase === true) {
  407. string = string.toLowerCase();
  408. substr = substr.toLowerCase();
  409. }
  410. return string.indexOf(substr) > -1;
  411. },
  412. setLoading : function(b) {// 原this.getActiveTab().setLoading()换成此方法,解决Window模式下无loading问题
  413. var mask = this.mask;
  414. if (!mask) {
  415. this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
  416. msg : "处理中,请稍后...",
  417. msgCls : 'z-index:10000;'
  418. });
  419. }
  420. if (b)
  421. mask.show();
  422. else
  423. mask.hide();
  424. },
  425. loadNewStore: function(pr_id){
  426. var me = this;
  427. var grid = Ext.getCmp('grid');
  428. grid.setLoading(true);//loading...
  429. Ext.Ajax.request({//拿到grid的columns
  430. url : basePath + "pm/mes/queryBOMStep.action",
  431. params: {
  432. id : pr_id
  433. },
  434. method : 'post',
  435. callback : function(options,success,response){
  436. grid.setLoading(false);
  437. var res = new Ext.decode(response.responseText);
  438. if(res.exceptionInfo){
  439. showError(res.exceptionInfo);return;
  440. }
  441. var data = res.data;
  442. if(!data || data.length == 0){
  443. grid.store.removeAll();
  444. grid.GridUtil.add10EmptyItems(grid);
  445. } else {
  446. if(grid.buffered) {
  447. var ln = data.length, records = [], i = 0;
  448. for (; i < ln; i++) {
  449. records.push(Ext.create(grid.store.model.getName(), data[i]));
  450. }
  451. grid.store.purgeRecords();
  452. grid.store.cacheRecords(records);
  453. grid.store.totalCount = ln;
  454. grid.store.guaranteedStart = -1;
  455. grid.store.guaranteedEnd = -1;
  456. var a = grid.store.pageSize - 1;
  457. a = a > ln - 1 ? ln - 1 : a;
  458. grid.store.guaranteeRange(0, a);
  459. } else {
  460. grid.store.loadData(data);
  461. }
  462. }
  463. //自定义event
  464. grid.addEvents({
  465. storeloaded: true
  466. });
  467. grid.fireEvent('storeloaded', grid, data);
  468. }
  469. });
  470. },
  471. cleanDetail : function() {
  472. var grid = Ext.getCmp('grid');
  473. var pr_code = Ext.getCmp('pr_code').value;
  474. var sp_bomversion = Ext.getCmp('sb_bomversion').value;
  475. var sb_id = Ext.getCmp('sb_id').value;
  476. var cr_code = Ext.getCmp('cr_code').value //途程
  477. if(pr_code == null || pr_code ==''){
  478. showError("产品编号不允许为空");
  479. return;
  480. }else if(sp_bomversion == null || sp_bomversion == ''){
  481. showError("BOM版本不允许为空");
  482. return;
  483. }else if(cr_code == '' || cr_code == null){
  484. showError("途程不允许为空");
  485. return;
  486. }
  487. grid.setLoading(true);
  488. Ext.Ajax.request({
  489. url : basePath + 'pm/mes/cleanBomStep.action',
  490. params : {
  491. caller:caller,
  492. pr_code : pr_code,
  493. sp_bomversion:sp_bomversion, //BOM版本编号
  494. cr_code:cr_code , //途程
  495. sb_id : sb_id
  496. },
  497. method : 'post',
  498. callback : function(options, success, response) {
  499. grid.setLoading(false);
  500. var localJson = new Ext.decode(response.responseText);
  501. if (localJson.success) {
  502. showMessage('提示', '清除明细成功!', 1000);
  503. //update成功后刷新页面进入可编辑的页面
  504. window.location.reload();
  505. } else if (localJson.exceptionInfo) {
  506. showError(localJson.exceptionInfo);
  507. return;
  508. }
  509. }
  510. });
  511. },
  512. itemclick:function(view,record,me){
  513. me.GridUtil.onGridItemClick(view,record);
  514. },
  515. loadTab: function(selModel, record){
  516. var me = this;
  517. var cr_code = Ext.getCmp('cr_code');
  518. var cr_stepcode = Ext.getCmp('cr_name');
  519. if(!record.data['leaf']){
  520. cr_code.setValue(record.data['text']);
  521. cr_stepcode.setValue('');
  522. }else{
  523. cr_stepcode.setValue(record.data['text']);
  524. }
  525. var tree = Ext.getCmp('tree-panel');
  526. if (!record.get('leaf')) {
  527. if(record.isExpanded() && record.childNodes.length > 0){//是根节点,且已展开
  528. record.collapse(true,true);//收拢
  529. } else {//未展开
  530. //看是否加载了其children
  531. if(record.childNodes.length == 0){
  532. //从后台加载
  533. tree.setLoading(true, tree.body);
  534. Ext.Ajax.request({//拿到tree数据
  535. url : basePath + 'pm/mes/getBOMStepTree.action',
  536. params: {
  537. caller:caller,
  538. cr_id: record.data['id'],
  539. pr_id:0
  540. },
  541. async: false,
  542. callback : function(options,success,response){
  543. tree.setLoading(false);
  544. var res = new Ext.decode(response.responseText);
  545. if(res.tree){
  546. record.appendChild(res.tree);
  547. record.expand(false,true);//展开
  548. } else if(res.exceptionInfo){
  549. showError(res.exceptionInfo);
  550. }
  551. }
  552. });
  553. } else {
  554. record.expand(false,true);//展开
  555. }
  556. }
  557. }
  558. tree.getExpandedItems(record);
  559. var choose = '';
  560. Ext.each(tree.expandedNodes, function(){
  561. me.lastCode += this.data['qtip'];
  562. choose += '&raquo;' + this.data['text'];
  563. });
  564. Ext.getCmp('form').setTitle("<font color=blue>" + choose + "</font>");
  565. }
  566. });