FtFindField.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /**
  2. * From-To dbfindtrigger
  3. * @author yingp
  4. */
  5. Ext.define('erp.view.core.form.FtFindField', {
  6. extend: 'Ext.form.FieldContainer',
  7. alias: 'widget.ftfindfield',
  8. layout: 'column',
  9. value: "BETWEEN '' AND ''",
  10. valuePrint:"",
  11. baseCls: null,
  12. autoScroll: false,
  13. height: 22,
  14. items: [],
  15. initComponent : function(){
  16. this.callParent(arguments);
  17. var me = this, allowBlank = (Ext.isDefined(me.allowBlank) ? me.allowBlank : true);
  18. Ext.apply(me.fieldDefaults, {
  19. allowBlank: allowBlank
  20. });
  21. me.from = me.insert(0, {
  22. xtype: 'dbfindtrigger',
  23. id: me.name + '_from',
  24. name: me.name,
  25. columnWidth: 0.5,
  26. fieldStyle: me.fieldStyle,
  27. listeners: {
  28. change: function(f){
  29. var from = f.value;
  30. var to = me.items.items[1].value;
  31. from = from == null || from == '' ? to == null || to == '' ? '' : to : from;
  32. to = to == null || to == '' ? from == null || from == '' ? '' : from : to;
  33. if(from == ''){
  34. me.value = '';
  35. me.valuePrint = '';
  36. } else {
  37. me.value = "BETWEEN '" + from + "' AND '" + to + "'";
  38. if(me.ownerCt){
  39. var tablename = me.ownerCt.tablename;
  40. me.valuePrint="{"+tablename+"."+me.name+"}>='"+from+"' and {"+tablename+"."+me.name+"}<='"+to+"'";
  41. }
  42. }
  43. },
  44. select:function(combo,records,eOpts){
  45. var con ="";
  46. var which = 'form';
  47. var cal = combo.dbCaller||caller;
  48. var key = combo.triggerName||combo.name;
  49. Ext.each(records,function(data){
  50. con = !Ext.isEmpty(data.data[Ext.util.Format.lowercase(combo.searchFieldArray)]) ? (combo.searchFieldArray + " = '" + data.data[Ext.util.Format.lowercase(combo.searchFieldArray)].replace(/\'/g,"''") + "'") : null;
  51. });
  52. me.setSelectValue(combo,which, cal, key, combo.getCondition(con)); //光标移开后自动dbfind
  53. }
  54. }
  55. });
  56. me.to = me.insert(1, {
  57. xtype: 'dbfindtrigger',
  58. id: me.name + '_to',
  59. name: me.name,
  60. columnWidth: 0.5,
  61. fieldStyle: me.fieldStyle,
  62. listeners: {
  63. change: function(f){
  64. var from = me.items.items[0].value;
  65. var to = f.value;
  66. from = from == null || from == '' ? to == null || to == '' ? '' : to : from;
  67. to = to == null || to == '' ? from == null || from == '' ? '' : from : to;
  68. if(from == ''){
  69. me.value = '';
  70. me.valuePrint = '';
  71. } else {
  72. me.value = "BETWEEN '" + from + "' AND '" + to + "'";
  73. if(me.ownerCt){
  74. var tablename = me.ownerCt.tablename;
  75. me.valuePrint="{"+tablename+"."+me.name+"}>='"+from+"' and {"+tablename+"."+me.name+"}<='"+to+"'";
  76. }
  77. }
  78. },
  79. select:function(combo,records,eOpts){
  80. var con ="";
  81. var which = 'form';
  82. var cal = combo.dbCaller||caller;
  83. var key = combo.triggerName||combo.name;
  84. Ext.each(records,function(data){
  85. con = !Ext.isEmpty(data.data[Ext.util.Format.lowercase(combo.searchFieldArray)]) ? (combo.searchFieldArray + " = '" + data.data[Ext.util.Format.lowercase(combo.searchFieldArray)].replace(/\'/g,"''") + "'") : null;
  86. });
  87. me.setSelectValue(combo,which, cal, key, combo.getCondition(con)); //光标移开后自动dbfind
  88. }
  89. }
  90. });
  91. },
  92. setValue: function(v){
  93. var f = Ext.getCmp(window.onTriggerClick);
  94. if(f){
  95. f.setValue(v);
  96. }
  97. if(v != null && v != '' && contains(v, '~', true)){
  98. this.items.items[0].setValue(v.split('~')[0]);
  99. this.items.items[1].setValue(v.split('~')[1]);
  100. }
  101. },
  102. listeners: {
  103. afterrender: function(){
  104. var tb = this.getEl().dom;
  105. if(tb.nodeName == 'TABLE') {
  106. return;
  107. }
  108. tb.childNodes[1].style.height = 22;
  109. tb.childNodes[1].style.overflow = 'hidden';
  110. }
  111. },
  112. reset: function(){
  113. this.items.items[0].reset();
  114. this.items.items[1].reset();
  115. },
  116. getValue: function(){
  117. if(this.items.items[0].value != null && this.items.items[0].value != ''){
  118. if(this.items.items[0].value == null || this.items.items[0].value == ''){
  119. return this.items.items[1].value + '~' + this.items.items[1].value;
  120. } else if(this.items.items[1].value == null || this.items.items[1].value == ''){
  121. return this.items.items[0].value + '~' + this.items.items[0].value;
  122. } else {
  123. return this.items.items[0].value + '~' + this.items.items[1].value;
  124. }
  125. } else {
  126. return '';
  127. }
  128. },
  129. isValid: function(){
  130. return true;
  131. },
  132. getFilter: function() {
  133. var me = this, fromVal = me.from.getValue(), toVal = me.to.getValue();
  134. return (fromVal || toVal) ? {
  135. "gte": fromVal,
  136. "lte": toVal
  137. } : null;
  138. },
  139. setSelectValue: function(trigger,which, caller, field, condition) {
  140. var me = this;
  141. Ext.Ajax.request({
  142. url: basePath + 'common/autoDbfind.action',
  143. params: {
  144. which: which,
  145. caller: caller,
  146. field: field,
  147. condition: condition,
  148. _config:getUrlParam('_config')
  149. },
  150. async: false,
  151. method: 'post',
  152. callback: function(options, success, response) {
  153. var res = new Ext.decode(response.responseText);
  154. if (res.exceptionInfo) {
  155. showError(res.exceptionInfo);
  156. return;
  157. }
  158. if (res.data) {
  159. var data = Ext.decode(res.data.replace(/,}/g, '}').replace(/,]/g, ']'));
  160. Ext.Array.each(res.dbfinds,function(ds){
  161. if (trigger.name.toUpperCase() == ds.field.toUpperCase()){
  162. trigger.setValue(data[0][ds.dbGridField]);
  163. }
  164. });
  165. } else {
  166. if (me.autoShowTriggerWin)
  167. me.onTriggerClick();
  168. }
  169. }
  170. });
  171. }
  172. });