DataList.js 12 KB

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