ChanceProcess.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. Ext.QuickTips.init();
  2. Ext.define('erp.controller.crm.chance.ChanceProcess', {
  3. extend: 'Ext.app.Controller',
  4. FormUtil: Ext.create('erp.util.FormUtil'),
  5. BaseUtil: Ext.create('erp.util.BaseUtil'),
  6. views:['crm.chance.ChanceProcess','crm.chance.ProcessGrid','core.form.ConDateField','core.form.MultiField','core.trigger.DbfindTrigger'],
  7. init:function(){
  8. var me = this;
  9. this.control({
  10. 'button[id=query]': {
  11. afterrender: function(btn) {
  12. setTimeout(function(){
  13. me.showFilterPanel(btn);
  14. }, 200);
  15. },
  16. click: function(btn) {
  17. me.showFilterPanel(btn);
  18. }
  19. },
  20. 'button[name=export]': {
  21. click: function() {
  22. var grid = Ext.getCmp('processgrid');
  23. me.BaseUtil.exportGrid(grid, '商机进度');
  24. }
  25. }
  26. });
  27. },
  28. showFilterPanel: function(btn) {
  29. var filter = Ext.getCmp(btn.getId() + '-filter');
  30. if(!filter) {
  31. filter = this.createFilterPanel(btn);
  32. }
  33. filter.show();
  34. },
  35. hideFilterPanel: function(btn) {
  36. var filter = Ext.getCmp(btn.getId() + '-filter');
  37. if(filter) {
  38. filter.hide();
  39. }
  40. },
  41. getCondition: function(pl) {
  42. var condition="1=1";
  43. Ext.each(pl.items.items, function(f){
  44. if(f.name != null && f.name != ''){
  45. if((f.xtype == 'checkbox' || f.xtype == 'radio')){
  46. if(f.value == true) {
  47. if(condition == ''){
  48. condition += f.name;
  49. } else {
  50. condition += ' AND ' + f.name;
  51. }
  52. }
  53. } else if(f.xtype == 'datefield' && f.value != null && f.value != '' && !contains(f.name, 'to:', true)){
  54. var v = Ext.Date.format(new Date(f.value), 'Y-m-d');
  55. if(condition == ''){
  56. condition += f.name + "=to_date('" + v + "', 'yyyy-MM-dd')";
  57. } else {
  58. condition += ' AND ' + f.name + "=to_date('" + v + "', 'yyyy-MM-dd')";
  59. }
  60. } else if(f.xtype == 'datetimefield' && f.value != null){
  61. var v = Ext.Date.format(new Date(f.value), 'Y-m-d H:i:s');
  62. if(condition == ''){
  63. condition += f.name + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  64. } else {
  65. condition += ' AND ' + f.name + "=to_date('" + v + "', 'yyyy-MM-dd HH24:mi:ss')";
  66. }
  67. } else if(f.xtype == 'numberfield' && f.value != null && f.value != '' && !contains(f.name, 'to:', true)){
  68. var endChar = f.name.substr(f.name.length - 1);
  69. if(endChar != '>' && endChar != '<')
  70. endChar = '=';
  71. else
  72. endChar = '';
  73. if(condition == ''){
  74. condition += f.name + endChar + f.value;
  75. } else {
  76. condition += ' AND ' + f.name + endChar + f.value;
  77. }
  78. } else if(f.xtype == 'combo' && f.value == '$ALL'){
  79. if(f.store.data.length > 1) {
  80. if(condition == ''){
  81. condition += '(';
  82. } else {
  83. condition += ' AND (';
  84. }
  85. var _a = '';
  86. f.store.each(function(d, idx){
  87. if(d.data.value != '$ALL') {
  88. if(_a == ''){
  89. _a += f.name + "='" + d.data.value + "'";
  90. } else {
  91. _a += ' OR ' + f.name + "='" + d.data.value + "'";
  92. }
  93. }
  94. });
  95. condition += _a + ')';
  96. }
  97. } else if(f.xtype=='adddbfindtrigger' && f.value != null && f.value != ''){
  98. if(condition == ''){
  99. condition += f.name + ' in (' ;
  100. } else {
  101. condition += ' AND ' + f.name + ' in (';
  102. }
  103. var str=f.value,constr="";
  104. for(var i=0;i<str.split("#").length;i++){
  105. if(i<str.split("#").length-1){
  106. constr+="'"+str.split("#")[i]+"',";
  107. }else constr+="'"+str.split("#")[i]+"'";
  108. }
  109. condition +=constr+")";
  110. } else {
  111. if(contains(f.name, 'to:', true)){
  112. if(!grid.toField){
  113. grid.toField = new Array();
  114. }
  115. grid.toField.push(f.name.split(':')[1]);
  116. } else {
  117. if(!Ext.isEmpty(f.value)){
  118. if(contains(f.value.toString(), 'BETWEEN', true) && contains(f.value.toString(), 'AND', true)){
  119. if(condition == ''){
  120. condition += f.name + " " + f.value;
  121. } else {
  122. condition += ' AND (' + f.name + " " + f.value + ")";
  123. }
  124. } else if(contains(f.value.toString(), '||', true)){
  125. var str = '';
  126. Ext.each(f.value.split('||'), function(v){
  127. if(v != null && v != ''){
  128. if(str == ''){
  129. str += f.name + "='" + v + "'";
  130. } else {
  131. str += ' OR ' + f.name + "='" + v + "'";
  132. }
  133. }
  134. });
  135. if(condition == ''){
  136. condition += "(" + str + ")";
  137. } else {
  138. condition += ' AND (' + str + ")";
  139. }
  140. } else if(f.value.toString().charAt(0) == '!'){
  141. if(condition == ''){
  142. condition += 'nvl(' + f.name + ",' ')<>'" + f.value.substr(1) + "'";
  143. } else {
  144. condition += ' AND (nvl(' + f.name + ",' ')<>'" + f.value.substr(1) + "')";
  145. }
  146. } else {
  147. if(f.value.toString().indexOf('%') >= 0) {
  148. if(condition == ''){
  149. condition += f.name + " like '" + f.value + "'";
  150. } else {
  151. condition += ' AND (' + f.name + " like '" + f.value + "')";
  152. }
  153. } else {
  154. if(condition == ''){
  155. condition += f.name + "='" + f.value + "'";
  156. } else {
  157. condition += ' AND (' + f.name + "='" + f.value + "')";
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. }
  165. });
  166. return condition;
  167. },
  168. createFilterPanel: function(btn) {
  169. var me = this;
  170. var filter = Ext.create('Ext.Window', {
  171. id: btn.getId() + '-filter',
  172. style: 'background:#f1f1f1',
  173. title: '筛选条件',
  174. width: 500,
  175. height: 415,
  176. layout: 'column',
  177. defaults: {
  178. margin: '2 2 2 10'
  179. },
  180. modal:true,
  181. items: [{
  182. xtype:'condatefield',
  183. id:'bc_recorddate',
  184. name:'bc_recorddate',
  185. columnWidth:1,
  186. fieldLabel:'商机日期'
  187. },{
  188. xtype: 'multifield',
  189. id: 'bc_custcode',
  190. name: 'bc_custcode',
  191. secondname:'bc_custname',
  192. columnWidth: 1,
  193. fieldLabel:'商机客户'
  194. },{
  195. xtype: 'multifield',
  196. id: 'bc_departmentcode',
  197. name: 'bc_departmentcode',
  198. secondname:'bc_department',
  199. columnWidth: 1,
  200. fieldLabel:'部门'
  201. },{
  202. xtype: 'combo',
  203. id: 'bc_currentprocess',
  204. name: 'bc_currentprocess',
  205. columnWidth: .5,
  206. fieldLabel:'商机阶段',
  207. queryMode: 'local',
  208. displayField: 'display',
  209. valueField: 'value',
  210. editable: false,
  211. store: Ext.create('Ext.data.Store', {
  212. fields: ['display', 'value'],
  213. data : [ ]
  214. }),
  215. listeners: {
  216. afterrender: function(f) {
  217. me.getStages(f);
  218. }
  219. }
  220. }],
  221. buttonAlign: 'center',
  222. buttons: [{
  223. text: '确定',
  224. width: 60,
  225. cls: 'x-btn-blue',
  226. handler: function(btn) {
  227. var fl = btn.ownerCt.ownerCt,
  228. con = me.getCondition(fl);
  229. me.query(con);
  230. fl.hide();
  231. }
  232. },{
  233. text: '关闭',
  234. width: 60,
  235. cls: 'x-btn-blue',
  236. handler: function(btn) {
  237. var fl = btn.ownerCt.ownerCt;
  238. fl.hide();
  239. }
  240. }]
  241. });
  242. return filter;
  243. },
  244. query: function(con) {
  245. var grid = Ext.getCmp('processgrid');
  246. grid.loadNewData(grid,con);
  247. },
  248. getStages: function(f) {
  249. Ext.Ajax.request({
  250. url : basePath + 'common/getFieldDatas.action',
  251. async: false,
  252. params: {
  253. caller: 'BusinessChanceStage',
  254. field: 'bs_name',
  255. condition: '1=1 order by bs_detno asc'
  256. },
  257. method : 'post',
  258. callback : function(options,success,response){
  259. var rs = new Ext.decode(response.responseText);
  260. if(rs.exceptionInfo){
  261. showError(rs.exceptionInfo);return null;
  262. }
  263. if(rs.success && rs.data){
  264. var cr = rs.data.split('#'),c = new Array();
  265. Ext.each(cr, function(r){
  266. c.push({display: r, value: r});
  267. });
  268. f.store.add(c);
  269. }
  270. }
  271. });
  272. }
  273. });