DataList.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. cls:'x-formpanel-btn-orange',
  15. xtype:'button',
  16. text:'查询',
  17. listeners: {
  18. click: 'onQuery'
  19. }
  20. },'->',{
  21. cls:'x-formpanel-btn-blue',
  22. xtype:'button',
  23. text:'新增',
  24. listeners: {
  25. click: 'onAdd'
  26. }
  27. }],
  28. columns : [{
  29. text : "id",
  30. width : 0,
  31. dataIndex : "id",
  32. xtype : "numbercolumn",
  33. },{
  34. text : "单据caller",
  35. width : 200.0,
  36. dataIndex : "mn_caller",
  37. xtype : "",
  38. },
  39. {
  40. text : "单据前缀",
  41. dataIndex : "mn_leadcode",
  42. width : 120.0,
  43. xtype : "",
  44. },
  45. {
  46. text : "单据规则",
  47. dataIndex : "mn_rule",
  48. width : 220.0,
  49. xtype : "",
  50. },{
  51. text : "规则长度",
  52. dataIndex : "mn_number",
  53. width : 120.0,
  54. xtype : "",
  55. }],
  56. dbSearchFields: [],
  57. condition:'',
  58. initComponent: function() {
  59. var me = this;
  60. if(me.columns){
  61. var fields = me.columns.map(column => column.dataIndex);
  62. me.columns = me.insertFirstColumn(me.columns);
  63. me.store = Ext.create('Ext.data.Store',{
  64. fields:fields,
  65. autoLoad: true,
  66. pageSize: 10,
  67. data: [],
  68. proxy: {
  69. timeout:8000,
  70. type: 'ajax',
  71. url: me.dataUrl,
  72. actionMethods: {
  73. read: 'GET'
  74. },
  75. reader: {
  76. type: 'json',
  77. rootProperty: 'data.list',
  78. totalProperty: 'data.total',
  79. }
  80. },
  81. listeners: {
  82. beforeload: function (store, op) {
  83. var condition = me.condition;
  84. if (Ext.isEmpty(condition)) {
  85. condition = "";
  86. }
  87. Ext.apply(store.proxy.extraParams, {
  88. number: op._page,
  89. size: store.pageSize,
  90. condition: JSON.stringify(condition)
  91. });
  92. }
  93. }
  94. });
  95. Ext.apply(me, {
  96. dockedItems:[{
  97. xtype: 'pagingtoolbar',
  98. dock: 'bottom',
  99. displayInfo: true,
  100. emptyMsg: "暂无数据",
  101. store: me.store,
  102. displayMsg: '显示{0}到{1}条数据,共有{2}条',
  103. beforePageText: "当前第",
  104. afterPageText: "页,共{0}页"
  105. }]
  106. });
  107. }
  108. me.callParent(arguments);
  109. },
  110. onVastDeal:function(url,type){
  111. var form = this.ownerCt;
  112. var grid = this;
  113. var data = grid.getGridSelected(type);
  114. if(!data){
  115. showToast('请勾选符合条件的行进行操作。');
  116. return false;
  117. }
  118. if(data&&data.length>0){
  119. var params = JSON.stringify({baseDTOs:data});
  120. form.BaseUtil.request({
  121. url: url,
  122. params: params,
  123. method: 'POST',
  124. async:false
  125. })
  126. .then(function() {
  127. showToast('操作成功');
  128. grid.store.load();
  129. })
  130. .catch(function(response) {
  131. showToast('操作失败');
  132. });
  133. }else{
  134. showToast('请勾选至少一条明细。');
  135. }
  136. },
  137. listeners:{
  138. itemClick: function(view,record,a,index,c) {
  139. var classList = c.target.classList.value;
  140. var form = view.ownerCt.ownerCt;
  141. if(classList.indexOf('fa-pencil')>-1){
  142. var config = {};
  143. config.initId = record.get('id');
  144. openTab(form._formXtype, '修改'+form._title, form._formXtype+config.initId, config);
  145. }else if(classList.indexOf('fa-trash-o')>-1){
  146. //删除
  147. var id = record.get('id');
  148. if(id){
  149. form.BaseUtil.request({
  150. url: form._deleteUrl+id,
  151. method: 'POST',
  152. })
  153. .then(function(localJson) {
  154. if(localJson.success){
  155. //解析参数
  156. showToast('删除成功');
  157. view.ownerCt.store.load();
  158. }
  159. })
  160. .catch(function() {
  161. showToast('删除失败');
  162. });
  163. }
  164. }
  165. }
  166. },
  167. getCondition: function(f,conditionExpression){
  168. var condition = '';
  169. if((f.xtype == 'checkbox' || f.xtype == 'radio')&&f.logic){
  170. }else if(f.xtype=='textfield'&&f.value!=''){
  171. condition=conditionExpression.replace(new RegExp("\\{0}","g"), f.value);
  172. }
  173. if(condition.length>0){
  174. condition+= ' AND ';
  175. }
  176. return condition;
  177. },
  178. insertFirstColumn:function(columns){
  179. var me=this;
  180. if(columns.length>0 && columns[0].xtype!='actioncolumn'){
  181. return Ext.Array.insert(columns,0,[{
  182. xtype:'actioncolumn',
  183. width:70,
  184. dataIndex:'actioncolumn',
  185. text:'操作',
  186. items: [{
  187. tooltip: '编辑',
  188. iconCls: 'x-fa fa-pencil fa-fw',
  189. scope:this
  190. },{
  191. text:'删除',
  192. iconCls:'x-fa fa-trash-o fa-fw',
  193. tooltip: '删除',
  194. scope:this
  195. }]
  196. }]);
  197. }
  198. return columns;
  199. },
  200. getGridSelected:function(type){
  201. var isErrorSelect = false;
  202. var checkField = this.statusCodeField;
  203. var me = this,
  204. items = me.selModel.getSelection(),
  205. data = new Array() ;
  206. Ext.each(items, function(item, index){
  207. if(!Ext.isEmpty(item.data[me.idField])){
  208. var o = new Object();
  209. if(me.idField){
  210. o['id'] = item.data[me.idField];
  211. }
  212. if(me.codeField){
  213. o['code'] = item.data[me.codeField];
  214. }
  215. if(type&&type==item.data[checkField]){
  216. isErrorSelect = true
  217. }
  218. data.push(o);
  219. }
  220. });
  221. if(isErrorSelect){
  222. return false;
  223. }
  224. return data;
  225. }
  226. })