DataList.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. },
  204. itemClick: function(view,record,a,index,c) {
  205. var classList = c.target.classList.value;
  206. var grid = this;
  207. if(classList.indexOf('fa-pencil')>-1){
  208. var form = this.ownerCt;
  209. this.dialog = form.getController().getView().add({
  210. xtype: 'sys-maxnumbers-window',
  211. bind: {
  212. title: '修改单据编码规则'
  213. },
  214. _parent:form,
  215. _combo:this,
  216. record:record,
  217. session: true
  218. });
  219. this.dialog.show();
  220. }else if(classList.indexOf('fa-trash-o')>-1){
  221. //删除
  222. var id = record.get('id');
  223. if(id){
  224. saas.util.BaseUtil.request({
  225. url: grid.deleteUrl+id,
  226. method: 'POST',
  227. })
  228. .then(function(localJson) {
  229. if(localJson.success){
  230. //解析参数
  231. saas.util.BaseUtil.showSuccessToast('删除成功');
  232. view.ownerCt.store.load();
  233. }
  234. })
  235. .catch(function(e) {
  236. saas.util.BaseUtil.showErrorToast('删除失败: ' + e.message);
  237. });
  238. }
  239. }
  240. }
  241. },
  242. insertFirstColumn:function(columns){
  243. var me=this;
  244. return columns;
  245. },
  246. getGridSelected:function(type){
  247. var isErrorSelect = false;
  248. var checkField = this.statusCodeField;
  249. var me = this,
  250. items = me.selModel.getSelection(),
  251. data = new Array() ;
  252. Ext.each(items, function(item, index){
  253. if(!Ext.isEmpty(item.data[me.idField])){
  254. var o = new Object();
  255. if(me.idField){
  256. o['id'] = item.data[me.idField];
  257. }
  258. if(me.codeField){
  259. o['code'] = item.data[me.codeField];
  260. }
  261. if(type&&type==item.data[checkField]){
  262. isErrorSelect = true
  263. }
  264. data.push(o);
  265. }
  266. });
  267. if(isErrorSelect){
  268. return false;
  269. }
  270. return data;
  271. },
  272. /**
  273. * 获得过滤条件
  274. */
  275. getConditions: function() {
  276. var me = this,
  277. tbar = me.getDockedItems()[0],
  278. items = Ext.Array.filter(tbar.items.items, function(item) {
  279. return !!item.name;
  280. }),
  281. conditions = [];
  282. for(var i = 0; i < items.length; i++) {
  283. var item = items[i];
  284. var field = item.name,
  285. func = item.getCondition,
  286. value = item.value,
  287. condition;
  288. if(value&&value!=''){
  289. if(typeof func == 'function') {
  290. condition = {
  291. type: 'condition',
  292. value: func(value)
  293. }
  294. }else {
  295. var type = item.fieldType || me.getDefaultFieldType(item),
  296. operation = item.operation || me.getDefaultFieldOperation(item),
  297. conditionValue = me.getConditionValue(item, value);
  298. if(!conditionValue) {
  299. continue;
  300. }
  301. condition = {
  302. type: type,
  303. field: field,
  304. operation: operation,
  305. value: conditionValue
  306. }
  307. }
  308. conditions.push(condition);
  309. }
  310. }
  311. return conditions;
  312. },
  313. /**
  314. * 只要arr1和arr2中存在相同项即返回真
  315. */
  316. isContainsAny: function (arr1, arr2) {
  317. for (var i = 0; i < arr2.length; i++) {
  318. var a2 = arr2[i];
  319. if (!!arr1.find(function (a1) {
  320. return a1 == a2
  321. })) {
  322. return true;
  323. }
  324. }
  325. return false;
  326. },
  327. getDefaultFieldType: function (field) {
  328. var me = this,
  329. xtypes = field.getXTypes().split('/'),
  330. type;
  331. if (me.isContainsAny(xtypes, ['numberfield'])) {
  332. type = 'number';
  333. } else if (me.isContainsAny(xtypes, ['datefield', 'condatefield', 'conmonthfield'])) {
  334. type = 'date';
  335. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  336. type = 'enum';
  337. } else if (me.isContainsAny(xtypes, ['combobox', 'multicombo', 'combo', 'radiofield', 'radio'])) {
  338. type = 'enum';
  339. } else {
  340. type = 'string';
  341. }
  342. return type;
  343. },
  344. getDefaultFieldOperation: function (field) {
  345. var me = this,
  346. xtypes = field.getXTypes().split('/'),
  347. operation;
  348. if (me.isContainsAny(xtypes, ['numberfield', 'datefield', 'dbfindtrigger'])) {
  349. operation = '=';
  350. } else if (me.isContainsAny(xtypes, ['condatefield', 'conmonthfield'])) {
  351. operation = 'between';
  352. } else if (me.isContainsAny(xtypes, ['multidbfindtrigger', 'combobox', 'multicombo', 'combo'])) {
  353. operation = 'in';
  354. } else {
  355. operation = 'like';
  356. }
  357. return operation;
  358. },
  359. /**
  360. * 处理部分字段值
  361. */
  362. getConditionValue: function (field, value) {
  363. var me = this,
  364. xtypes = field.getXTypes().split('/'),
  365. conditionValue;
  366. if (me.isContainsAny(xtypes, ['datefield'])) {
  367. conditionValue = Ext.Date.format(new Date(from), 'Y-m-d H:i:s');
  368. } else if (me.isContainsAny(xtypes, ['conmonthfield'])) {
  369. var from = value.from,
  370. to = value.to;
  371. conditionValue = from + ',' + to;
  372. } else if (me.isContainsAny(xtypes, ['condatefield'])) {
  373. var from = value.from,
  374. to = value.to;
  375. 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');
  376. } else if (me.isContainsAny(xtypes, ['dbfindtrigger'])) {
  377. conditionValue = value;
  378. } else if (me.isContainsAny(xtypes, ['combobox', 'combo'])) {
  379. conditionValue = '\'' + value + '\'';
  380. } else if (me.isContainsAny(xtypes, ['multicombo'])) {
  381. conditionValue = value.map ? value.map(function (v) {
  382. return '\'' + v.value + '\'';
  383. }).join(',') : '';
  384. } else {
  385. conditionValue = value;
  386. }
  387. return conditionValue;
  388. }
  389. })