|
@@ -197,7 +197,7 @@
|
|
|
</a-col>
|
|
|
<a-col :span="12">
|
|
|
<a-form-item label="币种(currency)" v-bind="validateInfos.currency" id="PurchaseOrderFormModal-currency" name="currency">
|
|
|
- <JDictSelectTag v-model:value="formData.currency" placeholder="请选择" dictCode="currency" disabled />
|
|
|
+ <JDictSelectTag v-model:value="formData.currency" placeholder="请选择" dictCode="currency" @change="handleChangeCurrency" />
|
|
|
</a-form-item>
|
|
|
</a-col>
|
|
|
<a-col :span="12">
|
|
@@ -364,6 +364,7 @@
|
|
|
queryVersonHistoryById,
|
|
|
queryPurVersonFormShipListByMainId,
|
|
|
queryPurVersonProductListByMainId,
|
|
|
+ getExchangeRate
|
|
|
} from '../PurchaseOrderyForm.api';
|
|
|
import { JVxeTable } from '/@/components/jeecg/JVxeTable';
|
|
|
import { purchaseOrderShipColumns, purchaseOrderProductColumns } from '../PurchaseOrderForm.data';
|
|
@@ -886,7 +887,68 @@
|
|
|
},
|
|
|
{ deep: true }
|
|
|
);
|
|
|
+ // 监听币种变化,获取汇率
|
|
|
+ watch(() => formData.currency,
|
|
|
+ async (newVal, oldVal) => {
|
|
|
+ if (newVal && newVal !== oldVal) {
|
|
|
+ // setExchangeRate();
|
|
|
+ await handleChangeCurrency(newVal, oldVal);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { immediate: true }
|
|
|
+ );
|
|
|
+ // 监听日期变化,获取汇率
|
|
|
+ watch(() => formData.billDate,
|
|
|
+ async (newDate, oldDate) => {
|
|
|
+ const currentCurrency = formData.currency;
|
|
|
+ if (currentCurrency && newDate !== oldDate) {
|
|
|
+ // 保留当前币种不变,但重新获取汇率并刷新子表
|
|
|
+ await handleChangeCurrency(currentCurrency, currentCurrency);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { immediate: false }
|
|
|
+ );
|
|
|
+ async function handleChangeCurrency (newCurrency?: string, oldCurrency?: string) {
|
|
|
+ if (!newCurrency || !oldCurrency) return;
|
|
|
+
|
|
|
+ const date = moment(formData.billDate);
|
|
|
+ const year = date.format('YYYY');
|
|
|
+ const month = date.format('MM');
|
|
|
|
|
|
+ try {
|
|
|
+ // 获取旧币种汇率(原币种)与 新币种汇率(新币种),并展示新币种汇率
|
|
|
+ const oldRateRes = await getExchangeRate({ year, month, currency: oldCurrency });
|
|
|
+ const oldExchangeRate = parseFloat(oldRateRes || '1');
|
|
|
+ const newRateRes = await getExchangeRate({ year, month, currency: newCurrency });
|
|
|
+ const newExchangeRate = parseFloat(newRateRes || '1');
|
|
|
+ formData.exchangeRate = isNaN(newExchangeRate) ? '' : newExchangeRate;
|
|
|
+ purOrderFormShipFormProductTable.dataSource = purOrderFormShipFormProductTable.dataSource.map(item => {
|
|
|
+ const originalTaxPriceOriginal = item.taxPriceOriginal;
|
|
|
+ if (!originalTaxPriceOriginal) return item;
|
|
|
+ // 换算逻辑:原币种金额 × 原汇率 ÷ 新汇率
|
|
|
+ const convertedTaxPriceOriginal = originalTaxPriceOriginal * oldExchangeRate / newExchangeRate;
|
|
|
+ return {
|
|
|
+ ...item,
|
|
|
+ taxPriceOriginal: convertedTaxPriceOriginal.toFixed(6) || '',
|
|
|
+ _needUpdate: true // 标记需要更新的行
|
|
|
+ };
|
|
|
+ });
|
|
|
+ // 手动触发 changeValues 计算其他字段
|
|
|
+ const updatedDataSource = purOrderFormShipFormProductTable.dataSource;
|
|
|
+ updatedDataSource.forEach((row,index) => {
|
|
|
+ if (row._needUpdate) {
|
|
|
+ changeValues({
|
|
|
+ col: { key: 'taxPriceOriginal' },
|
|
|
+ row: row,
|
|
|
+ rowIndex: index
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ console.error('汇率换算失败:', err);
|
|
|
+ formData.exchangeRate = '';
|
|
|
+ }
|
|
|
+ }
|
|
|
return {
|
|
|
discountHeadChange,
|
|
|
PurOrderFormShipFormShipTableRef,
|
|
@@ -928,6 +990,7 @@
|
|
|
changeValues,
|
|
|
SelectSupplierQuotationList,
|
|
|
addFromQuotation,
|
|
|
+ handleChangeCurrency,
|
|
|
};
|
|
|
},
|
|
|
});
|