DataList.js 13 KB

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