DbfindTriggerPanel.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. Ext.define('uas.view.trigger.DbfindTriggerPanel', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'dbfindtriggerpanel',
  4. dataUrl: '',
  5. dbSearchFields: [],
  6. condition:'',
  7. plugins: {
  8. gridHeaderFilter: true
  9. },
  10. dockedItems: [{
  11. name:'operateToolbar',
  12. cls:'x-grid-operateToolbar',
  13. xtype: 'toolbar',
  14. dock: 'top',
  15. height:32,
  16. items:[{
  17. cls:'x-btn-blue',
  18. xtype:'button',
  19. text:'筛选',
  20. handler:function(me){
  21. const grid = me.up('dbfindtriggerpanel');
  22. if(!grid.searchPlanWindow){
  23. grid.searchPlanWindow = Ext.create('widget.searchPlanWindow',{
  24. modal: false,
  25. height:grid.getHeight()*0.8,
  26. width:grid.getWidth()*0.8,
  27. renderTo:grid.ownerCt.getEl(),
  28. grid:grid
  29. }).show();
  30. }else{
  31. grid.searchPlanWindow.show();
  32. }
  33. }
  34. },{
  35. margin:'0 0 0 6',
  36. xtype:'button',
  37. text:'批处理'
  38. },{
  39. margin:'0 0 0 6',
  40. xtype:'button',
  41. text:'上一页'
  42. },{
  43. margin:'0 0 0 6',
  44. xtype:'button',
  45. text:'下一页'
  46. },{
  47. margin:'0 0 0 6',
  48. xtype:'button',
  49. text:'导出'
  50. },{
  51. margin:'0 0 0 6',
  52. xtype:'button',
  53. text:'个性设置'
  54. },{
  55. margin:'0 0 0 12',
  56. xtype:'button',
  57. text:'关闭'
  58. }]
  59. },{
  60. xtype: 'toolbar',
  61. dock: 'top',
  62. name:'searchPlan',
  63. cls:'x-grid-searchPlan',
  64. height:32,
  65. items:[{
  66. xtype:'displayfield',
  67. value:'查询方案:'
  68. }]
  69. },{
  70. xtype: 'toolbar',
  71. dock: 'top',
  72. name:'filterToolbar',
  73. cls:'x-grid-filterToolbar',
  74. height:32,
  75. items:[{
  76. xtype:'displayfield',
  77. value:'筛选条件:'
  78. },'->']
  79. },{
  80. xtype: 'dataListPaging'
  81. }],
  82. initComponent: function() {
  83. var me = this;
  84. me.initColumns();
  85. if(me.columns){
  86. var fields = me.columns.map(column => column.dataIndex);
  87. me.store = Ext.create('Ext.data.Store',{
  88. fields:fields,
  89. autoLoad: true,
  90. pageSize: 20,
  91. data: [],
  92. proxy: {
  93. type: 'ajax',
  94. timeout:8000,
  95. url: me.dataUrl,
  96. actionMethods: {
  97. read: 'GET'
  98. },
  99. reader: {
  100. type: 'json',
  101. rootProperty: 'data.list',
  102. totalProperty: 'data.total',
  103. },
  104. listeners: {
  105. exception: function(proxy, response, operation, eOpts) {
  106. if(operation.success) {
  107. if(response.timedout) {
  108. saas.util.BaseUtil.showErrorToast('请求超时');
  109. }
  110. }else {
  111. console.error('exception: ', response);
  112. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  113. }
  114. }
  115. }
  116. },
  117. listeners: {
  118. beforeload: function (store, op) {
  119. var condition = me.condition;
  120. if (Ext.isEmpty(condition)) {
  121. condition = [];
  122. }
  123. //添加默认条件
  124. if(me.up('window').trigger.defaultCondition) {
  125. condition.push({
  126. type: 'condition',
  127. value: me.ownerCt.trigger.defaultCondition
  128. });
  129. }
  130. Ext.apply(store.proxy.extraParams, {
  131. number: op._page,
  132. size: store.pageSize,
  133. condition: JSON.stringify(condition)
  134. });
  135. }
  136. }
  137. });
  138. }
  139. me.callParent(arguments);
  140. me.getSearchPlan();
  141. },
  142. listeners:{
  143. boxready: function(grid, width, height, eOpts) {
  144. var store = grid.getStore(),
  145. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  146. gridBodyBoxHeight = gridBodyBox.height;
  147. var pageSize = Math.floor(gridBodyBoxHeight / 33);
  148. store.setPageSize(pageSize);
  149. },
  150. itemClick: function(view,record) {
  151. var me = this;
  152. var dbfinds = me.dbfinds;
  153. var ownerTrigger = me.ownerCt.trigger;
  154. ownerTrigger.dbValues = record.data;
  155. if(dbfinds&&dbfinds.length>0){
  156. if(me.belong=='grid'){
  157. for (let index = 0; index < dbfinds.length; index++) {
  158. var item = dbfinds[index];
  159. var mainGrid = me.dbfindtrigger.column.ownerCt.ownerCt;
  160. var rec = mainGrid.selModel.getLastSelected();
  161. if(rec){
  162. var nowRec = me.dbfindtrigger.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
  163. nowRec.set(item.to,record.get(item.from));
  164. //me.column.getEditor().setValue(record.get(item.from));
  165. //mainGrid.up('detailGridField').fireEvent('edit');
  166. }
  167. }
  168. }else if(me.belong=='form'){
  169. for (let index = 0; index < dbfinds.length; index++) {
  170. var item = dbfinds[index];
  171. var field = me.ownerCt.belong.down('[name='+item.to+']');
  172. if(field){
  173. var val = record.get(item.from);
  174. if(field.xtype=='dbfindtrigger'){
  175. field.setValue(val);
  176. field.lastTriggerValue=val;
  177. }else{
  178. field.setValue(val);
  179. }
  180. }
  181. }
  182. }else {
  183. var dbfind = Ext.Array.findBy(dbfinds, function(d) {
  184. return d.to = ownerTrigger.name;
  185. });
  186. if(dbfind) {
  187. ownerTrigger.setValue(record.get(dbfind.from));
  188. }
  189. }
  190. ownerTrigger.aftertrigger(ownerTrigger,record);
  191. }
  192. me.ownerCt.close();
  193. }
  194. },
  195. initColumns: function() {
  196. var me = this,
  197. columns = me.columns || [];
  198. Ext.Array.each(columns, function(c) {
  199. Ext.applyIf(c, {
  200. width: 200
  201. });
  202. });
  203. },
  204. getSearchFields: function() {
  205. var me = this,
  206. searchFields = me.dbSearchFields;
  207. Ext.Array.each(searchFields, function(f) {
  208. f.enableKeyEvents = true;
  209. f.listeners = {
  210. keydown: function(th, e, eOpts) {
  211. if(e.keyCode == 13) {
  212. me.condition = '', items = [];
  213. Ext.Array.each(searchFields,function(f) {
  214. var field = th.ownerCt.down('[name='+f.name+']')
  215. items.push(field);
  216. });
  217. me.condition = me.getCondition(items);
  218. me.store.loadPage(1);
  219. }
  220. }
  221. }
  222. });
  223. return searchFields;
  224. },
  225. /**
  226. * 获得过滤条件
  227. */
  228. getCondition: function(items) {
  229. var me = this,
  230. conditions = [];
  231. for(var i = 0; i < items.length; i++) {
  232. var item = items[i];
  233. var field = item.name,
  234. func = item.getCondition,
  235. value = item.value,
  236. condition;
  237. if(value&&value!=''){
  238. if(typeof func == 'function') {
  239. condition = {
  240. type: 'condition',
  241. value: func(value)
  242. }
  243. }else {
  244. var xtype = item.xtype || 'textfield',
  245. type = item.fieldType || me.getDefaultFieldType(xtype),
  246. operation = item.operation || me.getDefaultFieldOperation(xtype),
  247. conditionValue = me.getConditionValue(xtype, value);
  248. if(!conditionValue) {
  249. continue;
  250. }
  251. condition = {
  252. type: type,
  253. field: field,
  254. operation: operation,
  255. value: conditionValue
  256. }
  257. }
  258. conditions.push(condition);
  259. }
  260. };
  261. return conditions;
  262. },
  263. getDefaultFieldType: function(xtype) {
  264. var type;
  265. if(Ext.Array.contains(['numberfield'], xtype)) {
  266. type = 'number';
  267. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  268. type = 'date';
  269. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  270. type = 'enum';
  271. }else {
  272. type = 'string';
  273. }
  274. return type;
  275. },
  276. getDefaultFieldOperation: function(xtype) {
  277. var operation;
  278. if(Ext.Array.contains(['numberfield'], xtype)) {
  279. operation = '=';
  280. }else if(Ext.Array.contains(['datefield'], xtype)) {
  281. operation = '=';
  282. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  283. operation = 'between';
  284. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  285. operation = 'in';
  286. }else {
  287. operation = 'like';
  288. }
  289. return operation;
  290. },
  291. /**
  292. * 处理部分字段值
  293. */
  294. getConditionValue: function(xtype, value) {
  295. var conditionValue;
  296. if(xtype == 'datefield') {
  297. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  298. }else if(xtype == 'condatefield') {
  299. var from = value.from,
  300. to = value.to;
  301. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d 00:00:00') + ',' + Ext.Date.format(new Date(to), 'Y-m-d 23:59:59');
  302. }else if(xtype == 'combobox' || xtype == 'combo') {
  303. conditionValue = '\'' + value + '\'';
  304. }else if(xtype == 'multicombo') {
  305. conditionValue = value.map(function(v) {
  306. return '\'' + v.value + '\'';
  307. }).join(',');
  308. }else {
  309. conditionValue = value;
  310. }
  311. return conditionValue;
  312. },
  313. onAddClick: function(){
  314. var grid = this;
  315. var trigger = grid.ownerCt.trigger;
  316. saas.util.BaseUtil.openTab(trigger.addXtype, '新增'+trigger.addTitle,trigger.addXtype + '_add');
  317. },
  318. getSearchPlan:function(){
  319. const me = this;
  320. Ext.Ajax.request({
  321. url: me.searchUrl,
  322. params: '',
  323. method: 'GET',
  324. async:false,
  325. success: function(response, opts) {
  326. var _data = Ext.decode(response.responseText);
  327. if(_data&&_data.data){
  328. const searchPlan = me.down('[name=searchPlan]');
  329. let items = [];
  330. Ext.Array.each(_data.data,function(p){
  331. if(p.children&&p.children.length>0){
  332. Ext.Array.each(p.children,function(item){
  333. items.push({
  334. text:item.text,
  335. xtype:'button'
  336. })
  337. })
  338. }
  339. });
  340. searchPlan.add(items);
  341. }
  342. },
  343. failure: function(response, opts) {}
  344. });
  345. }
  346. });