DataList.js 14 KB

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