DataList.js 12 KB

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