TaskPanel.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. Ext.define('erp.view.oa.task.TaskPanel',{
  2. extend: 'Ext.container.Container',
  3. alias: 'widget.TaskPanel',
  4. emptyText : '无数据',
  5. layout:'border',
  6. columnLines : true,
  7. autoScroll : true,
  8. requires:['erp.view.core.trigger.DbfindTrigger','erp.view.core.form.FileField'],
  9. BaseUtil: Ext.create('erp.util.BaseUtil'),
  10. GridUtil: Ext.create('erp.util.GridUtil'),
  11. listeners:{
  12. itemclick:function(selModel,record){
  13. if(record.data.handstatus!='已完成') Ext.getCmp('attachfile').setDisabled(false);
  14. selModel.ownerCt.GridUtil.onGridItemClick(selModel, record);
  15. }
  16. },
  17. initComponent : function(){
  18. var me = this;
  19. Ext.apply(me, {
  20. items: [me._gConfig(me.sourceForm),me._fConfig(me.sourceForm)]
  21. });
  22. me.callParent(arguments);
  23. },
  24. _gConfig:function(form){
  25. var me=this,c =form.down('#' + form.codeField);
  26. return {
  27. xtype:'gridpanel',
  28. title:'任务明细',
  29. region:'center',
  30. minHeight:100,
  31. columnLines:true,
  32. frame:false,
  33. columns:[{
  34. text:'ID',
  35. dataIndex:'id',
  36. width:0,
  37. },{
  38. cls : "x-grid-header",
  39. text: '任务描述',
  40. dataIndex: 'description',
  41. flex:1
  42. },{
  43. text:'截止时间',
  44. dataIndex:'enddate',
  45. xtype:'datecolumn'
  46. },{
  47. text:'执行人',
  48. dataIndex: 'resourcename',
  49. width:100,
  50. readOnly:true
  51. },{
  52. text:'当前状态',
  53. logic:'ignore',
  54. width:100,
  55. dataIndex:'handstatus',
  56. readOnly:true,
  57. renderer:function(val,mata,record){
  58. if(record.get('statuscode')=='AUDITED' && val=='已完成'){
  59. return '<img src="' + basePath + 'resource/images/renderer/finishrecord.png" >' +
  60. '<span style="color:green;padding-left:2px;">' + val + '</span>';
  61. }else if(record.get('statuscode')=='AUDITED' && val=='已启动'){
  62. return '<img src="' + basePath + 'resource/images/renderer/doing.png" >' +
  63. '<span style="color:blue;padding-left:2px;">' + val + '</span>';
  64. }else {
  65. return '<img src="' + basePath + 'resource/images/renderer/key1.png">'+'<span style="color:#8B8B83;padding-left:2px ">' + val + '<a/></span>';
  66. }
  67. }
  68. },{
  69. dataIndex:'attachs',
  70. text:'附件',
  71. width:0
  72. }],
  73. store:Ext.create('Ext.data.Store',{
  74. fields:['id','name','description','enddate','resourcename','resourcecode','resourceemid','handstatus','handstatuscode','statuscode','type','recorder','recorderid'],
  75. proxy: {
  76. type: 'ajax',
  77. url : basePath+'plm/task/getFormTasks.action',
  78. extraParams:{
  79. caller:caller,
  80. codevalue:c.getValue()
  81. },
  82. reader: {
  83. type: 'json',
  84. root: 'tasks'
  85. }
  86. },
  87. autoLoad:true,
  88. sorters:[{property : 'id',
  89. direction: 'ASC'}]
  90. }),
  91. listeners:{
  92. itemclick:me.loadFormRecord
  93. }
  94. };
  95. },
  96. _fConfig:function(form){
  97. var me=this,title=form.title,codeValue,url,keyValue;
  98. if (form.codeField) {
  99. var c = form.down('#' + form.codeField);
  100. if (c) {
  101. codeValue=c.getValue();
  102. }
  103. var u = new String(window.location.href);
  104. u = u.substr(u.indexOf('jsps'));
  105. url=u;
  106. }
  107. if(form.keyField){
  108. var c=form.down('#'+form.keyField);
  109. if(c) keyValue=c.getValue();
  110. }
  111. return {
  112. title:'添加任务',
  113. xtype:'form',
  114. style:'padding-top:20px',
  115. region:'south',
  116. layout:'column',
  117. defaults:{
  118. columnWidth:0.5,
  119. margin : '2 2 2 2'
  120. },
  121. items: [{
  122. fieldLabel: '任务名称',
  123. name: 'name',
  124. allowBlank: false,
  125. value:title,
  126. xtype:'textfield',
  127. },{
  128. fieldLabel: '开始时间',
  129. xtype:'datefield',
  130. name: 'startdate',
  131. value:new Date(),
  132. allowBlank: false
  133. },{
  134. fieldLabel:'结束时间',
  135. xtype:'datefield',
  136. name:'enddate',
  137. allowBlank:false
  138. },{
  139. xtype:'hidden',
  140. name:'duration'
  141. },{
  142. fieldLabel:'执行人',
  143. xtype:'dbfindtrigger',
  144. name:'resourcename',
  145. id:'resourcename'
  146. },{
  147. xtype:'hidden',
  148. name:'resourcecode',
  149. id:'resourcecode',
  150. columnWidth:0
  151. },{
  152. fieldLabel:'需要确认',
  153. xtype:'checkbox',
  154. name:'type',
  155. inputValue:1,
  156. listeners:{
  157. 'change':function(field,newvalue,oldvalue){
  158. var _f=field.ownerCt;
  159. if(newvalue){
  160. _f.down('dbfindtrigger[name=recorder]').show();
  161. }else _f.down('dbfindtrigger[name=recorder]').hide();
  162. }
  163. }
  164. },{
  165. fieldLabel:'确认人',
  166. xtype:'dbfindtrigger',
  167. hidden:true,
  168. name:'recorder',
  169. id:'recorder'
  170. },{
  171. fieldLabel:'确认人ID',
  172. xtype:'hidden',
  173. name:'recorderid'
  174. },{
  175. xtype:'textareafield',
  176. fieldLabel:'任务描述',
  177. name:'description',
  178. columnWidth:1
  179. },{
  180. xtype : 'hidden',
  181. name : 'sourcelink',
  182. value:url
  183. },{
  184. xtype : 'hidden',
  185. name : 'sourcecode',
  186. value:codeValue
  187. },{
  188. xtype : 'hidden',
  189. name : 'sourcecaller',
  190. value:caller||form.caller
  191. },{
  192. xtype:'hidden',
  193. name:'sourceid',
  194. value:keyValue
  195. },{
  196. xtype:'hidden',
  197. name:'statuscode'
  198. },{
  199. xtype:'hidden',
  200. name:'id'
  201. }],
  202. buttons: [{
  203. text: '新增',
  204. handler: function() {
  205. this.up('form').getForm().reset();
  206. }
  207. }, {
  208. text: '保存',
  209. itemId:'savetask',
  210. formBind: true,
  211. disabled: true,
  212. handler: function(btn) {
  213. me.onTaskAdd(btn.ownerCt.ownerCt);
  214. }
  215. },{
  216. text:'关闭',
  217. handler:function(btn){
  218. btn.ownerCt.ownerCt.ownerCt.ownerCt.close();
  219. }
  220. }]
  221. }
  222. },
  223. onTaskAdd : function(form) {
  224. var me = this,status=form.down('field[name=statuscode]'),url='plm/task/saveFormTask.action';
  225. if(status!=null && status.getValue()=='AUDITED') {
  226. alert('任务已启动无法修改!');
  227. return ;
  228. }
  229. var start = form.down('field[name=startdate]'),
  230. end = form.down('field[name=enddate]'),
  231. dur = form.down('field[name=duration]'),
  232. name = form.down('field[name=resourcename]'),taskId=form.down('field[name=id]').getValue();
  233. dur.setValue(Ext.Number.toFixed((end.getValue().getTime() - start.getValue().getTime())/(1000*60*60), 2));
  234. var v = form.getValues();
  235. Ext.each(Ext.Object.getKeys(v), function(k){//去掉页面非表单定义字段
  236. if(contains(k, 'ext-', true)){
  237. delete v[k];
  238. }
  239. });
  240. if(taskId!=null && taskId!='' && taskId!=0) url="plm/task/updateFormTask.action";
  241. Ext.Ajax.request({
  242. url : basePath + url,
  243. params : {
  244. formStore : unescape(Ext.encode(v).replace(/\\/g,"%"))
  245. },
  246. callback : function(opt, s, res) {
  247. form.setLoading(false);
  248. if (res.responseText=='success') {
  249. alert(taskId!=null?'添加成功!':'修改成功!');
  250. form.getForm().reset();
  251. form.ownerCt.down('gridpanel').getStore().load();
  252. } else {
  253. var r = Ext.decode(res.responseText);
  254. showError(r.exceptionInfo);
  255. }
  256. }
  257. });
  258. },
  259. loadFormRecord:function(view,record){
  260. this.ownerCt.down('form').getForm().loadRecord(record);
  261. }
  262. });