DataList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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. },
  214. itemClick: function(view,record,a,index,c) {
  215. var classList = c.target.classList.value;
  216. var grid = this;
  217. if(classList.indexOf('fa-pencil')>-1){
  218. var form = this.ownerCt;
  219. this.dialog = form.getController().getView().add({
  220. xtype: 'sys-maxnumbers-window',
  221. bind: {
  222. title: '修改单据编码规则'
  223. },
  224. _parent:form,
  225. _combo:this,
  226. record:record,
  227. session: true
  228. });
  229. this.dialog.show();
  230. }else if(classList.indexOf('fa-trash-o')>-1){
  231. //删除
  232. var id = record.get('id');
  233. if(id){
  234. saas.util.BaseUtil.request({
  235. url: grid.deleteUrl+id,
  236. method: 'POST',
  237. })
  238. .then(function(localJson) {
  239. if(localJson.success){
  240. //解析参数
  241. saas.util.BaseUtil.showSuccessToast('删除成功');
  242. view.ownerCt.store.load();
  243. }
  244. })
  245. .catch(function(e) {
  246. saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  247. });
  248. }
  249. }
  250. }
  251. },
  252. insertFirstColumn:function(columns){
  253. var me=this;
  254. return columns;
  255. },
  256. getGridSelected:function(type){
  257. var isErrorSelect = false;
  258. var checkField = this.statusCodeField;
  259. var me = this,
  260. items = me.selModel.getSelection(),
  261. data = new Array() ;
  262. Ext.each(items, function(item, index){
  263. if(!Ext.isEmpty(item.data[me.idField])){
  264. var o = new Object();
  265. if(me.idField){
  266. o['id'] = item.data[me.idField];
  267. }
  268. if(me.codeField){
  269. o['code'] = item.data[me.codeField];
  270. }
  271. if(type&&type==item.data[checkField]){
  272. isErrorSelect = true
  273. }
  274. data.push(o);
  275. }
  276. });
  277. if(isErrorSelect){
  278. return false;
  279. }
  280. return data;
  281. },
  282. /**
  283. * 获得过滤条件
  284. */
  285. getConditions: function() {
  286. var me = this,
  287. tbar = me.getDockedItems()[0],
  288. items = Ext.Array.filter(tbar.items.items, function(item) {
  289. return !!item.name;
  290. }),
  291. conditions = [];
  292. for(var i = 0; i < items.length; i++) {
  293. var item = items[i];
  294. var field = item.name,
  295. func = item.getCondition,
  296. value = item.value,
  297. condition;
  298. if(value&&value!=''){
  299. if(typeof func == 'function') {
  300. condition = {
  301. type: 'condition',
  302. value: func(value)
  303. }
  304. }else {
  305. var type = item.fieldType || me.getDefaultFieldType(item),
  306. operation = item.operation || me.getDefaultFieldOperation(item),
  307. conditionValue = me.getConditionValue(item, value);
  308. if(!conditionValue) {
  309. continue;
  310. }
  311. condition = {
  312. type: type,
  313. field: field,
  314. operation: operation,
  315. value: conditionValue
  316. }
  317. }
  318. conditions.push(condition);
  319. }
  320. }
  321. return conditions;
  322. },
  323. /**
  324. * 只要arr1和arr2中存在相同项即返回真
  325. */
  326. isContainsAny: function (arr1, arr2) {
  327. for (var i = 0; i < arr2.length; i++) {
  328. var a2 = arr2[i];
  329. if (!!arr1.find(function (a1) {
  330. return a1 == a2
  331. })) {
  332. return true;
  333. }
  334. }
  335. return false;
  336. },
  337. getDefaultFieldType: function (field) {
  338. var me = this,
  339. xtypes = field.getXTypes().split('/'),
  340. type;
  341. if (me.isContainsAny(xtypes, ['numberfield'])) {
  342. type = 'number';
  343. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  344. type = 'date';
  345. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  346. type = 'enum';
  347. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  348. type = 'enum';
  349. } else {
  350. type = 'string';
  351. }
  352. return type;
  353. },
  354. getDefaultFieldOperation: function (field) {
  355. var me = this,
  356. xtypes = field.getXTypes().split('/'),
  357. operation;
  358. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  359. operation = '=';
  360. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  361. operation = 'between';
  362. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  363. operation = 'in';
  364. } else {
  365. operation = 'like';
  366. }
  367. return operation;
  368. },
  369. /**
  370. * 处理部分字段值
  371. */
  372. getConditionValue: function (field, value) {
  373. var me = this,
  374. xtypes = field.getXTypes().split('/'),
  375. conditionValue;
  376. if (me.isContainsAny(xtypes, ['datefield'])) {
  377. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  378. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  379. var from = value.from,
  380. to = value.to;
  381. conditionValue = from + ',' + to;
  382. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  383. var from = value.from,
  384. to = value.to;
  385. 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');
  386. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  387. conditionValue = value;
  388. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  389. conditionValue = '\'' + value + '\'';
  390. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  391. conditionValue = value.map ? value.map(function (v) {
  392. return '\'' + v.value + '\'';
  393. }).join(',') : '';
  394. } else {
  395. conditionValue = value;
  396. }
  397. return conditionValue;
  398. }
  399. })