|
|
@@ -16,7 +16,7 @@
|
|
|
<!-- </block>-->
|
|
|
<!-- </view>-->
|
|
|
<view class='line'></view>
|
|
|
- <goodList :bastList="bastList" v-if="bastList.length > 0"></goodList>
|
|
|
+ <goodList :bastList="calculatedProducts" v-if="bastList.length > 0"></goodList>
|
|
|
<view class='loadingicon acea-row row-center-wrapper' v-if="bastList.length > 0">
|
|
|
<text class='loading iconfont icon-jiazai' :hidden='loading == false'></text>{{ loadTitle }}
|
|
|
</view>
|
|
|
@@ -31,12 +31,14 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
-import { ref } from 'vue'
|
|
|
+import {computed, ref} from 'vue'
|
|
|
import { onShow, onReachBottom,onLoad } from '@dcloudio/uni-app'
|
|
|
import { getSearchKeyword, getProductslist, getProductHot } from '@/api/store.js'
|
|
|
import goodList from '@/components/goodList'
|
|
|
import recommend from '@/components/recommend'
|
|
|
import { HTTP_REQUEST_URL_IMG } from "@/config/app";
|
|
|
+// 获取实时金价
|
|
|
+import useRealGoldPrice from "@/hooks/useRealGoldPrice";
|
|
|
|
|
|
// 响应式数据
|
|
|
const hostProduct = ref([])
|
|
|
@@ -53,6 +55,38 @@ const hotPage = ref(1)
|
|
|
const isScroll = ref(true)
|
|
|
const isbastList = ref(false)
|
|
|
const query = ref({})
|
|
|
+// 实时价格处理
|
|
|
+const {
|
|
|
+ realGoldprice, // 黄金实时销售价(基础)
|
|
|
+ realPtprice, // 铂金实时销售价(基础)
|
|
|
+ realAgprice, // 白银实时销售价(基础)
|
|
|
+} = useRealGoldPrice({});
|
|
|
+
|
|
|
+const calculatedProducts = computed(() => {
|
|
|
+ // 计算逻辑与原代码一致,但基于响应式数据 products
|
|
|
+ return bastList.value.map((product) => {
|
|
|
+ // 1. 将price字符串转为数字
|
|
|
+ const price = Number(product.price);
|
|
|
+ // 2. 计算乘积
|
|
|
+ const total = (price + product.sales) * realGoldprice.value;
|
|
|
+ // 3. 向上取整到两位小数(先放大100倍取整,再缩小100倍)
|
|
|
+ const roundedTotal = Math.ceil(total * 100) / 100;
|
|
|
+ // 4. 格式化保留两位小数
|
|
|
+ const formattedTotal = roundedTotal.toFixed(2);
|
|
|
+
|
|
|
+ const totalLaborCost = Number(product.totalLaborCost);
|
|
|
+ const additionalAmount = Number(product.additionalAmount);
|
|
|
+ console.log(totalLaborCost)
|
|
|
+ console.log(additionalAmount)
|
|
|
+ const totalPrice = (totalLaborCost+additionalAmount).toFixed(2);
|
|
|
+ console.log('totalPrice',totalPrice)
|
|
|
+ return {
|
|
|
+ ...product,
|
|
|
+ calculatedTotal: formattedTotal, // 新增计算结果字段
|
|
|
+ totalPrice
|
|
|
+ };
|
|
|
+ });
|
|
|
+});
|
|
|
|
|
|
// 获取热搜
|
|
|
function getRoutineHotSearch() {
|