DataList.js 10 KB

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