MultiDbfindTrigger.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /**
  2. * multi dbfind trigger
  3. * 改了下MultiDbfindTrigger的赋值方式,在grid中也会把多选的值用#号连接
  4. */
  5. Ext.define('uas.view.trigger.MultiDbfindTrigger', {
  6. extend: 'Ext.form.ComboBox',
  7. alias: 'widget.multidbfindtrigger',
  8. triggerCls: 'x-form-search-trigger',
  9. queryMode: 'local',
  10. displayField: 'dispaly',
  11. valueField: 'value',
  12. triggerCls: 'x-form-search-trigger',
  13. minChars:1, // 设置用户输入字符多少时触发查询
  14. tpl: '',
  15. enableKeyEvents:true,
  16. initComponent: function () {
  17. var me = this;
  18. Ext.apply(me, me.applyConfig());
  19. me.callParent();
  20. },
  21. applyConfig: function() {
  22. var me = this,
  23. dbtpls = me.dbtpls || [],
  24. fields = [],
  25. minWidth = 0,
  26. cols = '';
  27. for(let x = 0; x < dbtpls.length; x++) {
  28. let dbtpl = dbtpls[x],
  29. width = dbtpl.width || 100,
  30. field = dbtpl.field;
  31. fields.push(field);
  32. minWidth += width;
  33. if(dbtpls.length==(x+1)){
  34. cols += '<span style="padding:0 10px 0 10px;width:' + width + 'px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{' + field + '}</span>';
  35. }else{
  36. cols += '<span style="padding:0 10px 0 10px;width:' + width + 'px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;float:left;">{' + field + '}</span>';
  37. }
  38. }
  39. minWidth += 15;
  40. cfg = {
  41. store: Ext.create('Ext.data.Store', {
  42. fields: fields,
  43. data: []
  44. }),
  45. listConfig: {
  46. minWidth: minWidth,
  47. width: minWidth,
  48. maxHeight: 210,
  49. autoScroll: true
  50. },
  51. tpl: Ext.create('Ext.XTemplate',
  52. '<ul style="padding-left: 0px;"><tpl for=".">',
  53. '<li role="option" class="x-boundlist-item" style="list-style:none; padding: 0;">',
  54. '<div style="height:30px;">',
  55. '' + cols + '',
  56. '</li>',
  57. '</tpl></ul>'
  58. )
  59. };
  60. return cfg;
  61. },
  62. //输入值之后进行模糊查询
  63. doQuery: function(queryString, forceAll, rawQuery) {
  64. if(!this.fireEvent('beforequery', this)) {
  65. return;
  66. };
  67. queryString = queryString || '';
  68. var me = this;
  69. me.judge(me);
  70. var dbfinds=me.dbfinds;
  71. me.lastQueryValue=queryString;
  72. if(queryString.trim()==''){
  73. me.collapse( );
  74. }else{
  75. //加载数据
  76. var data,dbCondition=[];
  77. if(me.dbfinds){
  78. var dbtplcondition = "";
  79. for (let index = 0; index < dbfinds.length; index++) {
  80. var item = dbfinds[index].from;
  81. if(!dbfinds[index].ignore){
  82. dbtplcondition+= "upper("+item+") like '%"+queryString.toUpperCase()+"%' or ";
  83. }
  84. }
  85. dbtplcondition = "(" + dbtplcondition.substring(0,dbtplcondition.length-4) + ")";
  86. if(dbtplcondition.length>0){
  87. dbCondition = [{
  88. type: 'condition',
  89. value:dbtplcondition
  90. }];
  91. }
  92. }
  93. //添加默认条件
  94. if(me.defaultCondition) {
  95. dbCondition.push({
  96. type: 'condition',
  97. value: me.defaultCondition
  98. });
  99. }
  100. Ext.Ajax.request({
  101. url: me.dataUrl,
  102. params: {
  103. number: 1,
  104. size: 10,
  105. condition:JSON.stringify(dbCondition),
  106. page: 1,
  107. start: 0,
  108. limit: 10
  109. },
  110. method: 'GET',
  111. success: function(response, opts) {
  112. data = Ext.decode(response.responseText);
  113. data = data.data?data.data.list:[];
  114. if(data!=null && data.length>0 && me.store){
  115. me.store.loadData(data,false);
  116. me.expand();
  117. }else{
  118. me.store.removeAll();
  119. me.collapse();
  120. }
  121. },
  122. failure: function(response, opts) {}
  123. });
  124. }
  125. return true;
  126. },
  127. onTriggerClick:function(f){
  128. if(!this.fireEvent('beforetriggerclick', this)) {
  129. return;
  130. };
  131. f.blur(f);
  132. //判断dbfindtrigger归属
  133. f.judge(f);
  134. var panel = f.up('content-panel') || Ext.getCmp('content-panel'),panelEl;
  135. if(!f.column&&f.ownerCt.ownerCt.id.indexOf('window-')>-1){
  136. panelEl = f.ownerCt.ownerCt.getEl();
  137. }else{
  138. panelEl = panel.getEl()
  139. }
  140. var box = panelEl.getBox();
  141. var height = box.height;
  142. var width = box.width;
  143. var win = panel.add(Ext.create('Ext.window.Window', {
  144. cls:'x-window-dbfind',
  145. trigger:f,
  146. belong:f.ownerCt,
  147. modal:true,
  148. height: height * 0.9,
  149. width: width * 0.9,
  150. title: '查找' + f.addTitle,
  151. scrollable: true,
  152. bodyPadding: 10,
  153. constrain: true,
  154. closable: true,
  155. layout:'fit',
  156. renderTo:panelEl,
  157. items:[{
  158. xtype:'multidbfindtriggerpanel',
  159. columns: f.dbColumns,
  160. dataUrl: f.dataUrl,
  161. dbfinds: f.dbfinds,
  162. belong: f.belong,
  163. searchUrl: f.searchUrl,
  164. dbSearchFields:f.dbSearchFields?f.dbSearchFields:[],
  165. dbfindtrigger:f
  166. }]
  167. }));
  168. win.show();
  169. },
  170. listeners: {
  171. blur:function(f,e){
  172. return true;//先不使用
  173. var me = f,data;
  174. var dbfinds = me.dbfinds;
  175. if(f.value&&f.value!=''){
  176. //添加默认条件
  177. var searchField = null;
  178. var dbCondition = [];
  179. if(me.defaultCondition) {
  180. dbCondition.push({
  181. type: 'condition',
  182. value: me.defaultCondition
  183. });
  184. }
  185. for (let index = 0; index < dbfinds.length; index++) {
  186. var item = dbfinds[index].to;
  187. if(item==me.name){
  188. searchField = dbfinds[index].from;
  189. }
  190. }
  191. dbCondition.push({
  192. type: 'condition',
  193. value: searchField + "='"+me.value+"'"
  194. });
  195. Ext.Ajax.request({
  196. url: me.dataUrl,
  197. async:false,
  198. params: {
  199. number: 1,
  200. size: 1,
  201. condition:JSON.stringify(dbCondition),
  202. page: 1,
  203. start: 0,
  204. limit: 10
  205. },
  206. method: 'GET',
  207. success: function(response, opts) {
  208. data = Ext.decode(response.responseText);
  209. data = data.data?data.data.list:[];
  210. },
  211. failure: function(response, opts) {}
  212. });
  213. }
  214. if(!f.value||f.value==''||data.length>1||data.length==0){
  215. if(dbfinds&&dbfinds.length>0){
  216. if(me.belong=='grid'){
  217. for (let index = 0; index < dbfinds.length; index++) {
  218. var item = dbfinds[index];
  219. var rec = me.column.ownerCt.ownerCt.selModel.getLastSelected();
  220. var nowRec = me.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
  221. if(nowRec.get(item.to)&&nowRec.get(item.to)!=""){
  222. nowRec.set(item.to,null);
  223. }
  224. if(nowRec.modified){
  225. delete nowRec.modified[item.to];
  226. }
  227. if(JSON.stringify(nowRec.modified)=="{}"){
  228. nowRec.dirty = false
  229. }
  230. if(me.name==item.to){
  231. me.column.getEditor().setValue('');
  232. }
  233. }
  234. }
  235. }
  236. }else if(data.length==1){
  237. if(dbfinds&&dbfinds.length>0){
  238. if(me.belong=='grid'){
  239. for (let index = 0; index < dbfinds.length; index++) {
  240. var item = dbfinds[index];
  241. var rec = me.column.ownerCt.ownerCt.selModel.getLastSelected();
  242. var nowRec = me.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
  243. nowRec.set(item.to,data[0][item.from]);
  244. if(me.name==item.to){
  245. me.column.getEditor().setValue(data[0][item.from]);
  246. }
  247. }
  248. }
  249. }
  250. }
  251. },
  252. select:function(combo,record,eOpts){
  253. var me = combo;
  254. var dbfinds = me.dbfinds;
  255. if(dbfinds&&dbfinds.length>0){
  256. if(me.belong=='grid'){
  257. for (let index = 0; index < dbfinds.length; index++) {
  258. var item = dbfinds[index];
  259. var rec = me.column.ownerCt.ownerCt.selModel.getLastSelected();
  260. var nowRec = me.column.ownerCt.ownerCt.store.getData().getByKey(rec.id);
  261. nowRec.set(item.to,record.get(item.from));
  262. if(me.name==item.to){
  263. me.column.getEditor().setValue(record.get(item.from));
  264. }
  265. }
  266. }else if(me.belong=='form'){
  267. for (let index = 0; index < dbfinds.length; index++) {
  268. var item = dbfinds[index];
  269. var field = me.ownerCt.down('[name='+item.to+']');
  270. if(field){
  271. var val = record.get(item.from);
  272. if(field.xtype=='dbfindtrigger'){
  273. field.setRawValue(val);
  274. field.value = val;
  275. field.lastTriggerValue=val;
  276. }else{
  277. field.setValue(val);
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. },
  285. judge:function(f){
  286. if(f.ownerCt.xtype.trim().toUpperCase().indexOf('QUERYFORMPANEL')>-1){
  287. f.belong = 'form';
  288. return f.ownerCt.ownerCt
  289. }else if(f.ownerCt.xtype.trim().toUpperCase().indexOf('FORMPANEL')>-1){
  290. f.belong = 'form';
  291. return f.ownerCt
  292. }else if(f.column){
  293. f.belong = 'grid';
  294. return f.column.ownerCt.ownerCt.ownerCt
  295. }
  296. }
  297. });