AppMould.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.pm.mould.AppMould', {
  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.mould.AppMould','core.grid.Panel2','core.toolbar.Toolbar','core.form.MultiField',
  9. 'core.button.Save','core.button.Add','core.button.Submit','core.button.Print','core.button.ResAudit',
  10. 'core.button.Audit','core.button.Close','core.button.Delete','core.button.Update','core.button.DeleteDetail','core.button.ResSubmit',
  11. 'core.button.TurnOffPrice','core.form.FileField','core.button.TurnSale',
  12. 'core.trigger.TextAreaTrigger','core.trigger.DbfindTrigger','core.form.YnField',
  13. 'core.grid.YnColumn', 'core.grid.YnColumnNV'
  14. ],
  15. init:function(){
  16. var me = this;
  17. this.control({
  18. 'erpGridPanel2': {
  19. afterrender: function(grid){
  20. var status = Ext.getCmp('app_statuscode');
  21. if(status && status.value != 'ENTERING' && status.value != 'COMMITED'){
  22. Ext.each(grid.columns, function(c){
  23. c.setEditor(null);
  24. });
  25. }
  26. },
  27. itemclick: this.onGridItemClick
  28. },
  29. /**
  30. * 更改是否报价
  31. */
  32. '#updateoffer': {
  33. click: function(btn) {
  34. var record=btn.ownerCt.ownerCt.getSelectionModel().getLastSelected();
  35. me.UpdateOffer(record);
  36. }
  37. },
  38. 'erpSaveButton': {
  39. click: function(btn){
  40. var form = me.getForm(btn);
  41. if(Ext.getCmp(form.codeField).value == null || Ext.getCmp(form.codeField).value == ''){
  42. me.BaseUtil.getRandomNumber();//自动添加编号
  43. }
  44. this.FormUtil.beforeSave(this);
  45. }
  46. },
  47. 'erpDeleteButton' : {
  48. click: function(btn){
  49. me.FormUtil.onDelete(Ext.getCmp('app_id').value);
  50. }
  51. },
  52. 'erpUpdateButton': {
  53. afterrender: function(btn){
  54. var status = Ext.getCmp('app_statuscode');
  55. if(status && status.value != 'ENTERING'){
  56. btn.hide();
  57. }
  58. },
  59. click: function(btn){
  60. this.FormUtil.onUpdate(this);
  61. }
  62. },
  63. 'erpAddButton': {
  64. click: function(){
  65. me.FormUtil.onAdd('addAppMould', '新增开模申请单', 'jsps/pm/mould/appMould.jsp');
  66. }
  67. },
  68. 'erpCloseButton': {
  69. click: function(btn){
  70. me.FormUtil.beforeClose(me);
  71. }
  72. },
  73. 'erpSubmitButton': {
  74. afterrender: function(btn){
  75. var status = Ext.getCmp('app_statuscode');
  76. if(status && status.value != 'ENTERING'){
  77. btn.hide();
  78. }
  79. },
  80. click: function(btn){
  81. me.FormUtil.onSubmit(Ext.getCmp('app_id').value);
  82. }
  83. },
  84. 'erpResSubmitButton': {
  85. afterrender: function(btn){
  86. var status = Ext.getCmp('app_statuscode');
  87. if(status && status.value != 'COMMITED'){
  88. btn.hide();
  89. }
  90. },
  91. click: function(btn){
  92. me.FormUtil.onResSubmit(Ext.getCmp('app_id').value);
  93. }
  94. },
  95. 'erpAuditButton': {
  96. afterrender: function(btn){
  97. var status = Ext.getCmp('app_statuscode');
  98. if(status && status.value != 'COMMITED'){
  99. btn.hide();
  100. }
  101. },
  102. click: function(btn){
  103. me.FormUtil.onAudit(Ext.getCmp('app_id').value);
  104. }
  105. },
  106. 'erpResAuditButton': {
  107. afterrender: function(btn){
  108. var status = Ext.getCmp('app_statuscode');
  109. if(status && status.value != 'AUDITED'){
  110. btn.hide();
  111. }
  112. },
  113. click: function(btn){
  114. me.FormUtil.onResAudit(Ext.getCmp('app_id').value);
  115. }
  116. },
  117. 'erpPrintButton': {
  118. click: function(btn){
  119. me.FormUtil.onPrint(Ext.getCmp('app_id').value);
  120. }
  121. },
  122. 'erpTurnSaleButton':{
  123. afterrender: function(btn){
  124. var status = Ext.getCmp('app_statuscode'), turnstatus = Ext.getCmp('app_turnsalecode');
  125. if(status && status.value != 'AUDITED'){
  126. btn.hide();
  127. }
  128. if(turnstatus && turnstatus.value == 'TURNSA'){
  129. btn.hide();
  130. }
  131. },
  132. click: function(btn){
  133. warnMsg("确定要转入模销售单吗?", function(btn){
  134. if(btn == 'yes'){
  135. var id = Ext.getCmp('app_id').value;
  136. me.FormUtil.setLoading(true);
  137. Ext.Ajax.request({
  138. url : basePath + 'pm/mould/turnMouldSale.action',
  139. params: {
  140. id: id
  141. },
  142. method : 'post',
  143. callback : function(options,success,response){
  144. me.FormUtil.setLoading(false);
  145. var localJson = new Ext.decode(response.responseText);
  146. if(localJson.exceptionInfo){
  147. showError(localJson.exceptionInfo);
  148. return "";
  149. }
  150. if(localJson.success){
  151. if(localJson.log){
  152. showMessage("提示", localJson.log);
  153. }
  154. window.location.reload();
  155. }
  156. }
  157. });
  158. }
  159. });
  160. }
  161. },
  162. 'erpTurnOffPriceButton':{
  163. afterrender: function(btn){
  164. var status = Ext.getCmp('app_statuscode'), turnstatus = Ext.getCmp('app_turnpricecode');
  165. if(status && status.value != 'AUDITED'){
  166. btn.hide();
  167. }
  168. if(turnstatus && turnstatus.value == 'TURNPM'){
  169. btn.hide();
  170. }
  171. },
  172. click: function(btn){
  173. warnMsg("确定要转入模具报价单吗?", function(btn){
  174. if(btn == 'yes'){
  175. me.FormUtil.getActiveTab().setLoading(true);//loading...
  176. Ext.Ajax.request({
  177. url : basePath + 'pm/mould/turnPriceMould.action',
  178. params: {
  179. id: Ext.getCmp('app_id').value
  180. },
  181. method : 'post',
  182. callback : function(o, s, res){
  183. me.FormUtil.getActiveTab().setLoading(false);
  184. var r = new Ext.decode(res.responseText);
  185. if(r.exceptionInfo){
  186. showError(r.exceptionInfo);
  187. }
  188. if(r.success && r.id){
  189. var id = r.id, msg = '模具报价单号:<br>';
  190. for(var i in id) {
  191. msg += '<a href="javascript:openUrl(\'jsps/pm/mould/priceMould.jsp?formCondition=pd_id='
  192. + id[i].id + '&gridCondition=pmd_pdid=' + id[i].id + '\');">' + id[i].code + '</a><hr>';
  193. }
  194. showMessage('提示', msg);
  195. }
  196. }
  197. });
  198. }
  199. });
  200. }
  201. }
  202. });
  203. },
  204. UpdateOffer:function(record){
  205. var win = this.window;
  206. if (!win) {
  207. win = this.window = this.getWindow(record);
  208. }
  209. win.show();
  210. },
  211. getWindow : function(record) {
  212. var me = this;
  213. return Ext.create('Ext.window.Window',{
  214. width: 330,
  215. height: 180,
  216. closeAction: 'hide',
  217. cls: 'custom-blue',
  218. title:'<h1>更改是否报价</h1>',
  219. layout: {
  220. type: 'vbox'
  221. },
  222. items:[{
  223. margin: '5 0 0 5',
  224. xtype: 'erpYnField',
  225. fieldLabel: '是否报价',
  226. id:'isoffer',
  227. name: 'isoffer',
  228. readOnly:false,
  229. allowBlank: false,
  230. value : record.data.ad_isoffer
  231. }],
  232. buttonAlign:'center',
  233. buttons:[{
  234. xtype:'button',
  235. text:'保存',
  236. width:60,
  237. iconCls: 'x-button-icon-save',
  238. handler:function(btn){
  239. var w = btn.up('window');
  240. me.saveOffer(w);
  241. w.hide();
  242. }
  243. },{
  244. xtype:'button',
  245. columnWidth:0.1,
  246. text:'关闭',
  247. width:60,
  248. iconCls: 'x-button-icon-close',
  249. margin:'0 0 0 10',
  250. handler:function(btn){
  251. btn.up('window').hide();
  252. }
  253. }]
  254. });
  255. },
  256. saveOffer: function(w) {
  257. var isoffer = w.down('#isoffer').getValue(),
  258. grid = Ext.getCmp('grid'),
  259. app_id = Ext.getCmp('app_id').value,
  260. record = grid.getSelectionModel().getLastSelected();
  261. if(!isoffer) {
  262. showError('请先选择是否报价.') ;
  263. return;
  264. } else {
  265. var dd = {
  266. ad_id : record.data.ad_id,
  267. ad_appid : app_id,
  268. isoffer : isoffer ? isoffer : 1
  269. };
  270. Ext.Ajax.request({
  271. url : basePath +'pm/mould/updateIsOffer.action',
  272. params : {
  273. _noc: 1,
  274. data: unescape(Ext.JSON.encode(dd))
  275. },
  276. method : 'post',
  277. callback : function(opt, s, res){
  278. var r = new Ext.decode(res.responseText);
  279. if(r.success){
  280. showMessage('提示', '更新成功!', 1000);
  281. grid.GridUtil.loadNewStore(grid, {caller: 'AppMould', condition: 'ad_appid=' + app_id});
  282. } else if(r.exceptionInfo){
  283. showError(r.exceptionInfo);
  284. } else{
  285. saveFailure();
  286. }
  287. }
  288. });
  289. }
  290. },
  291. onGridItemClick: function(selModel, record){//grid行选择
  292. var id = record.get('ad_id');
  293. if(!Ext.isEmpty(id) && id != 0) {
  294. var btn = Ext.getCmp('updateoffer');
  295. btn && btn.setDisabled(false);
  296. }
  297. this.GridUtil.onGridItemClick(selModel, record);
  298. },
  299. getForm: function(btn){
  300. return btn.ownerCt.ownerCt;
  301. }
  302. });