DbfindTriggerPanel.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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.95,
  26. width:grid.getWidth()*0.95,
  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: 10,
  91. grid:me,
  92. data: [],
  93. proxy: {
  94. type: 'ajax',
  95. timeout:8000,
  96. url: me.dataUrl,
  97. actionMethods: {
  98. read: 'GET'
  99. },
  100. reader: {
  101. type: 'json',
  102. rootProperty: 'data.list',
  103. totalProperty: 'data.total',
  104. },
  105. listeners: {
  106. exception: function(proxy, response, operation, eOpts) {
  107. if(operation.success) {
  108. if(response.timedout) {
  109. saas.util.BaseUtil.showErrorToast('请求超时');
  110. }
  111. }else {
  112. console.error('exception: ', response);
  113. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  114. }
  115. }
  116. }
  117. },
  118. listeners: {
  119. beforeload: function (store, op) {
  120. var condition = me.condition;
  121. if (Ext.isEmpty(condition)) {
  122. condition = [];
  123. }
  124. //添加默认条件
  125. if(me.up('window').trigger.defaultCondition) {
  126. condition.push({
  127. type: 'condition',
  128. value: me.ownerCt.trigger.defaultCondition
  129. });
  130. }
  131. Ext.apply(store.proxy.extraParams, {
  132. number: op._page,
  133. size: store.pageSize,
  134. condition: JSON.stringify(condition)
  135. });
  136. },
  137. load: function(store, records, successful, operation, eOpts) {
  138. const grid = store.grid;
  139. const paging = grid.down('[xtype=dataListPaging]');
  140. const pageCountItem = paging.down('#pageCountItem');
  141. const dataCount = paging.down('#dataCountItem');
  142. if(store.totalCount!==Number.MAX_SAFE_INTEGER){
  143. //展示*号
  144. if(store.currentPage===Number.MAX_SAFE_INTEGER){
  145. let page = store.totalCount/store.pageSize;
  146. page = page>parseInt(page)?page+1:page;
  147. store.currentPage = page;
  148. paging.down('#inputItem').setValue(page);
  149. }
  150. pageCountItem.update(Ext.String.format(paging.afterPageText,store.currentPage));
  151. dataCount.setValue("行/共"+store.totalCount+"行");
  152. }
  153. }
  154. }
  155. });
  156. }
  157. me.callParent(arguments);
  158. me.getSearchPlan();
  159. },
  160. listeners:{
  161. itemClick: function(view,record) {
  162. var me = this;
  163. var dbfinds = me.dbfinds;
  164. var ownerTrigger = me.ownerCt.trigger;
  165. ownerTrigger.dbValues = record.data;
  166. if(dbfinds&&dbfinds.length>0){
  167. if(me.belong=='grid'){
  168. for (let index = 0; index < dbfinds.length; index++) {
  169. var item = dbfinds[index];
  170. var mainGrid = me.dbfindtrigger.column.ownerCt.ownerCt;
  171. var rec = mainGrid.selModel.getLastSelected();
  172. if(rec){
  173. var nowRec = me.dbfindtrigger.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
  174. nowRec.set(item.to,record.get(item.from));
  175. //me.column.getEditor().setValue(record.get(item.from));
  176. //mainGrid.up('detailGridField').fireEvent('edit');
  177. }
  178. }
  179. }else if(me.belong=='form'){
  180. for (let index = 0; index < dbfinds.length; index++) {
  181. var item = dbfinds[index];
  182. var field = me.ownerCt.belong.down('[name='+item.to+']');
  183. if(field){
  184. var val = record.get(item.from);
  185. if(field.xtype=='dbfindtrigger'){
  186. field.setValue(val);
  187. field.lastTriggerValue=val;
  188. }else{
  189. field.setValue(val);
  190. }
  191. }
  192. }
  193. }else {
  194. var dbfind = Ext.Array.findBy(dbfinds, function(d) {
  195. return d.to = ownerTrigger.name;
  196. });
  197. if(dbfind) {
  198. ownerTrigger.setValue(record.get(dbfind.from));
  199. }
  200. }
  201. ownerTrigger.aftertrigger(ownerTrigger,record);
  202. }
  203. me.ownerCt.close();
  204. }
  205. },
  206. initColumns: function() {
  207. var me = this,
  208. columns = me.columns || [];
  209. Ext.Array.each(columns, function(c) {
  210. Ext.applyIf(c, {
  211. width: 200
  212. });
  213. });
  214. },
  215. getSearchFields: function() {
  216. var me = this,
  217. searchFields = me.dbSearchFields;
  218. Ext.Array.each(searchFields, function(f) {
  219. f.enableKeyEvents = true;
  220. f.listeners = {
  221. keydown: function(th, e, eOpts) {
  222. if(e.keyCode == 13) {
  223. me.condition = '', items = [];
  224. Ext.Array.each(searchFields,function(f) {
  225. var field = th.ownerCt.down('[name='+f.name+']')
  226. items.push(field);
  227. });
  228. me.condition = me.getCondition(items);
  229. me.store.loadPage(1);
  230. }
  231. }
  232. }
  233. });
  234. return searchFields;
  235. },
  236. /**
  237. * 获得过滤条件
  238. */
  239. getCondition: function(items) {
  240. var me = this,
  241. conditions = [];
  242. for(var i = 0; i < items.length; i++) {
  243. var item = items[i];
  244. var field = item.name,
  245. func = item.getCondition,
  246. value = item.value,
  247. condition;
  248. if(value&&value!=''){
  249. if(typeof func == 'function') {
  250. condition = {
  251. type: 'condition',
  252. value: func(value)
  253. }
  254. }else {
  255. var xtype = item.xtype || 'textfield',
  256. type = item.fieldType || me.getDefaultFieldType(xtype),
  257. operation = item.operation || me.getDefaultFieldOperation(xtype),
  258. conditionValue = me.getConditionValue(xtype, value);
  259. if(!conditionValue) {
  260. continue;
  261. }
  262. condition = {
  263. type: type,
  264. field: field,
  265. operation: operation,
  266. value: conditionValue
  267. }
  268. }
  269. conditions.push(condition);
  270. }
  271. };
  272. return conditions;
  273. },
  274. getDefaultFieldType: function(xtype) {
  275. var type;
  276. if(Ext.Array.contains(['numberfield'], xtype)) {
  277. type = 'number';
  278. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  279. type = 'date';
  280. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  281. type = 'enum';
  282. }else {
  283. type = 'string';
  284. }
  285. return type;
  286. },
  287. getDefaultFieldOperation: function(xtype) {
  288. var operation;
  289. if(Ext.Array.contains(['numberfield'], xtype)) {
  290. operation = '=';
  291. }else if(Ext.Array.contains(['datefield'], xtype)) {
  292. operation = '=';
  293. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  294. operation = 'between';
  295. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  296. operation = 'in';
  297. }else {
  298. operation = 'like';
  299. }
  300. return operation;
  301. },
  302. /**
  303. * 处理部分字段值
  304. */
  305. getConditionValue: function(xtype, value) {
  306. var conditionValue;
  307. if(xtype == 'datefield') {
  308. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  309. }else if(xtype == 'condatefield') {
  310. var from = value.from,
  311. to = value.to;
  312. 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');
  313. }else if(xtype == 'combobox' || xtype == 'combo') {
  314. conditionValue = '\'' + value + '\'';
  315. }else if(xtype == 'multicombo') {
  316. conditionValue = value.map(function(v) {
  317. return '\'' + v.value + '\'';
  318. }).join(',');
  319. }else {
  320. conditionValue = value;
  321. }
  322. return conditionValue;
  323. },
  324. onAddClick: function(){
  325. var grid = this;
  326. var trigger = grid.ownerCt.trigger;
  327. saas.util.BaseUtil.openTab(trigger.addXtype, '新增'+trigger.addTitle,trigger.addXtype + '_add');
  328. },
  329. getSearchPlan:function(){
  330. const me = this;
  331. Ext.Ajax.request({
  332. url: me.searchUrl,
  333. params: '',
  334. method: 'GET',
  335. async:false,
  336. success: function(response, opts) {
  337. var _data = Ext.decode(response.responseText);
  338. if(_data&&_data.data){
  339. const searchPlan = me.down('[name=searchPlan]');
  340. let items = [];
  341. Ext.Array.each(_data.data,function(p){
  342. if(p.children&&p.children.length>0){
  343. Ext.Array.each(p.children,function(item){
  344. items.push({
  345. text:item.text,
  346. xtype:'button'
  347. })
  348. })
  349. }
  350. });
  351. searchPlan.add(items);
  352. }
  353. },
  354. failure: function(response, opts) {}
  355. });
  356. }
  357. });