DataList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. Ext.define('saas.view.sys.invitation.DataList', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'sys-invitation-datalist',
  4. controller: 'sys-invitation-datalist',
  5. viewModel: 'sys-invitation-datalist',
  6. autoScroll: true,
  7. frame:true,
  8. layout:'fit',
  9. dataUrl:'/api/commons/remind/apply/list',
  10. plugins: [{
  11. ptype: 'cellediting',
  12. clicksToEdit: 1
  13. }, {
  14. ptype: 'menuclipboard'
  15. }],
  16. tbar: [{
  17. width: 110,
  18. name: 're_applyname',
  19. xtype: 'textfield',
  20. emptyText : '姓名',
  21. enableKeyEvents: true,
  22. listeners: {
  23. keydown: {
  24. fn: function(th, e, eOpts) {
  25. if(e.keyCode == 13) {
  26. var grid = th.up('grid');
  27. grid.condition = grid.getConditions();
  28. grid.store.loadPage(1);
  29. }
  30. }
  31. }
  32. }
  33. },{
  34. width: 140,
  35. name: 're_status',
  36. emptyText : '批准状态',
  37. xtype: 'combobox',
  38. queryMode: 'local',
  39. displayField: 'display',
  40. valueField: 'value',
  41. editable:false,
  42. store: Ext.create('Ext.data.ArrayStore', {
  43. fields: ['display', 'value'],
  44. data: [
  45. ["全部", "ALL"],
  46. ["待批准", "2"],
  47. ["已批准", "1"],
  48. ["未批准", "0"]
  49. ]
  50. }),
  51. getCondition: function(value) {
  52. if(value == 'ALL') {
  53. return '1=1';
  54. }else {
  55. return 're_status=\'' + value + '\'';
  56. }
  57. },
  58. enableKeyEvents: true,
  59. listeners: {
  60. keydown: {
  61. fn: function(th, e, eOpts) {
  62. if(e.keyCode == 13) {
  63. var grid = th.up('grid');
  64. grid.condition = grid.getConditions();
  65. grid.store.loadPage(1);
  66. }
  67. }
  68. }
  69. }
  70. },{
  71. xtype:'button',
  72. text:'查询',
  73. listeners: {
  74. click:function(b){
  75. var grid = b.ownerCt.ownerCt;
  76. grid.condition = grid.getConditions();
  77. grid.store.loadPage(1);
  78. }
  79. }
  80. },'->',{
  81. xtype:'button',
  82. text:'刷新',
  83. listeners: {
  84. click: 'onRefresh'
  85. }
  86. }],
  87. columns : [{
  88. text : '批准',
  89. dataIndex : 'status',
  90. width:110,
  91. renderer:function(v,atr,rec,index){
  92. var grid = this;
  93. if(typeof(window.showWin)!='function'){
  94. window.showWin = function(x){
  95. var record = grid.store.getAt(x);
  96. grid.dialog = grid.add({
  97. xtype: 'sys-invitation-editwindow',
  98. bind: {
  99. title: '批准信息'
  100. },
  101. _parent:grid,
  102. record:record,
  103. session: true
  104. });
  105. grid.dialog.show();
  106. }
  107. }
  108. if(typeof(window.disagree)!='function'){
  109. window.disagree = function(x){
  110. grid.setLoading(true);
  111. var record = grid.store.getAt(x);
  112. var _params = {
  113. id:Number(record.get('id')),
  114. status:0
  115. };
  116. saas.util.BaseUtil.request({
  117. url: '/api/commons/remind/apply/confirm',
  118. params: JSON.stringify(_params),
  119. method: 'POST',
  120. })
  121. .then(function(localJson) {
  122. grid.setLoading(false);
  123. if(localJson.success){
  124. saas.util.BaseUtil.showSuccessToast('保存成功');
  125. grid.store.load();
  126. }
  127. })
  128. .catch(function(e) {
  129. grid.setLoading(false);
  130. saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message);
  131. });
  132. }
  133. }
  134. if(v&&v!=''){
  135. if(v=='2'){
  136. return "<input type='button' value='批准' style='padding:2px;color:white;font-size:13px;cursor:pointer;height:22px;background-color: #35baf6;border-color: #35baf6;display: inline-block;cursor: pointer;text-align: center;border-radius: 3px;border: 1px solid transparent;' onClick='window.showWin(\""+index+"\")'></input>"+"<span style='font-size: 19px;'> | </span>"+
  137. "<input type='button' value='不批准' style='padding:2px;color:white;font-size:13px;cursor:pointer;height:22px;background-color: #35baf6;border-color: #35baf6;display: inline-block;cursor: pointer;text-align: center;border-radius: 3px;border: 1px solid transparent;' onClick='window.disagree(\""+index+"\")'></input>";
  138. }else if(v=='1'){
  139. return '已批准';
  140. }else if(v=='0'){
  141. return '未批准'
  142. }
  143. }
  144. return v;
  145. }
  146. },{
  147. text : 'id',
  148. hidden:true,
  149. dataIndex : 'id',
  150. xtype : 'numbercolumn',
  151. },{
  152. text : 'accountId',
  153. hidden:true,
  154. dataIndex : 'accountId',
  155. xtype : 'numbercolumn',
  156. },{
  157. text : '姓名',
  158. width : 90.0,
  159. dataIndex : 'username',
  160. },{
  161. text : '手机号码',
  162. dataIndex : 'mobile',
  163. width : 150.0,
  164. },{
  165. text : '岗位角色id',
  166. hidden:true,
  167. dataIndex : 'roles'
  168. },{
  169. text : '岗位角色',
  170. dataIndex : 'roleNames',
  171. width : 220.0,
  172. }],
  173. dbSearchFields: [],
  174. condition:'',
  175. initComponent: function() {
  176. var me = this;
  177. if(me.columns){
  178. var fields = me.columns.map(column => column.dataIndex);
  179. me.store = Ext.create('Ext.data.Store',{
  180. fields:fields,
  181. autoLoad: true,
  182. pageSize: 11,
  183. data: [],
  184. proxy: {
  185. timeout:8000,
  186. type: 'ajax',
  187. url: me.dataUrl,
  188. actionMethods: {
  189. read: 'GET'
  190. },
  191. reader: {
  192. type: 'json',
  193. rootProperty: 'data.list',
  194. totalProperty: 'data.total',
  195. },
  196. listeners: {
  197. exception: function(proxy, response, operation, eOpts) {
  198. if(operation.success) {
  199. if(response.timedout) {
  200. saas.util.BaseUtil.showErrorToast('请求超时');
  201. }
  202. }else {
  203. if(response.timedout) {
  204. saas.util.BaseUtil.showErrorToast('请求超时');
  205. }else{
  206. if(proxy.showPowerMessage){
  207. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  208. }
  209. }
  210. }
  211. }
  212. }
  213. },
  214. listeners: {
  215. beforeload: function (store, op) {
  216. var condition = me.condition;
  217. if (Ext.isEmpty(condition)) {
  218. condition = [];
  219. }
  220. var _localStorage = Ext.decode(localStorage.getItem('app-state-session'));
  221. var nowCompanyId = _localStorage.account.companyId;
  222. condition.push({
  223. type:'condition',
  224. value:"companyId="+nowCompanyId
  225. });
  226. Ext.apply(store.proxy.extraParams, {
  227. number: op._page,
  228. size: store.pageSize,
  229. condition: JSON.stringify(condition)
  230. });
  231. }
  232. }
  233. });
  234. Ext.apply(me, {
  235. dockedItems:[{
  236. xtype: 'pagingtoolbar',
  237. dock: 'bottom',
  238. displayInfo: true,
  239. store: me.store
  240. }]
  241. });
  242. }
  243. me.callParent(arguments);
  244. },
  245. listeners:{
  246. boxready: function(grid, width, height, eOpts) {
  247. var store = grid.getStore(),
  248. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  249. gridBodyBoxHeight = gridBodyBox.height;
  250. var pageSize = Math.floor(gridBodyBoxHeight / 35);
  251. store.setPageSize(pageSize);
  252. }
  253. },
  254. getGridSelected:function(type){
  255. var isErrorSelect = false;
  256. var checkField = this.statusCodeField;
  257. var me = this,
  258. items = me.selModel.getSelection(),
  259. data = new Array() ;
  260. Ext.each(items, function(item, index){
  261. if(!Ext.isEmpty(item.data[me.idField])){
  262. var o = new Object();
  263. if(me.idField){
  264. o['id'] = item.data[me.idField];
  265. }
  266. if(me.codeField){
  267. o['code'] = item.data[me.codeField];
  268. }
  269. if(type&&type==item.data[checkField]){
  270. isErrorSelect = true
  271. }
  272. data.push(o);
  273. }
  274. });
  275. if(isErrorSelect){
  276. return false;
  277. }
  278. return data;
  279. },
  280. /**
  281. * 获得过滤条件
  282. */
  283. getConditions: function() {
  284. var me = this,
  285. tbar = me.getDockedItems()[0],
  286. items = Ext.Array.filter(tbar.items.items, function(item) {
  287. return !!item.name;
  288. }),
  289. conditions = [];
  290. for(var i = 0; i < items.length; i++) {
  291. var item = items[i];
  292. var field = item.name,
  293. func = item.getCondition,
  294. value = item.value,
  295. condition;
  296. if(value&&value!=''){
  297. if(typeof func == 'function') {
  298. condition = {
  299. type: 'condition',
  300. value: func(value)
  301. }
  302. }else {
  303. var type = item.fieldType || me.getDefaultFieldType(item),
  304. operation = item.operation || me.getDefaultFieldOperation(item),
  305. conditionValue = me.getConditionValue(item, value);
  306. if(!conditionValue) {
  307. continue;
  308. }
  309. condition = {
  310. type: type,
  311. field: field,
  312. operation: operation,
  313. value: conditionValue
  314. }
  315. }
  316. conditions.push(condition);
  317. }
  318. }
  319. return conditions;
  320. },
  321. /**
  322. * 只要arr1和arr2中存在相同项即返回真
  323. */
  324. isContainsAny: function (arr1, arr2) {
  325. for (var i = 0; i < arr2.length; i++) {
  326. var a2 = arr2[i];
  327. if (!!arr1.find(function (a1) {
  328. return a1 == a2
  329. })) {
  330. return true;
  331. }
  332. }
  333. return false;
  334. },
  335. getDefaultFieldType: function (field) {
  336. var me = this,
  337. xtypes = field.getXTypes().split('/'),
  338. type;
  339. if (me.isContainsAny(xtypes, ['numberfield'])) {
  340. type = 'number';
  341. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  342. type = 'date';
  343. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  344. type = 'enum';
  345. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  346. type = 'enum';
  347. } else {
  348. type = 'string';
  349. }
  350. return type;
  351. },
  352. getDefaultFieldOperation: function (field) {
  353. var me = this,
  354. xtypes = field.getXTypes().split('/'),
  355. operation;
  356. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  357. operation = '=';
  358. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  359. operation = 'between';
  360. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  361. operation = 'in';
  362. } else {
  363. operation = 'like';
  364. }
  365. return operation;
  366. },
  367. /**
  368. * 处理部分字段值
  369. */
  370. getConditionValue: function (field, value) {
  371. var me = this,
  372. xtypes = field.getXTypes().split('/'),
  373. conditionValue;
  374. if (me.isContainsAny(xtypes, ['datefield'])) {
  375. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  376. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  377. var from = value.from,
  378. to = value.to;
  379. conditionValue = from + ',' + to;
  380. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  381. var from = value.from,
  382. to = value.to;
  383. 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');
  384. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  385. conditionValue = value;
  386. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  387. conditionValue = '\'' + value + '\'';
  388. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  389. conditionValue = value.map ? value.map(function (v) {
  390. return '\'' + v.value + '\'';
  391. }).join(',') : '';
  392. } else {
  393. conditionValue = value;
  394. }
  395. return conditionValue;
  396. }
  397. })