GridPanel.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. Ext.define('saas.view.selfmakebalance-Gridpanel', {
  2. extend: 'Ext.grid.Panel',
  3. xtype: 'sale-selfmakebalance-gridpanel',
  4. requires: [
  5. 'Ext.grid.plugin.Exporter'
  6. ],
  7. cls: 'core-base-gridpanel',
  8. plugins: [{
  9. ptype: 'gridexporter',
  10. }, {
  11. ptype: 'menuclipboard'
  12. }, {
  13. ptype: 'cellediting',
  14. clicksToEdit: 1
  15. }],
  16. layout: 'fit',
  17. //基础属性
  18. border: 1,
  19. anchor: '100% 70%',
  20. loadMask: true,
  21. showIndex: true,
  22. columnWidth: 1.0,
  23. rootProperty: 'data',
  24. selModel: {
  25. checkOnly: true,
  26. type: 'checkboxmodel'
  27. },
  28. viewConfig: {
  29. getRowClass: function (record) {
  30. return record.get('hasAuditedBom') ? null : 'x-noauditedbom-2';
  31. }
  32. },
  33. calcuMakeBalance: false,
  34. // idField: 'id',
  35. // turnQtyField: 'mr_thisqty',
  36. columns: [{
  37. text: '本次数量',
  38. xtype: 'widgetcolumn',
  39. dataIndex: 'thisQty',
  40. width: 110,
  41. widget: {
  42. xtype: "numberfield",
  43. cls: 'widget-number',
  44. decimalPrecision: 8,
  45. minValue: 0,
  46. bind: '{record.thisQty}'
  47. }
  48. }, {
  49. text: '计划开工日期',
  50. xtype: 'widgetcolumn',
  51. dataIndex: 'planBeginDate',
  52. width: 150,
  53. widget: {
  54. xtype: "datefield",
  55. cls: 'widget-date',
  56. format: 'Y-m-d',
  57. bind: '{record.planBeginDate}'
  58. }
  59. }, {
  60. text: '物料id',
  61. dataIndex: 'prId',
  62. hidden: true
  63. }, {
  64. text: '物料编号',
  65. dataIndex: 'prCode',
  66. width: 150
  67. }, {
  68. text: '物料名称',
  69. dataIndex: 'prDetail',
  70. width: 150
  71. }, {
  72. text: '型号',
  73. dataIndex: 'prOrispeccode',
  74. width: 200
  75. }, {
  76. text: '供需平衡',
  77. dataIndex: 'balanceQty'
  78. }, {
  79. text: '需求',
  80. columns: [{
  81. text: '总需求',
  82. dataIndex: 'needQty',
  83. }, {
  84. text: '备货未核销',
  85. dataIndex: 'unClashQty',
  86. }, {
  87. text: '订单未发货',
  88. dataIndex: 'unSendQty',
  89. }, {
  90. text: '工单未领料',
  91. dataIndex: 'unPickQty',
  92. }, {
  93. text: '安全库存',
  94. dataIndex: 'safeStockQty',
  95. }]
  96. }, {
  97. text: '供应',
  98. columns: [{
  99. text: '总供应',
  100. dataIndex: 'supplyQty',
  101. }, {
  102. text: '良品库存',
  103. dataIndex: 'greatTotal',
  104. }, {
  105. text: '采购未交',
  106. dataIndex: 'purUnInQty',
  107. }, {
  108. text: '工单未完工',
  109. dataIndex: 'unMakeInQty',
  110. }]
  111. }],
  112. initComponent: function () {
  113. var me = this;
  114. me.store = Ext.create('Ext.data.Store', {
  115. autoLoad: false,
  116. data: [],
  117. listeners: {
  118. beforeload: function (store, op) {
  119. var gridpanel = me,
  120. params = {},
  121. keyWords = me.ownerCt.dockedItems.items[0].down('[name="keyWords"]').value;
  122. var params = JSON.stringify({ keyWords: keyWords, calcuMakeBalance: gridpanel.calcuMakeBalance });
  123. me.setLoading(true);
  124. saas.util.BaseUtil.request({
  125. url: '/api/make/makeBalance/list',
  126. method: 'POST',
  127. params: params
  128. })
  129. .then(function (localJson) {
  130. me.setLoading(false);
  131. if (localJson.success) {
  132. gridpanel.getStore().loadData(localJson.data);
  133. }
  134. })
  135. .catch(function (e) {
  136. me.setLoading(false);
  137. saas.util.BaseUtil.showErrorToast('计算失败: ' + e.message);
  138. });
  139. }
  140. }
  141. });
  142. Ext.apply(me, {
  143. dockedItems: [{
  144. xtype: 'toolbar',
  145. dock: 'top',
  146. items: [{
  147. text: '平衡计算',
  148. handler: function (b) {
  149. me.calcuMakeBalance = true;
  150. me.getStore().load();
  151. me.calcuMakeBalance = false;
  152. },
  153. }, {
  154. xtype: 'checkbox',
  155. name: '',
  156. columnWidth: 0.3,
  157. margin: '0 0 0 10',
  158. isFilter: true,
  159. boxLabel: '只显示供需平衡为负数的物料',
  160. checked: false,
  161. getFilter: function () {
  162. var me = this;
  163. let value = me.value, filter = {};
  164. if (value) {//已勾选
  165. filter = {
  166. filterFn: function (rec) {
  167. return rec.get('balanceQty') < 0;
  168. },
  169. anyMatch: true,
  170. caseSensitive: false
  171. };
  172. }
  173. return filter;
  174. },
  175. listeners: {
  176. change: function () {
  177. me.onFilter();
  178. }
  179. }
  180. }, {
  181. xtype: 'radiogroup',
  182. name: 'redio_vend',
  183. width: 200,
  184. margin: '0 0 0 80',
  185. cls: 'vendRadiogroup',
  186. simpleValue: true,
  187. items: [
  188. { boxLabel: '单级', inputValue: 'SINGLE', checked: true },
  189. { boxLabel: '多级', inputValue: 'MULTI' }
  190. ]
  191. }, '->',
  192. {
  193. iconCls: 'x-fa fa-question-circle',
  194. reference: 'qMark',
  195. name: 'qMark',
  196. cls: 'qMark',
  197. ui: 'header',
  198. tooltip: {
  199. text: '底色标识部分产品无BOM或者BOM未审核',
  200. anchor: 'top',
  201. title: '提示:',
  202. width: 350,
  203. dismissDelay: 7200000
  204. }
  205. }, {
  206. text: '生成工单',
  207. cls: 'x-formpanel-btn-blue',
  208. handler: function (btn) {
  209. me.turnMake();
  210. }
  211. }, {
  212. text: '导出',
  213. handler: me.onExport
  214. }]
  215. }]
  216. });
  217. me.callParent(arguments);
  218. },
  219. turnMake: function () {
  220. var me = this,
  221. makeType = me.dockedItems.items[1].query('[xtype="radiogroup"]')[0].lastValue,
  222. data = me.getGridSelected();
  223. if (data && data.length > 0) {
  224. me.setLoading(true);
  225. var params = JSON.stringify({ baseDTOs: data, makeType: makeType });
  226. console.log(params);
  227. saas.util.BaseUtil.request({
  228. url: '/api/make/makeBalance/turnMake',
  229. params: params,
  230. method: 'POST',
  231. async: false
  232. })
  233. .then(function (res) {
  234. if (res.success) {
  235. me.setLoading(false);
  236. me.selModel.deselectAll();
  237. saas.util.BaseUtil.showSuccessToast('转单成功');
  238. // var orderList=res.data;
  239. // if(orderList){
  240. // orderList.forEach(function(order) {
  241. // let intValue = order.id, codeValue = order.code, name = order.name,
  242. // opage = 'make-makebase-formpanel';
  243. // if(name == ''){
  244. // opage = 'osmake-osmake-formpanel'
  245. // }
  246. // saas.util.BaseUtil.openTab(opage, name + "(" + codeValue + ")", codeValue + intValue, {
  247. // initId: intValue
  248. // });
  249. // });
  250. // }
  251. }
  252. })
  253. .catch(function (res) {
  254. me.setLoading(false);
  255. saas.util.BaseUtil.showErrorToast(('操作失败: ') + res.message);
  256. });
  257. } else {
  258. saas.util.BaseUtil.showErrorToast('请勾选至少一条明细。');
  259. }
  260. },
  261. getGridSelected: function () {
  262. var me = this,
  263. items = me.selModel.getSelection(),
  264. data = new Array();
  265. Ext.each(items, function (item, index) {
  266. if (!Ext.isEmpty(item.data['prCode']) && item.data['thisQty'] > 0 && item.data['planBeginDate'] != null) {
  267. data.push({
  268. planBeginDate: Ext.isDate(item.data['planBeginDate']) ? item.data['planBeginDate'].getTime() : Ext.Date.parseDate(item.data['planBeginDate'],'Y-m-d H:i:s').getTime(),
  269. prCode: item.data['prCode'],
  270. prId: item.data['prId'],
  271. thisQty: item.data['thisQty']
  272. });
  273. }
  274. });
  275. return data;
  276. },
  277. onExport: function (me) {
  278. var grid = me.ownerCt.ownerCt;
  279. var cfg = {
  280. type: 'xlsx',
  281. title: '自制品供需平衡',
  282. fileName: '自制品供需平衡' + Ext.Date.format(new Date(), 'Y-m-d_H-i-s') + '.xlsx'
  283. };
  284. grid.setLoading(true);
  285. grid.saveDocumentAs(cfg);
  286. Ext.defer(function () {
  287. grid.setLoading(false);
  288. }, 5000);
  289. },
  290. onFilter: function () {
  291. var grid = this,
  292. filterFields = grid.query('[isFilter=true]');
  293. var filters = [];
  294. Ext.each(filterFields, function (filterField) {
  295. if (filterField.getFilter && filterField.getFilter()) {
  296. let filter = filterField.getFilter();
  297. if (filter) {
  298. filters.push(filter);
  299. }
  300. }
  301. });
  302. grid.store.clearFilter();
  303. grid.store.addFilter(filters);
  304. }
  305. });