DataList.js 14 KB

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