DataList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /**
  2. * Created by zhouy on 2018/10/18.
  3. */
  4. Ext.define('saas.view.purchase.sendQuotation.DataList', {
  5. extend: 'Ext.grid.Panel',
  6. xtype: 'purchase-sendQuotation-datalist',
  7. controller: 'purchase-sendQuotation-datalist',
  8. viewModel: 'purchase-sendQuotation-datalist',
  9. autoScroll: true,
  10. frame:true,
  11. layout:'fit',
  12. dataUrl:'/api/document/product/list',
  13. sendQuotationUrl:'/api/commons/number/delete/',
  14. plugins: [{
  15. ptype: 'menuclipboard'
  16. }],
  17. selModel: {
  18. checkOnly:true,
  19. type:'checkboxmodel'
  20. },
  21. tbar: [{
  22. width: 310,
  23. name: 'search',
  24. xtype: 'textfield',
  25. emptyText : '请输入物料编号/品牌/名称/型号',
  26. enableKeyEvents: true,
  27. getCondition: function (value) {
  28. return ' (pr_code like\'%' + value + '%\' or pr_detail like \'%' + value + '%\' or pr_brand like \'%' + value + '%\' or pr_orispeccode like \'%' + value + '%\') ';
  29. },
  30. listeners: {
  31. keydown: {
  32. fn: function(th, e, eOpts) {
  33. if(e.keyCode == 13) {
  34. var grid = th.up('grid');
  35. grid.condition = grid.getConditions();
  36. grid.store.loadPage(1);
  37. }
  38. }
  39. }
  40. }
  41. },{
  42. cls:'x-formpanel-btn-blue',
  43. xtype:'button',
  44. text:'查询',
  45. listeners: {
  46. click:function(b){
  47. var grid = b.ownerCt.ownerCt;
  48. grid.condition = grid.getConditions();
  49. grid.store.loadPage(1);
  50. }
  51. }
  52. },'->',{
  53. width: 180,
  54. name: 'endDate',
  55. xtype: 'numberfield',
  56. decimalPrecision:0,
  57. minValue:0,
  58. fieldLabel : '报价截至天数'
  59. },{
  60. cls:'x-formpanel-btn-blue',
  61. xtype:'button',
  62. text:'发起询价',
  63. listeners: {
  64. click: function(){
  65. var form = this.ownerCt.ownerCt;
  66. var grid = this.ownerCt.ownerCt.items.items[0].grid;
  67. var endDate = form.down('[name=endDate]');
  68. if(!endDate.value||endDate.value==0){
  69. saas.util.BaseUtil.showErrorToast('请填写报价截至天数');
  70. return false;
  71. }
  72. form.onVastDeal(sendQuotation,'发起询价');
  73. }
  74. }
  75. }],
  76. columns : [{
  77. text : 'id',
  78. width : 0,
  79. dataIndex : 'id',
  80. xtype : 'numbercolumn',
  81. hidden:true
  82. },{
  83. text : '物料编号',
  84. width : 200.0,
  85. dataIndex : 'pr_code',
  86. xtype : '',
  87. },
  88. {
  89. text : '品牌',
  90. dataIndex : 'pr_brand',
  91. width : 110.0,
  92. xtype : '',
  93. },
  94. {
  95. text : '名称',
  96. dataIndex : 'pr_detail',
  97. width : 150.0
  98. },{
  99. text : '型号',
  100. dataIndex : 'pr_orispeccode',
  101. width : 110.0
  102. },{
  103. text : '规格',
  104. dataIndex : 'pr_spec',
  105. width : 110.0
  106. },{
  107. text : '单位',
  108. dataIndex : 'pr_unit',
  109. width : 110.0
  110. }, {
  111. dataIndex: '',
  112. flex: 1
  113. }],
  114. dbSearchFields: [],
  115. condition:'',
  116. initComponent: function() {
  117. var me = this;
  118. if(me.columns){
  119. var fields = me.columns.map(column => column.dataIndex);
  120. me.columns = me.insertFirstColumn(me.columns);
  121. me.store = Ext.create('Ext.data.Store',{
  122. fields:fields,
  123. autoLoad: true,
  124. pageSize: 15,
  125. data: [],
  126. proxy: {
  127. timeout:8000,
  128. type: 'ajax',
  129. headers:{
  130. 'Access-Control-Allow-Origin': '*',
  131. "Content-Type": 'application/json;charset=UTF-8'
  132. },
  133. url: me.dataUrl,
  134. actionMethods: {
  135. read: 'GET'
  136. },
  137. reader: {
  138. type: 'json',
  139. rootProperty: 'data.list',
  140. totalProperty: 'data.total',
  141. }
  142. },
  143. listeners: {
  144. beforeload: function (store, op) {
  145. var condition = me.condition;
  146. if (Ext.isEmpty(condition)) {
  147. condition = '';
  148. }
  149. Ext.apply(store.proxy.extraParams, {
  150. w:1,
  151. page: op._page,
  152. count: store.pageSize,
  153. condition: JSON.stringify(condition)
  154. });
  155. }
  156. }
  157. });
  158. Ext.apply(me, {
  159. dockedItems:[{
  160. xtype: 'pagingtoolbar',
  161. dock: 'bottom',
  162. displayInfo: true,
  163. store: me.store
  164. }]
  165. });
  166. }
  167. me.callParent(arguments);
  168. },
  169. onVastDeal:function(url,type){
  170. var form = this.ownerCt;
  171. var grid = this;
  172. var data = grid.getGridSelected(type);
  173. if(!data){
  174. saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
  175. return false;
  176. }
  177. if(data&&data.length>0){
  178. var params = JSON.stringify({baseDTOs:data});
  179. saas.util.BaseUtil.request({
  180. url: url,
  181. params: params,
  182. method: 'POST',
  183. async:false
  184. })
  185. .then(function() {
  186. saas.util.BaseUtil.showSuccessToast('操作成功');
  187. grid.store.load();
  188. })
  189. .catch(function(e) {
  190. saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
  191. });
  192. }else{
  193. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。');
  194. }
  195. },
  196. listeners:{
  197. boxready: function(grid, width, height, eOpts) {
  198. var store = grid.getStore(),
  199. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  200. gridBodyBoxHeight = gridBodyBox.height;
  201. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  202. store.setPageSize(pageSize);
  203. grid.ownerCt.el.dom.style.left = '8px';
  204. grid.el.dom.style.padding = '0px'
  205. },
  206. itemClick: function(view,record,a,index,c) {
  207. var classList = c.target.classList.value;
  208. var grid = this;
  209. if(classList.indexOf('fa-pencil')>-1){
  210. var form = this.ownerCt;
  211. this.dialog = form.getController().getView().add({
  212. xtype: 'sys-maxnumbers-window',
  213. bind: {
  214. title: '修改单据编码规则'
  215. },
  216. _parent:form,
  217. _combo:this,
  218. record:record,
  219. session: true
  220. });
  221. this.dialog.show();
  222. }else if(classList.indexOf('fa-trash-o')>-1){
  223. //删除
  224. var id = record.get('id');
  225. if(id){
  226. saas.util.BaseUtil.request({
  227. url: grid.deleteUrl+id,
  228. method: 'POST',
  229. })
  230. .then(function(localJson) {
  231. if(localJson.success){
  232. //解析参数
  233. saas.util.BaseUtil.showSuccessToast('删除成功');
  234. view.ownerCt.store.load();
  235. }
  236. })
  237. .catch(function(e) {
  238. saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  239. });
  240. }
  241. }
  242. }
  243. },
  244. insertFirstColumn:function(columns){
  245. var me=this;
  246. return columns;
  247. },
  248. getGridSelected:function(type){
  249. var isErrorSelect = false;
  250. var checkField = this.statusCodeField;
  251. var me = this,
  252. items = me.selModel.getSelection(),
  253. data = new Array() ;
  254. Ext.each(items, function(item, index){
  255. if(!Ext.isEmpty(item.data[me.idField])){
  256. var o = new Object();
  257. if(me.idField){
  258. o['id'] = item.data[me.idField];
  259. }
  260. if(me.codeField){
  261. o['code'] = item.data[me.codeField];
  262. }
  263. if(type&&type==item.data[checkField]){
  264. isErrorSelect = true
  265. }
  266. data.push(o);
  267. }
  268. });
  269. if(isErrorSelect){
  270. return false;
  271. }
  272. return data;
  273. },
  274. /**
  275. * 获得过滤条件
  276. */
  277. getConditions: function() {
  278. var me = this,
  279. tbar = me.getDockedItems()[0],
  280. items = Ext.Array.filter(tbar.items.items, function(item) {
  281. return !!item.name;
  282. }),
  283. conditions = [];
  284. for(var i = 0; i < items.length; i++) {
  285. var item = items[i];
  286. var field = item.name,
  287. func = item.getCondition,
  288. value = item.value,
  289. condition;
  290. if(value&&value!=''){
  291. if(typeof func == 'function') {
  292. condition = {
  293. type: 'condition',
  294. value: func(value)
  295. }
  296. }else {
  297. var type = item.fieldType || me.getDefaultFieldType(item),
  298. operation = item.operation || me.getDefaultFieldOperation(item),
  299. conditionValue = me.getConditionValue(item, value);
  300. if(!conditionValue) {
  301. continue;
  302. }
  303. condition = {
  304. type: type,
  305. field: field,
  306. operation: operation,
  307. value: conditionValue
  308. }
  309. }
  310. conditions.push(condition);
  311. }
  312. }
  313. return conditions;
  314. },
  315. /**
  316. * 只要arr1和arr2中存在相同项即返回真
  317. */
  318. isContainsAny: function (arr1, arr2) {
  319. for (var i = 0; i < arr2.length; i++) {
  320. var a2 = arr2[i];
  321. if (!!arr1.find(function (a1) {
  322. return a1 == a2
  323. })) {
  324. return true;
  325. }
  326. }
  327. return false;
  328. },
  329. getDefaultFieldType: function (field) {
  330. var me = this,
  331. xtypes = field.getXTypes().split('/'),
  332. type;
  333. if (me.isContainsAny(xtypes, ['numberfield'])) {
  334. type = 'number';
  335. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  336. type = 'date';
  337. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  338. type = 'enum';
  339. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  340. type = 'enum';
  341. } else {
  342. type = 'string';
  343. }
  344. return type;
  345. },
  346. getDefaultFieldOperation: function (field) {
  347. var me = this,
  348. xtypes = field.getXTypes().split('/'),
  349. operation;
  350. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  351. operation = '=';
  352. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  353. operation = 'between';
  354. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  355. operation = 'in';
  356. } else {
  357. operation = 'like';
  358. }
  359. return operation;
  360. },
  361. /**
  362. * 处理部分字段值
  363. */
  364. getConditionValue: function (field, value) {
  365. var me = this,
  366. xtypes = field.getXTypes().split('/'),
  367. conditionValue;
  368. if (me.isContainsAny(xtypes, ['datefield'])) {
  369. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  370. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  371. var from = value.from,
  372. to = value.to;
  373. conditionValue = from + ',' + to;
  374. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  375. var from = value.from,
  376. to = value.to;
  377. 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');
  378. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  379. conditionValue = value;
  380. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  381. conditionValue = '\'' + value + '\'';
  382. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  383. conditionValue = value.map ? value.map(function (v) {
  384. return '\'' + v.value + '\'';
  385. }).join(',') : '';
  386. } else {
  387. conditionValue = value;
  388. }
  389. return conditionValue;
  390. }
  391. })