Feature.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  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','core.grid.YnColumn'
  13. ],
  14. init:function(){
  15. var me = this;
  16. this.control({
  17. 'erpGridPanel2': {
  18. itemclick: function(selModel, record){
  19. if(!Ext.getCmp('grid').readOnly){
  20. this.onGridItemClick(selModel, record);
  21. }
  22. }
  23. },
  24. 'erpGridPanel2[id=grid3]':{
  25. },
  26. 'erpUpdateFeatureButton': {
  27. afterrender: function(btn){
  28. var val = Ext.getCmp('fe_status').value;
  29. if(val != '已审核'){
  30. btn.hide();
  31. } else {
  32. Ext.getCmp('form').fename = Ext.getCmp('fe_name').value;//初始化fename
  33. btn.show();
  34. }
  35. },
  36. click: function(btn){
  37. // var val = Ext.getCmp('fe_name').value;
  38. // console.log(btn);
  39. // alert(Ext.getCmp('fe_name').readOnly);
  40. if(Ext.getCmp('fe_name').readOnly == true){
  41. Ext.getCmp('fe_name').setReadOnly(false);alert('可以修改特征名称了,修改完再次点击当前按钮即可保持修改');return;
  42. }
  43. // console.log(Ext.getCmp('fe_name'));
  44. // console.log(Ext.getCmp('form').fename + ' ' +Ext.getCmp('fe_name').value);
  45. if(Ext.getCmp('fe_name').value != Ext.getCmp('form').fename){
  46. me.updateFeature();
  47. } else {
  48. showError('特征名称未做修改哦!');return;
  49. }
  50. }
  51. },
  52. 'erpSaveButton': {
  53. click: function(btn){
  54. var form = me.getForm(btn);
  55. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  56. me.BaseUtil.getRandomNumber('Feature',2,'fe_code');//自动添加编号
  57. }
  58. var flag = this.check();
  59. if(flag != 0){//更新前 业务逻辑检验
  60. return;
  61. }
  62. //保存之前的一些前台的逻辑判定
  63. this.beforeSave();
  64. }
  65. },
  66. 'erpCloseButton': {
  67. click: function(btn){
  68. this.FormUtil.beforeClose(this);
  69. }
  70. },
  71. 'erpUpdateButton': {
  72. click: function(btn){
  73. var flag = this.check();
  74. if(flag != 0){//更新前 业务逻辑检验
  75. return;
  76. }
  77. this.beforeUpdate();
  78. }
  79. },
  80. 'erpDeleteButton': {
  81. afterrender: function(btn){
  82. if(Ext.getCmp('fe_statuscode').value != 'ENTERING'){
  83. btn.hide();
  84. } else {
  85. btn.show();
  86. }
  87. },
  88. click: function(btn){
  89. me.FormUtil.onDelete(Ext.getCmp('fe_id').value);
  90. }
  91. },
  92. 'erpAddButton': {
  93. click: function(){
  94. me.FormUtil.onAdd('addFeature', '新增特征', 'jsps/pm/bom/Feature.jsp');
  95. }
  96. },
  97. 'erpSubmitButton': {
  98. afterrender: function(btn){
  99. var status = Ext.getCmp('fe_statuscode');
  100. if(status && status.value != 'ENTERING'){
  101. btn.hide();
  102. }
  103. },
  104. click: function(btn){
  105. me.FormUtil.onSubmit(Ext.getCmp('fe_id').value);
  106. }
  107. },
  108. 'erpResSubmitButton': {
  109. afterrender: function(btn){
  110. var status = Ext.getCmp('fe_statuscode');
  111. if(status && status.value != 'COMMITED'){
  112. btn.hide();
  113. }
  114. },
  115. click: function(btn){
  116. me.FormUtil.onResSubmit(Ext.getCmp('fe_id').value);
  117. }
  118. },
  119. 'erpAuditButton': {
  120. afterrender: function(btn){
  121. var status = Ext.getCmp('fe_statuscode');
  122. if(status && status.value != 'COMMITED'){
  123. btn.hide();
  124. }
  125. },
  126. click: function(btn){
  127. me.FormUtil.onAudit(Ext.getCmp('fe_id').value);
  128. }
  129. },
  130. 'erpResAuditButton': {
  131. afterrender: function(btn){
  132. var status = Ext.getCmp('fe_statuscode');
  133. if(status && status.value != 'AUDITED'){
  134. btn.hide();
  135. }
  136. },
  137. click: function(btn){
  138. me.FormUtil.onResAudit(Ext.getCmp('fe_id').value);
  139. }
  140. },
  141. 'textfield[id=fe_name]': {
  142. blur: function(field){
  143. if(field.value != null && Ext.getCmp('fe_status').value != '已审核'){
  144. me.checkName();
  145. }
  146. }
  147. },
  148. 'textfield[id=fe_status]': {//坑爹 用statuscode就是不行
  149. afterrender: function(field){
  150. // alert(field.value);
  151. if(field.value != '已审核'){
  152. Ext.getCmp('addDetail').setDisabled(true);
  153. Ext.getCmp('updateRemark').setDisabled(true);
  154. Ext.getCmp('updateSpec').setDisabled(true);
  155. Ext.getCmp('forbidden').setDisabled(true);
  156. Ext.getCmp('noforbidden').setDisabled(true);
  157. Ext.getCmp('addRelation').setDisabled(true);
  158. Ext.getCmp('offRelation').setDisabled(true);
  159. Ext.getCmp('toyf').setDisabled(true);
  160. Ext.getCmp('tobz').setDisabled(true);
  161. } else {
  162. Ext.getCmp('addDetail').setDisabled(false);
  163. Ext.getCmp('updateRemark').setDisabled(false);
  164. Ext.getCmp('updateSpec').setDisabled(false);
  165. Ext.getCmp('forbidden').setDisabled(false);
  166. Ext.getCmp('noforbidden').setDisabled(false);
  167. Ext.getCmp('addRelation').setDisabled(false);
  168. Ext.getCmp('offRelation').setDisabled(false);
  169. Ext.getCmp('toyf').setDisabled(false);
  170. Ext.getCmp('tobz').setDisabled(false);
  171. }
  172. }
  173. },
  174. 'button[id=addDetail]': {
  175. click: function(btn){
  176. me.addDetail();
  177. }
  178. },
  179. 'button[id=addRelation]': {
  180. click: function(btn){
  181. me.addRelation();
  182. }
  183. },
  184. 'combocolumn[dataIndex=fr_value]':{
  185. beforerender:function(column){
  186. column.editor= {
  187. format:'',
  188. xtype: 'combo',
  189. listConfig:{
  190. maxHeight:180
  191. },
  192. store: {
  193. fields: ['display', 'value'],
  194. data :[],
  195. },
  196. displayField: 'display',
  197. editable:false,
  198. valueField: 'value',
  199. queryMode: 'local',
  200. onTriggerClick:function(trigger){
  201. if(findData.length<1){
  202. Ext.Array.each(Ext.getCmp('grid').getStore().data.items,function(item){
  203. findData.push({
  204. display:item.data.fd_value,
  205. value:item.data.fd_value,
  206. code:item.data.fd_valuecode
  207. });
  208. });
  209. }
  210. var me=this;
  211. this.getStore().loadData(findData);
  212. if (!me.readOnly && !me.disabled) {
  213. if (me.isExpanded) {
  214. me.collapse();
  215. } else {
  216. me.expand();
  217. }
  218. me.inputEl.focus();
  219. }
  220. },
  221. listeners:{
  222. select:function(field,records){
  223. column.ownerCt.ownerCt.getSelectionModel().selected.items[0].set('fr_valuecode',records[0].data.code);
  224. }
  225. }
  226. };
  227. }
  228. },
  229. 'button[id=forbidden]': {
  230. click: function(btn){
  231. var grid = Ext.getCmp('grid');
  232. var record = grid.selModel.lastSelected;
  233. if(record.data.fd_statuscode != 'DISABLED'){
  234. Ext.Ajax.request({
  235. url : basePath + 'pm/bom/updateByCondition.action',
  236. params : {
  237. tablename:'FeatureDetail',
  238. condition: 'fd_id=' + record.data.fd_id,
  239. update: "fd_status='已禁用',fd_statuscode='DISABLE',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "禁用'"
  240. },
  241. method : 'post',
  242. callback : function(options,success,response){
  243. me.GridUtil.getActiveTab().setLoading(false);
  244. var localJson = new Ext.decode(response.responseText);
  245. if(localJson.exceptionInfo){
  246. showError(localJson.exceptionInfo);return;
  247. }
  248. if(localJson.success){
  249. window.location.reload();
  250. }
  251. }
  252. });
  253. } else {
  254. showError('该明细已经被禁用');
  255. }
  256. }
  257. },
  258. 'button[id=offRelation]': {
  259. click: function(btn){
  260. var grid = Ext.getCmp('grid2');
  261. var record = grid.selModel.lastSelected;
  262. if(record&&(record.data.fr_status != '已禁用'||record.data.fr_status=='')){
  263. Ext.Ajax.request({
  264. url : basePath + 'pm/bom/updateByCondition.action',
  265. params : {
  266. tablename:'FeatureRelation',
  267. condition: 'fr_id=' +record.data.fr_id,
  268. update: "fr_status='已禁用',fr_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "禁用'"
  269. },
  270. method : 'post',
  271. callback : function(options,success,response){
  272. me.GridUtil.getActiveTab().setLoading(false);
  273. var localJson = new Ext.decode(response.responseText);
  274. if(localJson.exceptionInfo){
  275. showError(localJson.exceptionInfo);return;
  276. }
  277. if(localJson.success){
  278. me.GridUtil.loadNewStore(grid,{
  279. condition:'fr_feid='+record.data.fr_feid,
  280. caller:'FeatureRelation'
  281. });
  282. }
  283. }
  284. });
  285. } else {
  286. showError('未选择明细或该明细已经被禁用');
  287. }
  288. }
  289. },
  290. 'button[id=noforbidden]': {
  291. click: function(btn){
  292. var grid = Ext.getCmp('grid');
  293. var record = grid.selModel.lastSelected;
  294. if(record.data.fd_statuscode == 'DISABLE'){
  295. Ext.Ajax.request({
  296. url : basePath + 'pm/bom/updateByCondition.action',
  297. params : {
  298. tablename:'FeatureDetail',
  299. condition: 'fd_id=' + record.data.fd_id,
  300. update: "fd_status='可用',fd_statuscode='ABLED',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "反禁用'"
  301. },
  302. method : 'post',
  303. callback : function(options,success,response){
  304. me.GridUtil.getActiveTab().setLoading(false);
  305. var localJson = new Ext.decode(response.responseText);
  306. if(localJson.exceptionInfo){
  307. showError(localJson.exceptionInfo);return;
  308. }
  309. if(localJson.success){
  310. window.location.reload();
  311. }
  312. }
  313. });
  314. } else {
  315. showError('该明细已经是可用');
  316. }
  317. }
  318. },
  319. 'button[id=toyf]': {
  320. click: function(btn){
  321. var grid = Ext.getCmp('grid');
  322. var record = grid.selModel.lastSelected;
  323. if(record.data.fd_style != '研发'){
  324. Ext.Ajax.request({
  325. url : basePath + 'pm/bom/updateByCondition.action',
  326. params : {
  327. tablename:'FeatureDetail',
  328. condition: 'fd_id=' + record.data.fd_id,
  329. update: "fd_style='研发',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "转研发'"
  330. },
  331. method : 'post',
  332. callback : function(options,success,response){
  333. me.GridUtil.getActiveTab().setLoading(false);
  334. var localJson = new Ext.decode(response.responseText);
  335. if(localJson.exceptionInfo){
  336. showError(localJson.exceptionInfo);return;
  337. }
  338. if(localJson.success){
  339. window.location.reload();
  340. }
  341. }
  342. });
  343. } else {
  344. showError('该明细BOM阶段已经是研发');
  345. }
  346. }
  347. },
  348. 'button[id=tobz]': {
  349. click: function(btn){
  350. var grid = Ext.getCmp('grid');
  351. var record = grid.selModel.lastSelected;
  352. if(record.data.fd_style != '标准'){
  353. Ext.Ajax.request({
  354. url : basePath + 'pm/bom/updateByCondition.action',
  355. params : {
  356. tablename:'FeatureDetail',
  357. condition: 'fd_id=' + record.data.fd_id,
  358. update: "fd_style='标准',fd_log='"+em_name + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + "转标准'"
  359. },
  360. method : 'post',
  361. callback : function(options,success,response){
  362. me.GridUtil.getActiveTab().setLoading(false);
  363. var localJson = new Ext.decode(response.responseText);
  364. if(localJson.exceptionInfo){
  365. showError(localJson.exceptionInfo);return;
  366. }
  367. if(localJson.success){
  368. window.location.reload();
  369. }
  370. }
  371. });
  372. } else {
  373. showError('该明细BOM阶段已经是标准');
  374. }
  375. }
  376. },
  377. 'button[id=updateRemark]': {
  378. click: function(btn){
  379. me.updateRemark();
  380. }
  381. },
  382. 'button[id=updateSpec]': {
  383. click: function(btn){
  384. me.updateSpec();
  385. }
  386. },
  387. 'gridcolumn[name=fr_value]': {
  388. afterrender: function(field){
  389. console.log(field);
  390. }
  391. },
  392. 'field[name=fd_ifdefault]': {
  393. change: function(field){
  394. if(field.value == -1){
  395. var grid = Ext.getCmp('grid');
  396. var items = grid.store.data.items;
  397. Ext.each(items, function(item){
  398. if(item.data.fd_ifdefault==-1 && item.data.fd_detno != grid.selModel.lastSelected.data.fd_detno){
  399. console.log(item.data.fd_detno+ " == "+item.data.fd_ifdefault);
  400. item.data.fd_ifdefault = 0;
  401. }
  402. });
  403. }
  404. }
  405. },
  406. });
  407. },
  408. onGridItemClick: function(selModel, record){//grid行选择
  409. this.GridUtil.onGridItemClick(selModel, record);
  410. },
  411. getForm: function(btn){
  412. return btn.ownerCt.ownerCt;
  413. },
  414. beforeSave: function(){
  415. var me = this;
  416. var form = Ext.getCmp('form');
  417. if(! me.FormUtil.checkForm()){
  418. return;
  419. }
  420. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  421. me.FormUtil.getSeqId(form);
  422. }
  423. var detail = Ext.getCmp('grid');
  424. var relation = Ext.getCmp('grid2');
  425. var param1 = me.GridUtil.getGridStore(detail);
  426. var param2 = me.GridUtil.getGridStore(relation);
  427. if(detail.necessaryField.length > 0 && (param1.length == 0)){
  428. showError($I18N.common.grid.emptyDetail);
  429. return;
  430. } else {
  431. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  432. param2 = param2 == null ? [] : "[" + param2.toString().replace(/\\/g,"%") + "]";
  433. if(form.getForm().isValid()){
  434. Ext.each(form.items.items, function(item){
  435. if(item.xtype == 'numberfield'){
  436. if(item.value == null || item.value == ''){
  437. item.setValue(0);
  438. }
  439. }
  440. });
  441. var r = form.getValues();
  442. me.FormUtil.save(r, param1, param2);
  443. }else{
  444. me.FormUtil.checkForm();
  445. }
  446. }
  447. },
  448. beforeUpdate: function(){
  449. var me = this;
  450. var form = Ext.getCmp('form');
  451. if(! me.FormUtil.checkForm()){
  452. return;
  453. }
  454. if(Ext.getCmp(form.keyField).value == null || Ext.getCmp(form.keyField).value == ''){
  455. me.FormUtil.getSeqId(form);
  456. }
  457. var detail = Ext.getCmp('grid');
  458. var relation = Ext.getCmp('grid2');
  459. var param1 = me.GridUtil.getGridStore(detail);
  460. var param2 = me.GridUtil.getGridStore(relation);
  461. if(me.FormUtil.checkFormDirty() == '' && detail.necessaryField.length > 0 && (param1.length == 0) && (relation.necessaryField.length > 0 && (param2.length == 0))){
  462. showError($I18N.common.form.emptyData + '<br/>' + $I18N.common.grid.emptyDetail);
  463. return;
  464. } else {
  465. param1 = param1 == null ? [] : "[" + param1.toString().replace(/\\/g,"%") + "]";
  466. param2 = param2 == null ? [] : "[" + param2.toString().replace(/\\/g,"%") + "]";
  467. if(form.getForm().isValid()){
  468. Ext.each(form.items.items, function(item){
  469. if(item.xtype == 'numberfield'){
  470. if(item.value == null || item.value == ''){
  471. item.setValue(0);
  472. }
  473. }
  474. });
  475. var r = form.getValues();
  476. me.FormUtil.update(r, param1, param2);
  477. }else{
  478. me.FormUtil.checkForm();
  479. }
  480. }
  481. },
  482. check: function(){
  483. var flag=0;
  484. var grid = Ext.getCmp('grid');
  485. var items = grid.store.data.items;
  486. Ext.each(items, function(item, i){
  487. if(item.dirty&&flag==0){
  488. if(item.data.fd_value == '' || item.data.fd_value == null){
  489. showError("特征值不能为空");flag=1;//return;
  490. }else if(item.data.fd_valuecode == '' || item.data.fd_valuecode == null){
  491. showError("特征值码不能为空");flag=1;//return;
  492. }else if(item.data.fd_style == ''||item.data.fd_style == null){
  493. showError("BOM阶段不能为空"); flag=1;
  494. }
  495. Ext.each(items, function(t, j){
  496. if(i != j && item.data.fd_value == t.data.fd_value){
  497. showError("特征值不能重复");flag=1;//return;
  498. }else if(i != j && item.data.fd_valuecode == t.data.fd_valuecode){
  499. showError("特征值码不能重复");flag=1;//return;
  500. }
  501. });
  502. }
  503. });
  504. return flag;
  505. },
  506. checkName: function(){
  507. Ext.Ajax.request({//拿到grid的columns
  508. url : basePath + "pm/bom/checkName.action",
  509. params: {
  510. name: Ext.getCmp('fe_name').value
  511. },
  512. method : 'post',
  513. callback : function(options,success,response){
  514. var res = new Ext.decode(response.responseText);
  515. if(res.exceptionInfo){
  516. showError(res.exceptionInfo);return;
  517. }
  518. if(res.success){
  519. if(res.flag == 0){
  520. // alert('特征名称可用成功');
  521. // window.location.href = window.location.href;
  522. } else if (res.flag == 1){
  523. showError('特征名称已经存在,请重新修改');return;
  524. }
  525. }
  526. }
  527. });
  528. },
  529. updateFeature: function(){
  530. Ext.Ajax.request({//拿到grid的columns
  531. url : basePath + "pm/bom/updateFeatureName.action",
  532. params: {
  533. id: Ext.getCmp('fe_id').value,
  534. name: Ext.getCmp('fe_name').value
  535. },
  536. method : 'post',
  537. callback : function(options,success,response){
  538. var res = new Ext.decode(response.responseText);
  539. if(res.exceptionInfo){
  540. showError(res.exceptionInfo);return;
  541. }
  542. if(res.success){
  543. if(res.flag == 0){
  544. alert('更新成功');
  545. window.location.href = window.location.href;
  546. } else if (res.flag == 1){
  547. showError('特征名称已经存在,请重新修改');return;
  548. }
  549. }
  550. }
  551. });
  552. },
  553. addDetail: function(){
  554. var me = this;
  555. var win = new Ext.window.Window({
  556. id : 'win',
  557. title: "添加特征明细",
  558. height: "50%",
  559. width: "60%",
  560. maximizable : false,
  561. buttonAlign : 'center',
  562. layout : 'anchor',
  563. items: [{
  564. xtype: 'erpGridPanel2',
  565. anchor: '100% 100%',
  566. // title:'允许特征值列表',
  567. id:'grid3',
  568. condition: '1<>1',
  569. readOnly: false,
  570. caller:'FeatureDetail',
  571. detno: 'fd_detno',
  572. keyField: 'fd_id',
  573. mainField: 'fd_feid',
  574. necessaryField: 'fd_value',
  575. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  576. clicksToEdit: 1
  577. })],
  578. }],
  579. bbar: ['->',{
  580. text:'编辑',
  581. handler: function(btn){
  582. var grid=Ext.getCmp('grid3');
  583. if(grid.readOnly){
  584. grid.readOnly=false;
  585. btn.hide();
  586. } else {
  587. btn.hide();
  588. }
  589. }
  590. },{
  591. text:'保存',
  592. listeners: {
  593. click: function(){
  594. var grid = Ext.getCmp('grid3');
  595. var detno = Ext.getCmp('grid').getStore().getCount();
  596. console.log(grid.store.data.items);
  597. var error = '';
  598. Ext.each(grid.store.data.items, function(item){
  599. if(item.dirty){
  600. if(item.data.fd_value == '' || item.data.fd_value == null){
  601. error = "特征值不能为空";return;
  602. }
  603. if(item.data.fd_valuecode == '' || item.data.fd_valuecode == null){
  604. error = "特征值码不能为空";return;
  605. }
  606. Ext.each(Ext.getCmp('grid').store.data.items, function(it, i){
  607. if(item.data.fd_value == it.data.fd_value || item.data.fd_valuecode == it.data.fd_valuecode){
  608. error = "特征值或特征值码已经存在,不能重复";return;
  609. }
  610. });
  611. }
  612. });
  613. if(error != ''){
  614. showError(error);return;
  615. }
  616. Ext.each(grid.store.data.items, function(item){
  617. if(item.dirty == true){
  618. item.set('fd_code', Ext.getCmp('fe_code').value);
  619. item.set('fd_detno', ++detno);
  620. item.set('fd_log', em_name + '(' + em_code + ') 于 ' + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + " 增加特征明细");
  621. }
  622. });
  623. var param = me.GridUtil.getGridStore(grid);
  624. if(grid.necessaryField.length > 0 && (param == null || param == '')){
  625. showError('明细表还未添加数据');return;
  626. } else {
  627. me.GridUtil.getActiveTab().setLoading(true);//loading...
  628. Ext.Ajax.request({
  629. url : basePath + 'pm/bom/addFeatureDetail.action',
  630. params : {
  631. param: unescape(param.toString().replace(/\\/g,"%"))
  632. },
  633. method : 'post',
  634. callback : function(options,success,response){
  635. me.GridUtil.getActiveTab().setLoading(false);
  636. var localJson = new Ext.decode(response.responseText);
  637. if(localJson.exceptionInfo){
  638. showError(localJson.exceptionInfo);return;
  639. }
  640. if(localJson.success){
  641. // window.close();
  642. window.location.href = window.location.href;
  643. }
  644. }
  645. });
  646. }
  647. }
  648. }
  649. },'->']
  650. });
  651. win.show();
  652. },
  653. updateRemark: function(selModel, record){
  654. var me = this;
  655. var grid = Ext.getCmp('grid');
  656. var record = grid.selModel.lastSelected;
  657. var win = new Ext.window.Window({
  658. id : 'win2',
  659. title: "修改明细备注 (" + record.data.fd_id + ")",
  660. height: "200px",
  661. width: "400px",
  662. maximizable : false,
  663. buttonAlign : 'center',
  664. layout : 'anchor',
  665. items: [{
  666. xtype: 'textarea',
  667. anchor : '100% 100%',
  668. // fieldLabel:'备注',
  669. value: record.data.fd_remark,
  670. id:'remark',
  671. }],
  672. bbar: ['->',{
  673. iconCls: 'x-button-icon-submit',
  674. cls: 'x-btn-gray',
  675. text: '修 改',
  676. handler: function(){
  677. Ext.Ajax.request({
  678. url : basePath + 'pm/bom/updateRemark.action',
  679. params : {
  680. id: record.data.fd_id,
  681. remark: Ext.getCmp('remark').value
  682. },
  683. method : 'post',
  684. callback : function(options,success,response){
  685. me.GridUtil.getActiveTab().setLoading(false);
  686. var localJson = new Ext.decode(response.responseText);
  687. if(localJson.exceptionInfo){
  688. showError(localJson.exceptionInfo);return;
  689. }
  690. if(localJson.success){
  691. // window.close();
  692. window.location.href = window.location.href;
  693. }
  694. }
  695. });
  696. }
  697. },'->']
  698. });
  699. win.show();
  700. },
  701. updateSpec:function(selModel, record){
  702. var me = this;
  703. var grid = Ext.getCmp('grid');
  704. var record = grid.selModel.lastSelected;
  705. var win = new Ext.window.Window({
  706. id : 'win2',
  707. title: "修改规格描述 (" + record.data.fd_id + ")",
  708. height: "200px",
  709. width: "400px",
  710. maximizable : false,
  711. buttonAlign : 'center',
  712. layout : 'anchor',
  713. items: [{
  714. xtype: 'textarea',
  715. anchor : '100% 100%',
  716. // fieldLabel:'备注',
  717. value: record.data.fd_spec,
  718. id:'spec',
  719. }],
  720. bbar: ['->',{
  721. iconCls: 'x-button-icon-submit',
  722. cls: 'x-btn-gray',
  723. text: '修 改',
  724. handler: function(){
  725. Ext.Ajax.request({
  726. url : basePath + 'pm/bom/updateSpec.action',
  727. params : {
  728. id: record.data.fd_id,
  729. spec: Ext.getCmp('spec').value
  730. },
  731. method : 'post',
  732. callback : function(options,success,response){
  733. me.GridUtil.getActiveTab().setLoading(false);
  734. var localJson = new Ext.decode(response.responseText);
  735. if(localJson.exceptionInfo){
  736. showError(localJson.exceptionInfo);return;
  737. }
  738. if(localJson.success){
  739. // window.close();
  740. window.location.href = window.location.href;
  741. }
  742. }
  743. });
  744. }
  745. },'->']
  746. });
  747. win.show();
  748. },
  749. addRelation: function(){
  750. var me = this;
  751. var win = new Ext.window.Window({
  752. id : 'win',
  753. title: "添加约束",
  754. height: "60%",
  755. width: "80%",
  756. maximizable : false,
  757. buttonAlign : 'center',
  758. layout : 'anchor',
  759. items: [{
  760. xtype: 'erpGridPanel2',
  761. anchor: '100% 100%',
  762. // title:'允许特征值列表',
  763. id:'grid4',
  764. condition: '1<>1',
  765. readOnly: false,
  766. caller:'FeatureRelation',
  767. detno: 'fr_detno',
  768. keyField: 'fr_id',
  769. mainField: 'fr_feid',
  770. necessaryField: 'fr_value',
  771. bbar:{},
  772. listeners:{
  773. itemclick: function(selModel, record){
  774. me.GridUtil.onGridItemClick(selModel, record);
  775. }
  776. },
  777. plugins: [Ext.create('Ext.grid.plugin.CellEditing', {
  778. clicksToEdit: 1
  779. })],
  780. }],
  781. bbar: ['->',{
  782. text:'编辑',
  783. handler: function(btn){
  784. var grid=Ext.getCmp('grid4');
  785. if(grid.readOnly){
  786. grid.readOnly=false;
  787. var basegrid=Ext.getCmp('grid2');
  788. var maxdetno=0;
  789. Ext.Array.each(basegrid.store.data.items,function(item){
  790. if(item.data.fr_fecode>maxdetno){
  791. maxdetno=item.data.fr_detno;
  792. }
  793. });
  794. var gridstore=grid.store;
  795. var adddata=new Array();
  796. for(var k=0;k<20;k++){
  797. var o=new Object();
  798. o.fr_detno=k+maxdetno+1;
  799. adddata.push(o);
  800. }
  801. gridstore.loadData(adddata);
  802. btn.hide();
  803. } else {
  804. btn.hide();
  805. }
  806. }
  807. },{
  808. text:'保存',
  809. listeners: {
  810. click: function(){
  811. var grid = Ext.getCmp('grid4');
  812. var detno = Ext.getCmp('grid').getStore().getCount();
  813. var error = '';
  814. Ext.each(grid.store.data.items, function(item){
  815. if(item.dirty == true){
  816. if(item.data.fr_value == ''){
  817. error = "特征值不能为空";return;
  818. // showError("特征值不能为空");return;
  819. }
  820. if(item.data.fr_relacode == '' || item.data.fr_relaname == '' || item.data.fr_relavalue == ''){
  821. // showError("被约束特征信息不能为空");return;
  822. error = "被约束特征信息不能为空";return;
  823. }
  824. if(item.data.fr_relacode == item.data.fr_fecode){
  825. // showError("被约束特征ID不能是自己");return;
  826. error = "被约束特征ID不能是自己";return;
  827. }
  828. Ext.Ajax.request({
  829. url : basePath + 'pm/bom/getDescription.action',
  830. params : {
  831. tablename: "FeatureDetail",
  832. field: 'fd_id',
  833. condition: "fd_code='" + item.data.fr_relacode + "' and fd_value='" + item.data.fr_relavalue + "'",
  834. },
  835. method : 'post',
  836. callback : function(options,success,response){
  837. me.GridUtil.getActiveTab().setLoading(false);
  838. var localJson = new Ext.decode(response.responseText);
  839. if(localJson.exceptionInfo){
  840. // showError(localJson.exceptionInfo);return;
  841. error = localJson.exceptionInfo;return;
  842. }
  843. if(localJson.success){
  844. if(localJson.description == null){
  845. // showError("被约束特征不存在");return;
  846. error = "被约束特征不存在";return;
  847. }
  848. }
  849. }
  850. });
  851. }
  852. });
  853. if(error != ''){
  854. showError(error);return;
  855. }
  856. Ext.each(grid.store.data.items, function(item){
  857. if(item.dirty == true){
  858. item.set('fr_fecode', Ext.getCmp('fe_code').value);
  859. item.set('fr_fename', Ext.getCmp('fe_name').value);
  860. item.set('fr_log', em_name + '(' + em_code + ') 于 ' + Ext.util.Format.date(new Date(), 'Y-m-d H:i:s') + " 增加约束");
  861. }
  862. });
  863. var param = me.GridUtil.getGridStore(grid);
  864. if(grid.necessaryField.length > 0 && (param == null || param == '')){
  865. showError('明细表还未添加数据');return;
  866. } else {
  867. me.GridUtil.getActiveTab().setLoading(true);//loading...
  868. Ext.Ajax.request({
  869. url : basePath + 'pm/bom/addFeatureRelation.action',
  870. params : {
  871. param: unescape(param.toString().replace(/\\/g,"%"))
  872. },
  873. method : 'post',
  874. callback : function(options,success,response){
  875. me.GridUtil.getActiveTab().setLoading(false);
  876. var localJson = new Ext.decode(response.responseText);
  877. if(localJson.exceptionInfo){
  878. showError(localJson.exceptionInfo);return;
  879. }
  880. if(localJson.success){
  881. // window.close();
  882. window.location.reload();
  883. }
  884. }
  885. });
  886. }
  887. }
  888. }
  889. },'->']
  890. });
  891. win.show();
  892. },
  893. });