DataList.js 12 KB

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