DataList.js 11 KB

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