DataList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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. var grid = this;
  232. if(classList.indexOf('fa-pencil')>-1){
  233. var document = Ext.create('saas.view.document.kind.Kind',{});
  234. var form = this.ownerCt;
  235. this.dialog = this.getController().getView().add({
  236. xtype: 'document-kind-childwin',
  237. bind: {
  238. title: '修改账户信息'
  239. },
  240. dataKind:'accountinformation',
  241. belong:document.etc['accountinformation'],
  242. _parent:this,
  243. record:record,
  244. session: true
  245. });
  246. this.dialog.show();
  247. }
  248. }
  249. },
  250. insertFirstColumn:function(columns){
  251. var me=this;
  252. if(columns.length>0 && columns[0].xtype!='actioncolumn'){
  253. return Ext.Array.insert(columns,0,[{
  254. xtype:'actioncolumn',
  255. width:50,
  256. dataIndex:'actioncolumn',
  257. text:'操作',
  258. items: [{
  259. tooltip: '编辑',
  260. iconCls: 'x-fa fa-pencil fa-fw',
  261. scope:this
  262. }]
  263. }]);
  264. }
  265. return columns;
  266. },
  267. getGridSelected:function(type){
  268. var isErrorSelect = false;
  269. var checkField = this.statusCodeField;
  270. var me = this,
  271. items = me.selModel.getSelection(),
  272. data = new Array() ;
  273. Ext.each(items, function(item, index){
  274. if(!Ext.isEmpty(item.data[me.idField])){
  275. var o = new Object();
  276. if(me.idField){
  277. o['id'] = item.data[me.idField];
  278. }
  279. if(me.codeField){
  280. o['code'] = item.data[me.codeField];
  281. }
  282. if(type&&type==item.data[checkField]){
  283. isErrorSelect = true
  284. }
  285. data.push(o);
  286. }
  287. });
  288. if(isErrorSelect){
  289. return false;
  290. }
  291. return data;
  292. },
  293. /**
  294. * 获得过滤条件
  295. */
  296. getCondition: function(items) {
  297. var me = this,
  298. conditions = [];
  299. for(var i = 0; i < items.length; i++) {
  300. var item = items[i];
  301. var field = item.name,
  302. func = item.getCondition,
  303. value = item.value,
  304. condition;
  305. if(typeof func == 'function') {
  306. condition = {
  307. type: 'condition',
  308. value: func(value)
  309. }
  310. }else {
  311. var xtype = item.xtype || 'textfield',
  312. type = item.fieldType || me.getDefaultFieldType(xtype),
  313. operation = item.operation || me.getDefaultFieldOperation(xtype),
  314. conditionValue = me.getConditionValue(xtype, value);
  315. if(!conditionValue) {
  316. continue;
  317. }
  318. condition = {
  319. type: type,
  320. field: field,
  321. operation: operation,
  322. value: conditionValue
  323. }
  324. }
  325. conditions.push(condition);
  326. };
  327. return conditions;
  328. },
  329. getDefaultFieldType: function(xtype) {
  330. var type;
  331. if(Ext.Array.contains(['numberfield'], xtype)) {
  332. type = 'number';
  333. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  334. type = 'date';
  335. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  336. type = 'enum';
  337. }else {
  338. type = 'string';
  339. }
  340. return type;
  341. },
  342. getDefaultFieldOperation: function(xtype) {
  343. var operation;
  344. if(Ext.Array.contains(['numberfield'], xtype)) {
  345. operation = '=';
  346. }else if(Ext.Array.contains(['datefield'], xtype)) {
  347. operation = '=';
  348. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  349. operation = 'between';
  350. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  351. operation = 'in';
  352. }else {
  353. operation = 'like';
  354. }
  355. return operation;
  356. },
  357. /**
  358. * 处理部分字段值
  359. */
  360. getConditionValue: function(xtype, value) {
  361. var conditionValue;
  362. if(xtype == 'datefield') {
  363. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  364. }else if(xtype == 'condatefield') {
  365. var from = value.from,
  366. to = value.to;
  367. 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');
  368. }else if(xtype == 'combobox' || xtype == 'combo') {
  369. conditionValue = '\'' + value + '\'';
  370. }else if(xtype == 'multicombo') {
  371. conditionValue = value.map(function(v) {
  372. return '\'' + v.value + '\'';
  373. }).join(',');
  374. }else {
  375. conditionValue = value;
  376. }
  377. return conditionValue;
  378. },
  379. refresh:function(){
  380. //debugger
  381. }
  382. })