QuoteWin.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. for (var x = 0; x < gridData.length; x++) {
  53. var d = gridData[x];
  54. var idx = d.get('no');
  55. if (!d.get('lapQty') || !d.get('price')) {
  56. saas.util.BaseUtil.showErrorToast('序号为' + idx + '的行梯度单价有误');
  57. return false;
  58. }
  59. }
  60. return true;
  61. },
  62. items: [{
  63. xtype: 'textfield',
  64. fieldLabel: '品牌',
  65. name: 'prodBrand',
  66. readOnly: true,
  67. value: record.get('prodBrand')
  68. }, {
  69. xtype: 'textfield',
  70. fieldLabel: '名称',
  71. name: 'prodName',
  72. readOnly: true,
  73. value: record.get('prodName')
  74. }, {
  75. xtype: 'textfield',
  76. fieldLabel: '型号',
  77. name: 'prodOrispeccode',
  78. readOnly: true,
  79. value: record.get('prodOrispeccode')
  80. }, {
  81. xtype: 'textfield',
  82. fieldLabel: '规格',
  83. name: 'prodSpec',
  84. readOnly: true,
  85. value: record.get('prodSpec')
  86. }, {
  87. xtype: 'numberfield',
  88. fieldLabel: '交期(天)',
  89. name: 'leadtime',
  90. allowBlank: false,
  91. vtype: 'positiveNumber',
  92. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>"
  93. }, {
  94. xtype: 'numberfield',
  95. fieldLabel: '税率',
  96. name: 'taxrate',
  97. maxValue: 100,
  98. allowBlank: false,
  99. vtype: 'positiveNumber',
  100. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>"
  101. }, {
  102. xtype: 'detailGridField',
  103. detnoColumn: 'no',
  104. minHeight: 145,
  105. emptyRows: 3,
  106. showCount: false,
  107. width: 280,
  108. store: Ext.create('Ext.data.Store', {
  109. fields: [{
  110. name: 'no',
  111. type: 'int'
  112. }, {
  113. name: 'lapQty',
  114. type: 'int'
  115. }, {
  116. name: 'price',
  117. type: 'float'
  118. }],
  119. data: []
  120. }),
  121. columns: [{
  122. text: '梯度',
  123. dataIndex: 'lapQty',
  124. xtype: 'numbercolumn',
  125. editor: {
  126. xtype: "numberfield",
  127. decimalPrecision: 0,
  128. minValue: 0
  129. },
  130. renderer: function (v, m, r) {
  131. return saas.util.BaseUtil.numberFormat(v, 0, false);
  132. },
  133. }, {
  134. text: '单价',
  135. dataIndex: 'price',
  136. xtype: 'numbercolumn',
  137. editor: {
  138. xtype: "numberfield",
  139. decimalPrecision: 4,
  140. minValue: 0
  141. },
  142. renderer: function (v, m, r) {
  143. return saas.util.BaseUtil.numberFormat(v, 4, true);
  144. },
  145. }]
  146. }, {
  147. xtype: 'textfield',
  148. name: 'message',
  149. columnWidth: 1,
  150. fieldLabel: '回复信息',
  151. hidden: true
  152. }]
  153. }],
  154. buttonAlign: 'center',
  155. buttons: [{
  156. text: '确定',
  157. handler: function () {
  158. if(quoted && record.get('qutations')) {
  159. me.close();
  160. return;
  161. }
  162. var win = this.up('window'),
  163. form = win.down('form'),
  164. grid = form.down('grid');
  165. if (form.isValid()) {
  166. var values = form.getValues();
  167. Ext.Object.mergeIf(values, record.data);
  168. values.detail = grid.store.getData().items.map(function(r) {
  169. return r.data;
  170. })
  171. me.onQuote(values);
  172. }
  173. }
  174. }, {
  175. text: '取消',
  176. handler: function () {
  177. me.close();
  178. }
  179. }]
  180. });
  181. me.callParent(arguments);
  182. },
  183. listeners: {
  184. afterrender: function() {
  185. var me = this,
  186. form = me.down('form'),
  187. leadtimeField = form.getForm().findField('leadtime'),
  188. taxrateField = form.getForm().findField('taxrate'),
  189. messageField = form.getForm().findField('message'),
  190. grid = form.down('grid'),
  191. store = grid.store,
  192. record = me.record,
  193. qutations = record.get('qutations'),
  194. quoted = me.quoted,
  195. storeData = [];
  196. if(quoted) {
  197. leadtimeField.setReadOnly(true);
  198. taxrateField.setReadOnly(true);
  199. grid.setGridDisabled();
  200. leadtimeField.setValue(qutations.leadTime);
  201. taxrateField.setValue(qutations.taxRate);
  202. storeData = qutations.replies.map(function(r, i) {
  203. r.no = i + 1;
  204. return r;
  205. });
  206. store.loadData(storeData);
  207. if(qutations.agreed == 0) {
  208. messageField.setValue(qutations.refusereason);
  209. messageField.setVisible(true);
  210. }
  211. }
  212. }
  213. },
  214. onQuote: function (values) {
  215. var view = this;
  216. var params = {
  217. sourceId: values.sourceId,
  218. inquiry: {
  219. id: values.sourceId,
  220. enUU: values.enUU,
  221. recorderUU: values.recorderUU,
  222. code: values.inquiryCode,
  223. },
  224. userUU: values.userUU,
  225. userName: values.userName,
  226. userTel: values.userTel,
  227. currency: "RMB",
  228. taxrate: values.taxrate,
  229. leadtime: values.leadtime, // 交期
  230. replies: values.detail.map(function(d) {
  231. return {
  232. lapQty: d.lapQty,
  233. price: d.price
  234. }
  235. }), // 梯度价格,
  236. date: Ext.Date.format(new Date(), 'Y-m-d H:i:s'), // 当前日期
  237. qutoApp: "sp", // 固定标识
  238. endDate: values.endDate,
  239. prodTitle: values.prodName,
  240. spec: values.prodSpec,
  241. cmpCode: values.prodOrispeccode,
  242. inbrand: values.prodBrand,
  243. isReplace: 0,
  244. };
  245. view.setLoading(true);
  246. saas.util.BaseUtil.request({
  247. // url: 'http://10.1.80.23:8560/api/sale/sale/businessChance/saveQuote',
  248. url: '/api/sale/sale/businessChance/saveQuote',
  249. params: JSON.stringify(params),
  250. method: 'POST'
  251. }).then(function (res) {
  252. view.setLoading(false);
  253. saas.util.BaseUtil.showSuccessToast('报价成功');
  254. view.close();
  255. view.listView.refresh();
  256. }).catch(function (e) {
  257. view.setLoading(false);
  258. saas.util.BaseUtil.showErrorToast('报价失败: ' + e.message);
  259. });
  260. },
  261. });