DataList.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.sys.invitation.DataList', {
  5. extend: 'Ext.grid.Panel',
  6. xtype: 'sys-invitation-datalist',
  7. controller: 'sys-invitation-datalist',
  8. viewModel: 'sys-invitation-datalist',
  9. autoScroll: true,
  10. frame:true,
  11. layout:'fit',
  12. dataUrl:'/api/commons/remind/apply/list',
  13. plugins: [{
  14. ptype: 'cellediting',
  15. clicksToEdit: 1
  16. }],
  17. tbar: [{
  18. width: 110,
  19. name: 'username',
  20. xtype: 'textfield',
  21. emptyText : '姓名'
  22. },{
  23. width: 140,
  24. name: 're_status',
  25. emptyText : '批准状态',
  26. xtype: 'combobox',
  27. queryMode: 'local',
  28. displayField: 'display',
  29. valueField: 'value',
  30. editable:false,
  31. store: Ext.create('Ext.data.ArrayStore', {
  32. fields: ['display', 'value'],
  33. data: [
  34. ["全部", "ALL"],
  35. ["待批准", "2"],
  36. ["已批准", "1"],
  37. ["未批准", "0"]
  38. ]
  39. }),
  40. getCondition: function(value) {
  41. if(value == 'ALL') {
  42. return '1=1';
  43. }else {
  44. return 're_status=\'' + value + '\'';
  45. }
  46. }
  47. },{
  48. xtype:'button',
  49. text:'查询',
  50. listeners: {
  51. click:function(b){
  52. var grid = b.ownerCt.ownerCt;
  53. var tbar = b.ownerCt;
  54. grid.condition = '';
  55. var items = [];
  56. var fields = tbar.items.items.map(f => f.name);
  57. Ext.each(fields, function(f, index){
  58. var field = tbar.down('[name='+f+']');
  59. if(field){
  60. items.push(field);
  61. }
  62. });
  63. grid.condition = grid.getCondition(items);
  64. grid.store.loadPage(1);
  65. }
  66. }
  67. },'->',{
  68. xtype:'button',
  69. text:'刷新',
  70. listeners: {
  71. click: 'onRefresh'
  72. }
  73. }],
  74. columns : [{
  75. text : '操作',
  76. dataIndex : 'status',
  77. width:110,
  78. renderer:function(v,atr,rec,index){
  79. var grid = this;
  80. if(typeof(window.showWin)!='function'){
  81. window.showWin = function(x){
  82. var record = grid.store.getAt(x);
  83. grid.dialog = grid.add({
  84. xtype: 'sys-invitation-editwindow',
  85. bind: {
  86. title: '批准信息'
  87. },
  88. _parent:grid,
  89. record:record,
  90. session: true
  91. });
  92. grid.dialog.show();
  93. }
  94. }
  95. if(typeof(window.disagree)!='function'){
  96. window.disagree = function(x){
  97. grid.setLoading(true);
  98. var record = grid.store.getAt(x);
  99. var _params = {
  100. id:Number(record.get('id')),
  101. status:0
  102. };
  103. saas.util.BaseUtil.request({
  104. url: '/api/commons/remind/apply/confirm',
  105. params: JSON.stringify(_params),
  106. method: 'POST',
  107. })
  108. .then(function(localJson) {
  109. grid.setLoading(false);
  110. if(localJson.success){
  111. saas.util.BaseUtil.showSuccessToast('保存成功');
  112. grid.store.load();
  113. }
  114. })
  115. .catch(function(res) {
  116. grid.setLoading(false);
  117. console.error(res);
  118. saas.util.BaseUtil.showErrorToast('保存失败: ' + res.message);
  119. });
  120. }
  121. }
  122. if(v&&v!=''){
  123. if(v=='2'){
  124. 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>"+
  125. "<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>";
  126. }else if(v=='1'){
  127. return '已批准';
  128. }else if(v=='0'){
  129. return '未批准'
  130. }
  131. }
  132. return v;
  133. }
  134. },{
  135. text : 'id',
  136. hidden:true,
  137. dataIndex : 'id',
  138. xtype : 'numbercolumn',
  139. },{
  140. text : 'accountId',
  141. hidden:true,
  142. dataIndex : 'accountId',
  143. xtype : 'numbercolumn',
  144. },{
  145. text : '姓名',
  146. width : 90.0,
  147. dataIndex : 'username',
  148. },{
  149. text : '手机号码',
  150. dataIndex : 'mobile',
  151. width : 150.0,
  152. },{
  153. text : '岗位角色id',
  154. hidden:true,
  155. dataIndex : 'roles'
  156. },{
  157. text : '岗位角色',
  158. dataIndex : 'roleNames',
  159. width : 220.0,
  160. }],
  161. dbSearchFields: [],
  162. condition:'',
  163. initComponent: function() {
  164. var me = this;
  165. if(me.columns){
  166. var fields = me.columns.map(column => column.dataIndex);
  167. me.store = Ext.create('Ext.data.Store',{
  168. fields:fields,
  169. autoLoad: true,
  170. pageSize: 11,
  171. data: [],
  172. proxy: {
  173. timeout:8000,
  174. type: 'ajax',
  175. url: me.dataUrl,
  176. actionMethods: {
  177. read: 'GET'
  178. },
  179. reader: {
  180. type: 'json',
  181. rootProperty: 'data.list',
  182. totalProperty: 'data.total',
  183. },
  184. listeners: {
  185. exception: function(proxy, response, operation, eOpts) {
  186. if(operation.success) {
  187. if(response.timedout) {
  188. saas.util.BaseUtil.showErrorToast('请求超时');
  189. }
  190. }else {
  191. if(response.timedout) {
  192. saas.util.BaseUtil.showErrorToast('请求超时');
  193. }else{
  194. if(proxy.showPowerMessage){
  195. saas.util.BaseUtil.showErrorToast('查询失败:' + response.responseJson?response.responseJson.message:'请求超时');
  196. }
  197. }
  198. }
  199. }
  200. }
  201. },
  202. listeners: {
  203. beforeload: function (store, op) {
  204. var condition = me.condition;
  205. if (Ext.isEmpty(condition)) {
  206. condition = '';
  207. }
  208. Ext.apply(store.proxy.extraParams, {
  209. number: op._page,
  210. size: store.pageSize,
  211. condition: JSON.stringify(condition)
  212. });
  213. }
  214. }
  215. });
  216. Ext.apply(me, {
  217. dockedItems:[{
  218. xtype: 'pagingtoolbar',
  219. dock: 'bottom',
  220. displayInfo: true,
  221. store: me.store
  222. }]
  223. });
  224. }
  225. me.callParent(arguments);
  226. },
  227. listeners:{
  228. boxready: function(grid, width, height, eOpts) {
  229. var store = grid.getStore(),
  230. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  231. gridBodyBoxHeight = gridBodyBox.height;
  232. var pageSize = Math.floor(gridBodyBoxHeight / 35);
  233. store.setPageSize(pageSize);
  234. }
  235. },
  236. getGridSelected:function(type){
  237. var isErrorSelect = false;
  238. var checkField = this.statusCodeField;
  239. var me = this,
  240. items = me.selModel.getSelection(),
  241. data = new Array() ;
  242. Ext.each(items, function(item, index){
  243. if(!Ext.isEmpty(item.data[me.idField])){
  244. var o = new Object();
  245. if(me.idField){
  246. o['id'] = item.data[me.idField];
  247. }
  248. if(me.codeField){
  249. o['code'] = item.data[me.codeField];
  250. }
  251. if(type&&type==item.data[checkField]){
  252. isErrorSelect = true
  253. }
  254. data.push(o);
  255. }
  256. });
  257. if(isErrorSelect){
  258. return false;
  259. }
  260. return data;
  261. },
  262. /**
  263. * 获得过滤条件
  264. */
  265. getCondition: function(items) {
  266. var me = this,
  267. conditions = [];
  268. for(var i = 0; i < items.length; i++) {
  269. var item = items[i];
  270. var field = item.name,
  271. func = item.getCondition,
  272. value = item.value,
  273. condition;
  274. if(value&&value!=''){
  275. if(typeof func == 'function') {
  276. condition = {
  277. type: 'condition',
  278. value: func(value)
  279. }
  280. }else {
  281. var xtype = item.xtype || 'textfield',
  282. type = item.fieldType || me.getDefaultFieldType(xtype),
  283. operation = item.operation || me.getDefaultFieldOperation(xtype),
  284. conditionValue = me.getConditionValue(xtype, value);
  285. if(!conditionValue) {
  286. continue;
  287. }
  288. condition = {
  289. type: type,
  290. field: field,
  291. operation: operation,
  292. value: conditionValue
  293. }
  294. }
  295. conditions.push(condition);
  296. }
  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. this.store.load()
  352. }
  353. })