DataList.js 12 KB

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