Task.js 5.3 KB

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