DataList.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.stock.stockamount.DataList', {
  5. extend: 'Ext.grid.Panel',
  6. xtype: 'stock-stockamount-datalist',
  7. controller: 'stock-stockamount-datalist',
  8. viewModel: 'stock-stockamount-datalist',
  9. autoScroll: true,
  10. frame:true,
  11. layout:'fit',
  12. //工具类
  13. FormUtil: Ext.create('saas.util.FormUtil'),
  14. BaseUtil: Ext.create('saas.util.BaseUtil'),
  15. dataUrl:'/api/document/product/ReserveCost',
  16. tbar: [{
  17. width: 150,
  18. name: 'pr_code',
  19. xtype: 'textfield',
  20. emptyText : '物料编号'
  21. },{
  22. width: 150,
  23. name: 'pr_detail',
  24. xtype: 'textfield',
  25. emptyText : '物料名称'
  26. },{
  27. width: 150,
  28. name: 'wh_code',
  29. xtype: 'textfield',
  30. emptyText : '仓库编号'
  31. },{
  32. width: 150,
  33. name: 'wh_name',
  34. xtype: 'textfield',
  35. emptyText : '仓库名称'
  36. },{
  37. cls:'x-formpanel-btn-orange',
  38. xtype:'button',
  39. text:'查询',
  40. listeners: {
  41. click:function(b){
  42. var grid = b.ownerCt.ownerCt;
  43. var tbar = b.ownerCt;
  44. grid.condition = '';
  45. var items = [];
  46. var fields = tbar.items.items.map(f => f.name);
  47. Ext.each(fields, function(f, index){
  48. var field = tbar.down('[name='+f+']');
  49. if(field){
  50. items.push(field);
  51. }
  52. });
  53. grid.condition = grid.getCondition(items);
  54. grid.store.loadPage(1);
  55. }
  56. }
  57. },'->'],
  58. columns : [{
  59. text : "物料编号",
  60. width : 150,
  61. dataIndex : "rc_prodCode",
  62. xtype : "",
  63. },{
  64. text : "物料名称",
  65. width : 150.0,
  66. dataIndex : "rc_prodDetail",
  67. },
  68. {
  69. text : "物料规格",
  70. dataIndex : "rc_prodSpec",
  71. width : 120.0,
  72. },
  73. {
  74. text : "单位",
  75. dataIndex : "rc_prodUnit",
  76. width : 80.0,
  77. },
  78. {
  79. text : "仓库编号",
  80. dataIndex : "rc_whCode",
  81. width : 100,
  82. },
  83. {
  84. text : "仓库名称",
  85. dataIndex : "rc_whName",
  86. width : 120.0,
  87. },
  88. {
  89. text : "数量",
  90. format:'0,000',
  91. xtype:'numbercolumn',
  92. dataIndex : "rc_number",
  93. width : 120.0,
  94. },
  95. {
  96. text : "单价",
  97. dataIndex : "rc_price",
  98. width : 120.0,
  99. renderer : function(v) {
  100. var arr = (v + '.').split('.');
  101. var xr = (new Array(arr[1].length>8?8:arr[1].length)).fill('0');
  102. var format = '0.' + xr.join();
  103. return Ext.util.Format.number(v, format);
  104. }
  105. },
  106. {
  107. text : "金额",
  108. dataIndex : "rc_amount",
  109. flex : 1.0,
  110. renderer : function(v) {
  111. var arr = (v + '.').split('.');
  112. var xr = (new Array(arr[1].length>2?2:arr[1].length)).fill('0');
  113. var format = '0.' + xr.join();
  114. return Ext.util.Format.number(v, format);
  115. },
  116. }],
  117. dbSearchFields: [],
  118. condition:'',
  119. initComponent: function() {
  120. var me = this;
  121. if(me.columns){
  122. var fields = me.columns.map(column => column.dataIndex);
  123. me.store = Ext.create('Ext.data.Store',{
  124. fields:fields,
  125. autoLoad: true,
  126. pageSize: 11,
  127. data: [],
  128. proxy: {
  129. timeout:8000,
  130. type: 'ajax',
  131. url: me.dataUrl,
  132. actionMethods: {
  133. read: 'GET'
  134. },
  135. reader: {
  136. type: 'json',
  137. rootProperty: 'data.list',
  138. totalProperty: 'data.total',
  139. }
  140. },
  141. listeners: {
  142. beforeload: function (store, op) {
  143. var condition = me.condition;
  144. if (Ext.isEmpty(condition)) {
  145. condition = "";
  146. }
  147. Ext.apply(store.proxy.extraParams, {
  148. number: op._page,
  149. size: store.pageSize,
  150. condition: JSON.stringify(condition)
  151. });
  152. }
  153. }
  154. });
  155. Ext.apply(me, {
  156. dockedItems:[{
  157. xtype: 'pagingtoolbar',
  158. dock: 'bottom',
  159. displayInfo: true,
  160. store: me.store
  161. }]
  162. });
  163. }
  164. me.callParent(arguments);
  165. },
  166. getGridSelected:function(type){
  167. var isErrorSelect = false;
  168. var checkField = this.statusCodeField;
  169. var me = this,
  170. items = me.selModel.getSelection(),
  171. data = new Array() ;
  172. Ext.each(items, function(item, index){
  173. if(!Ext.isEmpty(item.data[me.idField])){
  174. var o = new Object();
  175. if(me.idField){
  176. o['id'] = item.data[me.idField];
  177. }
  178. if(me.codeField){
  179. o['code'] = item.data[me.codeField];
  180. }
  181. if(type&&type==item.data[checkField]){
  182. isErrorSelect = true
  183. }
  184. data.push(o);
  185. }
  186. });
  187. if(isErrorSelect){
  188. return false;
  189. }
  190. return data;
  191. },
  192. /**
  193. * 获得过滤条件
  194. */
  195. getCondition: function(items) {
  196. var me = this,
  197. conditions = [];
  198. for(var i = 0; i < items.length; i++) {
  199. var item = items[i];
  200. var field = item.name,
  201. func = item.getCondition,
  202. value = item.value,
  203. condition;
  204. if(typeof func == 'function') {
  205. condition = {
  206. type: 'condition',
  207. value: func(value)
  208. }
  209. }else {
  210. var xtype = item.xtype || 'textfield',
  211. type = item.fieldType || me.getDefaultFieldType(xtype),
  212. operation = item.operation || me.getDefaultFieldOperation(xtype),
  213. conditionValue = me.getConditionValue(xtype, value);
  214. if(!conditionValue) {
  215. continue;
  216. }
  217. condition = {
  218. type: type,
  219. field: field,
  220. operation: operation,
  221. value: conditionValue
  222. }
  223. }
  224. conditions.push(condition);
  225. };
  226. return conditions;
  227. },
  228. getDefaultFieldType: function(xtype) {
  229. var type;
  230. if(Ext.Array.contains(['numberfield'], xtype)) {
  231. type = 'number';
  232. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  233. type = 'date';
  234. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  235. type = 'enum';
  236. }else {
  237. type = 'string';
  238. }
  239. return type;
  240. },
  241. getDefaultFieldOperation: function(xtype) {
  242. var operation;
  243. if(Ext.Array.contains(['numberfield'], xtype)) {
  244. operation = '=';
  245. }else if(Ext.Array.contains(['datefield'], xtype)) {
  246. operation = '=';
  247. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  248. operation = 'between';
  249. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  250. operation = 'in';
  251. }else {
  252. operation = 'like';
  253. }
  254. return operation;
  255. },
  256. /**
  257. * 处理部分字段值
  258. */
  259. getConditionValue: function(xtype, value) {
  260. var conditionValue;
  261. if(xtype == 'datefield') {
  262. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  263. }else if(xtype == 'condatefield') {
  264. var from = value.from,
  265. to = value.to;
  266. 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');
  267. }else if(xtype == 'combobox' || xtype == 'combo') {
  268. conditionValue = '\'' + value + '\'';
  269. }else if(xtype == 'multicombo') {
  270. conditionValue = value.map(function(v) {
  271. return '\'' + v.value + '\'';
  272. }).join(',');
  273. }else {
  274. conditionValue = value;
  275. }
  276. return conditionValue;
  277. },
  278. refresh:function(){
  279. //debugger
  280. }
  281. })