|
@@ -131,6 +131,7 @@
|
|
|
</div>
|
|
|
</InfoCard>
|
|
|
<newDetailModel ref="newDetailModel" :data="orderDetail"></newDetailModel>
|
|
|
+ <ServiceList v-show="false" ref="serviceListRef"></ServiceList>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
@@ -141,13 +142,15 @@ import { paymentTypeOptions } from '../../data/options.js';
|
|
|
import { div, calcDiscountRate, roundToTwoDecimals } from '@/utils/number/';
|
|
|
import TableCard from '../../ui/TableCard.vue';
|
|
|
import newDetailModel from '@/views/order/components/new-detailModel.vue';
|
|
|
+import ServiceList from '../product-info-submodule/ServiceList.vue';
|
|
|
export default {
|
|
|
name: 'OrderDetailCard',
|
|
|
components: {
|
|
|
InfoCard,
|
|
|
ProductCard,
|
|
|
TableCard,
|
|
|
- newDetailModel
|
|
|
+ newDetailModel,
|
|
|
+ ServiceList
|
|
|
},
|
|
|
props: {
|
|
|
orderDetail: {
|
|
@@ -241,9 +244,9 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
orderDetail: {
|
|
|
- handler(newVal) {
|
|
|
+ async handler(newVal) {
|
|
|
this.orderDetailInfo = newVal || {};
|
|
|
- this.init();
|
|
|
+ await this.init();
|
|
|
},
|
|
|
deep: true,
|
|
|
immediate: true
|
|
@@ -259,43 +262,52 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- init() {
|
|
|
- this.orderData = this.orderDetailInfo?.orderData || {}
|
|
|
- let productData = this.orderDetailInfo?.productData || []
|
|
|
- if(productData.length > 0) {
|
|
|
- productData = productData.map(product => {
|
|
|
- try {
|
|
|
- const parsedFilter = this.parseProductFilter(product);
|
|
|
- const rate = this.calculateDiscountRate(product);
|
|
|
- const validityPeriod = this.calculateValidityPeriod(
|
|
|
- parsedFilter.buy_cycle,
|
|
|
- parsedFilter.buy_type,
|
|
|
- parsedFilter.give_cycle,
|
|
|
- parsedFilter.give_type,
|
|
|
- product
|
|
|
- );
|
|
|
- const subAccountCount = this.buildSubAccountCount(product, parsedFilter);
|
|
|
- const mainAccountCount = this.buildMainAccountCount(product);
|
|
|
- const linkedOrder = this.processLinkedOrder(product);
|
|
|
- const finalPrice = this.formatNumber(product.final_price);
|
|
|
- const originalPrice = this.formatNumber(product.original_price);
|
|
|
- this.parsedFilter = parsedFilter;
|
|
|
- return {
|
|
|
- ...product,
|
|
|
- filter: parsedFilter,
|
|
|
- rate,
|
|
|
- validity_period: validityPeriod,
|
|
|
- subAccountCount,
|
|
|
- mainAccountCount,
|
|
|
- linkedOrder,
|
|
|
- final_price: finalPrice,
|
|
|
- original_price: originalPrice
|
|
|
- };
|
|
|
- } catch (error) {
|
|
|
- console.error('产品信息初始化失败:', error);
|
|
|
- return product;
|
|
|
- }
|
|
|
- });
|
|
|
+ async init() {
|
|
|
+ this.orderData = this.orderDetailInfo?.orderData || {};
|
|
|
+ let productData = this.orderDetailInfo?.productData || [];
|
|
|
+
|
|
|
+ if (productData.length > 0) {
|
|
|
+ // 使用 Promise.all 来并行处理每个 product 的异步操作
|
|
|
+ productData = await Promise.all(
|
|
|
+ productData.map(async (product) => {
|
|
|
+ try {
|
|
|
+ const parsedFilter = this.parseProductFilter(product);
|
|
|
+ const serviceIds = parsedFilter.serviceIds || [];
|
|
|
+
|
|
|
+ // 等待异步方法完成
|
|
|
+ const bigServiceNames = await this.buildBigServiceNames(serviceIds);
|
|
|
+ const rate = this.calculateDiscountRate(product);
|
|
|
+ const validityPeriod = this.calculateValidityPeriod(
|
|
|
+ parsedFilter.buy_cycle,
|
|
|
+ parsedFilter.buy_type,
|
|
|
+ parsedFilter.give_cycle,
|
|
|
+ parsedFilter.give_type,
|
|
|
+ product
|
|
|
+ );
|
|
|
+ const subAccountCount = this.buildSubAccountCount(product, parsedFilter);
|
|
|
+ const mainAccountCount = this.buildMainAccountCount(product);
|
|
|
+ const linkedOrder = this.processLinkedOrder(product);
|
|
|
+ const finalPrice = this.formatNumber(product.final_price);
|
|
|
+ const originalPrice = this.formatNumber(product.original_price);
|
|
|
+
|
|
|
+ return {
|
|
|
+ ...product,
|
|
|
+ filter: parsedFilter,
|
|
|
+ rate,
|
|
|
+ validity_period: validityPeriod,
|
|
|
+ subAccountCount,
|
|
|
+ mainAccountCount,
|
|
|
+ linkedOrder,
|
|
|
+ bigServiceNames,
|
|
|
+ final_price: finalPrice,
|
|
|
+ original_price: originalPrice
|
|
|
+ };
|
|
|
+ } catch (error) {
|
|
|
+ console.error('产品信息初始化失败:', error);
|
|
|
+ return product;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
this.setTotalAmounts(productData);
|
|
@@ -322,6 +334,34 @@ export default {
|
|
|
}
|
|
|
return RETURN_BOOL[product] || false;
|
|
|
},
|
|
|
+ buildBigServiceNames(serviceIds) {
|
|
|
+ return new Promise((resolve) => {
|
|
|
+ if (!serviceIds || serviceIds.length === 0) {
|
|
|
+ resolve('');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 避免修改原始数组,创建新的整型数组
|
|
|
+ const numericServiceIds = serviceIds.map(id => parseInt(id));
|
|
|
+
|
|
|
+ this.$nextTick(() => {
|
|
|
+ try {
|
|
|
+ const serviceListRef = this.$refs.serviceListRef;
|
|
|
+ if (!serviceListRef || typeof serviceListRef.calcAlreadyBuyServiceNamesArr !== 'function') {
|
|
|
+ resolve('');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const res = serviceListRef.calcAlreadyBuyServiceNamesArr(numericServiceIds);
|
|
|
+ const serviceData = Array.isArray(res) ? res.join('、') : '';
|
|
|
+ resolve(serviceData);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error calculating service names:', error);
|
|
|
+ resolve('');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ },
|
|
|
parseProductFilter(product) {
|
|
|
let parsedFilter = {};
|
|
|
if (typeof product.filter === 'string') {
|
|
@@ -347,13 +387,11 @@ export default {
|
|
|
|
|
|
// 构造子账号数量字符串。
|
|
|
buildSubAccountCount(product, filter) {
|
|
|
- console.log(product.product_type, 'product')
|
|
|
|
|
|
if (product.product_type === 'VIP订阅' || product.product_type === '大会员') {
|
|
|
const buyCount = Number(filter?.buyAccountCount) || 0;
|
|
|
const giftCount = Number(filter?.giftAccountCount) || 0;
|
|
|
const countTotal = buyCount + giftCount;
|
|
|
- console.log(buyCount,giftCount, 'buyCount')
|
|
|
return `付费${buyCount}个,赠送${giftCount}个,合计:<span class="color_main">${countTotal}</span>个`;
|
|
|
}
|
|
|
return '';
|
|
@@ -380,7 +418,6 @@ export default {
|
|
|
setTotalAmounts(productData) {
|
|
|
const totalFinalPrice = productData.reduce((acc, cur) => acc + Number(cur.final_price), 0).toFixed(2);
|
|
|
const totalOriginalPrice = productData.reduce((acc, cur) => acc + Number(cur.original_price), 0).toFixed(2);
|
|
|
- console.log(totalOriginalPrice, 'totalOriginalPrice')
|
|
|
const rateTotal = div(totalFinalPrice, totalOriginalPrice) ? (div(totalFinalPrice, totalOriginalPrice) * 100).toFixed(2) + '%' : '无法计算';
|
|
|
|
|
|
this.orderData.final_price_total = totalFinalPrice;
|