MakeMaterial.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.make.MakeMaterial', {
  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.grid.Panel2','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.CleanDetail','core.button.UpdateMaterial','core.button.CopyByConfigs','core.button.DecomSetting'],
  14. init:function(){
  15. var me = this;
  16. me.FormUtil = Ext.create('erp.util.FormUtil');
  17. me.GridUtil = Ext.create('erp.util.GridUtil');
  18. me.BaseUtil = Ext.create('erp.util.BaseUtil');
  19. this.control({
  20. '#ma_remark':{
  21. beforerender: function(field){
  22. field.readOnly=false;
  23. }
  24. },
  25. '#ma_teamcode':{
  26. beforerender: function(field){
  27. field.readOnly=false;
  28. }
  29. },
  30. '#ma_style':{
  31. beforerender: function(field){
  32. field.readOnly=false;
  33. }
  34. },
  35. 'erpGridPanel2': {
  36. afterrender: function(grid){
  37. var status = Ext.getCmp('ma_statuscode');
  38. if(status && status.value != 'ENTERING' ){
  39. grid.setReadOnly(true);
  40. }
  41. },
  42. reconfigure:function(grid){
  43. var items = grid.store.data.items;
  44. var totaluseqty = grid.store.getSum(items, 'mm_totaluseqty');
  45. var havegetqty = grid.store.getSum(items, 'mm_havegetqty');
  46. if( totaluseqty!=0 || havegetqty!=0){
  47. }
  48. },
  49. itemclick: function(view,record){
  50. me.itemclick(view,record,me);
  51. }
  52. },
  53. 'field[name=ma_currency]': {
  54. beforetrigger: function(field) {
  55. var value = Ext.getCmp('ma_date').value;
  56. if(value) {
  57. field.findConfig = 'cm_yearmonth=' + Ext.Date.format(value, 'Ym');
  58. }
  59. }
  60. },
  61. 'erpSaveButton': {
  62. click: function(btn){
  63. var form = me.getForm(btn), codeField = Ext.getCmp(form.codeField);
  64. if(codeField.value == null || codeField.value == ''){
  65. me.BaseUtil.getRandomNumber(caller);//自动添加编号
  66. var res = me.getLeadCode(Ext.getCmp('ma_kind').value);
  67. if(res != null && res != ''){
  68. codeField.setValue(res + codeField.getValue());
  69. }
  70. }
  71. console.log(123456);
  72. this.FormUtil.beforeSave(this);
  73. }
  74. },
  75. 'erpCloseButton': {
  76. click: function(btn){
  77. this.FormUtil.beforeClose(this);
  78. }
  79. },
  80. 'erpCleanDetailButton':{
  81. click: function(btn){
  82. me.cleanDetail();
  83. }
  84. },
  85. 'erpUpdateMaterialButton': {
  86. click: function(btn){
  87. this.FormUtil.onUpdate(this);
  88. }
  89. },
  90. 'erpDecomSettingButton':{
  91. afterrender: function(btn){
  92. var ma_kind = Ext.getCmp("ma_kind");
  93. if(ma_kind && ma_kind.value != '返工' ){
  94. btn.hide();
  95. }
  96. },
  97. click: function(btn){
  98. var ma_screcode = Ext.getCmp('ma_screcode').value;
  99. var grid = Ext.getCmp('grid');
  100. var caller = 'DecomSetting!Make';
  101. var id = Ext.getCmp('ma_id').value;
  102. var result = 0;
  103. if(ma_screcode != null && ma_screcode !=''){
  104. Ext.Ajax.request({
  105. url : basePath + 'common/getFieldData.action',
  106. async: false,
  107. params: {
  108. caller: 'reworkdetail left join rework on re_id = rd_reid',
  109. field: 'count(rd_sncode)',
  110. condition: "re_code= '" + ma_screcode +"'"
  111. },
  112. method : 'post',
  113. callback : function(opt, s, res){
  114. var r = new Ext.decode(res.responseText);
  115. if(r.exceptionInfo){
  116. showError(r.exceptionInfo);return;
  117. } else if(r.success){
  118. result = r.data;
  119. }
  120. }
  121. });
  122. }else{
  123. showError("返工需求单号为空");return;
  124. }
  125. if(result > 0){
  126. var dbwin = new Ext.window.Window({
  127. id : 'dcswin',
  128. title: '拆解部件设定',
  129. height: "100%",
  130. width: "80%",
  131. maximizable : true,
  132. buttonAlign : 'center',
  133. layout : 'anchor',
  134. items: [],
  135. listeners:{
  136. beforeclose: function(){
  137. window.location.reload();
  138. }
  139. }
  140. });
  141. dbwin.add({
  142. tag : 'iframe',
  143. frame : true,
  144. anchor : '100% 100%',
  145. layout : 'fit',
  146. 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>'
  147. });
  148. dbwin.show();
  149. }else{
  150. showError("不存在序列号");return;
  151. }
  152. /*var items = grid.getStore().data.items;//获取store里面的数据
  153. */
  154. }
  155. },
  156. 'dbfindtrigger[name=ma_saledetno]': {
  157. afterrender: function(t){
  158. t.dbKey = "ma_salecode";
  159. t.mappingKey = "sd_code";
  160. t.dbMessage = "请先选择订单编号!";
  161. }
  162. },
  163. 'combo[name=ma_sourcekind]':{
  164. change:function(field,newValue){
  165. var codefield=Ext.getCmp('ma_salecode');
  166. var detnofield=Ext.getCmp('ma_saledetno');
  167. if(newValue=='Sale'){
  168. //销售预测
  169. codefield.dbCaller='Make!Base';
  170. detnofield.dbCaller='Make!Base';
  171. }else if(newValue=='SaleForeCast'){
  172. codefield.dbCaller='Make!Base!ForeCast';
  173. detnofield.dbCaller='Make!Base!ForeCast';
  174. }
  175. }
  176. },
  177. 'dbfindtrigger[name=mm_prodcode]': {
  178. },
  179. 'textfield[name=ma_wccode]': {
  180. change: function(field){
  181. if(field.value != null && field.value != ''){
  182. var grid = Ext.getCmp('grid');
  183. var d = field.value;
  184. Ext.Array.each(grid.getStore().data.items,function(item){
  185. if(item.data['mm_prodcode'] != null && item.data['mm_prodcode'] != '' ){
  186. if(item.data['mm_wccode'] == null ||item.data['mm_wccode'] == '' ){
  187. item.set('mm_wccode',d);
  188. }
  189. }
  190. });
  191. }
  192. }
  193. },
  194. 'datefield[name=ma_planenddate]':{
  195. change: function(f) {
  196. var c = Ext.getCmp('ma_planbegindate').getValue();
  197. var value = f.value;
  198. if( c != null && c != '' && value !=null && value != ''){
  199. if(c > value){
  200. Ext.getCmp('ma_planbegindate').setValue('');
  201. showError('计划完工日期不能早于计划开工日期');
  202. }
  203. }
  204. }
  205. },
  206. 'datefield[name=ma_planbegindate]':{
  207. change: function(f) {
  208. var c = Ext.getCmp('ma_planenddate').getValue();
  209. var value = f.value;
  210. if( value !=null && value != ''){
  211. var formatV = new Date(Ext.util.Format.date(value, 'Y-m-d'));
  212. if(c != null && c != '' ){
  213. if(value > c){
  214. Ext.getCmp('ma_planenddate').setValue('');
  215. showError('计划完工日期不能早于计划开工日期');
  216. }
  217. }
  218. }
  219. }
  220. },
  221. 'field[name=ma_prodcode]': {
  222. change: function(f){
  223. if(f.value != null && f.value != ''){
  224. me.FormUtil.getFieldValue('BOM', 'bo_id', "bo_mothercode='" + f.value + "'", 'ma_bomid');
  225. }
  226. }
  227. },
  228. 'field[name=ma_remark]': {
  229. beforerender: function(t){
  230. if(Ext.getCmp('ma_remark')){
  231. Ext.getCmp('ma_remark').setReadOnly(true);
  232. }
  233. }
  234. },
  235. 'field[name=ma_price]': {
  236. change: function(f){
  237. if(f.value == null || f.value == ''){
  238. f.value = 0;
  239. }
  240. if(Ext.getCmp('ma_total')){//字段存在赋值,不存在不赋值
  241. Ext.getCmp('ma_total').setValue(f.value*Ext.getCmp('ma_qty').value);
  242. }
  243. }
  244. },
  245. 'field[name=mm_oneuseqty]': {
  246. change: function(f){//制单需求=制单套数*单位用量
  247. if(f.value != null && f.value > 0 && Ext.getCmp('ma_qty') && Ext.getCmp('ma_qty').value > 0){
  248. var record = Ext.getCmp('grid').selModel.getLastSelected();
  249. if(record.data['mm_qty'] != f.value*Ext.getCmp('ma_qty').value){
  250. record.set('mm_qty', f.value*Ext.getCmp('ma_qty').value);
  251. }
  252. }
  253. }
  254. },
  255. 'dbfindtrigger[name=ma_craftcode]': {
  256. beforetrigger: function(field) {
  257. var t = field.up('form').down('field[name=ma_prodcode]'),
  258. value = t.getValue();
  259. if(value) {
  260. field.findConfig = "cr_prodcode='" + value + "'";
  261. }
  262. }
  263. },
  264. 'dbfindtrigger[name=ma_bomversion]': {
  265. beforetrigger: function(field) {
  266. var value1 = Ext.getCmp('ma_prodcode').value;
  267. var value2 = Ext.getCmp('ma_craftcode').value;
  268. if(value1 && value2) {
  269. field.findConfig = "sb_prodcode='"+value1+"' and sb_craftcode = '"+value2+"'";
  270. }else if(value1){
  271. field.findConfig = "sb_prodcode='"+value1+"'";
  272. }else if(value2){
  273. field.findConfig = "sb_craftcode = '"+value2+"'";
  274. }
  275. }
  276. }
  277. });
  278. },
  279. getForm: function(btn){
  280. return btn.ownerCt.ownerCt;
  281. },
  282. cleanDetail : function() {
  283. var grid = Ext.getCmp('grid');
  284. grid.setLoading(true);
  285. Ext.Ajax.request({
  286. url : basePath + 'pm/make/cleanMaterial.action',
  287. params : {
  288. id : Ext.getCmp('ma_id').value
  289. },
  290. method : 'post',
  291. callback : function(options, success, response) {
  292. grid.setLoading(false);
  293. var localJson = new Ext.decode(response.responseText);
  294. if (localJson.success) {
  295. showMessage('提示', '清除成功!', 1000);
  296. //update成功后刷新页面进入可编辑的页面
  297. window.location.reload();
  298. } else if (localJson.exceptionInfo) {
  299. showError(str);
  300. return;
  301. }
  302. }
  303. });
  304. },
  305. itemclick:function(view,record,me){
  306. var show=0;
  307. me.GridUtil.onGridItemClick(view,record);
  308. var fieldValue=record.data["mm_prodcode"];
  309. if(fieldValue==undefined||fieldValue==""||fieldValue==null){
  310. show=1;
  311. return;
  312. }
  313. var status = Ext.getCmp('ma_statuscode').getValue();
  314. /*if(show==1 || status=='FINISH' ){
  315. Ext.getCmp('SubRelation').setDisabled(true);
  316. Ext.getCmp('ModifyMaterial').setDisabled(true);
  317. }else {
  318. Ext.getCmp('SubRelation').setDisabled(false);
  319. Ext.getCmp('ModifyMaterial').setDisabled(false);
  320. }*/
  321. },
  322. getFdValue: function(tablename,field, condition){//根据特征项code和特征值码获取特征值
  323. var result = '';
  324. Ext.Ajax.request({
  325. url : basePath + "/common/getFieldData.action",
  326. params: {
  327. caller: tablename,
  328. field: field,
  329. condition: condition
  330. },
  331. method : 'post',
  332. async: false,
  333. callback : function(options,success,response){
  334. var res = new Ext.decode(response.responseText);
  335. if(res.exceptionInfo){
  336. showError(res.exceptionInfo);return;
  337. }
  338. if(res.success){
  339. result = res.data;
  340. }
  341. }
  342. });
  343. return result;
  344. },
  345. getRandomNumber: function(table, type, codeField){
  346. if(Ext.getCmp('ma_kind')){
  347. var form = Ext.getCmp('form');
  348. if(form){
  349. table = table == null ? form.tablename : table;
  350. }
  351. type = type == null ? 2 : type;
  352. codeField = codeField == null ? form.codeField : codeField;
  353. Ext.Ajax.request({
  354. url : basePath + 'pm/make/getCodeString.action',
  355. async: false,//同步ajax请求
  356. params: {
  357. caller: caller,//如果table==null,则根据caller去form表取对应table
  358. table: table,
  359. type: type,
  360. conKind:Ext.getCmp('ma_kind').getValue()
  361. },
  362. method : 'post',
  363. callback : function(options,success,response){
  364. var localJson = new Ext.decode(response.responseText);
  365. if(localJson.exceptionInfo){
  366. showError(localJson.exceptionInfo);
  367. }
  368. if(localJson.success){
  369. Ext.getCmp(codeField).setValue(localJson.code);
  370. }
  371. }
  372. });
  373. } else {
  374. this.BaseUtil.getRandomNumber(caller);//自动添加编号
  375. }
  376. },
  377. getLeadCode: function(type) {
  378. var result = null;
  379. Ext.Ajax.request({
  380. url : basePath + 'common/getFieldData.action',
  381. async: false,
  382. params: {
  383. caller: 'MakeKind',
  384. field: 'mk_excode',
  385. condition: 'mk_name=\'' + type + '\''
  386. },
  387. method : 'post',
  388. callback : function(opt, s, res){
  389. var r = new Ext.decode(res.responseText);
  390. if(r.exceptionInfo){
  391. showError(r.exceptionInfo);return;
  392. } else if(r.success){
  393. result = r.data;
  394. }
  395. }
  396. });
  397. return result;
  398. },
  399. onEnd : function(id,text){
  400. var me = this;
  401. var form = Ext.getCmp('form');
  402. if(form.endUrl && !me.contains(form.endUrl, '?caller=', true)){
  403. form.endUrl = form.endUrl + "?caller=" + caller;
  404. }
  405. me.setLoading(true);//loading...
  406. Ext.Ajax.request({
  407. url : basePath + form.endUrl,
  408. params: {
  409. id: id,
  410. remark: text
  411. },
  412. method : 'post',
  413. callback : function(options,success,response){
  414. me.setLoading(false);
  415. var localJson = new Ext.decode(response.responseText);
  416. if(localJson.success){
  417. endSuccess(function(){
  418. window.location.reload();
  419. });
  420. } else {
  421. if(localJson.exceptionInfo){
  422. var str = localJson.exceptionInfo;
  423. if(str.trim().substr(0, 12) == 'AFTERSUCCESS'){//特殊情况:操作成功,但是出现警告,允许刷新页面
  424. str = str.replace('AFTERSUCCESS', '');
  425. showError(str);
  426. endSuccess(function(){
  427. window.location.reload();
  428. });
  429. } else {
  430. showError(str);return;
  431. }
  432. }
  433. }
  434. }
  435. });
  436. },
  437. /**
  438. * string:原始字符串
  439. * substr:子字符串
  440. * isIgnoreCase:忽略大小写
  441. */
  442. contains: function(string, substr, isIgnoreCase){
  443. if (string == null || substr == null) return false;
  444. if (isIgnoreCase === undefined || isIgnoreCase === true) {
  445. string = string.toLowerCase();
  446. substr = substr.toLowerCase();
  447. }
  448. return string.indexOf(substr) > -1;
  449. },
  450. setLoading : function(b) {// 原this.getActiveTab().setLoading()换成此方法,解决Window模式下无loading问题
  451. var mask = this.mask;
  452. if (!mask) {
  453. this.mask = mask = new Ext.LoadMask(Ext.getBody(), {
  454. msg : "处理中,请稍后...",
  455. msgCls : 'z-index:10000;'
  456. });
  457. }
  458. if (b)
  459. mask.show();
  460. else
  461. mask.hide();
  462. },
  463. openTab : function (panel,id){
  464. var o = (typeof panel == "string" ? panel : id || panel.id);
  465. var main = parent.Ext.getCmp("content-panel");
  466. /*var tab = main.getComponent(o); */
  467. if(!main) {
  468. main =parent.parent.Ext.getCmp("content-panel");
  469. }
  470. var tab = main.getComponent(o);
  471. if (tab) {
  472. main.setActiveTab(tab);
  473. } else if(typeof panel!="string"){
  474. panel.id = o;
  475. var p = main.add(panel);
  476. main.setActiveTab(p);
  477. }
  478. }
  479. });