DataList.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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:'http://192.168.253.31:8560/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 : 120.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. width : 120.0,
  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.showToast('请勾选符合条件的行进行操作。');
  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.showToast('操作成功');
  156. grid.store.load();
  157. })
  158. .catch(function(response) {
  159. saas.util.BaseUtil.showToast('操作失败');
  160. });
  161. }else{
  162. saas.util.BaseUtil.showToast('请勾选至少一条明细。');
  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 = form.getController().getView().add({
  180. xtype: 'document-kind-childwin',
  181. bind: {
  182. title: '修改单据编码规则'
  183. },
  184. dataKind:'maxnumbers',
  185. belong:document.etc['maxnumbers'],
  186. _parent:form,
  187. _combo:this,
  188. record:record,
  189. session: true
  190. });
  191. this.dialog.show();
  192. }
  193. }
  194. },
  195. insertFirstColumn:function(columns){
  196. var me=this;
  197. if(columns.length>0 && columns[0].xtype!='actioncolumn'){
  198. return Ext.Array.insert(columns,0,[{
  199. xtype:'actioncolumn',
  200. width:50,
  201. dataIndex:'actioncolumn',
  202. text:'操作',
  203. items: [{
  204. tooltip: '编辑',
  205. iconCls: 'x-fa fa-pencil fa-fw',
  206. scope:this
  207. }]
  208. }]);
  209. }
  210. return columns;
  211. },
  212. getGridSelected:function(type){
  213. var isErrorSelect = false;
  214. var checkField = this.statusCodeField;
  215. var me = this,
  216. items = me.selModel.getSelection(),
  217. data = new Array() ;
  218. Ext.each(items, function(item, index){
  219. if(!Ext.isEmpty(item.data[me.idField])){
  220. var o = new Object();
  221. if(me.idField){
  222. o['id'] = item.data[me.idField];
  223. }
  224. if(me.codeField){
  225. o['code'] = item.data[me.codeField];
  226. }
  227. if(type&&type==item.data[checkField]){
  228. isErrorSelect = true
  229. }
  230. data.push(o);
  231. }
  232. });
  233. if(isErrorSelect){
  234. return false;
  235. }
  236. return data;
  237. },
  238. /**
  239. * 获得过滤条件
  240. */
  241. getCondition: function(items) {
  242. var me = this,
  243. conditions = [];
  244. for(var i = 0; i < items.length; i++) {
  245. var item = items[i];
  246. var field = item.name,
  247. func = item.getCondition,
  248. value = item.value,
  249. condition;
  250. if(typeof func == 'function') {
  251. condition = {
  252. type: 'condition',
  253. value: func(value)
  254. }
  255. }else {
  256. var xtype = item.xtype || 'textfield',
  257. type = item.fieldType || me.getDefaultFieldType(xtype),
  258. operation = item.operation || me.getDefaultFieldOperation(xtype),
  259. conditionValue = me.getConditionValue(xtype, value);
  260. if(!conditionValue) {
  261. continue;
  262. }
  263. condition = {
  264. type: type,
  265. field: field,
  266. operation: operation,
  267. value: conditionValue
  268. }
  269. }
  270. conditions.push(condition);
  271. };
  272. return conditions;
  273. },
  274. getDefaultFieldType: function(xtype) {
  275. var type;
  276. if(Ext.Array.contains(['numberfield'], xtype)) {
  277. type = 'number';
  278. }else if(Ext.Array.contains(['datefield', 'condatefield'], xtype)) {
  279. type = 'date';
  280. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo', 'radiofield', 'radio'], xtype)) {
  281. type = 'enum';
  282. }else {
  283. type = 'string';
  284. }
  285. return type;
  286. },
  287. getDefaultFieldOperation: function(xtype) {
  288. var operation;
  289. if(Ext.Array.contains(['numberfield'], xtype)) {
  290. operation = '=';
  291. }else if(Ext.Array.contains(['datefield'], xtype)) {
  292. operation = '=';
  293. }else if(Ext.Array.contains(['condatefield'], xtype)) {
  294. operation = 'between';
  295. }else if(Ext.Array.contains(['combobox', 'multicombo', 'combo'], xtype)) {
  296. operation = 'in';
  297. }else {
  298. operation = 'like';
  299. }
  300. return operation;
  301. },
  302. /**
  303. * 处理部分字段值
  304. */
  305. getConditionValue: function(xtype, value) {
  306. var conditionValue;
  307. if(xtype == 'datefield') {
  308. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  309. }else if(xtype == 'condatefield') {
  310. var from = value.from,
  311. to = value.to;
  312. 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');
  313. }else if(xtype == 'combobox' || xtype == 'combo') {
  314. conditionValue = '\'' + value + '\'';
  315. }else if(xtype == 'multicombo') {
  316. conditionValue = value.map(function(v) {
  317. return '\'' + v.value + '\'';
  318. }).join(',');
  319. }else {
  320. conditionValue = value;
  321. }
  322. return conditionValue;
  323. },
  324. refresh:function(){
  325. //debugger
  326. }
  327. })