DataList.js 11 KB

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