UUSetting.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. Ext.define('saas.view.document.uusetting.UUSetting', {
  2. extend: 'Ext.panel.Panel',
  3. xtype: 'document-uusetting',
  4. autoScroll: true,
  5. layout:'fit',
  6. controller:'document-uusetting',
  7. viewModel: {
  8. type: 'document-uusetting'
  9. },
  10. defaultType:'vendorkind',
  11. requires: [
  12. 'Ext.button.Segmented'
  13. ],
  14. etc:{
  15. common: {
  16. columns: [{
  17. xtype:'actioncolumn',
  18. text:'操作',
  19. align: 'center',
  20. items: [{
  21. xtype: 'button',
  22. tooltip: 'UU设置',
  23. iconCls: 'x-sa sa-setting',
  24. handler: 'onUUSetting'
  25. }]
  26. }]
  27. },
  28. vendorkind:{
  29. columns: [{
  30. text: '供应商编号',
  31. dataIndex: 've_code',
  32. width: 120
  33. }, {
  34. text: '供应商名称',
  35. dataIndex: 've_name',
  36. width: 120
  37. }, {
  38. text: '状态',
  39. dataIndex: 've_status',
  40. width: 80,
  41. align: 'center'
  42. }, {
  43. text: '类型',
  44. dataIndex: 've_type',
  45. width: 100,
  46. align: 'center'
  47. }, {
  48. text: '采购员',
  49. dataIndex: 've_buyername',
  50. width: 120,
  51. }, {
  52. text: '供应商UU',
  53. dataIndex: 've_uu',
  54. width: 120
  55. }],
  56. },
  57. customerkind:{
  58. columns: [{
  59. text: '客户编号',
  60. dataIndex: 'cu_code',
  61. width: 120
  62. }, {
  63. text: '客户名称',
  64. dataIndex: 'cu_name',
  65. width: 120
  66. }, {
  67. text: '状态',
  68. dataIndex: 'cu_status',
  69. width: 80,
  70. align: 'center'
  71. }, {
  72. text: '类型',
  73. dataIndex: 'cu_type',
  74. width: 100,
  75. align: 'center'
  76. }, {
  77. text: '业务员',
  78. dataIndex: 'cu_sellername',
  79. width: 120,
  80. }, {
  81. text: '客户UU',
  82. dataIndex: 'cu_uu',
  83. width: 120
  84. }],
  85. }
  86. },
  87. initComponent: function() {
  88. var me = this;
  89. Ext.apply(me, {
  90. dockedItems: [{
  91. xtype: 'toolbar',
  92. dock: 'top',
  93. padding: '12 5 0 12',
  94. items: [{
  95. xtype: 'segmentedbutton',
  96. reference: 'dataKind',
  97. value: 'vendorkind',
  98. name : 'segmentedbutton',
  99. items: [{
  100. name:'vendorkind',
  101. text: '供应商',
  102. value: 'vendorkind',
  103. }, {
  104. name:'customerkind',
  105. text: '客户',
  106. value: 'customerkind',
  107. }],
  108. listeners: {
  109. toggle: 'onToggle'
  110. }
  111. }, '->', {
  112. xtype: 'textfield',
  113. name: 'vendorkind',
  114. hidden: false,
  115. emptyText: '输入供应商编号或名称',
  116. getCondition: function(value) {
  117. return ' (ve_code like\'%' + value + '%\' or ve_name like \'%'+value+'%\' ) ';
  118. },
  119. enableKeyEvents: true,
  120. listeners: {
  121. keydown: function(th, e, eOpts) {
  122. if(e.keyCode == 13) {
  123. me.getController().onQuery();
  124. }
  125. }
  126. }
  127. }, {
  128. xtype: 'textfield',
  129. name: 'customerkind',
  130. hidden: true,
  131. emptyText: '输入客户编号或名称',
  132. getCondition: function(value) {
  133. return ' (cu_code like\'%' + value + '%\' or cu_name like \'%'+value+'%\' ) ';
  134. },
  135. enableKeyEvents: true,
  136. listeners: {
  137. keydown: function(th, e, eOpts) {
  138. if(e.keyCode == 13) {
  139. me.getController().onQuery();
  140. }
  141. }
  142. }
  143. }, {
  144. xtype: 'button',
  145. text: '查询',
  146. handler: 'onQuery'
  147. }]
  148. }],
  149. items:[{
  150. xtype:'grid',
  151. margin: 12,
  152. flex: 1,
  153. border: 1,
  154. plugins: [{
  155. ptype: 'menuclipboard'
  156. }],
  157. dockedItems: [{
  158. xtype: 'pagingtoolbar',
  159. dock: 'bottom',
  160. cls:'x-basepanel-pagingtoolbar',
  161. displayInfo: true,
  162. bind: {
  163. store: '{vendorkind}',
  164. }
  165. }],
  166. listeners:{
  167. boxready: 'onBoxReady',
  168. render:'loadDefualt'
  169. }
  170. }],
  171. });
  172. me.callParent(arguments);
  173. },
  174. /**
  175. * 获得过滤条件
  176. */
  177. getConditions: function() {
  178. var me = this,
  179. items = me.dockedItems.items[0].query('[xtype=textfield]'),
  180. conditions = [];
  181. for(let i = 0; i < items.length; i++) {
  182. var item = items[i];
  183. var field = item.name,
  184. func = item.getCondition,
  185. value = item.value,
  186. condition;
  187. if(!item.isVisible()) {
  188. continue;
  189. }
  190. if(value !== undefined && value !== null && value !== ''){
  191. if(typeof func == 'function') {
  192. condition = {
  193. type: 'condition',
  194. value: func(value)
  195. }
  196. }else {
  197. var type = item.fieldType || me.getDefaultFieldType(item),
  198. operation = item.operation || me.getDefaultFieldOperation(item),
  199. conditionValue = me.getConditionValue(item, value);
  200. if(conditionValue === undefined && conditionValue === null && conditionValue === '') {
  201. continue;
  202. }
  203. condition = {
  204. type: type,
  205. field: field,
  206. operation: operation,
  207. value: conditionValue
  208. }
  209. }
  210. conditions.push(condition);
  211. }
  212. }
  213. return conditions;
  214. },
  215. /**
  216. * 只要arr1和arr2中存在相同项即返回真
  217. */
  218. isContainsAny: function (arr1, arr2) {
  219. for (var i = 0; i < arr2.length; i++) {
  220. var a2 = arr2[i];
  221. if (!!arr1.find(function (a1) {
  222. return a1 == a2
  223. })) {
  224. return true;
  225. }
  226. }
  227. return false;
  228. },
  229. getDefaultFieldType: function (field) {
  230. var me = this,
  231. xtypes = field.getXTypes().split('/'),
  232. type;
  233. if (me.isContainsAny(xtypes, ['numberfield'])) {
  234. type = 'number';
  235. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  236. type = 'date';
  237. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  238. type = 'enum';
  239. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  240. type = 'enum';
  241. } else {
  242. type = 'string';
  243. }
  244. return type;
  245. },
  246. getDefaultFieldOperation: function (field) {
  247. var me = this,
  248. xtypes = field.getXTypes().split('/'),
  249. operation;
  250. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  251. operation = '=';
  252. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  253. operation = 'between';
  254. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  255. operation = 'in';
  256. } else {
  257. operation = 'like';
  258. }
  259. return operation;
  260. },
  261. /**
  262. * 处理部分字段值
  263. */
  264. getConditionValue: function (field, value) {
  265. var me = this,
  266. xtypes = field.getXTypes().split('/'),
  267. conditionValue;
  268. if (me.isContainsAny(xtypes, ['datefield'])) {
  269. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  270. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  271. var from = value.from,
  272. to = value.to;
  273. conditionValue = from + ',' + to;
  274. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  275. var from = value.from,
  276. to = value.to;
  277. 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');
  278. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  279. conditionValue = value;
  280. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  281. conditionValue = '\'' + value + '\'';
  282. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  283. conditionValue = value.map ? value.map(function (v) {
  284. return '\'' + v.value + '\'';
  285. }).join(',') : '';
  286. } else {
  287. conditionValue = value;
  288. }
  289. return conditionValue;
  290. },
  291. refresh: function() {
  292. var store = this.down('grid').store;
  293. store.load();
  294. }
  295. })