DataList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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:'http://10.1.80.23:8560/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. saas.util.BaseUtil.showSuccessToast('操作成功');
  185. debugger
  186. grid.store.load();
  187. })
  188. .catch(function(e) {
  189. grid.setLoading(false);
  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(leadTime){
  249. var me = this,
  250. items = me.selModel.getSelection(),
  251. data = new Array() ;
  252. Ext.each(items, function(item, index){
  253. var o = new Object();
  254. o['prodCode']=item.get('pr_code');
  255. o['prodName']=item.get('pr_detail');
  256. o['prodSpec']=item.get('pr_spec');
  257. o['prodOrispeccode']=item.get('pr_orispeccode');
  258. o['prodBrand']=item.get('pr_brand');
  259. o['leadTime']=leadTime;
  260. data.push(o);
  261. });
  262. return data;
  263. },
  264. /**
  265. * 获得过滤条件
  266. */
  267. getConditions: function() {
  268. var me = this,
  269. tbar = me.getDockedItems()[0],
  270. items = Ext.Array.filter(tbar.items.items, function(item) {
  271. return !!item.name;
  272. }),
  273. conditions = [];
  274. for(var i = 0; i < items.length; i++) {
  275. var item = items[i];
  276. var field = item.name,
  277. func = item.getCondition,
  278. value = item.value,
  279. condition;
  280. if(value&&value!=''){
  281. if(typeof func == 'function') {
  282. condition = {
  283. type: 'condition',
  284. value: func(value)
  285. }
  286. }else {
  287. var type = item.fieldType || me.getDefaultFieldType(item),
  288. operation = item.operation || me.getDefaultFieldOperation(item),
  289. conditionValue = me.getConditionValue(item, value);
  290. if(!conditionValue) {
  291. continue;
  292. }
  293. condition = {
  294. type: type,
  295. field: field,
  296. operation: operation,
  297. value: conditionValue
  298. }
  299. }
  300. conditions.push(condition);
  301. }
  302. }
  303. return conditions;
  304. },
  305. /**
  306. * 只要arr1和arr2中存在相同项即返回真
  307. */
  308. isContainsAny: function (arr1, arr2) {
  309. for (var i = 0; i < arr2.length; i++) {
  310. var a2 = arr2[i];
  311. if (!!arr1.find(function (a1) {
  312. return a1 == a2
  313. })) {
  314. return true;
  315. }
  316. }
  317. return false;
  318. },
  319. getDefaultFieldType: function (field) {
  320. var me = this,
  321. xtypes = field.getXTypes().split('/'),
  322. type;
  323. if (me.isContainsAny(xtypes, ['numberfield'])) {
  324. type = 'number';
  325. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  326. type = 'date';
  327. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  328. type = 'enum';
  329. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  330. type = 'enum';
  331. } else {
  332. type = 'string';
  333. }
  334. return type;
  335. },
  336. getDefaultFieldOperation: function (field) {
  337. var me = this,
  338. xtypes = field.getXTypes().split('/'),
  339. operation;
  340. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  341. operation = '=';
  342. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  343. operation = 'between';
  344. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  345. operation = 'in';
  346. } else {
  347. operation = 'like';
  348. }
  349. return operation;
  350. },
  351. /**
  352. * 处理部分字段值
  353. */
  354. getConditionValue: function (field, value) {
  355. var me = this,
  356. xtypes = field.getXTypes().split('/'),
  357. conditionValue;
  358. if (me.isContainsAny(xtypes, ['datefield'])) {
  359. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  360. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  361. var from = value.from,
  362. to = value.to;
  363. conditionValue = from + ',' + to;
  364. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  365. var from = value.from,
  366. to = value.to;
  367. 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');
  368. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  369. conditionValue = value;
  370. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  371. conditionValue = '\'' + value + '\'';
  372. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  373. conditionValue = value.map ? value.map(function (v) {
  374. return '\'' + v.value + '\'';
  375. }).join(',') : '';
  376. } else {
  377. conditionValue = value;
  378. }
  379. return conditionValue;
  380. }
  381. })