DataList.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. xtype: 'numbercolumn',
  91. align: 'end',
  92. dataIndex : "rc_number",
  93. width : 120.0,
  94. renderer : function(v) {
  95. var arr = (v + '.').split('.');
  96. var xr = (new Array(arr[1].length>3?3:arr[1].length)).fill('0');
  97. var format = '0.' + xr.join();
  98. return Ext.util.Format.number(v, format);
  99. }
  100. },
  101. {
  102. text : "单价",
  103. xtype: 'numbercolumn',
  104. align: 'end',
  105. dataIndex : "rc_price",
  106. width : 120.0,
  107. renderer : function(v) {
  108. var arr = (v + '.').split('.');
  109. var xr = (new Array(arr[1].length>8?8:arr[1].length)).fill('0');
  110. var format = '0.' + xr.join();
  111. return Ext.util.Format.number(v, format);
  112. }
  113. },
  114. {
  115. text : "金额",
  116. xtype: 'numbercolumn',
  117. dataIndex : "rc_amount",
  118. flex : 1.0,
  119. renderer : function(v) {
  120. var arr = (v + '.').split('.');
  121. var xr = (new Array(arr[1].length>2?2:arr[1].length)).fill('0');
  122. var format = '0.' + xr.join();
  123. return Ext.util.Format.number(v, format);
  124. },
  125. }],
  126. dbSearchFields: [],
  127. condition:'',
  128. initComponent: function() {
  129. var me = this;
  130. if(me.columns){
  131. var fields = me.columns.map(column => column.dataIndex);
  132. me.store = Ext.create('Ext.data.Store',{
  133. fields:fields,
  134. autoLoad: true,
  135. pageSize: 11,
  136. data: [],
  137. proxy: {
  138. timeout:8000,
  139. type: 'ajax',
  140. url: me.dataUrl,
  141. actionMethods: {
  142. read: 'GET'
  143. },
  144. reader: {
  145. type: 'json',
  146. rootProperty: 'data.list',
  147. totalProperty: 'data.total',
  148. }
  149. },
  150. listeners: {
  151. beforeload: function (store, op) {
  152. var condition = me.condition;
  153. if (Ext.isEmpty(condition)) {
  154. condition = "";
  155. }
  156. Ext.apply(store.proxy.extraParams, {
  157. number: op._page,
  158. size: store.pageSize,
  159. condition: JSON.stringify(condition)
  160. });
  161. }
  162. }
  163. });
  164. Ext.apply(me, {
  165. dockedItems:[{
  166. xtype: 'pagingtoolbar',
  167. dock: 'bottom',
  168. displayInfo: true,
  169. store: me.store
  170. }]
  171. });
  172. }
  173. me.callParent(arguments);
  174. },
  175. getGridSelected:function(type){
  176. var isErrorSelect = false;
  177. var checkField = this.statusCodeField;
  178. var me = this,
  179. items = me.selModel.getSelection(),
  180. data = new Array() ;
  181. Ext.each(items, function(item, index){
  182. if(!Ext.isEmpty(item.data[me.idField])){
  183. var o = new Object();
  184. if(me.idField){
  185. o['id'] = item.data[me.idField];
  186. }
  187. if(me.codeField){
  188. o['code'] = item.data[me.codeField];
  189. }
  190. if(type&&type==item.data[checkField]){
  191. isErrorSelect = true
  192. }
  193. data.push(o);
  194. }
  195. });
  196. if(isErrorSelect){
  197. return false;
  198. }
  199. return data;
  200. },
  201. /**
  202. * 获得过滤条件
  203. */
  204. getCondition: function(items) {
  205. var me = this,
  206. conditions = [];
  207. for(var i = 0; i < items.length; i++) {
  208. var item = items[i];
  209. var field = item.name,
  210. func = item.getCondition,
  211. value = item.value,
  212. condition;
  213. if(typeof func == 'function') {
  214. condition = {
  215. type: 'condition',
  216. value: func(value)
  217. }
  218. }else {
  219. var xtype = item.xtype || 'textfield',
  220. type = item.fieldType || me.getDefaultFieldType(xtype),
  221. operation = item.operation || me.getDefaultFieldOperation(xtype),
  222. conditionValue = me.getConditionValue(xtype, value);
  223. if(!conditionValue) {
  224. continue;
  225. }
  226. condition = {
  227. type: type,
  228. field: field,
  229. operation: operation,
  230. value: conditionValue
  231. }
  232. }
  233. conditions.push(condition);
  234. };
  235. return conditions;
  236. },
  237. getDefaultFieldType: function(xtype) {
  238. var type;
  239. if(Ext.Array.contains(['numberfield'], xtype)) {
  240. type = 'number';
  241. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  242. type = 'date';
  243. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  244. type = 'enum';
  245. }else {
  246. type = 'string';
  247. }
  248. return type;
  249. },
  250. getDefaultFieldOperation: function(xtype) {
  251. var operation;
  252. if(Ext.Array.contains(['numberfield'], xtype)) {
  253. operation = '=';
  254. }else if(Ext.Array.contains(['datefield'], xtype)) {
  255. operation = '=';
  256. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  257. operation = 'between';
  258. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  259. operation = 'in';
  260. }else {
  261. operation = 'like';
  262. }
  263. return operation;
  264. },
  265. /**
  266. * 处理部分字段值
  267. */
  268. getConditionValue: function(xtype, value) {
  269. var conditionValue;
  270. if(xtype == 'datefield') {
  271. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  272. }else if(xtype == 'condatefield') {
  273. var from = value.from,
  274. to = value.to;
  275. 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');
  276. }else if(xtype == 'combobox' || xtype == 'combo') {
  277. conditionValue = '\'' + value + '\'';
  278. }else if(xtype == 'multicombo') {
  279. conditionValue = value.map(function(v) {
  280. return '\'' + v.value + '\'';
  281. }).join(',');
  282. }else {
  283. conditionValue = value;
  284. }
  285. return conditionValue;
  286. },
  287. refresh:function(){
  288. //debugger
  289. }
  290. })