Task.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. * 新增任务
  3. */
  4. Ext.define('erp.view.core.window.Task', {
  5. extend : 'Ext.window.Window',
  6. alias : 'widget.taskwindow',
  7. requires : ['erp.view.core.trigger.DbfindTrigger',
  8. 'erp.view.core.form.FileField',
  9. 'erp.view.core.form.ConDateHourMinuteField'],
  10. width : '80%',
  11. height : 410,
  12. cls : 'custom-blue',
  13. closeAction : 'hide',
  14. title : '添加任务',
  15. sourceform : null,
  16. initComponent : function() {
  17. var me = this;
  18. me.items = me.items || [];
  19. me.items.push(me.createTaskForm());
  20. this.callParent(arguments);
  21. if (me.sourceform) {
  22. me.setDefaultValue(me.sourceform);
  23. }
  24. },
  25. createTaskForm : function() {
  26. var me = this;
  27. return Ext.create('Ext.form.Panel', {
  28. bodyStyle : 'background:#f1f2f5;border:none;',
  29. layout : 'column',
  30. defaults : {
  31. columnWidth : 1 / 3,
  32. margin : '2 2 2 2'
  33. },
  34. items : [{
  35. xtype : 'textfield',
  36. name : 'name',
  37. fieldLabel : '任务名称',
  38. allowBlank : false
  39. }, {
  40. xtype : 'textfield',
  41. name : 'sourcecode',
  42. fieldLabel : '关联单号',
  43. readOnly : true
  44. }, {
  45. xtype : 'checkbox',
  46. boxLabel : '是否需要确认',
  47. checked : true,
  48. name : 'type',
  49. inputValue : 1
  50. }, {
  51. xtype : 'condatehourminutefield',
  52. name : 'startdate',
  53. id : 'startdate',
  54. logic : 'enddate',
  55. secondname : 'enddate',
  56. fieldLabel : '任务处理时间',
  57. columnWidth : 2 / 3,
  58. allowBlank : false
  59. }, {
  60. xtype : 'numberfield',
  61. name : 'duration',
  62. fieldLabel : '持续时间(时)',
  63. hideTrigger : true,
  64. readOnly : true,
  65. value : 24
  66. }, {
  67. xtype : 'hidden',
  68. id : 'enddate',
  69. name : 'enddate',
  70. fieldLabel : '结束时间',
  71. allowBlank : false
  72. }, {
  73. xtype : 'fieldcontainer',
  74. fieldLabel : '处理人',
  75. name : 'resourcename',
  76. columnWidth : 1,
  77. layout : 'hbox',
  78. defaults : {
  79. margin : '0 2 0 2'
  80. },
  81. getSubmitData : function() {
  82. var c = this.query('checkbox[value=true]'), names = new Array();
  83. Ext.each(c, function() {
  84. names.push(this.boxLabel);
  85. });
  86. c = this.query('dbfindtrigger');
  87. Ext.each(c, function() {
  88. if (!Ext.isEmpty(this.value)) {
  89. names.push(this.value);
  90. }
  91. });
  92. return names.join(',');
  93. },
  94. items : [{
  95. xtype : 'dbfindtrigger',
  96. name : 'ma_recorder',
  97. isFormField : false,
  98. listeners : {
  99. aftertrigger : function(t, r) {
  100. t.setValue(r.get('em_name'));
  101. }
  102. }
  103. }, {
  104. xtype : 'button',
  105. iconCls : 'x-button-icon-add',
  106. cls : 'x-btn-tb',
  107. handler : function(b) {
  108. b.ownerCt.insert(
  109. b.ownerCt.items.items.length- 1, {
  110. xtype : 'dbfindtrigger',
  111. name : 'ma_recorder',
  112. isFormField : false,
  113. listeners : {
  114. aftertrigger : function(t, r) {
  115. t.setValue(r.get('em_name'));
  116. }
  117. }
  118. });
  119. }
  120. }]
  121. }, {
  122. xtype : 'mfilefield',
  123. name : 'attachs',
  124. columnWidth : 1,
  125. id : 'attachs'
  126. }, {
  127. xtype : 'textarea',
  128. name : 'description',
  129. fieldLabel : '描述',
  130. allowBlank : false,
  131. height : 160,
  132. columnWidth : 1,
  133. value : (window.errmessage || '')
  134. }, {
  135. xtype : 'hidden',
  136. name : 'sourcelink'
  137. }],
  138. buttonAlign : 'center',
  139. buttons : [{
  140. text : '重置',
  141. cls : 'x-btn-blue',
  142. handler : function(b) {
  143. b.ownerCt.ownerCt.getForm().reset();
  144. }
  145. }, {
  146. text : '确定',
  147. cls : 'x-btn-blue',
  148. formBind : true,
  149. handler : function(b) {
  150. var start = new Date(Ext.getCmp('startdate').items.items[5].value);
  151. var end = new Date(Ext.getCmp('enddate').value);
  152. if (start - end > 0) {
  153. showError('任务处理时间输入有误,请检查后重新输入');
  154. } else {
  155. me.onTaskAdd(b.ownerCt.ownerCt);
  156. }
  157. }
  158. }, {
  159. text : '关闭',
  160. cls : 'x-btn-blue',
  161. handler : function(b) {
  162. b.ownerCt.ownerCt.ownerCt.close();
  163. }
  164. }]
  165. });
  166. },
  167. onTaskAdd : function(form) {
  168. var me = this;
  169. var start = form.down('field[name=startdate]'), end = form
  170. .down('field[name=enddate]'), dur = form
  171. .down('field[name=duration]'), name = form
  172. .down('fieldcontainer[name=resourcename]');
  173. dur.setValue(Ext.Number
  174. .toFixed((new Date(end.getValue()).getTime() - new Date(start
  175. .getValue()).getTime())
  176. / (1000 * 60 * 60), 2));
  177. var v = form.getValues();
  178. Ext.each(Ext.Object.getKeys(v), function(k) {// 去掉页面非表单定义字段
  179. if (contains(k, 'ext-', true)) {
  180. delete v[k];
  181. }
  182. });
  183. v.resourcename = name.getSubmitData();
  184. form.setLoading(true);
  185. Ext.Ajax.request({
  186. url : basePath + 'plm/task/addbilltask.action',
  187. params : {
  188. formStore : unescape(Ext.encode(v).replace(/\\/g, "%"))
  189. },
  190. callback : function(opt, s, res) {
  191. form.setLoading(false);
  192. var r = Ext.decode(res.responseText);
  193. if (r.success) {
  194. alert('添加成功!');
  195. me.close();
  196. } else if (r.exceptionInfo) {
  197. showError(r.exceptionInfo);
  198. }
  199. }
  200. });
  201. },
  202. setDefaultValue : function(form) {
  203. var me = this;
  204. me.down('textfield[name=name]').setValue(form.title);
  205. if (form.codeField) {
  206. var c = form.down('#' + form.codeField);
  207. if (c) {
  208. me.down('textfield[name=sourcecode]').setValue(c.getValue());
  209. }
  210. var u = new String(window.location.href);
  211. u = u.substr(u.indexOf('jsps'));
  212. me.down('field[name=sourcelink]').setValue(u);
  213. }
  214. }
  215. });