DataList.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. Ext.define('saas.view.sys.account.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'sys-account-datalist',
  4. controller: 'sys-account-datalist',
  5. viewModel: 'sys-account-datalist',
  6. autoScroll: true,
  7. frame:true,
  8. layout:'fit',
  9. dataUrl:'/api/account/account/accountRole/list',
  10. _openUrl:'/api/account/account/enable',
  11. _closeUrl:'/api/account/account/disable',
  12. plugins: [{
  13. ptype: 'menuclipboard'
  14. }],
  15. tbar: [{
  16. width: 150,
  17. name: 'username',
  18. xtype: 'textfield',
  19. emptyText : '账户名称',
  20. enableKeyEvents: true,
  21. listeners: {
  22. keydown: {
  23. fn: function(th, e, eOpts) {
  24. if(e.keyCode == 13) {
  25. var grid = th.up('grid');
  26. grid.condition = grid.getConditions();
  27. grid.store.loadPage(1);
  28. }
  29. }
  30. }
  31. }
  32. },{
  33. width: 140,
  34. name: 'mobile',
  35. xtype: 'textfield',
  36. emptyText : '手机号码',
  37. // regex:/^1(3|4|5|7|8|9)\d{9}$/,
  38. // regexText:'请输入正确的手机号码',
  39. enableKeyEvents: true,
  40. listeners: {
  41. keydown: {
  42. fn: function(th, e, eOpts) {
  43. if(e.keyCode == 13) {
  44. var grid = th.up('grid');
  45. grid.condition = grid.getConditions();
  46. grid.store.loadPage(1);
  47. }
  48. }
  49. }
  50. }
  51. },{
  52. xtype:'button',
  53. text:'查询',
  54. listeners: {
  55. click:function(b){
  56. var grid = b.up('grid');
  57. grid.condition = grid.getConditions();
  58. grid.store.loadPage(1);
  59. }
  60. }
  61. },'->',{
  62. xtype:'button',
  63. text:'新增',
  64. listeners: {
  65. click: 'onAdd'
  66. }
  67. },{
  68. xtype:'button',
  69. text:'刷新',
  70. listeners: {
  71. click: 'onRefresh'
  72. }
  73. }],
  74. columns : [{
  75. text : 'id',
  76. hidden:true,
  77. dataIndex : 'id',
  78. xtype : 'numbercolumn',
  79. },{
  80. text : 'accountId',
  81. hidden:true,
  82. dataIndex : 'accountId',
  83. xtype : 'numbercolumn',
  84. },{
  85. text : '账户名称',
  86. width : 200.0,
  87. dataIndex : 'username',
  88. xtype : '',
  89. },
  90. {
  91. text : '真实姓名',
  92. dataIndex : 'realname',
  93. width : 110.0,
  94. xtype : '',
  95. },
  96. {
  97. text : '联系电话',
  98. dataIndex : 'mobile',
  99. width : 110.0,
  100. },{
  101. text : '邮箱',
  102. dataIndex : 'email',
  103. width : 180.0,
  104. xtype : '',
  105. },{
  106. text : '岗位角色id',
  107. hidden:true,
  108. dataIndex : 'roleIds',
  109. width : 110.0,
  110. xtype : '',
  111. },{
  112. text : '岗位角色',
  113. dataIndex : 'roleNames',
  114. width : 220.0
  115. },{
  116. text: '账户状态',
  117. dataIndex: 'enabled',
  118. width:90,
  119. xtype: 'actioncolumn',
  120. align : 'center',
  121. items: [{
  122. iconCls:'',
  123. getClass: function(v, meta, rec) {
  124. if(rec.get('enabled')){
  125. return 'x-grid-checkcolumn-checked-btn';
  126. }else{
  127. return 'x-grid-checkcolumn-btn';
  128. }
  129. },
  130. handler: function(view, rowIndex, colIndex) {
  131. var rec = view.getStore().getAt(rowIndex);
  132. var type=rec.get('enabled');
  133. // 禁用/启用
  134. var grid = this.ownerCt.ownerCt;
  135. var params = {
  136. accountId:rec.get('id')
  137. };
  138. saas.util.BaseUtil.request({
  139. url: (!type?grid._openUrl:grid._closeUrl),
  140. params: params,
  141. method: 'POST',
  142. headers : {
  143. 'Access-Control-Allow-Origin': '*',
  144. "Content-Type":'application/x-www-form-urlencoded'
  145. }
  146. })
  147. .then(function(localJson) {
  148. if(localJson.success){
  149. saas.util.BaseUtil.showSuccessToast('操作成功');
  150. grid.store.load();
  151. }
  152. })
  153. .catch(function(e) {
  154. saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
  155. });
  156. }
  157. }]
  158. }, {
  159. dataIndex: '',
  160. flex: 1
  161. }],
  162. dbSearchFields: [],
  163. condition:'',
  164. initComponent: function() {
  165. var me = this;
  166. if(me.columns){
  167. var fields = me.columns.map(column => column.dataIndex);
  168. me.columns = me.insertFirstColumn(me.columns);
  169. me.store = Ext.create('Ext.data.Store',{
  170. fields:fields,
  171. autoLoad: true,
  172. pageSize: 11,
  173. data: [],
  174. proxy: {
  175. timeout:8000,
  176. type: 'ajax',
  177. url: me.dataUrl,
  178. actionMethods: {
  179. read: 'GET'
  180. },
  181. reader: {
  182. type: 'json',
  183. rootProperty: 'data.list',
  184. totalProperty: 'data.total',
  185. },
  186. listeners: {
  187. exception: function(proxy, response, operation, eOpts) {
  188. if(operation.success) {
  189. if(response.timedout) {
  190. saas.util.BaseUtil.showErrorToast('请求超时');
  191. }
  192. }else {
  193. if(response.timedout) {
  194. saas.util.BaseUtil.showErrorToast('请求超时');
  195. }else{
  196. if(proxy.showPowerMessage){
  197. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  198. }
  199. }
  200. }
  201. }
  202. }
  203. },
  204. listeners: {
  205. beforeload: function (store, op) {
  206. var condition = me.condition;
  207. if (Ext.isEmpty(condition)) {
  208. condition = '';
  209. }
  210. Ext.apply(store.proxy.extraParams, {
  211. number: op._page,
  212. size: store.pageSize,
  213. condition: JSON.stringify(condition)
  214. });
  215. }
  216. }
  217. });
  218. Ext.apply(me, {
  219. dockedItems:[{
  220. xtype: 'pagingtoolbar',
  221. dock: 'bottom',
  222. displayInfo: true,
  223. store: me.store
  224. }]
  225. });
  226. }
  227. me.callParent(arguments);
  228. },
  229. onVastDeal:function(url,type){
  230. var form = this.ownerCt;
  231. var grid = this;
  232. var data = grid.getGridSelected(type);
  233. if(!data){
  234. saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
  235. return false;
  236. }
  237. if(data&&data.length>0){
  238. var params = JSON.stringify({baseDTOs:data});
  239. saas.util.BaseUtil.request({
  240. url: url,
  241. params: params,
  242. method: 'POST',
  243. async:false
  244. })
  245. .then(function() {
  246. saas.util.BaseUtil.showSuccessToast('操作成功');
  247. grid.store.load();
  248. })
  249. .catch(function(e) {
  250. saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
  251. });
  252. }else{
  253. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。');
  254. }
  255. },
  256. listeners:{
  257. boxready: function(grid, width, height, eOpts) {
  258. var store = grid.getStore(),
  259. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  260. gridBodyBoxHeight = gridBodyBox.height;
  261. var pageSize = Math.floor(gridBodyBoxHeight / 35);
  262. store.setPageSize(pageSize);
  263. },
  264. itemClick: function(view,record,a,index,c) {
  265. var classList = c.target.classList.value;
  266. if(classList.indexOf('fa-pencil')>-1){
  267. this.dialog = this.getController().getView().add({
  268. xtype: 'sys-account-editwindow',
  269. bind: {
  270. title: '修改账户信息'
  271. },
  272. _parent:this,
  273. record:record,
  274. session: true
  275. });
  276. this.dialog.show();
  277. }
  278. }
  279. },
  280. insertFirstColumn:function(columns){
  281. var me=this;
  282. if(columns.length>0 && columns[0].xtype!='actioncolumn'){
  283. return Ext.Array.insert(columns,0,[{
  284. xtype:'actioncolumn',
  285. width:50,
  286. dataIndex:'actioncolumn',
  287. text:'操作',
  288. align: 'center',
  289. items: [{
  290. tooltip: '编辑',
  291. iconCls: 'x-fa fa-pencil fa-fw',
  292. scope:this
  293. }]
  294. }]);
  295. }
  296. return columns;
  297. },
  298. getGridSelected:function(type){
  299. var isErrorSelect = false;
  300. var checkField = this.statusCodeField;
  301. var me = this,
  302. items = me.selModel.getSelection(),
  303. data = new Array() ;
  304. Ext.each(items, function(item, index){
  305. if(!Ext.isEmpty(item.data[me.idField])){
  306. var o = new Object();
  307. if(me.idField){
  308. o['id'] = item.data[me.idField];
  309. }
  310. if(me.codeField){
  311. o['code'] = item.data[me.codeField];
  312. }
  313. if(type&&type==item.data[checkField]){
  314. isErrorSelect = true
  315. }
  316. data.push(o);
  317. }
  318. });
  319. if(isErrorSelect){
  320. return false;
  321. }
  322. return data;
  323. },
  324. /**
  325. * 获得过滤条件
  326. */
  327. getConditions: function() {
  328. var me = this,
  329. tbar = me.getDockedItems()[0],
  330. items = Ext.Array.filter(tbar.items.items, function(item) {
  331. return !!item.name;
  332. }),
  333. conditions = [];
  334. for(var i = 0; i < items.length; i++) {
  335. var item = items[i];
  336. var field = item.name,
  337. func = item.getCondition,
  338. value = item.value,
  339. condition;
  340. if(value&&value!=''){
  341. if(typeof func == 'function') {
  342. condition = {
  343. type: 'condition',
  344. value: func(value)
  345. }
  346. }else {
  347. var type = item.fieldType || me.getDefaultFieldType(item),
  348. operation = item.operation || me.getDefaultFieldOperation(item),
  349. conditionValue = me.getConditionValue(item, value);
  350. if(!conditionValue) {
  351. continue;
  352. }
  353. condition = {
  354. type: type,
  355. field: field,
  356. operation: operation,
  357. value: conditionValue
  358. }
  359. }
  360. conditions.push(condition);
  361. }
  362. }
  363. return conditions;
  364. },
  365. /**
  366. * 只要arr1和arr2中存在相同项即返回真
  367. */
  368. isContainsAny: function (arr1, arr2) {
  369. for (var i = 0; i < arr2.length; i++) {
  370. var a2 = arr2[i];
  371. if (!!arr1.find(function (a1) {
  372. return a1 == a2
  373. })) {
  374. return true;
  375. }
  376. }
  377. return false;
  378. },
  379. getDefaultFieldType: function (field) {
  380. var me = this,
  381. xtypes = field.getXTypes().split('/'),
  382. type;
  383. if (me.isContainsAny(xtypes, ['numberfield'])) {
  384. type = 'number';
  385. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  386. type = 'date';
  387. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  388. type = 'enum';
  389. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  390. type = 'enum';
  391. } else {
  392. type = 'string';
  393. }
  394. return type;
  395. },
  396. getDefaultFieldOperation: function (field) {
  397. var me = this,
  398. xtypes = field.getXTypes().split('/'),
  399. operation;
  400. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  401. operation = '=';
  402. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  403. operation = 'between';
  404. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  405. operation = 'in';
  406. } else {
  407. operation = 'like';
  408. }
  409. return operation;
  410. },
  411. /**
  412. * 处理部分字段值
  413. */
  414. getConditionValue: function (field, value) {
  415. var me = this,
  416. xtypes = field.getXTypes().split('/'),
  417. conditionValue;
  418. if (me.isContainsAny(xtypes, ['datefield'])) {
  419. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  420. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  421. var from = value.from,
  422. to = value.to;
  423. conditionValue = from + ',' + to;
  424. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  425. var from = value.from,
  426. to = value.to;
  427. 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');
  428. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  429. conditionValue = value;
  430. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  431. conditionValue = '\'' + value + '\'';
  432. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  433. conditionValue = value.map ? value.map(function (v) {
  434. return '\'' + v.value + '\'';
  435. }).join(',') : '';
  436. } else {
  437. conditionValue = value;
  438. }
  439. return conditionValue;
  440. }
  441. })