MultiDbfindTriggerPanel.js 13 KB

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