QuoteWin.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. Ext.define('saas.view.sale.b2b.QuoteWin', {
  2. extend: 'Ext.window.Window',
  3. xtype: 'quotewin',
  4. title: '报价信息',
  5. width: '800',
  6. height: '400',
  7. scrollable: true,
  8. cls: 'x-window-dbfind',
  9. closlayout: 'fit',
  10. modal: true,
  11. bodyPadding: 20,
  12. initComponent: function () {
  13. var me = this;
  14. var record = me.record;
  15. var quoted = me.quoted;
  16. Ext.apply(me, {
  17. items: [{
  18. xtype: 'form',
  19. layout: 'column',
  20. fieldDefaults: {
  21. margin: '0 0 10 0',
  22. labelAlign: 'right',
  23. labelWidth: 90,
  24. columnWidth: 0.5,
  25. },
  26. isValid: function (values) {
  27. var leadtimeField = this.getForm().findField('leadtime');
  28. var taxrateField = this.getForm().findField('taxrate');
  29. var grid = this.down('grid');
  30. var gridData = grid.store.getData().items;
  31. var count = gridData.length > 0;
  32. if(leadtimeField.getValue() == undefined) {
  33. saas.util.BaseUtil.showErrorToast('交期不可为空');
  34. return false;
  35. }
  36. if(leadtimeField.getValue() <= 0) {
  37. saas.util.BaseUtil.showErrorToast('交期必须大于零');
  38. return false;
  39. }
  40. if(taxrateField.getValue() == undefined) {
  41. saas.util.BaseUtil.showErrorToast('税率不可为空');
  42. return false;
  43. }
  44. if(taxrateField.getValue() <= 0) {
  45. saas.util.BaseUtil.showErrorToast('税率必须大于零');
  46. return false;
  47. }
  48. if(!count) {
  49. saas.util.BaseUtil.showErrorToast('梯度单价不可为空');
  50. return false;
  51. }
  52. let lastQ = 0;
  53. for (var x = 0; x < gridData.length; x++) {
  54. let d = gridData[x];
  55. let idx = d.get('no');
  56. if (!d.get('lapQty')) {
  57. saas.util.BaseUtil.showErrorToast('序号为' + idx + '的行梯度有误');
  58. return false;
  59. }
  60. if(d.get('lapQty') <= lastQ) {
  61. saas.util.BaseUtil.showErrorToast('序号为' + idx + '的行梯度需要大于上一梯度设置');
  62. return false;
  63. }
  64. if(!d.get('price')) {
  65. saas.util.BaseUtil.showErrorToast('序号为' + idx + '的行单价有误');
  66. return false;
  67. }
  68. lastQ = d.get('lapQty');
  69. }
  70. return true;
  71. },
  72. items: [{
  73. xtype: 'textfield',
  74. fieldLabel: '品牌',
  75. name: 'prodBrand',
  76. readOnly: true,
  77. value: record.get('prodBrand')
  78. }, {
  79. xtype: 'textfield',
  80. fieldLabel: '名称',
  81. name: 'prodName',
  82. readOnly: true,
  83. value: record.get('prodName')
  84. }, {
  85. xtype: 'textfield',
  86. fieldLabel: '型号',
  87. name: 'prodOrispeccode',
  88. readOnly: true,
  89. value: record.get('prodOrispeccode')
  90. }, {
  91. xtype: 'textfield',
  92. fieldLabel: '规格',
  93. name: 'prodSpec',
  94. readOnly: true,
  95. value: record.get('prodSpec')
  96. }, {
  97. xtype: 'numberfield',
  98. fieldLabel: '交期(天)',
  99. name: 'leadtime',
  100. allowBlank: false,
  101. vtype: 'positiveNumber',
  102. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>"
  103. }, {
  104. xtype: 'numberfield',
  105. fieldLabel: '税率',
  106. name: 'taxrate',
  107. maxValue: 100,
  108. allowBlank: false,
  109. vtype: 'positiveNumber',
  110. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>"
  111. }, {
  112. xtype: 'detailGridField',
  113. detnoColumn: 'no',
  114. minHeight: 145,
  115. emptyRows: 3,
  116. showCount: false,
  117. width: 280,
  118. store: Ext.create('Ext.data.Store', {
  119. fields: [{
  120. name: 'no',
  121. type: 'int'
  122. }, {
  123. name: 'lapQty',
  124. type: 'int',
  125. vtype: 'positiveNumber'
  126. }, {
  127. name: 'price',
  128. type: 'float',
  129. vtype: 'positiveNumber'
  130. }],
  131. data: []
  132. }),
  133. columns: [{
  134. text: '梯度',
  135. dataIndex: 'lapQty',
  136. xtype: 'numbercolumn',
  137. editor: {
  138. xtype: "numberfield",
  139. decimalPrecision: 0,
  140. minValue: 0
  141. },
  142. renderer: function (v, m, r) {
  143. return saas.util.BaseUtil.numberFormat(v, 0, false);
  144. },
  145. }, {
  146. text: '单价',
  147. dataIndex: 'price',
  148. xtype: 'numbercolumn',
  149. editor: {
  150. xtype: "numberfield",
  151. decimalPrecision: 4,
  152. minValue: 0
  153. },
  154. renderer: function (v, m, r) {
  155. return saas.util.BaseUtil.numberFormat(v, 4, true);
  156. },
  157. }],
  158. listeners: {
  159. beforeaddrow: function(grid, index, data) {
  160. if(grid.store.getCount() < 5) {
  161. return true;
  162. }else {
  163. saas.util.BaseUtil.showErrorToast('最多只能设置5条梯度价格');
  164. return false;
  165. }
  166. }
  167. }
  168. }, {
  169. xtype: 'textfield',
  170. name: 'message',
  171. columnWidth: 1,
  172. fieldLabel: '回复信息',
  173. hidden: true
  174. }]
  175. }],
  176. buttonAlign: 'center',
  177. buttons: [{
  178. text: '确定',
  179. handler: function () {
  180. if(quoted && record.get('qutations')) {
  181. me.close();
  182. return;
  183. }
  184. var win = this.up('window'),
  185. form = win.down('form'),
  186. grid = form.down('grid');
  187. if (form.isValid()) {
  188. var values = form.getValues();
  189. Ext.Object.mergeIf(values, record.data);
  190. values.detail = grid.store.getData().items.map(function(r) {
  191. return r.data;
  192. })
  193. me.onQuote(values);
  194. }
  195. }
  196. }, {
  197. text: '取消',
  198. handler: function () {
  199. me.close();
  200. }
  201. }]
  202. });
  203. me.callParent(arguments);
  204. },
  205. listeners: {
  206. afterrender: function() {
  207. var me = this,
  208. form = me.down('form'),
  209. leadtimeField = form.getForm().findField('leadtime'),
  210. taxrateField = form.getForm().findField('taxrate'),
  211. messageField = form.getForm().findField('message'),
  212. grid = form.down('grid'),
  213. store = grid.store,
  214. record = me.record,
  215. qutations = record.get('qutations'),
  216. quoted = me.quoted,
  217. storeData = [];
  218. if(quoted) {
  219. leadtimeField.setReadOnly(true);
  220. taxrateField.setReadOnly(true);
  221. grid.setGridDisabled();
  222. leadtimeField.setValue(qutations.leadTime);
  223. taxrateField.setValue(qutations.taxRate);
  224. storeData = qutations.replies.map(function(r, i) {
  225. r.no = i + 1;
  226. return r;
  227. });
  228. store.loadData(storeData);
  229. if(qutations.agreed == 0) {
  230. messageField.setValue(qutations.refusereason);
  231. messageField.setVisible(true);
  232. }
  233. }
  234. }
  235. },
  236. onQuote: function (values) {
  237. var view = this;
  238. var params = {
  239. sourceId: values.sourceId,
  240. inquiry: {
  241. id: values.sourceId,
  242. enUU: values.enUU,
  243. recorderUU: values.recorderUU,
  244. code: values.inquiryCode,
  245. },
  246. userUU: values.userUU,
  247. userName: values.userName,
  248. userTel: values.userTel,
  249. currency: "RMB",
  250. taxrate: values.taxrate,
  251. leadtime: values.leadtime, // 交期
  252. replies: values.detail.map(function(d) {
  253. return {
  254. lapQty: d.lapQty,
  255. price: d.price
  256. }
  257. }), // 梯度价格,
  258. date: Ext.Date.format(new Date(), 'Y-m-d H:i:s'), // 当前日期
  259. qutoApp: "sp", // 固定标识
  260. endDate: values.endDate,
  261. prodTitle: values.prodName,
  262. spec: values.prodSpec,
  263. cmpCode: values.prodOrispeccode,
  264. inbrand: values.prodBrand,
  265. isReplace: 0,
  266. };
  267. view.setLoading(true);
  268. saas.util.BaseUtil.request({
  269. // url: 'http://10.1.80.23:8560/api/sale/sale/businessChance/saveQuote',
  270. url: '/api/sale/sale/businessChance/saveQuote',
  271. params: JSON.stringify(params),
  272. method: 'POST'
  273. }).then(function (res) {
  274. view.setLoading(false);
  275. saas.util.BaseUtil.showSuccessToast('报价成功');
  276. view.close();
  277. view.listView.refresh();
  278. }).catch(function (e) {
  279. view.setLoading(false);
  280. saas.util.BaseUtil.showErrorToast('报价失败: ' + e.message);
  281. });
  282. },
  283. });