FeederUse.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mes.FeederUse', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:[
  7. 'pm.mes.FeederUse','core.form.Panel','common.query.GridPanel','common.datalist.GridPanel',
  8. 'common.datalist.Toolbar',
  9. 'core.form.YnField','core.grid.YnColumn', 'core.grid.TfColumn',
  10. 'core.button.Query','core.button.Close',
  11. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger'
  12. ],
  13. init:function(){
  14. var me = this;
  15. this.control({
  16. 'erpQueryButton' : {
  17. click: function(btn) {
  18. var macode = Ext.getCmp('fu_makecode').value,linecode = Ext.getCmp('fu_linecode').value;
  19. if(Ext.isEmpty(macode)) {
  20. showError('请先选择制造单号!');
  21. return;
  22. }
  23. if(Ext.isEmpty(linecode)) {
  24. showError('请先选择线别!');
  25. return;
  26. }
  27. //适用Feeder规格列表
  28. var querygrid = Ext.getCmp('querygrid');
  29. var form = btn.ownerCt.ownerCt;
  30. var urlcondition = querygrid.defaultCondition || '';
  31. condition = me.spellCondition(form, urlcondition);
  32. if(Ext.isEmpty(condition)) {
  33. condition = querygrid.emptyCondition || '1=1';
  34. }
  35. me.beforeQuery(caller, condition);
  36. var gridParam = {caller: caller, condition: condition, start: 1, end: getUrlParam('_end')||1000};
  37. querygrid.GridUtil.loadNewStore(querygrid, gridParam);
  38. //已领Feeder列表
  39. var grid = Ext.getCmp('grid');
  40. if(grid) {
  41. var maid = Ext.getCmp('fu_maid').value, linecode = Ext.getCmp('fu_linecode').value, cond;
  42. if(!Ext.isEmpty(linecode)){
  43. cond = "fu_maid=" + maid +" and fu_linecode='" + linecode +"'";
  44. } else {
  45. cond += " and fu_maid=" + maid;
  46. }
  47. grid.formCondition = cond;
  48. grid.getCount(null, grid.getCondition() || '');
  49. }
  50. }
  51. },
  52. '#feedercode': {
  53. specialkey: function(f, e){//按ENTER自动把摘要复制到下一行
  54. if (e.getKey() == e.ENTER) {
  55. if(f.value != null && f.value != '' ){
  56. me.onConfirm();
  57. }
  58. }
  59. }
  60. },
  61. '#confirm' : {
  62. click: function(btn) {
  63. me.onConfirm();
  64. }
  65. },
  66. '#returnAll' : {
  67. click: function(btn) {
  68. var result = Ext.getCmp('t_result');
  69. var macode = Ext.getCmp('fu_makecode').value;
  70. if(Ext.isEmpty(macode)) {
  71. showError('请先选择制造单号!');
  72. return;
  73. }
  74. warnMsg("确定全部退回?", function(btn){
  75. if(btn == 'yes'){
  76. me.FormUtil.getActiveTab().setLoading(true);//loading...
  77. Ext.Ajax.request({
  78. url : basePath + 'pm/mes/returnAllFeeder.action',
  79. params: {
  80. makecode : Ext.getCmp('fu_makecode').value
  81. },
  82. method : 'post',
  83. callback : function(options,success,response){
  84. me.FormUtil.getActiveTab().setLoading(false);
  85. var r = new Ext.decode(response.responseText);
  86. if(r.exceptionInfo){
  87. result.append(r.exceptionInfo,'error');
  88. showError(r.exceptionInfo);
  89. }
  90. if(r.success){
  91. result.append('\n全部退回成功!','success');
  92. alert('全部退回成功!');
  93. me.GridUtil.loadNewStore(form.ownerCt.down('querygrid'), {caller: caller, condition: "msl_makecode='" + Ext.Cmp('fu_makecode').value + "' and fu_linecode='" + Ext.Cmp('fu_linecode').value + "'"});
  94. me.GridUtil.loadNewStore(form.ownerCt.down('grid'), {caller: caller, condition: "fu_makecode='" + Ext.Cmp('fu_makecode').value + "' and fu_linecode='" + Ext.Cmp('fu_linecode').value + "'"});
  95. }
  96. }
  97. });
  98. }
  99. });
  100. }
  101. },
  102. 'tabpanel > #tab-list': {
  103. activate: function(panel) {
  104. if(panel.boxReady) {
  105. var grid = Ext.getCmp('grid');
  106. if(grid) {
  107. var macode = Ext.getCmp('fu_makecode').value, linecode = Ext.getCmp('fu_linecode').value, condition;
  108. if(!Ext.isEmpty(macode) && Ext.isEmpty(linecode)){
  109. condition = "fu_makecode='" + macode + "'";
  110. }
  111. if(!Ext.isEmpty(linecode) && Ext.isEmpty(macode)){
  112. condition = "fu_linecode='" + linecode + "'";
  113. }
  114. if(!Ext.isEmpty(linecode) && !Ext.isEmpty(macode)){
  115. condition = "fu_makecode='" + macode + "' and fu_linecode='" + linecode + "'";
  116. }
  117. grid.formCondition = condition;
  118. grid.getCount(null, grid.getCondition() || '');
  119. }
  120. } else {
  121. panel.boxReady = true;
  122. var macode = Ext.getCmp('fu_makecode').value, linecode = Ext.getCmp('fu_linecode').value, condition;
  123. if(!Ext.isEmpty(macode) && Ext.isEmpty(linecode)){
  124. condition = "fu_makecode='" + macode + "'";
  125. }
  126. if(!Ext.isEmpty(linecode) && Ext.isEmpty(macode)){
  127. condition = "fu_linecode='" + linecode + "'";
  128. }
  129. if(!Ext.isEmpty(linecode) && !Ext.isEmpty(macode)){
  130. condition = "fu_makecode='" + macode + "' and fu_linecode='" + linecode + "'";
  131. }
  132. panel.add({
  133. xtype: 'erpDatalistGridPanel',
  134. caller: 'FeederUse',
  135. anchor: '100% 100%',
  136. formCondition: condition
  137. });
  138. }
  139. }
  140. }
  141. });
  142. },
  143. beforeQuery: function(call, cond) {
  144. Ext.Ajax.request({
  145. url: basePath + 'common/form/beforeQuery.action',
  146. params: {
  147. caller: call,
  148. condition: cond
  149. },
  150. async: false,
  151. callback: function(opt, s, r) {
  152. var rs = Ext.decode(r.responseText);
  153. if(rs.exceptionInfo) {
  154. showError(rs.exceptionInfo);
  155. }
  156. }
  157. });
  158. },
  159. spellCondition: function(form, condition){
  160. Ext.each(form.items.items, function(f){
  161. if(f.logic != null && f.logic != ''){
  162. if(f.xtype == 'checkbox' && f.value == true){
  163. if(condition == ''){
  164. condition += f.logic;
  165. } else {
  166. condition += ' AND ' + f.logic;
  167. }
  168. } else if(f.xtype == 'datefield' && f.value != null){
  169. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  170. if(condition == ''){
  171. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  172. } else {
  173. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd')";
  174. }
  175. } else if(f.xtype == 'datetimefield' && f.value != null){
  176. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  177. if(condition == ''){
  178. condition += f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  179. } else {
  180. condition += ' AND ' + f.logic + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  181. }
  182. } else if(f.xtype == 'numberfield' && f.value != null && f.value != ''){
  183. if(condition == ''){
  184. condition += f.logic + '=' + f.value;
  185. } else {
  186. condition += ' AND ' + f.logic + '=' + f.value;
  187. }
  188. } else if(f.xtype == 'yeardatefield' && f.value != null && f.value != ''){
  189. if(condition == ''){
  190. condition += f.logic + '=' + f.value;
  191. } else {
  192. condition += ' AND ' + f.logic + '=' + f.value;
  193. }
  194. }else if(f.xtype == 'combo' && f.value == '$ALL'){
  195. if(f.store.data.length > 1) {
  196. if(condition == ''){
  197. condition += '(';
  198. } else {
  199. condition += ' AND (';
  200. }
  201. var _a = '';
  202. f.store.each(function(d, idx){
  203. if(d.data.value != '$ALL') {
  204. if(_a == ''){
  205. _a += f.logic + "='" + d.data.value + "'";
  206. } else {
  207. _a += ' OR ' + f.logic + "='" + d.data.value + "'";
  208. }
  209. }
  210. });
  211. condition += _a + ')';
  212. }
  213. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  214. if(condition == ''){
  215. condition += f.logic + ' in (' ;
  216. } else {
  217. condition += ' AND ' + f.logic + ' in (';
  218. }
  219. var str=f.value,constr="";
  220. for(var i=0;i<str.split("#").length;i++){
  221. if(i<str.split("#").length-1){
  222. constr+="'"+str.split("#")[i]+"',";
  223. }else constr+="'"+str.split("#")[i]+"'";
  224. }
  225. condition +=constr+")";
  226. } else {
  227. if(f.value != null && f.value != ''){
  228. var val = String(f.value);
  229. if(contains(val, 'BETWEEN', true) && contains(val, 'AND', true)){
  230. if(condition == ''){
  231. condition += f.logic + " " + f.value;
  232. } else {
  233. condition += ' AND (' + f.logic + " " + f.value + ")";
  234. }
  235. } else if(f.logic == 'ym_view_param') {
  236. if(condition == ''){
  237. condition += " " + f.value;
  238. } else {
  239. condition += ' AND (' + f.value + ")";
  240. }
  241. } else if(contains(val, '||', true)){
  242. var str = '';
  243. Ext.each(f.value.split('||'), function(v){
  244. if(v != null && v != ''){
  245. if(str == ''){
  246. str += f.logic + "='" + v + "'";
  247. } else {
  248. str += ' OR ' + f.logic + "='" + v + "'";
  249. }
  250. }
  251. });
  252. if(condition == ''){
  253. condition += str;
  254. } else {
  255. condition += ' AND (' + str + ")";
  256. }
  257. } else {
  258. if(val.indexOf('%') >= 0) {
  259. if(condition == ''){
  260. condition += f.logic + " like '" + f.value + "'";
  261. } else {
  262. condition += ' AND (' + f.logic + " like '" + f.value + "')";
  263. }
  264. } else {
  265. if(f.logic=='CONDITION'){
  266. if(condition == ''){
  267. condition += f.value ;
  268. } else {
  269. condition += ' AND ' + f.value;
  270. }
  271. }else{
  272. if(condition == ''){
  273. condition += f.logic + "='" + f.value + "'";
  274. } else {
  275. condition += ' AND (' + f.logic + "='" + f.value + "')";
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. });
  284. return condition;
  285. },
  286. onConfirm : function(){
  287. var me = this, get = Ext.getCmp('get').value, back = Ext.getCmp('back').value;
  288. var result = Ext.getCmp('t_result'), feedercode = Ext.getCmp('feedercode').value,
  289. reason = Ext.getCmp('reason'), isuse = Ext.getCmp('isuse');
  290. var grid1 = Ext.getCmp('querygrid'), grid2 = Ext.getCmp('grid');
  291. var macode = Ext.getCmp('fu_makecode').value, maid = Ext.getCmp('fu_maid').value, linecode = Ext.getCmp('fu_linecode').value, condition1, condition2;
  292. if(!Ext.isEmpty(maid) && Ext.isEmpty(maid)){
  293. condition1 = "mc_makecode='" + macode+"'";
  294. condition2 = "fu_maid=" + maid;
  295. }
  296. if(!Ext.isEmpty(linecode) && !Ext.isEmpty(maid)){
  297. condition1 = "mc_makecode='" + macode+"' and ps_linecode='" + linecode + "'";
  298. condition2 = "fu_maid=" + maid + " and fu_linecode='" + linecode + "'";
  299. }
  300. if(Ext.isEmpty(feedercode)){
  301. showError('请先采集飞达编号!');
  302. return;
  303. }
  304. if(get){
  305. if(Ext.isEmpty(macode)){
  306. showError('请先指定制造单号!');
  307. return;
  308. }
  309. if(Ext.isEmpty(linecode)){
  310. showError('请先指定线别!');
  311. return;
  312. }
  313. me.FormUtil.getActiveTab().setLoading(true);//loading...
  314. Ext.Ajax.request({
  315. url : basePath + 'pm/mes/getFeeder.action',
  316. params: {
  317. feedercode: feedercode,
  318. makecode : Ext.getCmp('fu_makecode').value,
  319. linecode : Ext.getCmp('fu_linecode').value
  320. },
  321. method : 'post',
  322. callback : function(options,success,response){
  323. me.FormUtil.getActiveTab().setLoading(false);
  324. var r = new Ext.decode(response.responseText);
  325. if(r.exceptionInfo){
  326. result.append(r.exceptionInfo, 'error');
  327. }
  328. if(r.success){
  329. result.append('飞达:' + feedercode + ',领用成功!');
  330. var gridParam = {caller: caller, condition: condition1, start: 1, end: getUrlParam('_end')||1000};
  331. grid1.GridUtil.loadNewStore(grid1, gridParam);
  332. if(grid2) {
  333. grid2.formCondition = condition2;
  334. grid2.getCount(null, grid2.getCondition() || '');
  335. }
  336. }
  337. }
  338. });
  339. } else if(back){
  340. if(isuse.value == 1){//选择是停用,则需要填写退回原因
  341. if(Ext.isEmpty(reason.value)){
  342. showError('请先填写退回原因!');
  343. return;
  344. }
  345. }
  346. me.FormUtil.getActiveTab().setLoading(true);//loading...
  347. Ext.Ajax.request({
  348. url : basePath + 'pm/mes/returnFeeder.action',
  349. params: {
  350. feedercode: feedercode,
  351. reason : reason.value,
  352. isuse : isuse.value
  353. },
  354. method : 'post',
  355. callback : function(options,success,response){
  356. me.FormUtil.getActiveTab().setLoading(false);
  357. var r = new Ext.decode(response.responseText);
  358. if(r.exceptionInfo){
  359. result.append(r.exceptionInfo, 'error');
  360. }
  361. if(r.success){
  362. result.append('飞达:' + feedercode + ',退回成功!');
  363. var gridParam = {caller: caller, condition: condition1, start: 1, end: getUrlParam('_end')||1000};
  364. grid1.GridUtil.loadNewStore(grid1, gridParam);
  365. if(grid2) {
  366. grid2.formCondition = condition2;
  367. grid2.getCount(null, grid2.getCondition() || '');
  368. }
  369. }
  370. }
  371. });
  372. }
  373. }
  374. });