MakeBase.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakeBase', {
  3. extend: 'Ext.app.Controller',
  4. requires: ['erp.util.FormUtil', 'erp.util.GridUtil', 'erp.util.BaseUtil'],
  5. views:[
  6. 'core.form.Panel','pm.make.MakeBase','core.toolbar.Toolbar','core.form.MultiField','core.form.YnField',
  7. 'core.button.Save','core.button.MakeDownPut','core.button.Add','core.button.Submit','core.button.ResAudit',
  8. 'core.button.Audit','core.button.ResMakeDownPut','core.button.Close','core.button.Delete','core.button.Update','core.button.ResSubmit',
  9. 'core.trigger.DbfindTrigger','core.trigger.TextAreaTrigger','core.grid.YnColumn','core.button.Flow','core.button.UpdateTeamcode',
  10. 'core.trigger.MultiDbfindTrigger','core.button.EnforceEnd','core.button.End', 'core.button.ResEnd','core.button.ModifyMaterial',
  11. 'core.button.SubRelation','core.button.UpdateRemark','erp.view.core.grid.HeaderFilter','core.button.MakeSNCode',
  12. 'core.button.MakeStop','core.button.MakeResStop','core.button.ModifyDetail','core.button.Modify','core.button.VindicateMake',
  13. 'core.button.CopyByConfigs','core.button.DecomSetting','core.button.UpdateMaCraft'
  14. ],
  15. init:function(){
  16. var me = this;
  17. me.FormUtil = Ext.create('erp.util.FormUtil');
  18. me.GridUtil = Ext.create('erp.util.GridUtil');
  19. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  20. this.control({
  21. '#ma_remark':{
  22. beforerender: function(field){
  23. field.readOnly=false;
  24. }
  25. },
  26. /* '#ma_firstitemcheck':{
  27. change:function(f){
  28. if (f.value==-1) {
  29. Ext.getCmp('ma_allowpronum').setFieldStyle("color:#000000");
  30. Ext.getCmp('ma_allowpronum').allowBlank=false;
  31. }else {
  32. Ext.getCmp('ma_allowpronum').allowBlank=true;
  33. }
  34. }
  35. },*/
  36. '#ma_teamcode':{
  37. beforerender: function(field){
  38. field.readOnly=false;
  39. }
  40. },
  41. '#ma_style':{
  42. beforerender: function(field){
  43. field.readOnly=false;
  44. }
  45. },
  46. 'erpGridPanel2': {
  47. afterrender: function(grid){
  48. var status = Ext.getCmp('ma_statuscode');
  49. if(status && status.value != 'ENTERING' ){
  50. grid.setReadOnly(true);
  51. }
  52. },
  53. reconfigure:function(grid){
  54. var items = grid.store.data.items;
  55. var totaluseqty = grid.store.getSum(items, 'mm_totaluseqty');
  56. var havegetqty = grid.store.getSum(items, 'mm_havegetqty');
  57. if( totaluseqty!=0 || havegetqty!=0){
  58. /*Ext.getCmp('resAudit').hide();
  59. Ext.getCmp('resCheck').hide();*/
  60. }
  61. },
  62. itemclick: function(view,record){
  63. me.itemclick(view,record,me);
  64. }
  65. },
  66. 'field[name=ma_currency]': {
  67. beforetrigger: function(field) {
  68. var value = Ext.getCmp('ma_date').value;
  69. if(value) {
  70. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  71. }
  72. }
  73. },
  74. 'erpMakeSNCodeButton':{
  75. click: function(){
  76. var id = Ext.getCmp('ma_id').value;
  77. /*var url = "jsps/pm/make/makeIMEI.jsp?whoami=Make!MakeSN";*/
  78. var url = "jsps/common/import.jsp?whoami=Make!MakeSN";
  79. var panelId = caller + "ma_id_" + id + "ma_idIS"+id;
  80. var panel = Ext.getCmp(panelId);
  81. var main = parent.Ext.getCmp("content-panel");
  82. if(!main){
  83. main = parent.parent.Ext.getCmp("content-panel");
  84. }
  85. if(!panel){
  86. var title = "";
  87. panel = {
  88. title : '工单序列号导入',
  89. tag : 'iframe',
  90. tabConfig:{tooltip:me.BaseUtil.getActiveTab().tabConfig.tooltip+'(ma_id"="' + id +')'},
  91. border : false,
  92. layout : 'fit',
  93. iconCls : 'x-tree-icon-tab-tab1',
  94. html : '<iframe id="iframe_maindetail_'+caller+"_"+id+'" src="' + url + '" height="100%" width="100%" frameborder="0" style="border-width: 0px;padding: 0px;" scrolling="auto"></iframe>',
  95. closable : true,
  96. listeners : {
  97. close : function(){
  98. if(!main){
  99. main = parent.parent.Ext.getCmp("content-panel");
  100. }
  101. main.setActiveTab(main.getActiveTab().id);
  102. }
  103. }
  104. };
  105. this.openTab(panel, panelId);
  106. }else{
  107. main.setActiveTab(panel);
  108. }
  109. }
  110. },
  111. 'erpDecomSettingButton':{
  112. afterrender: function(btn){
  113. var ma_kind = Ext.getCmp("ma_kind");
  114. if(ma_kind && ma_kind.value != '返工' ){
  115. btn.hide();
  116. }
  117. },
  118. click: function(btn){
  119. var ma_screcode = Ext.getCmp('ma_screcode').value;
  120. var grid = Ext.getCmp('grid');
  121. var caller = 'DecomSetting!Make';
  122. var id = Ext.getCmp('ma_id').value;
  123. var result = 0;
  124. if(ma_screcode != null && ma_screcode !=''){
  125. Ext.Ajax.request({
  126. url : basePath + 'common/getFieldData.action',
  127. async: false,
  128. params: {
  129. caller: 'reworkdetail left join rework on re_id = rd_reid',
  130. field: 'count(rd_sncode)',
  131. condition: "re_code= '" + ma_screcode +"'"
  132. },
  133. method : 'post',
  134. callback : function(opt, s, res){
  135. var r = new Ext.decode(res.responseText);
  136. if(r.exceptionInfo){
  137. showError(r.exceptionInfo);return;
  138. } else if(r.success){
  139. result = r.data;
  140. }
  141. }
  142. });
  143. }else{
  144. showError("返工需求单号为空");return;
  145. }
  146. if(result > 0){
  147. var dbwin = new Ext.window.Window({
  148. id : 'dcswin',
  149. title: '拆解部件设定',
  150. height: "100%",
  151. width: "90%",
  152. maximizable : true,
  153. buttonAlign : 'center',
  154. layout : 'anchor',
  155. items: [],
  156. listeners:{
  157. beforeclose: function(){
  158. window.location.reload();
  159. }
  160. }
  161. });
  162. dbwin.add({
  163. tag : 'iframe',
  164. frame : true,
  165. anchor : '100% 100%',
  166. layout : 'fit',
  167. html : '<iframe id="iframe_DecomSetting!Make" src="'+basePath+'jsps/pm/make/decomSetting.jsp?whoami='+caller+'&formCondition=ma_idIS'+id+'&gridCondition=mm_maidIS'+id+'" height="100%" width="100%" frameborder="0" scrolling="no"></iframe>'
  168. });
  169. dbwin.show();
  170. }else{
  171. showError("不存在序列号");return;
  172. }
  173. /*var items = grid.getStore().data.items;//获取store里面的数据
  174. */
  175. }
  176. },
  177. 'erpMakeDownPutButton':{
  178. afterrender: function(btn){
  179. var status = Ext.getCmp('ma_statuscode');
  180. if(status && status.value != 'AUDITED' ){
  181. btn.hide();
  182. }
  183. },
  184. click: function(btn){
  185. //var istrue =me.checkFirstItem();
  186. //if (!istrue) {
  187. // return false;
  188. //}
  189. warnMsg("确定要下放吗?", function(btn){
  190. if(btn == 'yes'){
  191. me.FormUtil.setLoading(true);
  192. Ext.Ajax.request({
  193. url : basePath + 'pm/make/MakeDownPut.action',
  194. params: {
  195. id: Ext.getCmp('ma_id').value,
  196. caller : caller
  197. },
  198. method : 'post',
  199. callback : function(options,success,response){
  200. me.FormUtil.setLoading(false);
  201. var localJson = new Ext.decode(response.responseText);
  202. if(localJson.success){
  203. Ext.Msg.alert("提示","下放成功!",function(){
  204. window.location.reload();
  205. });
  206. } else {
  207. if(localJson.exceptionInfo){
  208. var str = localJson.exceptionInfo;
  209. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  210. str = str.replace('AFTERSUCCESS', '');
  211. showMessage('提示', str);
  212. window.location.reload();
  213. } else if(str == 'OK'){
  214. Ext.Msg.alert("提示","下放成功!");
  215. } else {
  216. showError(str);return;
  217. }
  218. }
  219. }
  220. }
  221. });
  222. }
  223. });
  224. }
  225. },
  226. 'erpVindicateMakeButton':{
  227. click: function(btn){
  228. var id = Ext.getCmp("ma_id").value;
  229. if(id != null && id != '' && id != 0 && id != '0'){
  230. me.FormUtil.onAdd('MakeMaterial' + id, '用料表维护', 'jsps/pm/make/makeMaterial.jsp?formCondition=ma_id=' + id +"&gridCondition=mm_maid=" + id);
  231. }
  232. }
  233. },
  234. 'erpResMakeDownPutButton':{
  235. afterrender: function(btn){
  236. var status = Ext.getCmp('ma_statuscode');
  237. if(status && status.value != 'STARTED' ){
  238. btn.hide();
  239. }
  240. },
  241. click: function(btn){
  242. var me = this;
  243. me.FormUtil.setLoading(true);
  244. Ext.Ajax.request({
  245. url : basePath + 'pm/make/ResMakeDownPut.action',
  246. params: {
  247. id: Ext.getCmp('ma_id').value,
  248. caller : caller
  249. },
  250. method : 'post',
  251. callback : function(options,success,response){
  252. me.FormUtil.setLoading(false);
  253. var localJson = new Ext.decode(response.responseText);
  254. if(localJson.success){
  255. Ext.Msg.alert("提示","取消下放成功!",function(){
  256. window.location.reload();
  257. });
  258. } else {
  259. if(localJson.exceptionInfo){
  260. var str = localJson.exceptionInfo;
  261. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  262. str = str.replace('AFTERSUCCESS', '');
  263. showMessage('提示', str);
  264. window.location.reload();
  265. } else if(str == 'OK'){
  266. Ext.Msg.alert("提示","取消下放成功!");
  267. } else {
  268. showError(str);return;
  269. }
  270. }
  271. }
  272. }
  273. });
  274. }
  275. },
  276. 'erpMakeStopButton':{
  277. afterrender: function(btn){
  278. var status = Ext.getCmp('ma_statuscode');
  279. if(status && status.value != 'STARTED' ){
  280. btn.hide();
  281. }
  282. },
  283. click: function(btn){
  284. warnMsg("确定要暂停吗?", function(btn){
  285. if(btn == 'yes'){
  286. Ext.Ajax.request({
  287. url : basePath + 'pm/make/MakeStop.action',
  288. params: {
  289. id: Ext.getCmp('ma_id').value,
  290. caller : caller
  291. },
  292. method : 'post',
  293. callback : function(options,success,response){
  294. var localJson = new Ext.decode(response.responseText);
  295. if(localJson.success){
  296. Ext.Msg.alert("提示","暂停成功!",function(){
  297. window.location.reload();
  298. });
  299. } else {
  300. if(localJson.exceptionInfo){
  301. var str = localJson.exceptionInfo;
  302. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  303. str = str.replace('AFTERSUCCESS', '');
  304. showMessage('提示', str);
  305. window.location.reload();
  306. } else if(str == 'OK'){
  307. Ext.Msg.alert("提示","暂停成功!");
  308. } else {
  309. showError(str);return;
  310. }
  311. }
  312. }
  313. }
  314. });
  315. }
  316. });
  317. }
  318. },
  319. 'erpMakeResStopButton':{
  320. afterrender: function(btn){
  321. var status = Ext.getCmp('ma_statuscode');
  322. if(status && status.value != 'STOP' ){
  323. btn.hide();
  324. }
  325. },
  326. click: function(btn){
  327. Ext.Ajax.request({
  328. url : basePath + 'pm/make/ResMakeStop.action',
  329. params: {
  330. id: Ext.getCmp('ma_id').value,
  331. caller : caller
  332. },
  333. method : 'post',
  334. callback : function(options,success,response){
  335. var localJson = new Ext.decode(response.responseText);
  336. if(localJson.success){
  337. Ext.Msg.alert("提示","取消暂停成功!",function(){
  338. window.location.reload();
  339. });
  340. } else {
  341. if(localJson.exceptionInfo){
  342. var str = localJson.exceptionInfo;
  343. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  344. str = str.replace('AFTERSUCCESS', '');
  345. showMessage('提示', str);
  346. window.location.reload();
  347. } else if(str == 'OK'){
  348. Ext.Msg.alert("提示","取消暂停成功!");
  349. } else {
  350. showError(str);return;
  351. }
  352. }
  353. }
  354. }
  355. });
  356. }
  357. },
  358. 'erpSaveButton': {
  359. click: function(btn){
  360. var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField);
  361. if(codeField.value == null || codeField.value == ''){
  362. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  363. var res = me.getLeadCode(Ext.getCmp('ma_kind').value);
  364. if(res != null && res != ''){
  365. codeField.setValue(res + codeField.getValue());
  366. }
  367. }
  368. this.FormUtil.beforeSave(this);
  369. }
  370. },
  371. 'erpCloseButton': {
  372. click: function(btn){
  373. this.FormUtil.beforeClose(this);
  374. }
  375. },
  376. /*'erpDeleteDetailButton': {
  377. afterrender: function(btn){
  378. btn.ownerCt.add({
  379. xtype: 'erpSubRelationButton'
  380. });
  381. btn.ownerCt.add({
  382. xtype: 'erpModifyMaterialButton'
  383. });
  384. }
  385. },*/
  386. 'erpUpdateButton': {
  387. afterrender: function(btn){
  388. var status = Ext.getCmp('ma_statuscode');
  389. if(status && status.value != 'ENTERING' ){
  390. btn.hide();
  391. }
  392. },
  393. click: function(btn){
  394. if (Ext.getCmp('ma_firstitemcheck').value!=-1) {
  395. Ext.getCmp('ma_allowpronum').allowBlank=true;
  396. }
  397. this.FormUtil.onUpdate(this);
  398. /*var oldmaqty=0;
  399. if (Ext.getCmp('ma_id').value>0){
  400. oldmaqty=me.getFdValue('make','ma_qty','ma_id='+Ext.getCmp('ma_id').value);
  401. }
  402. if (oldmaqty-Ext.getCmp('ma_qty').value!=0){
  403. alert('工单需求数量已经被修改,请重新计算用料!');
  404. }*/
  405. }
  406. },
  407. 'erpDeleteButton': {
  408. click: function(btn){
  409. me.FormUtil.onDelete(Ext.getCmp('ma_id').value);
  410. }
  411. },
  412. 'erpAddButton': {
  413. click: function(){
  414. me.FormUtil.onAdd('addMakeBase', '新增单据', 'jsps/pm/make/makeBase.jsp?whoami=' + caller);
  415. }
  416. },
  417. 'erpSubmitButton': {
  418. afterrender: function(btn){
  419. var status = Ext.getCmp('ma_statuscode');
  420. if(status && status.value != 'ENTERING'){
  421. btn.hide();
  422. }
  423. },
  424. click: function(btn){
  425. //var istrue =me.checkFirstItem();
  426. //if (!istrue) {
  427. // return false;
  428. //}
  429. /*var type = Ext.getCmp('ma_tasktype').getValue();
  430. if(type != 'MAKE'){// 委外工单 考虑加工单价
  431. var p = Ext.getCmp('ma_price');
  432. if(p && (Ext.isEmpty(p.value) || p.value == 0)){
  433. Ext.Msg.alert("提示","请先填写加工单价后再提交!");
  434. return;
  435. }
  436. }*/
  437. me.FormUtil.onSubmit(Ext.getCmp('ma_id').value);
  438. }
  439. },
  440. 'erpResSubmitButton': {
  441. afterrender: function(btn){
  442. var status = Ext.getCmp('ma_statuscode');
  443. if(status && status.value != 'COMMITED'){
  444. btn.hide();
  445. }
  446. },
  447. click: function(btn){
  448. me.FormUtil.onResSubmit(Ext.getCmp('ma_id').value);
  449. }
  450. },
  451. 'erpAuditButton': {
  452. afterrender: function(btn){
  453. var status = Ext.getCmp('ma_statuscode');
  454. if(status && status.value != 'COMMITED'){
  455. btn.hide();
  456. }
  457. },
  458. click: function(btn){
  459. me.FormUtil.onAudit(Ext.getCmp('ma_id').value);
  460. }
  461. },
  462. 'erpResAuditButton': {
  463. afterrender: function(btn){
  464. var status = Ext.getCmp('ma_statuscode');
  465. if(status && status.value != 'AUDITED'){
  466. btn.hide();
  467. }
  468. var checkStatus = Ext.getCmp('ma_checkstatuscode');
  469. if(checkStatus && checkStatus.value == 'COMMITED'){
  470. btn.hide();
  471. }
  472. },
  473. click: function(btn){
  474. if (!confirm('确定要反审核单据?')){
  475. return;
  476. }
  477. me.FormUtil.onResAudit(Ext.getCmp('ma_id').value);
  478. }
  479. },
  480. 'erpEnforceEndButton':{
  481. afterrender: function(btn){
  482. var status = Ext.getCmp('ma_statuscode');
  483. if(status && status.value == 'FINISH'){
  484. btn.hide();
  485. }
  486. },
  487. click: function(btn){
  488. warnMsg("确定要强制结案吗?", function(btn){
  489. if(btn == 'yes'){
  490. Ext.Ajax.request({
  491. url : basePath + 'pm/make/enforceEndMake.action',
  492. params: {
  493. id: Ext.getCmp('ma_id').value
  494. },
  495. method : 'post',
  496. callback : function(options,success,response){
  497. var localJson = new Ext.decode(response.responseText);
  498. if(localJson.success){
  499. Ext.Msg.alert("提示","操作成功!");
  500. window.location.reload();
  501. } else {
  502. if(localJson.exceptionInfo){
  503. var str = localJson.exceptionInfo;
  504. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  505. str = str.replace('AFTERSUCCESS', '');
  506. showMessage('提示', str);
  507. window.location.reload();
  508. } else if(str == 'OK'){
  509. Ext.Msg.alert("提示","强制结案成功!");
  510. } else {
  511. showError(str);return;
  512. }
  513. }
  514. }
  515. }
  516. });
  517. }
  518. });
  519. }
  520. },
  521. 'erpChangeMaterialButton': {
  522. afterrender: function(btn){
  523. btn.hide();//暂时不启用
  524. var status = Ext.getCmp('ma_statuscode');
  525. if(status && status.value != 'AUDITED'){
  526. btn.hide();
  527. }
  528. }
  529. },
  530. 'dbfindtrigger[name=ma_saledetno]': {
  531. afterrender: function(t){
  532. t.dbKey = "ma_salecode";
  533. t.mappingKey = "sd_code";
  534. t.dbMessage = "请先选择订单编号!";
  535. }
  536. },
  537. 'combo[name=ma_sourcekind]':{
  538. change:function(field,newValue){
  539. var codefield=Ext.getCmp('ma_salecode');
  540. var detnofield=Ext.getCmp('ma_saledetno');
  541. if(newValue=='Sale'){
  542. //销售预测
  543. codefield.dbCaller='Make!Base';
  544. detnofield.dbCaller='Make!Base';
  545. }else if(newValue=='SaleForeCast'){
  546. codefield.dbCaller='Make!Base!ForeCast';
  547. detnofield.dbCaller='Make!Base!ForeCast';
  548. }
  549. }
  550. },
  551. 'dbfindtrigger[name=mm_prodcode]': {
  552. /*focus: function(t){
  553. var grid = Ext.getCmp('grid');
  554. var c = null;
  555. Ext.each(grid.store.data.items, function(item){
  556. if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != ''){
  557. if(c == null){
  558. c = "(pr_code<>'" + item.data['mm_prodcode'] + "'";
  559. } else {
  560. c += " and pr_code<>'" + item.data['mm_prodcode'] + "'";
  561. }
  562. }
  563. });
  564. if(c != null){
  565. t.dbBaseCondition = c + ")";
  566. }
  567. }*/
  568. },
  569. 'textfield[name=ma_wccode]': {
  570. change: function(field){
  571. if(field.value != null && field.value != ''){
  572. var grid = Ext.getCmp('grid');
  573. var d = field.value;
  574. if(grid){
  575. Ext.Array.each(grid.getStore().data.items,function(item){
  576. if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != '' ){
  577. if(item.data['mm_wccode'] == null ||item.data['mm_wccode'] == '' ){
  578. item.set('mm_wccode',d);
  579. }
  580. }
  581. });
  582. }
  583. }
  584. }
  585. },
  586. 'datefield[name=ma_planenddate]':{
  587. change: function(f) {
  588. var c = Ext.getCmp('ma_planbegindate').getValue();
  589. var value = f.value;
  590. if( c != null && c != '' && value !=null && value != ''){
  591. if(c > value){
  592. Ext.getCmp('ma_planbegindate').setValue('');
  593. showError('计划完工日期不能早于计划开工日期');
  594. }
  595. }
  596. }
  597. },
  598. 'datefield[name=ma_planbegindate]':{
  599. change: function(f) {
  600. var c = Ext.getCmp('ma_planenddate').getValue();
  601. var value = f.value;
  602. if( value !=null && value != ''){
  603. var formatV = new Date(Ext.util.Format.date(value, 'Y-m-d'));
  604. if(c != null && c != '' ){
  605. if(value > c){
  606. Ext.getCmp('ma_planenddate').setValue('');
  607. showError('计划完工日期不能早于计划开工日期');
  608. }
  609. }
  610. }
  611. }
  612. },
  613. 'erpEndButton': {
  614. afterrender: function(btn){
  615. var status = Ext.getCmp('ma_statuscode');
  616. if(status && status.value != 'AUDITED'){
  617. btn.hide();
  618. }
  619. },
  620. click: function(btn){
  621. Ext.MessageBox.show({
  622. title:'结案',
  623. msg:'请输入结案原因:',
  624. width:300,
  625. buttons:Ext.MessageBox.OKCANCEL,
  626. multiline:true,
  627. fn:function(btn,text){
  628. if(btn == 'ok'){
  629. me.onEnd(Ext.getCmp('ma_id').value,text);
  630. }
  631. }
  632. })
  633. }
  634. },
  635. 'erpResEndButton': {
  636. afterrender: function(btn){
  637. var status = Ext.getCmp('ma_statuscode');
  638. if(status && status.value != 'FINISH'){
  639. btn.hide();
  640. }
  641. },
  642. click: function(btn){
  643. me.FormUtil.onResEnd(Ext.getCmp('ma_id').value);
  644. }
  645. },
  646. 'erpSubRelationButton':{
  647. click:function(btn){
  648. var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["mm_id"];
  649. var formCondition="mm_id IS"+id;
  650. var gridCondition="mp_mmid IS"+id;
  651. var linkCaller='MakeBase!Sub';
  652. var win = new Ext.window.Window(
  653. {
  654. id : 'win',
  655. height : '90%',
  656. width : '95%',
  657. maximizable : true,
  658. buttonAlign : 'center',
  659. layout : 'anchor',
  660. items : [ {
  661. tag : 'iframe',
  662. frame : true,
  663. anchor : '100% 100%',
  664. layout : 'fit',
  665. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/pm/make/makeCommon.jsp?_noc=1&whoami='+linkCaller+'&gridCondition='+gridCondition+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  666. } ]
  667. });
  668. win.show();
  669. },
  670. afterrender:function(btn){
  671. btn.setDisabled(true);
  672. }
  673. },
  674. 'erpModifyMaterialButton':{
  675. click:function(btn){
  676. var id=btn.ownerCt.ownerCt.ownerCt.items.items[1].selModel.selected.items[0].data["mm_id"];
  677. var formCondition="mm_id IS"+id;
  678. var linkCaller='MakeMaterial!Modify';
  679. var win = new Ext.window.Window(
  680. {
  681. id : 'win',
  682. height : '90%',
  683. width : '95%',
  684. maximizable : true,
  685. buttonAlign : 'center',
  686. layout : 'anchor',
  687. items : [ {
  688. tag : 'iframe',
  689. frame : true,
  690. anchor : '100% 100%',
  691. layout : 'fit',
  692. html : '<iframe id="iframe_'+linkCaller+'" src="'+basePath+'jsps/pm/make/modifyForm.jsp?_noc=0&whoami='+linkCaller+'&formCondition='+formCondition+'" height="100%" width="100%" frameborder="0" scrolling="auto"></iframe>'
  693. } ],
  694. listeners:{
  695. 'beforeclose':function(view ,opt){
  696. var grid = Ext.getCmp('grid');
  697. var value = Ext.getCmp('ma_id').value;
  698. var gridCondition = grid.mainField + '=' + value,
  699. gridParam = {caller: caller, condition: gridCondition};
  700. me.GridUtil.loadNewStore(grid, gridParam);
  701. }
  702. }
  703. });
  704. win.show();
  705. },
  706. afterrender:function(btn){
  707. btn.setDisabled(true);
  708. }
  709. },
  710. 'field[name=ma_prodcode]': {
  711. change: function(f){
  712. if(f.value != null && f.value != ''){
  713. me.FormUtil.getFieldValue('BOM', 'bo_id', "bo_mothercode='" + f.value + "'", 'ma_bomid');
  714. }
  715. }
  716. },
  717. /*'field[name=ma_qty]': {
  718. change: function(f){
  719. if(f.value == null || f.value == ''){
  720. f.value = 0;
  721. }
  722. if(Ext.getCmp('ma_total')){
  723. Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_price').value);
  724. }
  725. var grid = Ext.getCmp('grid');
  726. if(grid){
  727. var items = grid.store.data.items;
  728. Ext.each(items, function(item){//制单需求=制单套数*单位用量
  729. if(item.data['mm_oneuseqty'] != null && item.data['mm_oneuseqty'] != 0){
  730. item.set('mm_qty', item.data['mm_oneuseqty']*f.value);
  731. }
  732. });
  733. }
  734. }
  735. },*/
  736. 'erpUpdateRemarkButton':{
  737. click:function(){
  738. var remark=Ext.getCmp('ma_remark');
  739. me.updateRemark(remark.value,Ext.getCmp('ma_id').value);
  740. }
  741. },
  742. 'erpUpdateTeamcodeButton':{
  743. click:function(){
  744. var linecode=Ext.getCmp('ma_linecode');
  745. me.updateTeamcode(linecode.value,Ext.getCmp('ma_id').value);
  746. }
  747. },
  748. 'field[name=ma_price]': {
  749. change: function(f){
  750. if(f.value == null || f.value == ''){
  751. f.value = 0;
  752. }
  753. if(Ext.getCmp('ma_total')){//字段存在赋值,不存在不赋值
  754. Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_qty').value);
  755. }
  756. }
  757. },
  758. 'field[name=mm_oneuseqty]': {
  759. change: function(f){//制单需求=制单套数*单位用量
  760. if(f.value != null && f.value > 0 && Ext.getCmp('ma_qty') && Ext.getCmp('ma_qty').value > 0){
  761. var record = Ext.getCmp('grid').selModel.getLastSelected();
  762. if(record.data['mm_qty'] != f.value*Ext.getCmp('ma_qty').value){
  763. record.set('mm_qty', f.value*Ext.getCmp('ma_qty').value);
  764. }
  765. }
  766. }
  767. },
  768. 'dbfindtrigger[name=ma_craftcode]': {
  769. beforetrigger: function(field) {
  770. var t = field.up('form').down('field[name=ma_prodcode]'),
  771. value = t.getValue();
  772. if(value) {
  773. field.findConfig = "cr_prodcode='" + value + "'";
  774. }
  775. }
  776. },
  777. 'dbfindtrigger[name=ma_bomversion]': {
  778. beforetrigger: function(field) {
  779. var value1 = Ext.getCmp('ma_prodcode').value;
  780. var value2 = Ext.getCmp('ma_craftcode').value;
  781. if(value1 && value2) {
  782. field.findConfig = "sb_prodcode='"+value1+"' and sb_craftcode = '"+value2+"'";
  783. }else if(value1){
  784. field.findConfig = "sb_prodcode='"+value1+"'";
  785. }else if(value2){
  786. field.findConfig = "sb_craftcode = '"+value2+"'";
  787. }
  788. }
  789. },
  790. 'erpUpdateMaCraftButton':{
  791. afterrender:function(btn){
  792. var status = Ext.getCmp("ma_statuscode");
  793. if((status && (status.value == 'ENTERING' || status.value == 'FINISH'))){
  794. btn.hide();
  795. }
  796. },
  797. click:function(){
  798. var me=this;
  799. var cr_code = Ext.getCmp('ma_craftcode'),
  800. bg = 'background:#fffac0;color:#515151;';
  801. var win = Ext.getCmp('cr_win');
  802. if(win == null){
  803. win = Ext.create('Ext.window.Window',{
  804. width:400,
  805. height:200,
  806. id:'cr_win',
  807. title:'<h1>请选择工单途程</h1>',
  808. layout : 'anchor',
  809. bodyStyle: 'background: #f1f1f1;',
  810. bodyPadding:5,
  811. layout: 'column',
  812. buttonAlign:'center',
  813. defaults:{
  814. columnWidth:0.8
  815. },
  816. items:[{
  817. xtype:'dbfindtrigger',
  818. fieldLabel:'途程编号',
  819. labelStyle:"color:red;",
  820. name:'macraftcode',
  821. editable:false,
  822. id:'macraftcode',
  823. fieldStyle: cr_code.allowBlank ? '' : bg,
  824. listeners:{
  825. beforetrigger: function(field) {
  826. var t = Ext.getCmp("ma_prodcode");
  827. if(t && t.value) {
  828. field.findConfig = "cr_prodcode='" + t.value + "'";
  829. }
  830. }
  831. }
  832. },{
  833. xtype:'textfield',
  834. fieldLabel:'途程名称',
  835. name:'macraftname',
  836. editable:false,
  837. id:'macraftname'
  838. },{
  839. xtype:'textfield',
  840. fieldLabel:'BOM版本',
  841. name:'mabomversion',
  842. editable:false,
  843. id:'mabomversion',
  844. value:Ext.getCmp("ma_bomversion")?Ext.getCmp("ma_bomversion").value:''
  845. }],
  846. buttonAlign:'center',
  847. buttons:[{
  848. xtype:'button',
  849. columnWidth:0.12,
  850. text:'确认',
  851. width:60,
  852. iconCls: 'x-button-icon-save',
  853. handler:function(btn){
  854. var macraftcode=Ext.getCmp('macraftcode').getValue();
  855. var maid=Ext.getCmp('ma_id').value;
  856. var mabomversion = Ext.getCmp('mabomversion').getValue();
  857. if(macraftcode == null ||macraftcode == ''){
  858. showError("请选择工单途程编号");
  859. return ;
  860. }else if(cr_code == macraftcode){
  861. showError("不允许修改成同一个途程编号!");
  862. return ;
  863. }
  864. me.updateMaCraft(macraftcode,maid,mabomversion);
  865. }
  866. },{
  867. xtype:'button',
  868. columnWidth:0.1,
  869. text:'关闭',
  870. width:60,
  871. iconCls: 'x-button-icon-close',
  872. margin:'0 0 0 10',
  873. handler:function(btn){
  874. Ext.getCmp('cr_win').close();
  875. }
  876. }]
  877. }).show();
  878. }else{
  879. win.show();
  880. }
  881. }
  882. }
  883. });
  884. },
  885. getForm: function(btn){
  886. return btn.ownerCt.ownerCt;
  887. },
  888. itemclick:function(view,record,me){
  889. var show=0;
  890. me.GridUtil.onGridItemClick(view,record);
  891. var fieldValue=record.data["mm_prodcode"];
  892. if(fieldValue==undefined||fieldValue==""||fieldValue==null){
  893. show=1;
  894. return;
  895. }
  896. var status = Ext.getCmp('ma_statuscode').getValue();
  897. if(show==1 || status=='FINISH' ){
  898. Ext.getCmp('SubRelation').setDisabled(true);
  899. Ext.getCmp('ModifyMaterial').setDisabled(true);
  900. }else {
  901. Ext.getCmp('SubRelation').setDisabled(false);
  902. Ext.getCmp('ModifyMaterial').setDisabled(false);
  903. }
  904. },
  905. updateRemark:function(remark,id){
  906. Ext.Ajax.request({
  907. url : basePath + 'pm/make/updateRemark.action',
  908. params: {remark:remark,id:id},
  909. method : 'post',
  910. async:false,
  911. callback : function(options,success,response){
  912. var res = new Ext.decode(response.responseText);
  913. if(res.exceptionInfo != null){
  914. showError(res.exceptionInfo);return;
  915. }
  916. showMessage("提示", '更新成功!');
  917. window.location.reload();
  918. }
  919. });
  920. },
  921. updateTeamcode:function(value,id){
  922. Ext.Ajax.request({
  923. url : basePath + 'pm/make/updateTeamcode.action',
  924. params: {value:value,id:id},
  925. method : 'post',
  926. async:false,
  927. callback : function(options,success,response){
  928. var res = new Ext.decode(response.responseText);
  929. if(res.exceptionInfo != null){
  930. showError(res.exceptionInfo);return;
  931. }
  932. showMessage("提示", '更新成功!');
  933. window.location.reload();
  934. }
  935. });
  936. },
  937. updateMaStyle:function(value,id){
  938. Ext.Ajax.request({
  939. url : basePath + 'pm/make/updateMaStyle.action',
  940. params: {value:value,id:id},
  941. method : 'post',
  942. async:false,
  943. callback : function(options,success,response){
  944. var res = new Ext.decode(response.responseText);
  945. if(res.exceptionInfo != null){
  946. showError(res.exceptionInfo);return;
  947. }
  948. showMessage("提示", '更新成功!');
  949. window.location.reload();
  950. }
  951. });
  952. },
  953. updateMaCraft:function(value,id,mabomversion){
  954. Ext.Ajax.request({
  955. url : basePath + 'pm/make/updateMaCraft.action',
  956. params: {
  957. caller:caller,
  958. id:id,
  959. cr_code:value,
  960. mabomversion:mabomversion
  961. },
  962. method : 'post',
  963. async:false,
  964. callback : function(options,success,response){
  965. var res = new Ext.decode(response.responseText);
  966. if(res.exceptionInfo != null){
  967. showError(res.exceptionInfo);return;
  968. }
  969. showMessage("提示", '更新成功!');
  970. window.location.reload();
  971. }
  972. });
  973. },
  974. getFdValue: function(tablename,field, condition){//根据特征项code和特征值码获取特征值
  975. var result = '';
  976. Ext.Ajax.request({
  977. url : basePath + "/common/getFieldData.action",
  978. params: {
  979. caller: tablename,
  980. field: field,
  981. condition: condition
  982. },
  983. method : 'post',
  984. async: false,
  985. callback : function(options,success,response){
  986. var res = new Ext.decode(response.responseText);
  987. if(res.exceptionInfo){
  988. showError(res.exceptionInfo);return;
  989. }
  990. if(res.success){
  991. result = res.data;
  992. }
  993. }
  994. });
  995. return result;
  996. },
  997. getRandomNumber: function(table, type, codeField){
  998. if(Ext.getCmp('ma_kind')){
  999. var form = Ext.getCmp('form');
  1000. if(form){
  1001. table = table == null ? form.tablename : table;
  1002. }
  1003. type = type == null ? 2 : type;
  1004. codeField = codeField == null ? form.codeField : codeField;
  1005. Ext.Ajax.request({
  1006. url : basePath + 'pm/make/getCodeString.action',
  1007. async: false,//同步ajax请求
  1008. params: {
  1009. caller: caller,//如果table==null,则根据caller去form表取对应table
  1010. table: table,
  1011. type: type,
  1012. conKind:Ext.getCmp('ma_kind').getValue()
  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);
  1019. }
  1020. if(localJson.success){
  1021. Ext.getCmp(codeField).setValue(localJson.code);
  1022. }
  1023. }
  1024. });
  1025. } else {
  1026. this.BaseUtil.getRandomNumber(caller);//自动添加编号
  1027. }
  1028. },
  1029. getLeadCode: function(type) {
  1030. var result = null;
  1031. Ext.Ajax.request({
  1032. url : basePath + 'common/getFieldData.action',
  1033. async: false,
  1034. params: {
  1035. caller: 'MakeKind',
  1036. field: 'mk_excode',
  1037. condition: 'mk_name=\'' + type + '\''
  1038. },
  1039. method : 'post',
  1040. callback : function(opt, s, res){
  1041. var r = new Ext.decode(res.responseText);
  1042. if(r.exceptionInfo){
  1043. showError(r.exceptionInfo);return;
  1044. } else if(r.success){
  1045. result = r.data;
  1046. }
  1047. }
  1048. });
  1049. return result;
  1050. },
  1051. onEnd : function(id,text){
  1052. var me = this;
  1053. var form = Ext.getCmp('form');
  1054. if(form.endUrl && !me.contains(form.endUrl, '?caller=', true)){
  1055. form.endUrl = form.endUrl + "?caller=" + caller;
  1056. }
  1057. me.setLoading(true);//loading...
  1058. Ext.Ajax.request({
  1059. url : basePath + form.endUrl,
  1060. params: {
  1061. id: id,
  1062. remark: text
  1063. },
  1064. method : 'post',
  1065. callback : function(options,success,response){
  1066. me.setLoading(false);
  1067. var localJson = new Ext.decode(response.responseText);
  1068. if(localJson.success){
  1069. endSuccess(function(){
  1070. window.location.reload();
  1071. });
  1072. } else {
  1073. if(localJson.exceptionInfo){
  1074. var str = localJson.exceptionInfo;
  1075. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  1076. str = str.replace('AFTERSUCCESS', '');
  1077. showError(str);
  1078. endSuccess(function(){
  1079. window.location.reload();
  1080. });
  1081. } else {
  1082. showError(str);return;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. });
  1088. },
  1089. /**
  1090. * string:原始字符串
  1091. * substr:子字符串
  1092. * isIgnoreCase:忽略大小写
  1093. */
  1094. contains: function(string, substr, isIgnoreCase){
  1095. if (string == null || substr == null) return false;
  1096. if (isIgnoreCase === undefined || isIgnoreCase === true) {
  1097. string = string.toLowerCase();
  1098. substr = substr.toLowerCase();
  1099. }
  1100. return string.indexOf(substr) > -1;
  1101. },
  1102. setLoading : function(b) {// 原this.getActiveTab().setLoading()换成此方法,解决Window模式下无loading问题
  1103. var mask = this.mask;
  1104. if (!mask) {
  1105. this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
  1106. msg : "处理中,请稍后...",
  1107. msgCls : 'z-index:10000;'
  1108. });
  1109. }
  1110. if (b)
  1111. mask.show();
  1112. else
  1113. mask.hide();
  1114. },
  1115. openTab : function (panel,id){
  1116. var o = (typeof panel == "string" ? panel : id || panel.id);
  1117. var main = parent.Ext.getCmp("content-panel");
  1118. /*var tab = main.getComponent(o); */
  1119. if(!main) {
  1120. main =parent.parent.Ext.getCmp("content-panel");
  1121. }
  1122. var tab = main.getComponent(o);
  1123. if (tab) {
  1124. main.setActiveTab(tab);
  1125. } else if(typeof panel!="string"){
  1126. panel.id = o;
  1127. var p = main.add(panel);
  1128. main.setActiveTab(p);
  1129. }
  1130. },
  1131. checkFirstItem:function(f){
  1132. if (Ext.getCmp('ma_firstitemcheck').value==-1) {
  1133. Ext.getCmp('ma_allowpronum').allowBlank=false;
  1134. if (Ext.getCmp('ma_allowpronum').value<0 || Ext.getCmp('ma_allowpronum').value>=Ext.getCmp('ma_qty').value) {
  1135. showError("首件允生产个数必须大于等于0且小于工单数量!");
  1136. return false;
  1137. }
  1138. }else {
  1139. Ext.getCmp('ma_allowpronum').allowBlank=true;
  1140. }
  1141. return true;
  1142. }
  1143. });