DataList.js 8.9 KB

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