DataList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  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. },
  169. listeners: {
  170. beforeload: function (store, op) {
  171. var condition = me.condition;
  172. if (Ext.isEmpty(condition)) {
  173. condition = '';
  174. }
  175. Ext.apply(store.proxy.extraParams, {
  176. number: op._page,
  177. size: store.pageSize,
  178. condition: JSON.stringify(condition)
  179. });
  180. }
  181. }
  182. });
  183. Ext.apply(me, {
  184. dockedItems:[{
  185. xtype: 'pagingtoolbar',
  186. dock: 'bottom',
  187. displayInfo: true,
  188. store: me.store
  189. }]
  190. });
  191. }
  192. me.callParent(arguments);
  193. },
  194. onVastDeal:function(url,type){
  195. var form = this.ownerCt;
  196. var grid = this;
  197. var data = grid.getGridSelected(type);
  198. if(!data){
  199. saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
  200. return false;
  201. }
  202. if(data&&data.length>0){
  203. var params = JSON.stringify({baseDTOs:data});
  204. saas.util.BaseUtil.request({
  205. url: url,
  206. params: params,
  207. method: 'POST',
  208. async:false
  209. })
  210. .then(function() {
  211. saas.util.BaseUtil.showSuccessToast('操作成功');
  212. grid.store.load();
  213. })
  214. .catch(function(response) {
  215. saas.util.BaseUtil.showErrorToast('操作失败');
  216. });
  217. }else{
  218. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。');
  219. }
  220. },
  221. listeners:{
  222. boxready: function(grid, width, height, eOpts) {
  223. var store = grid.getStore(),
  224. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  225. gridBodyBoxHeight = gridBodyBox.height;
  226. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  227. store.setPageSize(pageSize);
  228. },
  229. itemClick: function(view,record,a,index,c) {
  230. var classList = c.target.classList.value;
  231. if(classList.indexOf('fa-pencil')>-1){
  232. this.dialog = this.getController().getView().add({
  233. xtype: 'sys-account-editwindow',
  234. bind: {
  235. title: '修改账户信息'
  236. },
  237. _parent:this,
  238. record:record,
  239. session: true
  240. });
  241. this.dialog.show();
  242. }
  243. }
  244. },
  245. insertFirstColumn:function(columns){
  246. var me=this;
  247. if(columns.length>0 && columns[0].xtype!='actioncolumn'){
  248. return Ext.Array.insert(columns,0,[{
  249. xtype:'actioncolumn',
  250. width:50,
  251. dataIndex:'actioncolumn',
  252. text:'操作',
  253. items: [{
  254. tooltip: '编辑',
  255. iconCls: 'x-fa fa-pencil fa-fw',
  256. scope:this
  257. }]
  258. }]);
  259. }
  260. return columns;
  261. },
  262. getGridSelected:function(type){
  263. var isErrorSelect = false;
  264. var checkField = this.statusCodeField;
  265. var me = this,
  266. items = me.selModel.getSelection(),
  267. data = new Array() ;
  268. Ext.each(items, function(item, index){
  269. if(!Ext.isEmpty(item.data[me.idField])){
  270. var o = new Object();
  271. if(me.idField){
  272. o['id'] = item.data[me.idField];
  273. }
  274. if(me.codeField){
  275. o['code'] = item.data[me.codeField];
  276. }
  277. if(type&&type==item.data[checkField]){
  278. isErrorSelect = true
  279. }
  280. data.push(o);
  281. }
  282. });
  283. if(isErrorSelect){
  284. return false;
  285. }
  286. return data;
  287. },
  288. /**
  289. * 获得过滤条件
  290. */
  291. getCondition: function(items) {
  292. var me = this,
  293. conditions = [];
  294. for(var i = 0; i < items.length; i++) {
  295. var item = items[i];
  296. var field = item.name,
  297. func = item.getCondition,
  298. value = item.value,
  299. condition;
  300. if(typeof func == 'function') {
  301. condition = {
  302. type: 'condition',
  303. value: func(value)
  304. }
  305. }else {
  306. var xtype = item.xtype || 'textfield',
  307. type = item.fieldType || me.getDefaultFieldType(xtype),
  308. operation = item.operation || me.getDefaultFieldOperation(xtype),
  309. conditionValue = me.getConditionValue(xtype, value);
  310. if(!conditionValue) {
  311. continue;
  312. }
  313. condition = {
  314. type: type,
  315. field: field,
  316. operation: operation,
  317. value: conditionValue
  318. }
  319. }
  320. conditions.push(condition);
  321. };
  322. return conditions;
  323. },
  324. getDefaultFieldType: function(xtype) {
  325. var type;
  326. if(Ext.Array.contains(['numberfield'], xtype)) {
  327. type = 'number';
  328. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  329. type = 'date';
  330. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  331. type = 'enum';
  332. }else {
  333. type = 'string';
  334. }
  335. return type;
  336. },
  337. getDefaultFieldOperation: function(xtype) {
  338. var operation;
  339. if(Ext.Array.contains(['numberfield'], xtype)) {
  340. operation = '=';
  341. }else if(Ext.Array.contains(['datefield'], xtype)) {
  342. operation = '=';
  343. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  344. operation = 'between';
  345. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  346. operation = 'in';
  347. }else {
  348. operation = 'like';
  349. }
  350. return operation;
  351. },
  352. /**
  353. * 处理部分字段值
  354. */
  355. getConditionValue: function(xtype, value) {
  356. var conditionValue;
  357. if(xtype == 'datefield') {
  358. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  359. }else if(xtype == 'condatefield') {
  360. var from = value.from,
  361. to = value.to;
  362. 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');
  363. }else if(xtype == 'combobox' || xtype == 'combo') {
  364. conditionValue = '\'' + value + '\'';
  365. }else if(xtype == 'multicombo') {
  366. conditionValue = value.map(function(v) {
  367. return '\'' + v.value + '\'';
  368. }).join(',');
  369. }else {
  370. conditionValue = value;
  371. }
  372. return conditionValue;
  373. },
  374. refresh:function(){
  375. //debugger
  376. }
  377. })