QuoteWin.js 10 KB

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