DataList.js 10 KB

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