DataList.js 10 KB

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