DataList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.purchase.deviceQuery.DataList', {
  5. extend: 'Ext.grid.Panel',
  6. xtype: 'purchase-deviceQuery-datalist',
  7. controller: 'purchase-deviceQuery-datalist',
  8. viewModel: 'purchase-deviceQuery-datalist',
  9. autoScroll: true,
  10. frame:true,
  11. style:'padding:0;',
  12. layout:'fit',
  13. dataUrl:'/api/purchase/purchase/device/list',
  14. deleteUrl:'/api/commons/number/delete/',
  15. plugins: [{
  16. ptype: 'menuclipboard'
  17. }],
  18. tbar: [{
  19. width: 240,
  20. name: 'mn_name',
  21. xtype: 'textfield',
  22. allowBlank:true,
  23. emptyText : '请输入型号/物料名称/品牌搜索',
  24. enableKeyEvents: true,
  25. listeners: {
  26. keydown: {
  27. fn: function(th, e, eOpts) {
  28. if(e.keyCode == 13) {
  29. var grid = th.up('grid');
  30. grid.condition = grid.getConditions();
  31. grid.store.loadPage(1);
  32. }
  33. }
  34. }
  35. },
  36. getCondition:function(v){
  37. return v;
  38. }
  39. },{
  40. cls:'x-formpanel-btn-blue',
  41. xtype:'button',
  42. text:'查询',
  43. listeners: {
  44. click:function(b){
  45. var grid = b.ownerCt.ownerCt;
  46. grid.condition = grid.getConditions();
  47. grid.store.loadPage(1);
  48. }
  49. }
  50. },'->'],
  51. columns : [{
  52. text : 'id',
  53. width : 0,
  54. dataIndex : 'id',
  55. xtype : 'numbercolumn',
  56. hidden:true
  57. },{
  58. text : '品牌',
  59. width : 150.0,
  60. dataIndex : 'pr_brand',
  61. xtype : '',
  62. },{
  63. text : '名称',
  64. width : 200.0,
  65. dataIndex : 'pr_detail',
  66. xtype : '',
  67. },{
  68. text : '型号',
  69. width : 200.0,
  70. dataIndex : 'pr_orispeccode',
  71. xtype : '',
  72. },{
  73. text : '规格',
  74. width : 200,
  75. dataIndex : 'pr_spec',
  76. xtype : '',
  77. },{
  78. text : '包装',
  79. width : 100,
  80. dataIndex : 'pr_pack',
  81. xtype : '',
  82. },{
  83. text : '供应商',
  84. width : 150.0,
  85. dataIndex : 'pr_vendor',
  86. xtype : '',
  87. },{
  88. text : '库存',
  89. width : 100,
  90. dataIndex : 'pr_qty',
  91. xtype : 'numbercolumn',
  92. renderer: function(v, m, r) {
  93. return saas.util.BaseUtil.numberFormat(v, 0, false);
  94. },
  95. },{
  96. hidden:true,
  97. text : '梯度',
  98. width : 100.0,
  99. dataIndex : 'pr_level',
  100. xtype : '',
  101. },{
  102. hidden:true,
  103. text : '大陆交货单价',
  104. width : 200.0,
  105. dataIndex : 'pr_cnprice',
  106. xtype : '',
  107. },{
  108. hidden:true,
  109. text : '香港交货单价',
  110. width : 200.0,
  111. dataIndex : 'pr_hkprice',
  112. xtype : '',
  113. },{
  114. hidden:true,
  115. text : '交期',
  116. width : 200.0,
  117. dataIndex : 'pr_leadtime',
  118. xtype : '',
  119. },
  120. {
  121. dataIndex: '',
  122. flex: 1
  123. }],
  124. initComponent: function() {
  125. var me = this;
  126. if(me.columns){
  127. var fields = me.columns.map(column => column.dataIndex);
  128. me.columns = me.insertFirstColumn(me.columns);
  129. me.store = Ext.create('Ext.data.Store',{
  130. fields:fields,
  131. autoLoad: true,
  132. pageSize: 15,
  133. data: [],
  134. proxy: {
  135. timeout:8000,
  136. type: 'ajax',
  137. headers:{
  138. 'Access-Control-Allow-Origin': '*',
  139. "Content-Type": 'application/json;charset=UTF-8'
  140. },
  141. url: me.dataUrl,
  142. actionMethods: {
  143. read: 'GET'
  144. },
  145. reader: {
  146. type: 'json',
  147. rootProperty: 'data.content',
  148. totalProperty: 'data.totalElements',
  149. }
  150. },
  151. listeners: {
  152. beforeload: function (store, op) {
  153. var condition = me.condition;
  154. if (Ext.isEmpty(condition)) {
  155. condition = '';
  156. }
  157. Ext.apply(store.proxy.extraParams, {
  158. type :'component',
  159. keyword :condition==''?' ':condition[0].value,
  160. page: op._page,
  161. count: store.pageSize,
  162. filter: '',
  163. sorting:''
  164. });
  165. }
  166. }
  167. });
  168. Ext.apply(me, {
  169. dockedItems:[{
  170. xtype: 'pagingtoolbar',
  171. dock: 'bottom',
  172. displayInfo: true,
  173. store: me.store
  174. }]
  175. });
  176. }
  177. me.callParent(arguments);
  178. },
  179. onVastDeal:function(url,type){
  180. var form = this.ownerCt;
  181. var grid = this;
  182. var data = grid.getGridSelected(type);
  183. if(!data){
  184. saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
  185. return false;
  186. }
  187. if(data&&data.length>0){
  188. var params = JSON.stringify({baseDTOs:data});
  189. saas.util.BaseUtil.request({
  190. url: url,
  191. params: params,
  192. method: 'POST',
  193. async:false
  194. })
  195. .then(function() {
  196. saas.util.BaseUtil.showSuccessToast('操作成功');
  197. grid.store.load();
  198. })
  199. .catch(function(e) {
  200. saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
  201. });
  202. }else{
  203. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。');
  204. }
  205. },
  206. listeners:{
  207. boxready: function(grid, width, height, eOpts) {
  208. var store = grid.getStore(),
  209. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  210. gridBodyBoxHeight = gridBodyBox.height;
  211. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  212. store.setPageSize(pageSize);
  213. grid.ownerCt.el.dom.style.left = '8px';
  214. grid.el.dom.style.padding = '0px'
  215. },
  216. itemClick: function(view,record,a,index,c) {
  217. var classList = c.target.classList.value;
  218. var grid = this;
  219. if(classList.indexOf('fa-pencil')>-1){
  220. var form = this.ownerCt;
  221. this.dialog = form.getController().getView().add({
  222. xtype: 'sys-maxnumbers-window',
  223. bind: {
  224. title: '修改单据编码规则'
  225. },
  226. _parent:form,
  227. _combo:this,
  228. record:record,
  229. session: true
  230. });
  231. this.dialog.show();
  232. }else if(classList.indexOf('fa-trash-o')>-1){
  233. //删除
  234. var id = record.get('id');
  235. if(id){
  236. saas.util.BaseUtil.request({
  237. url: grid.deleteUrl+id,
  238. method: 'POST',
  239. })
  240. .then(function(localJson) {
  241. if(localJson.success){
  242. //解析参数
  243. saas.util.BaseUtil.showSuccessToast('删除成功');
  244. view.ownerCt.store.load();
  245. }
  246. })
  247. .catch(function(e) {
  248. saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  249. });
  250. }
  251. }
  252. }
  253. },
  254. insertFirstColumn:function(columns){
  255. var me=this;
  256. return columns;
  257. },
  258. getGridSelected:function(type){
  259. var isErrorSelect = false;
  260. var checkField = this.statusCodeField;
  261. var me = this,
  262. items = me.selModel.getSelection(),
  263. data = new Array() ;
  264. Ext.each(items, function(item, index){
  265. if(!Ext.isEmpty(item.data[me.idField])){
  266. var o = new Object();
  267. if(me.idField){
  268. o['id'] = item.data[me.idField];
  269. }
  270. if(me.codeField){
  271. o['code'] = item.data[me.codeField];
  272. }
  273. if(type&&type==item.data[checkField]){
  274. isErrorSelect = true
  275. }
  276. data.push(o);
  277. }
  278. });
  279. if(isErrorSelect){
  280. return false;
  281. }
  282. return data;
  283. },
  284. /**
  285. * 获得过滤条件
  286. */
  287. getConditions: function() {
  288. var me = this,
  289. tbar = me.getDockedItems()[0],
  290. items = Ext.Array.filter(tbar.items.items, function(item) {
  291. return !!item.name;
  292. }),
  293. conditions = [];
  294. for(var i = 0; i < items.length; i++) {
  295. var item = items[i];
  296. var field = item.name,
  297. func = item.getCondition,
  298. value = item.value,
  299. condition;
  300. if(value&&value!=''){
  301. if(typeof func == 'function') {
  302. condition = {
  303. type: 'condition',
  304. value: func(value)
  305. }
  306. }else {
  307. var type = item.fieldType || me.getDefaultFieldType(item),
  308. operation = item.operation || me.getDefaultFieldOperation(item),
  309. conditionValue = me.getConditionValue(item, value);
  310. if(!conditionValue) {
  311. continue;
  312. }
  313. condition = {
  314. type: type,
  315. field: field,
  316. operation: operation,
  317. value: conditionValue
  318. }
  319. }
  320. conditions.push(condition);
  321. }
  322. }
  323. return conditions;
  324. },
  325. /**
  326. * 只要arr1和arr2中存在相同项即返回真
  327. */
  328. isContainsAny: function (arr1, arr2) {
  329. for (var i = 0; i < arr2.length; i++) {
  330. var a2 = arr2[i];
  331. if (!!arr1.find(function (a1) {
  332. return a1 == a2
  333. })) {
  334. return true;
  335. }
  336. }
  337. return false;
  338. },
  339. getDefaultFieldType: function (field) {
  340. var me = this,
  341. xtypes = field.getXTypes().split('/'),
  342. type;
  343. if (me.isContainsAny(xtypes, ['numberfield'])) {
  344. type = 'number';
  345. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  346. type = 'date';
  347. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  348. type = 'enum';
  349. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  350. type = 'enum';
  351. } else {
  352. type = 'string';
  353. }
  354. return type;
  355. },
  356. getDefaultFieldOperation: function (field) {
  357. var me = this,
  358. xtypes = field.getXTypes().split('/'),
  359. operation;
  360. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  361. operation = '=';
  362. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  363. operation = 'between';
  364. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  365. operation = 'in';
  366. } else {
  367. operation = 'like';
  368. }
  369. return operation;
  370. },
  371. /**
  372. * 处理部分字段值
  373. */
  374. getConditionValue: function (field, value) {
  375. var me = this,
  376. xtypes = field.getXTypes().split('/'),
  377. conditionValue;
  378. if (me.isContainsAny(xtypes, ['datefield'])) {
  379. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  380. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  381. var from = value.from,
  382. to = value.to;
  383. conditionValue = from + ',' + to;
  384. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  385. var from = value.from,
  386. to = value.to;
  387. 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');
  388. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  389. conditionValue = value;
  390. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  391. conditionValue = '\'' + value + '\'';
  392. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  393. conditionValue = value.map ? value.map(function (v) {
  394. return '\'' + v.value + '\'';
  395. }).join(',') : '';
  396. } else {
  397. conditionValue = value;
  398. }
  399. return conditionValue;
  400. }
  401. })