DataList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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. layout:'fit',
  11. style:'border:1px solid #fff',
  12. dataUrl:'/api/document/product/list',
  13. sendQuotationUrl:'/api/purchase/purchase/inquiry/send',
  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. margin:'0 10 0 30',
  54. width: 180,
  55. name: 'endDate',
  56. xtype: 'numberfield',
  57. decimalPrecision:0,
  58. minValue:0,
  59. fieldLabel : '报价截至天数'
  60. },{
  61. cls:'x-formpanel-btn-blue',
  62. xtype:'button',
  63. text:'发起询价',
  64. listeners: {
  65. click: function(){
  66. var grid = this.ownerCt.ownerCt;
  67. var endDate = grid.down('[name=endDate]');
  68. if(!endDate.value||endDate.value==0){
  69. saas.util.BaseUtil.showErrorToast('请填写报价截至天数');
  70. return false;
  71. }
  72. grid.onVastDeal(grid.sendQuotationUrl,endDate.value);
  73. }
  74. }
  75. },'->',{
  76. ignore:true,
  77. style:'text-align: center;',
  78. xtype:'displayfield',
  79. value:'<a href=\"javascript:saas.util.BaseUtil.openTab(\'purchase-quotationList-datalist\',\'询价信息查询\',\'maintab-query-quotationList\')\">询价信息查询</a>'
  80. }],
  81. columns : [{
  82. text : 'id',
  83. width : 0,
  84. dataIndex : 'id',
  85. xtype : 'numbercolumn',
  86. hidden:true
  87. },{
  88. text : '物料编号',
  89. width : 200.0,
  90. dataIndex : 'pr_code',
  91. xtype : '',
  92. },
  93. {
  94. text : '品牌',
  95. dataIndex : 'pr_brand',
  96. width : 110.0,
  97. xtype : '',
  98. },
  99. {
  100. text : '名称',
  101. dataIndex : 'pr_detail',
  102. width : 150.0
  103. },{
  104. text : '型号',
  105. dataIndex : 'pr_orispeccode',
  106. width : 110.0
  107. },{
  108. text : '规格',
  109. dataIndex : 'pr_spec',
  110. width : 110.0
  111. },{
  112. text : '单位',
  113. dataIndex : 'pr_unit',
  114. width : 110.0
  115. }, {
  116. dataIndex: '',
  117. flex: 1
  118. }],
  119. dbSearchFields: [],
  120. condition:'',
  121. initComponent: function() {
  122. var me = this;
  123. if(me.columns){
  124. var fields = me.columns.map(column => column.dataIndex);
  125. me.columns = me.insertFirstColumn(me.columns);
  126. me.store = Ext.create('Ext.data.Store',{
  127. fields:fields,
  128. autoLoad: true,
  129. pageSize: 15,
  130. data: [],
  131. proxy: {
  132. timeout:8000,
  133. type: 'ajax',
  134. headers:{
  135. 'Access-Control-Allow-Origin': '*',
  136. "Content-Type": 'application/json;charset=UTF-8'
  137. },
  138. url: me.dataUrl,
  139. actionMethods: {
  140. read: 'GET'
  141. },
  142. reader: {
  143. type: 'json',
  144. rootProperty: 'data.list',
  145. totalProperty: 'data.total',
  146. }
  147. },
  148. listeners: {
  149. beforeload: function (store, op) {
  150. var condition = me.condition;
  151. if (Ext.isEmpty(condition)) {
  152. condition = '';
  153. }
  154. Ext.apply(store.proxy.extraParams, {
  155. number: op._page,
  156. size: store.pageSize,
  157. condition: JSON.stringify(condition)
  158. });
  159. }
  160. }
  161. });
  162. Ext.apply(me, {
  163. dockedItems:[{
  164. xtype: 'pagingtoolbar',
  165. dock: 'bottom',
  166. displayInfo: true,
  167. store: me.store
  168. }]
  169. });
  170. }
  171. me.callParent(arguments);
  172. },
  173. onVastDeal:function(url,leadTime){
  174. var grid = this;
  175. var data = grid.getGridSelected(leadTime);
  176. if(!data){
  177. saas.util.BaseUtil.showErrorToast('请勾选符合条件的行进行操作。');
  178. return false;
  179. }
  180. if(data&&data.length>0){
  181. grid.setLoading(true);
  182. var params = JSON.stringify(data);
  183. saas.util.BaseUtil.request({
  184. url: url,
  185. params: params,
  186. method: 'POST'
  187. })
  188. .then(function(res) {
  189. grid.setLoading(false);
  190. if(res.data.length>0){
  191. saas.util.BaseUtil.showErrorToast('询价结果: 成功'+(data.length-res.data.length) +'条,失败'+res.data.length+'条');
  192. }else{
  193. saas.util.BaseUtil.showSuccessToast('询价成功'+data.length+'条');
  194. }
  195. grid.store.load();
  196. grid.selModel.deselectAll();
  197. })
  198. .catch(function(e) {
  199. grid.setLoading(false);
  200. saas.util.BaseUtil.showErrorToast('操作失败: ' + e.message);
  201. });
  202. }else{
  203. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。');
  204. }
  205. },
  206. listeners:{
  207. boxready: function(grid, width, height, eOpts) {
  208. var store = grid.getStore(),
  209. gridBodyBox = grid.body.dom.getBoundingClientRect(),
  210. gridBodyBoxHeight = gridBodyBox.height;
  211. var pageSize = Math.floor(gridBodyBoxHeight / 32);
  212. store.setPageSize(pageSize);
  213. grid.ownerCt.el.dom.style.left = '8px';
  214. grid.el.dom.style.padding = '0px'
  215. },
  216. itemClick: function(view,record,a,index,c) {
  217. var classList = c.target.classList.value;
  218. var grid = this;
  219. if(classList.indexOf('fa-pencil')>-1){
  220. var form = this.ownerCt;
  221. this.dialog = form.getController().getView().add({
  222. xtype: 'sys-maxnumbers-window',
  223. bind: {
  224. title: '修改单据编码规则'
  225. },
  226. _parent:form,
  227. _combo:this,
  228. record:record,
  229. session: true
  230. });
  231. this.dialog.show();
  232. }else if(classList.indexOf('fa-trash-o')>-1){
  233. //删除
  234. var id = record.get('id');
  235. if(id){
  236. saas.util.BaseUtil.request({
  237. url: grid.deleteUrl+id,
  238. method: 'POST',
  239. })
  240. .then(function(localJson) {
  241. if(localJson.success){
  242. //解析参数
  243. saas.util.BaseUtil.showSuccessToast('删除成功');
  244. view.ownerCt.store.load();
  245. }
  246. })
  247. .catch(function(e) {
  248. saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  249. });
  250. }
  251. }
  252. }
  253. },
  254. insertFirstColumn:function(columns){
  255. var me=this;
  256. return columns;
  257. },
  258. getGridSelected:function(leadTime){
  259. var me = this,
  260. items = me.selModel.getSelection(),
  261. data = new Array() ;
  262. Ext.each(items, function(item, index){
  263. var o = new Object();
  264. o['prodCode']=item.get('pr_code');
  265. o['prodName']=item.get('pr_detail');
  266. o['prodSpec']=item.get('pr_spec');
  267. o['prodOrispeccode']=item.get('pr_orispeccode');
  268. o['prodBrand']=item.get('pr_brand');
  269. o['leadTime']=leadTime;
  270. data.push(o);
  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!=''&&!item.ignore){
  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. })