QuoteWin.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. Ext.define('saas.view.sale.b2b.QuoteWin', {
  2. extend: 'Ext.window.Window',
  3. xtype: 'quotewin',
  4. title: '报价信息',
  5. width: 600,
  6. cls: 'x-window-dbfind',
  7. closlayout: 'fit',
  8. modal: true,
  9. bodyPadding: 20,
  10. initComponent: function () {
  11. var me = this;
  12. var record = me.record;
  13. Ext.apply(me, {
  14. items: [{
  15. xtype: 'form',
  16. layout: 'column',
  17. fieldDefaults: {
  18. margin: '0 0 10 0',
  19. labelAlign: 'right',
  20. labelWidth: 90,
  21. columnWidth: 0.5,
  22. },
  23. isValid: function (values) {
  24. var leadtimeField = this.getForm().findField('leadtime');
  25. var taxrateField = this.getForm().findField('taxrate');
  26. var grid = this.down('grid');
  27. var gridData = grid.store.getData().items;
  28. var flag = gridData.length > 0;
  29. for (var x = 0; x < gridData.length; x++) {
  30. var d = gridData[x];
  31. if (!d.get('step') || !d.get('price')) {
  32. flag = false
  33. }
  34. }
  35. if(flag) {
  36. flag = leadtimeField.getValue() && taxrateField.getValue();
  37. }
  38. return flag;
  39. },
  40. items: [{
  41. xtype: 'textfield',
  42. fieldLabel: '品牌',
  43. name: 'prodBrand',
  44. readOnly: true,
  45. value: record.get('prodBrand')
  46. }, {
  47. xtype: 'textfield',
  48. fieldLabel: '名称',
  49. name: 'prodName',
  50. readOnly: true,
  51. value: record.get('prodName')
  52. }, {
  53. xtype: 'textfield',
  54. fieldLabel: '型号',
  55. name: 'prodOrispeccode',
  56. readOnly: true,
  57. value: record.get('prodOrispeccode')
  58. }, {
  59. xtype: 'textfield',
  60. fieldLabel: '规格',
  61. name: 'prodSpec',
  62. readOnly: true,
  63. value: record.get('prodSpec')
  64. }, {
  65. xtype: 'numberfield',
  66. fieldLabel: '交期(天)',
  67. name: 'leadtime',
  68. allowBlank: false,
  69. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>"
  70. }, {
  71. xtype: 'numberfield',
  72. fieldLabel: '税率',
  73. name: 'taxrate',
  74. minValue: 0,
  75. maxValue: 100,
  76. allowBlank: false,
  77. beforeLabelTextTpl: "<font color=\"red\" style=\"position:relative; top:2px;right:2px; font-weight: bolder;\">*</font>"
  78. }, {
  79. xtype: 'detailGridField',
  80. detnoColumn: 'no',
  81. minHeight: 145,
  82. emptyRows: 3,
  83. showCount: false,
  84. width: 280,
  85. store: Ext.create('Ext.data.Store', {
  86. fields: [{
  87. name: 'no',
  88. type: 'int'
  89. }, {
  90. name: 'step',
  91. type: 'int'
  92. }, {
  93. name: 'price',
  94. type: 'float'
  95. }],
  96. data: []
  97. }),
  98. columns: [{
  99. text: '梯度',
  100. dataIndex: 'step',
  101. xtype: 'numbercolumn',
  102. editor: {
  103. xtype: "numberfield",
  104. decimalPrecision: 0,
  105. minValue: 0
  106. },
  107. renderer: function (v, m, r) {
  108. return saas.util.BaseUtil.numberFormat(v, 0, false);
  109. },
  110. }, {
  111. text: '单价',
  112. dataIndex: 'price',
  113. xtype: 'numbercolumn',
  114. editor: {
  115. xtype: "numberfield",
  116. decimalPrecision: 4,
  117. minValue: 0
  118. },
  119. renderer: function (v, m, r) {
  120. return saas.util.BaseUtil.numberFormat(v, 4, true);
  121. },
  122. }]
  123. }]
  124. }],
  125. buttonAlign: 'center',
  126. buttons: [{
  127. text: '确定',
  128. handler: function () {
  129. var win = this.up('window'),
  130. form = win.down('form'),
  131. grid = form.down('grid');
  132. if (form.isValid()) {
  133. var values = form.getValues();
  134. Ext.Object.mergeIf(values, record.data);
  135. values.detail = grid.store.getData().items.map(function(r) {
  136. return r.data;
  137. })
  138. me.onQuote(values);
  139. } else {
  140. saas.util.BaseUtil.showErrorToast('表单校验失败,请检查字段是否合法');
  141. }
  142. }
  143. }, {
  144. text: '取消',
  145. handler: function () {
  146. me.close();
  147. }
  148. }]
  149. });
  150. me.callParent(arguments);
  151. },
  152. onQuote: function (values) {
  153. var view = this;
  154. var params = {
  155. sourceId: values.sourceId,
  156. inquiry: {
  157. id: values.sourceId,
  158. enUU: values.enUU,
  159. recorderUU: values.recorderUU,
  160. code: values.inquiryCode,
  161. },
  162. userUU: values.userUU,
  163. userName: values.userName,
  164. userTel: values.userTel,
  165. currency: "RMB",
  166. taxrate: values.taxrate,
  167. leadtime: values.leadtime, // 交期
  168. replies: values.detail.map(function(d) {
  169. return {
  170. lapQty: d.step,
  171. price: d.price
  172. }
  173. }), // 梯度价格,
  174. date: Ext.Date.format(new Date(), 'Y-m-d H:i:s'), // 当前日期
  175. qutoApp: "sp", // 固定标识
  176. endDate: values.endDate,
  177. prodTitle: values.prodName,
  178. spec: values.prodSpec,
  179. cmpCode: values.prodOrispeccode,
  180. inbrand: values.prodBrand,
  181. isReplace: 0,
  182. };
  183. view.setLoading(true);
  184. saas.util.BaseUtil.request({
  185. // url: 'http://10.1.80.23:8560/api/sale/sale/businessChance/saveQuote',
  186. url: '/api/sale/sale/businessChance/saveQuote',
  187. params: JSON.stringify(params),
  188. method: 'POST'
  189. }).then(function (res) {
  190. view.setLoading(false);
  191. saas.util.BaseUtil.showSuccessToast('报价成功');
  192. view.close();
  193. view.listView.refresh();
  194. }).catch(function (e) {
  195. view.setLoading(false);
  196. saas.util.BaseUtil.showErrorToast('报价失败: ' + e.message);
  197. });
  198. },
  199. });