订单结算修改,增加限时折扣
This commit is contained in:
@@ -58,6 +58,9 @@
|
||||
v-for="(item, index) in shopProductList.hots"
|
||||
:key="index"
|
||||
>
|
||||
<view class="limitDiscount" v-if="showLimitDiscount(item)"
|
||||
>限时折扣</view
|
||||
>
|
||||
<image
|
||||
class="panelfiveitemimage"
|
||||
:src="item.coverImg"
|
||||
@@ -151,6 +154,10 @@
|
||||
<text class="unit" v-if="item.unitName"
|
||||
>/{{ item.unitName }}</text
|
||||
>
|
||||
|
||||
<text class="old-price"
|
||||
>¥{{ item.salePrice }}</text
|
||||
>
|
||||
</view>
|
||||
</view>
|
||||
<view class="panelfiveitemNum">
|
||||
@@ -189,16 +196,21 @@
|
||||
>¥</text
|
||||
>
|
||||
<!-- 会员价与价格 -->
|
||||
<text class="price">
|
||||
{{
|
||||
shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1
|
||||
? item.memberPrice || item.salePrice
|
||||
: item.salePrice
|
||||
}}
|
||||
</text>
|
||||
<view class="price">
|
||||
<GoodsPrice
|
||||
:limitDiscount="limitTimeDiscountRes"
|
||||
:cart="item"
|
||||
:shopUserInfo="shopUserInfo"
|
||||
:shopInfo="shopInfo"
|
||||
></GoodsPrice>
|
||||
</view>
|
||||
|
||||
<text class="unit" v-if="item.unitName"
|
||||
>/{{ item.unitName }}</text
|
||||
>
|
||||
<text class="old-price"
|
||||
>¥{{ item.salePrice }}</text
|
||||
>
|
||||
<!-- <text v-if="item.suitNum>1 && item.type!= 'sku'"
|
||||
style="font-size: 16rpx;">「{{item.suitNum}}{{item.unitName}}起点」</text> -->
|
||||
</view>
|
||||
@@ -357,12 +369,16 @@
|
||||
mode=""
|
||||
></image>
|
||||
</view>
|
||||
|
||||
<view
|
||||
v-if="index == '0'"
|
||||
class="topSort"
|
||||
:class="'c' + (index1 + 1)"
|
||||
>TOP{{ index1 + 1 }}</view
|
||||
>
|
||||
<view class="limitDiscount" v-else-if="showLimitDiscount(item1)"
|
||||
>限时折扣</view
|
||||
>
|
||||
<view class="goods_right" style="overflow: hidden">
|
||||
<view class="name">{{ item1.name }}</view>
|
||||
<!-- <view class="lookBack" v-if="index=='0'">本店销量第{{index1+1}}名</view>-->
|
||||
@@ -417,16 +433,21 @@
|
||||
<view v-else class="flex-between" style="flex-wrap: inherit">
|
||||
<view class="money">
|
||||
<view>¥</view>
|
||||
<text class="money_num">
|
||||
{{
|
||||
shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1
|
||||
? item1.memberPrice || item1.salePrice
|
||||
: item1.salePrice
|
||||
}}
|
||||
</text>
|
||||
<view class="money_num">
|
||||
<GoodsPrice
|
||||
:limitDiscount="limitTimeDiscountRes"
|
||||
:cart="item1"
|
||||
:shopUserInfo="shopUserInfo"
|
||||
:shopInfo="shopInfo"
|
||||
></GoodsPrice>
|
||||
</view>
|
||||
<text class="money_num" v-if="item1.unitName"
|
||||
>/{{ item1.unitName }}</text
|
||||
>
|
||||
<text class="old-price"
|
||||
>¥{{ item1.salePrice }}</text
|
||||
>
|
||||
|
||||
<!-- <text v-if="item1.suitNum>1 && item1.type!= 'sku'"
|
||||
style="font-size: 14rpx;">
|
||||
「{{item1.suitNum}}{{item1.unitName}}起点」
|
||||
@@ -513,6 +534,7 @@
|
||||
:cartLists_count="cartLists_count"
|
||||
:cartList="matchedProducts"
|
||||
:showCart="showCart"
|
||||
:limitDiscount="limitTimeDiscountRes"
|
||||
@customevent="websocketsendMessage"
|
||||
@close="showCart = !showCart"
|
||||
:orderinfo="orderinfo"
|
||||
@@ -772,11 +794,23 @@
|
||||
</view>
|
||||
<Loading :isLoading="!useSocket.isConnected" />
|
||||
<ModalList></ModalList>
|
||||
<recommendGoodsModal
|
||||
v-if="isDataLoaded"
|
||||
@onBuyClick="onBuyClick"
|
||||
></recommendGoodsModal>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
//价格计算辅助函数
|
||||
import * as orderUtils from "@/utils/order-utils.js";
|
||||
import BigNumber from "bignumber.js";
|
||||
|
||||
import GoodsPrice from "@/components/goods-price.vue";
|
||||
|
||||
import * as limitTimeDiscountapi from "@/common/api/market/limitTimeDiscount.js";
|
||||
import ModalList from "@/components/modal-list.vue";
|
||||
import recommendGoodsModal from "./components/recommend-goods-modal.vue";
|
||||
import {
|
||||
ref,
|
||||
reactive,
|
||||
@@ -784,6 +818,7 @@ import {
|
||||
watchEffect,
|
||||
getCurrentInstance,
|
||||
computed,
|
||||
provide,
|
||||
watch,
|
||||
} from "vue";
|
||||
|
||||
@@ -805,6 +840,49 @@ import dayjs from "dayjs";
|
||||
import isBetween from "dayjs/plugin/isBetween";
|
||||
dayjs.extend(isBetween);
|
||||
|
||||
//点单智能推荐
|
||||
function onBuyClick(item) {
|
||||
console.log("onBuyClick", item);
|
||||
console.log("shopProductList", shopProductList);
|
||||
let index = -1;
|
||||
let index1 = -1;
|
||||
if (!item.isHot) {
|
||||
if (
|
||||
item.type == "sku" ||
|
||||
(item.type == "package" && item.groupType == "1")
|
||||
) {
|
||||
for (let i in shopProductList.productInfo) {
|
||||
const cate = shopProductList.productInfo[i];
|
||||
const goodsList = cate.productList;
|
||||
const index1 = goodsList.findIndex((goods) => goods.id == item.id);
|
||||
if (index1 > -1) {
|
||||
index = i;
|
||||
clickspecifications(item, index, index1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uni.$u.throttle(() => singleclick(item, "+"), 500);
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
item.type == "sku" ||
|
||||
(item.type == "package" && item.groupType == "1")
|
||||
) {
|
||||
for (let i in shopProductList.hots) {
|
||||
const goods = shopProductList.hots[i];
|
||||
if (goods.id==item.id) {
|
||||
index = i;
|
||||
clickspecifications(item, index, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
uni.$u.throttle(() => singleclick(item, "+"), 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取全局属性
|
||||
const { proxy } = getCurrentInstance();
|
||||
|
||||
@@ -852,8 +930,8 @@ store.updateNavbarConfig({
|
||||
isTransparent: false,
|
||||
hasPlaceholder: false, //是否要占位符
|
||||
});
|
||||
|
||||
const shopInfo = uni.cache.get("shopInfo");
|
||||
const shopInfo = reactive({});
|
||||
Object.assign(shopInfo, uni.cache.get("shopInfo"));
|
||||
const shopTable = uni.cache.get("shopTable");
|
||||
const distance = uni.cache.get("distance"); //距离
|
||||
|
||||
@@ -1082,6 +1160,8 @@ const selectSpec = async (specType, option) => {
|
||||
}
|
||||
};
|
||||
|
||||
const shopUserInfo = ref(uni.cache.get("shopUserInfo"));
|
||||
|
||||
// 监听 specifications 的变化
|
||||
watch(
|
||||
() => specifications.item.groupSnap,
|
||||
@@ -1567,8 +1647,21 @@ const updateProductQuantities = () => {
|
||||
|
||||
//websocket产值
|
||||
const websocketsendMessage = (data) => {
|
||||
console.log(data);
|
||||
uni.$u.debounce(useSocket.sendMessage(data), 500);
|
||||
const sendData = { ...data, is_time_discount: 0 };
|
||||
if (cartStore.limitTimeDiscount && cartStore.limitTimeDiscount.id && data.discount_sale_amount*1<=0) {
|
||||
if (
|
||||
orderUtils.canUseLimitTimeDiscount(
|
||||
data,
|
||||
cartStore.limitTimeDiscount,
|
||||
shopInfo,
|
||||
shopUserInfo.value,
|
||||
"product_id"
|
||||
)
|
||||
) {
|
||||
sendData.is_time_discount = 1;
|
||||
}
|
||||
}
|
||||
uni.$u.debounce(useSocket.sendMessage(sendData), 500);
|
||||
};
|
||||
|
||||
// 用于记录已经处理过的消息的 msg_id
|
||||
@@ -1627,6 +1720,7 @@ async function onMessage(Message) {
|
||||
// 初始化
|
||||
if (Message.operate_type == "init") {
|
||||
cartStore.carts = Message.data;
|
||||
cartStore.limitTimeDiscount = Message.time_dis_info;
|
||||
uni.hideLoading();
|
||||
isLoading.value = false;
|
||||
// 初始化商品数量
|
||||
@@ -1697,6 +1791,10 @@ async function onMessage(Message) {
|
||||
},
|
||||
});
|
||||
}
|
||||
if (Message.operate_type == "time_discount_save") {
|
||||
console.log("time_discount_save", Message.data);
|
||||
cartStore.limitTimeDiscount = Message.data;
|
||||
}
|
||||
|
||||
//除去p 每次返回都回执消息
|
||||
await websocketsendMessage({
|
||||
@@ -1835,35 +1933,6 @@ function combineOrderInfoDetailMap(orderinfo) {
|
||||
|
||||
// 计算购物车商品费用
|
||||
const totalPrices = computed(() => {
|
||||
// 待支付订单
|
||||
let cartone = 0;
|
||||
if (orderinfo.value) {
|
||||
let combinedArray = [];
|
||||
for (const key in orderinfo.value.detailMap) {
|
||||
if (orderinfo.value.detailMap.hasOwnProperty(key)) {
|
||||
let subArray = orderinfo.value.detailMap[key];
|
||||
combinedArray = [...combinedArray, ...subArray];
|
||||
}
|
||||
}
|
||||
// 购物车总数价格
|
||||
cartone = combinedArray.reduce((total, item) => {
|
||||
// 是否启用会员价 0否1是
|
||||
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
return (
|
||||
total +
|
||||
parseFloat(item.memberPrice || item.price) *
|
||||
parseFloat(item.num - item.returnNum)
|
||||
);
|
||||
} else {
|
||||
// salePrice销售价
|
||||
return (
|
||||
total +
|
||||
parseFloat(item.price || 0) * parseFloat(item.num - item.returnNum)
|
||||
);
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
// 购物车总数价格
|
||||
let cart = 0;
|
||||
if (matchedProducts.value.length > 0) {
|
||||
@@ -1877,6 +1946,18 @@ const totalPrices = computed(() => {
|
||||
}
|
||||
});
|
||||
}
|
||||
if (limitTimeDiscountRes.value && limitTimeDiscountRes.value.id) {
|
||||
//限时折扣
|
||||
const price = orderUtils.returnPrice({
|
||||
goods: item,
|
||||
shopInfo,
|
||||
limitTimeDiscountRes: limitTimeDiscountRes.value,
|
||||
shopUserInfo: shopUserInfo.value,
|
||||
idKey: "id",
|
||||
});
|
||||
console.log("限时折扣", item, price);
|
||||
return total + parseFloat(price) * parseFloat(item.cartNumber);
|
||||
}
|
||||
// 是否启用会员价 0否1是
|
||||
if (shopInfo.isVip == 1 && shopInfo.isMemberPrice == 1) {
|
||||
// memberPrice会员价
|
||||
@@ -2059,6 +2140,7 @@ const productqueryProduct = async () => {
|
||||
);
|
||||
cartStore.setGoodsMap(i.id, i);
|
||||
});
|
||||
|
||||
cartStore.goodsIsloading = true;
|
||||
scrollTopSize.value = 0;
|
||||
topArr.value = [];
|
||||
@@ -2081,11 +2163,49 @@ const productqueryProduct = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
provide("cartStore", cartStore);
|
||||
provide("shopUserInfo", shopUserInfo);
|
||||
provide("shopInfo", shopInfo);
|
||||
|
||||
onLoad(async (e) => {
|
||||
await proxy.$onLaunched;
|
||||
});
|
||||
|
||||
const limitTimeDiscountRes = ref(null);
|
||||
|
||||
function showLimitDiscount(item) {
|
||||
if (!limitTimeDiscountRes.value) {
|
||||
return false;
|
||||
}
|
||||
return orderUtils.canUseLimitTimeDiscount(
|
||||
item,
|
||||
limitTimeDiscountRes.value,
|
||||
shopInfo,
|
||||
shopUserInfo.value,
|
||||
"id"
|
||||
);
|
||||
}
|
||||
|
||||
onShow(async () => {
|
||||
limitTimeDiscountapi
|
||||
.getConfig({
|
||||
shopId: uni.cache.get("shopId"),
|
||||
})
|
||||
.then((res) => {
|
||||
console.log("limitTimeDiscountapi", res);
|
||||
if (res && typeof res == "object") {
|
||||
limitTimeDiscountRes.value = res;
|
||||
cartStore.limitTimeDiscount = res;
|
||||
websocketsendMessage({
|
||||
type: "shopping",
|
||||
operate_type: "time_discount_save",
|
||||
table_code: uni.cache.get("tableCode"),
|
||||
shop_id: uni.cache.get("shopId"),
|
||||
operate_type: "time_discount_save",
|
||||
data: res,
|
||||
});
|
||||
}
|
||||
});
|
||||
// 监听页面显示和隐藏
|
||||
useSocket.setOnMessage(onMessage);
|
||||
useSocket.onShowconnect();
|
||||
@@ -2304,6 +2424,8 @@ function toHistory() {
|
||||
|
||||
.panelfiveitemsex {
|
||||
.panelfiveitemsex_oen {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
.tips {
|
||||
font-family: Source Han Sans CN, Source Han Sans CN;
|
||||
font-weight: 400;
|
||||
@@ -2412,7 +2534,8 @@ function toHistory() {
|
||||
position: relative;
|
||||
|
||||
.left {
|
||||
width: 200rpx;
|
||||
// width: 200rpx;
|
||||
width: 156rpx;
|
||||
background-color: #f6f6f6;
|
||||
line-height: normal;
|
||||
box-sizing: border-box;
|
||||
@@ -2554,6 +2677,7 @@ function toHistory() {
|
||||
width: 200rpx;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
border-radius: 18rpx;
|
||||
top: 0;
|
||||
left: 0;
|
||||
z-index: 9;
|
||||
@@ -2578,6 +2702,7 @@ function toHistory() {
|
||||
font-size: 24rpx;
|
||||
color: #ffffff;
|
||||
border-radius: 20rpx 0rpx 20rpx 0rpx;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.topSort.c1 {
|
||||
@@ -2632,10 +2757,11 @@ function toHistory() {
|
||||
|
||||
.money {
|
||||
font-weight: bold;
|
||||
font-size: 24rpx;
|
||||
font-size: 20rpx;
|
||||
color: #333;
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
align-items: baseline;
|
||||
white-space: nowrap;
|
||||
|
||||
.money_num {
|
||||
font-size: 28rpx;
|
||||
@@ -3073,4 +3199,25 @@ function toHistory() {
|
||||
height: 36rpx;
|
||||
}
|
||||
}
|
||||
.old-price {
|
||||
color: #999;
|
||||
font-size: 24rpx;
|
||||
text-decoration: line-through;
|
||||
margin-left: 8rpx;
|
||||
}
|
||||
.limitDiscount {
|
||||
background-color: #cc5617;
|
||||
padding: 2rpx 10rpx;
|
||||
white-space: nowrap;
|
||||
text-align: center;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
font-weight: 400;
|
||||
font-size: 24rpx;
|
||||
color: #ffffff;
|
||||
border-radius: 20rpx 0rpx 20rpx 0rpx;
|
||||
z-index: 9;
|
||||
color: #fff;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user