DataList.js 12 KB

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