DataList.js 12 KB

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