DataList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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. mobile:record.get('mobile')
  116. };
  117. saas.util.BaseUtil.request({
  118. url: '/api/commons/remind/apply/confirm',
  119. params: JSON.stringify(_params),
  120. method: 'POST',
  121. })
  122. .then(function(localJson) {
  123. grid.setLoading(false);
  124. if(localJson.success){
  125. saas.util.BaseUtil.showSuccessToast('保存成功');
  126. grid.store.load();
  127. }
  128. })
  129. .catch(function(e) {
  130. grid.setLoading(false);
  131. saas.util.BaseUtil.showErrorToast('保存失败: ' + e.message);
  132. });
  133. }
  134. }
  135. if(v&&v!=''){
  136. if(v=='2'){
  137. 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>"+
  138. "<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>";
  139. }else if(v=='1'){
  140. return '已批准';
  141. }else if(v=='0'){
  142. return '未批准'
  143. }
  144. }
  145. return v;
  146. }
  147. },{
  148. text : 'id',
  149. hidden:true,
  150. dataIndex : 'id',
  151. xtype : 'numbercolumn',
  152. },{
  153. text : 'accountId',
  154. hidden:true,
  155. dataIndex : 'accountId',
  156. xtype : 'numbercolumn',
  157. },{
  158. text : '姓名',
  159. width : 90.0,
  160. dataIndex : 'username',
  161. },{
  162. text : '手机号码',
  163. dataIndex : 'mobile',
  164. width : 150.0,
  165. },{
  166. text : '岗位角色id',
  167. hidden:true,
  168. dataIndex : 'roles'
  169. },{
  170. text : '岗位角色',
  171. dataIndex : 'roleNames',
  172. width : 220.0,
  173. }],
  174. dbSearchFields: [],
  175. condition:'',
  176. initComponent: function() {
  177. var me = this;
  178. if(me.columns){
  179. var fields = me.columns.map(column => column.dataIndex);
  180. me.store = Ext.create('Ext.data.Store',{
  181. fields:fields,
  182. autoLoad: true,
  183. pageSize: 11,
  184. data: [],
  185. proxy: {
  186. timeout:8000,
  187. type: 'ajax',
  188. url: me.dataUrl,
  189. actionMethods: {
  190. read: 'GET'
  191. },
  192. reader: {
  193. type: 'json',
  194. rootProperty: 'data.list',
  195. totalProperty: 'data.total',
  196. },
  197. listeners: {
  198. exception: function(proxy, response, operation, eOpts) {
  199. if(operation.success) {
  200. if(response.timedout) {
  201. saas.util.BaseUtil.showErrorToast('请求超时');
  202. }
  203. }else {
  204. if(response.timedout) {
  205. saas.util.BaseUtil.showErrorToast('请求超时');
  206. }else{
  207. if(proxy.showPowerMessage){
  208. saas.util.BaseUtil.showErrorToast('查询失败:' + (response.responseJson?response.responseJson.message:'请求超时'));
  209. }
  210. }
  211. }
  212. }
  213. }
  214. },
  215. listeners: {
  216. beforeload: function (store, op) {
  217. var condition = me.condition;
  218. if (Ext.isEmpty(condition)) {
  219. condition = [];
  220. }
  221. var _localStorage = Ext.decode(sessionStorage.getItem('app-state-session'));
  222. var nowCompanyId = _localStorage.account.companyId;
  223. condition.push({
  224. type:'condition',
  225. value:"companyId="+nowCompanyId
  226. });
  227. Ext.apply(store.proxy.extraParams, {
  228. number: op._page,
  229. size: store.pageSize,
  230. condition: JSON.stringify(condition)
  231. });
  232. }
  233. }
  234. });
  235. Ext.apply(me, {
  236. dockedItems:[{
  237. xtype: 'pagingtoolbar',
  238. dock: 'bottom',
  239. displayInfo: true,
  240. store: me.store
  241. }]
  242. });
  243. }
  244. me.callParent(arguments);
  245. },
  246. listeners:{
  247. boxready: function(grid, width, height, eOpts) {
  248. var store = grid.getStore(),
  249. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  250. gridBodyBoxHeight = gridBodyBox.height;
  251. var pageSize = Math.floor(gridBodyBoxHeight / 35);
  252. store.setPageSize(pageSize);
  253. grid.ownerCt.el.dom.style.left = '8px';
  254. grid.el.dom.style.padding = '0px'
  255. }
  256. },
  257. getGridSelected:function(type){
  258. var isErrorSelect = false;
  259. var checkField = this.statusCodeField;
  260. var me = this,
  261. items = me.selModel.getSelection(),
  262. data = new Array() ;
  263. Ext.each(items, function(item, index){
  264. if(!Ext.isEmpty(item.data[me.idField])){
  265. var o = new Object();
  266. if(me.idField){
  267. o['id'] = item.data[me.idField];
  268. }
  269. if(me.codeField){
  270. o['code'] = item.data[me.codeField];
  271. }
  272. if(type&&type==item.data[checkField]){
  273. isErrorSelect = true
  274. }
  275. data.push(o);
  276. }
  277. });
  278. if(isErrorSelect){
  279. return false;
  280. }
  281. return data;
  282. },
  283. /**
  284. * 获得过滤条件
  285. */
  286. getConditions: function() {
  287. var me = this,
  288. tbar = me.getDockedItems()[0],
  289. items = Ext.Array.filter(tbar.items.items, function(item) {
  290. return !!item.name;
  291. }),
  292. conditions = [];
  293. for(var i = 0; i < items.length; i++) {
  294. var item = items[i];
  295. var field = item.name,
  296. func = item.getCondition,
  297. value = item.value,
  298. condition;
  299. if(value&&value!=''){
  300. if(typeof func == 'function') {
  301. condition = {
  302. type: 'condition',
  303. value: func(value)
  304. }
  305. }else {
  306. var type = item.fieldType || me.getDefaultFieldType(item),
  307. operation = item.operation || me.getDefaultFieldOperation(item),
  308. conditionValue = me.getConditionValue(item, value);
  309. if(!conditionValue) {
  310. continue;
  311. }
  312. condition = {
  313. type: type,
  314. field: field,
  315. operation: operation,
  316. value: conditionValue
  317. }
  318. }
  319. conditions.push(condition);
  320. }
  321. }
  322. return conditions;
  323. },
  324. /**
  325. * 只要arr1和arr2中存在相同项即返回真
  326. */
  327. isContainsAny: function (arr1, arr2) {
  328. for (var i = 0; i < arr2.length; i++) {
  329. var a2 = arr2[i];
  330. if (!!arr1.find(function (a1) {
  331. return a1 == a2
  332. })) {
  333. return true;
  334. }
  335. }
  336. return false;
  337. },
  338. getDefaultFieldType: function (field) {
  339. var me = this,
  340. xtypes = field.getXTypes().split('/'),
  341. type;
  342. if (me.isContainsAny(xtypes, ['numberfield'])) {
  343. type = 'number';
  344. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  345. type = 'date';
  346. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  347. type = 'enum';
  348. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  349. type = 'enum';
  350. } else {
  351. type = 'string';
  352. }
  353. return type;
  354. },
  355. getDefaultFieldOperation: function (field) {
  356. var me = this,
  357. xtypes = field.getXTypes().split('/'),
  358. operation;
  359. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  360. operation = '=';
  361. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  362. operation = 'between';
  363. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  364. operation = 'in';
  365. } else {
  366. operation = 'like';
  367. }
  368. return operation;
  369. },
  370. /**
  371. * 处理部分字段值
  372. */
  373. getConditionValue: function (field, value) {
  374. var me = this,
  375. xtypes = field.getXTypes().split('/'),
  376. conditionValue;
  377. if (me.isContainsAny(xtypes, ['datefield'])) {
  378. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  379. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  380. var from = value.from,
  381. to = value.to;
  382. conditionValue = from + ',' + to;
  383. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  384. var from = value.from,
  385. to = value.to;
  386. 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');
  387. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  388. conditionValue = value;
  389. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  390. conditionValue = '\'' + value + '\'';
  391. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  392. conditionValue = value.map ? value.map(function (v) {
  393. return '\'' + v.value + '\'';
  394. }).join(',') : '';
  395. } else {
  396. conditionValue = value;
  397. }
  398. return conditionValue;
  399. }
  400. })