DataList.js 13 KB

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