DataList.js 12 KB

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