DataList.js 11 KB

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