DataList.js 13 KB

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