DataList.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. }
  254. },
  255. getGridSelected:function(type){
  256. var isErrorSelect = false;
  257. var checkField = this.statusCodeField;
  258. var me = this,
  259. items = me.selModel.getSelection(),
  260. data = new Array() ;
  261. Ext.each(items, function(item, index){
  262. if(!Ext.isEmpty(item.data[me.idField])){
  263. var o = new Object();
  264. if(me.idField){
  265. o['id'] = item.data[me.idField];
  266. }
  267. if(me.codeField){
  268. o['code'] = item.data[me.codeField];
  269. }
  270. if(type&&type==item.data[checkField]){
  271. isErrorSelect = true
  272. }
  273. data.push(o);
  274. }
  275. });
  276. if(isErrorSelect){
  277. return false;
  278. }
  279. return data;
  280. },
  281. /**
  282. * 获得过滤条件
  283. */
  284. getConditions: function() {
  285. var me = this,
  286. tbar = me.getDockedItems()[0],
  287. items = Ext.Array.filter(tbar.items.items, function(item) {
  288. return !!item.name;
  289. }),
  290. conditions = [];
  291. for(var i = 0; i < items.length; i++) {
  292. var item = items[i];
  293. var field = item.name,
  294. func = item.getCondition,
  295. value = item.value,
  296. condition;
  297. if(value&&value!=''){
  298. if(typeof func == 'function') {
  299. condition = {
  300. type: 'condition',
  301. value: func(value)
  302. }
  303. }else {
  304. var type = item.fieldType || me.getDefaultFieldType(item),
  305. operation = item.operation || me.getDefaultFieldOperation(item),
  306. conditionValue = me.getConditionValue(item, value);
  307. if(!conditionValue) {
  308. continue;
  309. }
  310. condition = {
  311. type: type,
  312. field: field,
  313. operation: operation,
  314. value: conditionValue
  315. }
  316. }
  317. conditions.push(condition);
  318. }
  319. }
  320. return conditions;
  321. },
  322. /**
  323. * 只要arr1和arr2中存在相同项即返回真
  324. */
  325. isContainsAny: function (arr1, arr2) {
  326. for (var i = 0; i < arr2.length; i++) {
  327. var a2 = arr2[i];
  328. if (!!arr1.find(function (a1) {
  329. return a1 == a2
  330. })) {
  331. return true;
  332. }
  333. }
  334. return false;
  335. },
  336. getDefaultFieldType: function (field) {
  337. var me = this,
  338. xtypes = field.getXTypes().split('/'),
  339. type;
  340. if (me.isContainsAny(xtypes, ['numberfield'])) {
  341. type = 'number';
  342. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  343. type = 'date';
  344. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  345. type = 'enum';
  346. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  347. type = 'enum';
  348. } else {
  349. type = 'string';
  350. }
  351. return type;
  352. },
  353. getDefaultFieldOperation: function (field) {
  354. var me = this,
  355. xtypes = field.getXTypes().split('/'),
  356. operation;
  357. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  358. operation = '=';
  359. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  360. operation = 'between';
  361. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  362. operation = 'in';
  363. } else {
  364. operation = 'like';
  365. }
  366. return operation;
  367. },
  368. /**
  369. * 处理部分字段值
  370. */
  371. getConditionValue: function (field, value) {
  372. var me = this,
  373. xtypes = field.getXTypes().split('/'),
  374. conditionValue;
  375. if (me.isContainsAny(xtypes, ['datefield'])) {
  376. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  377. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  378. var from = value.from,
  379. to = value.to;
  380. conditionValue = from + ',' + to;
  381. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  382. var from = value.from,
  383. to = value.to;
  384. 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');
  385. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  386. conditionValue = value;
  387. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  388. conditionValue = '\'' + value + '\'';
  389. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  390. conditionValue = value.map ? value.map(function (v) {
  391. return '\'' + v.value + '\'';
  392. }).join(',') : '';
  393. } else {
  394. conditionValue = value;
  395. }
  396. return conditionValue;
  397. }
  398. })