Feature.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.bom.Feature', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. GridUtil: Ext.create('erp.util.GridUtil'),
  6. BaseUtil: Ext.create('erp.util.BaseUtil'),
  7. views:[
  8. 'core.form.Panel','pm.bom.Feature','core.grid.Panel2','core.toolbar.Toolbar',
  9. 'core.button.Save','core.button.Add','core.button.Upload','core.button.UpdateFeature',
  10. 'core.button.Submit','core.button.ResSubmit','core.button.Audit','core.button.ResAudit',
  11. 'core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail',
  12. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.form.YnField',
  13. 'core.grid.YnColumn','core.grid.YnColumnNV'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'erpGridPanel2': {
  19. itemclick: function(selModel, record){
  20. if(!Ext.getCmp('grid').readOnly){
  21. this.onGridItemClick(selModel, record);
  22. }
  23. }
  24. },
  25. 'erpUpdateFeatureButton': {
  26. afterrender: function(btn){
  27. var val = Ext.getCmp('fe_status').value;
  28. if(val != '已审核'){
  29. btn.hide();
  30. } else {
  31. Ext.getCmp('form').fename = Ext.getCmp('fe_name').value;//初始化fename
  32. btn.show();
  33. }
  34. },
  35. click: function(btn){
  36. if(Ext.getCmp('fe_name').readOnly == true){
  37. Ext.getCmp('fe_name').setReadOnly(false);alert('可以修改特征名称了,修改完再次点击当前按钮即可保持修改');return;
  38. }
  39. if(Ext.getCmp('fe_name').value != Ext.getCmp('form').fename){
  40. me.updateFeature();
  41. } else {
  42. showError('特征名称未做修改哦!');return;
  43. }
  44. }
  45. },
  46. 'erpSaveButton': {
  47. click: function(btn){
  48. var form = me.getForm(btn);
  49. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  50. me.BaseUtil.getRandomNumber('Feature',2,'fe_code');//自动添加编号
  51. }
  52. var flag = this.check();
  53. if(flag != 0){//更新前 业务逻辑检验
  54. return;
  55. }
  56. //保存之前的一些前台的逻辑判定
  57. this.FormUtil.beforeSave(this);
  58. }
  59. },
  60. 'erpCloseButton': {
  61. click: function(btn){
  62. this.FormUtil.beforeClose(this);
  63. }
  64. },
  65. 'erpUpdateButton': {
  66. click: function(btn){
  67. var flag = this.check();
  68. if(flag != 0){//更新前 业务逻辑检验
  69. return;
  70. }
  71. this.FormUtil.onUpdate(this);
  72. }
  73. },
  74. 'erpDeleteButton': {
  75. afterrender: function(btn){
  76. if(Ext.getCmp('fe_statuscode').value != 'ENTERING'){
  77. btn.hide();
  78. } else {
  79. btn.show();
  80. }
  81. },
  82. click: function(btn){
  83. me.FormUtil.onDelete(Ext.getCmp('fe_id').value);
  84. }
  85. },
  86. 'erpAddButton': {
  87. click: function(){
  88. me.FormUtil.onAdd('addFeature', '新增特征', 'jsps/pm/bom/Feature.jsp');
  89. }
  90. },
  91. 'erpSubmitButton': {
  92. afterrender: function(btn){
  93. var status = Ext.getCmp('fe_statuscode');
  94. if(status && status.value != 'ENTERING'){
  95. btn.hide();
  96. }
  97. },
  98. click: function(btn){
  99. me.FormUtil.onSubmit(Ext.getCmp('fe_id').value);
  100. }
  101. },
  102. 'erpResSubmitButton': {
  103. afterrender: function(btn){
  104. var status = Ext.getCmp('fe_statuscode');
  105. if(status && status.value != 'COMMITED'){
  106. btn.hide();
  107. }
  108. },
  109. click: function(btn){
  110. me.FormUtil.onResSubmit(Ext.getCmp('fe_id').value);
  111. }
  112. },
  113. 'erpAuditButton': {
  114. afterrender: function(btn){
  115. var status = Ext.getCmp('fe_statuscode');
  116. if(status && status.value != 'COMMITED'){
  117. btn.hide();
  118. }
  119. },
  120. click: function(btn){
  121. me.FormUtil.onAudit(Ext.getCmp('fe_id').value);
  122. }
  123. },
  124. 'erpResAuditButton': {
  125. afterrender: function(btn){
  126. var status = Ext.getCmp('fe_statuscode');
  127. if(status && status.value != 'AUDITED'){
  128. btn.hide();
  129. }
  130. },
  131. click: function(btn){
  132. me.FormUtil.onResAudit(Ext.getCmp('fe_id').value);
  133. }
  134. },
  135. 'textfield[id=fe_name]': {
  136. blur: function(field){
  137. if(field.value != null && Ext.getCmp('fe_status').value != '已审核'){
  138. me.checkName();
  139. }
  140. }
  141. },
  142. 'textfield[id=fe_status]': {//坑爹 用statuscode就是不行
  143. afterrender: function(field){
  144. if(field.value != '已审核'){
  145. Ext.getCmp('addDetail').setDisabled(true);
  146. Ext.getCmp('updateRemark').setDisabled(true);
  147. Ext.getCmp('forbidden').setDisabled(true);
  148. Ext.getCmp('noforbidden').setDisabled(true);
  149. Ext.getCmp('toyf').setDisabled(true);
  150. Ext.getCmp('tobz').setDisabled(true);
  151. } else {
  152. Ext.getCmp('addDetail').setDisabled(false);
  153. Ext.getCmp('updateRemark').setDisabled(false);
  154. Ext.getCmp('forbidden').setDisabled(false);
  155. Ext.getCmp('noforbidden').setDisabled(false);
  156. Ext.getCmp('toyf').setDisabled(false);
  157. Ext.getCmp('tobz').setDisabled(false);
  158. }
  159. }
  160. },
  161. 'button[id=addDetail]': {
  162. click: function(btn){
  163. me.addDetail();
  164. }
  165. },
  166. 'combocolumn[dataIndex=fr_value]':{
  167. beforerender:function(column){
  168. column.editor= {
  169. format:'',
  170. xtype: 'combo',
  171. listConfig:{
  172. maxHeight:180
  173. },
  174. store: {
  175. fields: ['display', 'value'],
  176. data :[],
  177. },
  178. displayField: 'display',
  179. editable:false,
  180. valueField: 'value',
  181. queryMode: 'local',
  182. onTriggerClick:function(trigger){
  183. if(findData.length<1){
  184. Ext.Array.each(Ext.getCmp('grid').getStore().data.items,function(item){
  185. findData.push({
  186. display:item.data.fd_value,
  187. value:item.data.fd_value,
  188. code:item.data.fd_valuecode
  189. });
  190. });
  191. }
  192. var me=this;
  193. this.getStore().loadData(findData);
  194. if (!me.readOnly && !me.disabled) {
  195. if (me.isExpanded) {
  196. me.collapse();
  197. } else {
  198. me.expand();
  199. }
  200. me.inputEl.focus();
  201. }
  202. },
  203. listeners:{
  204. select:function(field,records){
  205. column.ownerCt.ownerCt.getSelectionModel().selected.items[0].set('fr_valuecode',records[0].data.code);
  206. }
  207. }
  208. };
  209. }
  210. },
  211. 'button[id=forbidden]': {
  212. click: function(btn){
  213. var grid = Ext.getCmp('grid');
  214. var record = grid.selModel.lastSelected;
  215. if(record.data.fd_statuscode != 'DISABLED'){
  216. Ext.Ajax.request({
  217. url : basePath + 'pm/bom/updateByCondition.action',
  218. params : {
  219. tablename:'FeatureDetail',
  220. condition: 'fd_id=' + record.data.fd_id,
  221. update: "fd_status='已禁用',fd_statuscode='DISABLE',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "禁用'"
  222. },
  223. method : 'post',
  224. callback : function(options,success,response){
  225. me.GridUtil.getActiveTab().setLoading(false);
  226. var localJson = new Ext.decode(response.responseText);
  227. if(localJson.exceptionInfo){
  228. showError(localJson.exceptionInfo);return;
  229. }
  230. if(localJson.success){
  231. window.location.reload();
  232. }
  233. }
  234. });
  235. } else {
  236. showError('该明细已经被禁用');
  237. }
  238. }
  239. },
  240. 'button[id=noforbidden]': {
  241. click: function(btn){
  242. var grid = Ext.getCmp('grid');
  243. var record = grid.selModel.lastSelected;
  244. if(record.data.fd_statuscode == 'DISABLE'){
  245. Ext.Ajax.request({
  246. url : basePath + 'pm/bom/updateByCondition.action',
  247. params : {
  248. tablename:'FeatureDetail',
  249. condition: 'fd_id=' + record.data.fd_id,
  250. update: "fd_status='可用',fd_statuscode='ABLED',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "反禁用'"
  251. },
  252. method : 'post',
  253. callback : function(options,success,response){
  254. me.GridUtil.getActiveTab().setLoading(false);
  255. var localJson = new Ext.decode(response.responseText);
  256. if(localJson.exceptionInfo){
  257. showError(localJson.exceptionInfo);return;
  258. }
  259. if(localJson.success){
  260. window.location.reload();
  261. }
  262. }
  263. });
  264. } else {
  265. showError('该明细已经是可用');
  266. }
  267. }
  268. },
  269. 'button[id=toyf]': {
  270. click: function(btn){
  271. var grid = Ext.getCmp('grid');
  272. var record = grid.selModel.lastSelected;
  273. if(record.data.fd_style != '非标准'){
  274. Ext.Ajax.request({
  275. url : basePath + 'pm/bom/updateByCondition.action',
  276. params : {
  277. tablename:'FeatureDetail',
  278. condition: 'fd_id=' + record.data.fd_id,
  279. update: "fd_style='非标准',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "转非标准'"
  280. },
  281. method : 'post',
  282. callback : function(options,success,response){
  283. me.GridUtil.getActiveTab().setLoading(false);
  284. var localJson = new Ext.decode(response.responseText);
  285. if(localJson.exceptionInfo){
  286. showError(localJson.exceptionInfo);return;
  287. }
  288. if(localJson.success){
  289. window.location.reload();
  290. }
  291. }
  292. });
  293. } else {
  294. showError('该明细BOM阶段已经是非标准');
  295. }
  296. }
  297. },
  298. 'button[id=tobz]': {
  299. click: function(btn){
  300. var grid = Ext.getCmp('grid');
  301. var record = grid.selModel.lastSelected;
  302. if(record.data.fd_style != '标准'){
  303. Ext.Ajax.request({
  304. url : basePath + 'pm/bom/updateByCondition.action',
  305. params : {
  306. tablename:'FeatureDetail',
  307. condition: 'fd_id=' + record.data.fd_id,
  308. update: "fd_style='标准',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "转标准'"
  309. },
  310. method : 'post',
  311. callback : function(options,success,response){
  312. me.GridUtil.getActiveTab().setLoading(false);
  313. var localJson = new Ext.decode(response.responseText);
  314. if(localJson.exceptionInfo){
  315. showError(localJson.exceptionInfo);return;
  316. }
  317. if(localJson.success){
  318. window.location.reload();
  319. }
  320. }
  321. });
  322. } else {
  323. showError('该明细BOM阶段已经是标准');
  324. }
  325. }
  326. },
  327. 'button[id=updateRemark]': {
  328. click: function(btn){
  329. me.updateRemark();
  330. }
  331. },
  332. 'gridcolumn[name=fr_value]': {
  333. afterrender: function(field){
  334. console.log(field);
  335. }
  336. },
  337. 'field[name=fd_ifdefault]': {
  338. change: function(field){
  339. if(field.value == -1){
  340. var grid = Ext.getCmp('grid');
  341. var items = grid.store.data.items;
  342. Ext.each(items, function(item){
  343. if(item.data.fd_ifdefault==-1 && item.data.fd_detno != grid.selModel.lastSelected.data.fd_detno){
  344. console.log(item.data.fd_detno+ " == "+item.data.fd_ifdefault);
  345. item.data.fd_ifdefault = 0;
  346. }
  347. });
  348. }
  349. }
  350. },
  351. });
  352. },
  353. onGridItemClick: function(selModel, record){//grid行选择
  354. this.GridUtil.onGridItemClick(selModel, record);
  355. },
  356. getForm: function(btn){
  357. return btn.ownerCt.ownerCt;
  358. },
  359. check: function(){
  360. var flag=0;
  361. var grid = Ext.getCmp('grid');
  362. var items = grid.store.data.items;
  363. Ext.each(items, function(item, i){
  364. if(item.dirty && flag==0 && item.data[grid.necessaryField] != null && item.data[grid.necessaryField] != ""){
  365. if(item.data.fd_value == '' || item.data.fd_value == null){
  366. showError("特征值不能为空");flag=1;//return;
  367. }else if(item.data.fd_valuecode == '' || item.data.fd_valuecode == null){
  368. showError("特征值码不能为空");flag=1;//return;
  369. }else if(item.data.fd_style == ''||item.data.fd_style == null){
  370. showError("BOM阶段不能为空"); flag=1;
  371. }
  372. Ext.each(items, function(t, j){
  373. if(i != j && item.data.fd_value == t.data.fd_value){
  374. showError("特征值不能重复");flag=1;//return;
  375. }else if(i != j && item.data.fd_valuecode == t.data.fd_valuecode){
  376. showError("特征值码不能重复");flag=1;//return;
  377. }
  378. });
  379. }
  380. });
  381. return flag;
  382. },
  383. checkName: function(){
  384. Ext.Ajax.request({//拿到grid的columns
  385. url : basePath + "pm/bom/checkName.action",
  386. params: {
  387. name: Ext.getCmp('fe_name').value
  388. },
  389. method : 'post',
  390. callback : function(options,success,response){
  391. var res = new Ext.decode(response.responseText);
  392. if(res.exceptionInfo){
  393. showError(res.exceptionInfo);return;
  394. }
  395. if(res.success){
  396. if(res.flag == 0){
  397. // window.location.href = window.location.href;
  398. } else if (res.flag == 1){
  399. showError('特征名称已经存在,请重新修改');return;
  400. }
  401. }
  402. }
  403. });
  404. },
  405. updateFeature: function(){
  406. Ext.Ajax.request({//拿到grid的columns
  407. url : basePath + "pm/bom/updateFeatureName.action",
  408. params: {
  409. id: Ext.getCmp('fe_id').value,
  410. name: Ext.getCmp('fe_name').value
  411. },
  412. method : 'post',
  413. callback : function(options,success,response){
  414. var res = new Ext.decode(response.responseText);
  415. if(res.exceptionInfo){
  416. showError(res.exceptionInfo);return;
  417. }
  418. if(res.success){
  419. if(res.flag == 0){
  420. alert('更新成功');
  421. window.location.href = window.location.href;
  422. } else if (res.flag == 1){
  423. showError('特征名称已经存在,请重新修改');return;
  424. }
  425. }
  426. }
  427. });
  428. },
  429. addDetail: function(){
  430. var me = this;
  431. var win = new Ext.window.Window({
  432. id : 'win',
  433. title: "添加特征明细",
  434. height: "50%",
  435. width: "60%",
  436. maximizable : false,
  437. buttonAlign : 'center',
  438. layout : 'anchor',
  439. items: [{
  440. xtype: 'erpGridPanel2',
  441. anchor: '100% 100%',
  442. id:'grid3',
  443. condition: '1<>1',
  444. readOnly: false,
  445. caller:'FeatureDetail',
  446. detno: 'fd_detno',
  447. keyField: 'fd_id',
  448. mainField: 'fd_feid',
  449. necessaryField: 'fd_value',
  450. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  451. clicksToEdit: 1
  452. })],
  453. }],
  454. bbar: ['->',{
  455. text:'编辑',
  456. handler: function(btn){
  457. var grid=Ext.getCmp('grid3');
  458. if(grid.readOnly){
  459. grid.readOnly=false;
  460. btn.hide();
  461. } else {
  462. btn.hide();
  463. }
  464. }
  465. },{
  466. text:'保存',
  467. listeners: {
  468. click: function(){
  469. var grid = Ext.getCmp('grid3');
  470. var detno = Ext.getCmp('grid').getStore().getCount();
  471. console.log(grid.store.data.items);
  472. var error = '';
  473. Ext.each(grid.store.data.items, function(item){
  474. if(item.dirty){
  475. if(item.data.fd_value == '' || item.data.fd_value == null){
  476. error = "特征值不能为空";return;
  477. }
  478. if(item.data.fd_valuecode == '' || item.data.fd_valuecode == null){
  479. error = "特征值码不能为空";return;
  480. }
  481. Ext.each(Ext.getCmp('grid').store.data.items, function(it, i){
  482. if(item.data.fd_value == it.data.fd_value || item.data.fd_valuecode == it.data.fd_valuecode){
  483. error = "特征值或特征值码已经存在,不能重复";return;
  484. }
  485. });
  486. }
  487. });
  488. if(error != ''){
  489. showError(error);return;
  490. }
  491. Ext.each(grid.store.data.items, function(item){
  492. if(item.dirty == true){
  493. item.set('fd_code', Ext.getCmp('fe_code').value);
  494. item.set('fd_detno', ++detno);
  495. item.set('fd_log', em_name + '(' + em_code + ') 于 ' + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + " 增加特征明细");
  496. }
  497. });
  498. var param = me.GridUtil.getGridStore(grid);
  499. if(grid.necessaryField.length > 0 && (param == null || param == '')){
  500. showError('明细表还未添加数据');return;
  501. } else {
  502. me.GridUtil.getActiveTab().setLoading(true);//loading...
  503. Ext.Ajax.request({
  504. url : basePath + 'pm/bom/addFeatureDetail.action',
  505. params : {
  506. param: unescape(param.toString().replace(/\\/g,"%"))
  507. },
  508. method : 'post',
  509. callback : function(options,success,response){
  510. me.GridUtil.getActiveTab().setLoading(false);
  511. var localJson = new Ext.decode(response.responseText);
  512. if(localJson.exceptionInfo){
  513. showError(localJson.exceptionInfo);return;
  514. }
  515. if(localJson.success){
  516. // window.close();
  517. window.location.href = window.location.href;
  518. }
  519. }
  520. });
  521. }
  522. }
  523. }
  524. },'->']
  525. });
  526. win.show();
  527. },
  528. updateRemark: function(selModel, record){
  529. var me = this;
  530. var grid = Ext.getCmp('grid');
  531. var record = grid.selModel.lastSelected;
  532. var win = new Ext.window.Window({
  533. id : 'win2',
  534. title: "修改明细备注 (" + record.data.fd_id + ")",
  535. height: "200px",
  536. width: "400px",
  537. maximizable : false,
  538. buttonAlign : 'center',
  539. layout : 'anchor',
  540. items: [{
  541. xtype: 'textarea',
  542. anchor : '100% 100%',
  543. value: record.data.fd_remark,
  544. id:'remark',
  545. }],
  546. bbar: ['->',{
  547. iconCls: 'x-button-icon-submit',
  548. cls: 'x-btn-gray',
  549. text: '修 改',
  550. handler: function(){
  551. Ext.Ajax.request({
  552. url : basePath + 'pm/bom/updateRemark.action',
  553. params : {
  554. id: record.data.fd_id,
  555. remark: Ext.getCmp('remark').value
  556. },
  557. method : 'post',
  558. callback : function(options,success,response){
  559. me.GridUtil.getActiveTab().setLoading(false);
  560. var localJson = new Ext.decode(response.responseText);
  561. if(localJson.exceptionInfo){
  562. showError(localJson.exceptionInfo);return;
  563. }
  564. if(localJson.success){
  565. // window.close();
  566. window.location.href = window.location.href;
  567. }
  568. }
  569. });
  570. }
  571. },'->']
  572. });
  573. win.show();
  574. }
  575. });