DataList.js 8.8 KB

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