AppMould.js 10 KB

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