下单页面增加生日有礼弹窗,关注公众号弹窗,订单结算增加满减活动,修改霸王餐,增加结算成功私域引流和公众号弹窗

This commit is contained in:
2025-10-17 11:24:59 +08:00
parent b44c1c468b
commit d858a34698
23 changed files with 9193 additions and 5939 deletions

View File

@@ -0,0 +1,11 @@
// 引入 request 文件
import request from "@/common/api/request.js";
import { prveUrl } from "./config.js";
export const config = (data) => {
return request({
url: prveUrl + "/user/birthdayGift",
method: "get",
data: data,
});
};

View File

@@ -0,0 +1,11 @@
// 引入 request 文件
import request from "@/common/api/request.js";
import { prveUrl } from "./config.js";
export const config = (data) => {
return request({
url: prveUrl + "/user/discountActivity",
method: "get",
data: data,
});
};

View File

@@ -0,0 +1,11 @@
// 引入 request 文件
import request from "@/common/api/request.js";
import { prveUrl } from "./config.js";
export const config = (data) => {
return request({
url: prveUrl + "/user/drainageConfig",
method: "get",
data: data,
});
};

View File

@@ -0,0 +1,545 @@
<template>
<view>
<up-popup
:show="show"
bgColor="transparent"
:safeAreaInsetBottom="false"
@close="close"
mode="center"
>
<view class="container">
<view
class="content"
:style="contentStyle"
:class="`content${currentPage}`"
>
<!-- 顶部标题图 -->
<view class="top">
<image class="image" :src="imageList.gift" mode="widthFix"></image>
</view>
<!-- 优惠券列表 -->
<view class="list">
<view
class="item"
:style="kuangStyle"
v-for="(item, index) in couponList"
:key="index"
>
<!-- <view class="kuang">
<image
class="kuang-img"
:src="imageList.kuang"
mode="aspectFit"
></image>
</view> -->
<!-- 优惠券金额 -->
<view>
<template
v-if="
item.couponInfo.couponType == 3 ||
item.couponInfo.couponType == 1
"
>
<text class="big-title">{{
returnTitle(item.couponInfo)
}}</text>
<text class="u-m-l-12 small-title">
{{ returnSmallTitle(item.couponInfo) }}
</text>
</template>
<template v-else>
<text class="big-title" style="font-size: 48rpx">{{
returnTitle(item.couponInfo)
}}</text>
</template>
</view>
<!-- 优惠券名称与领取按钮 -->
<view class="u-flex u-row-between u-m-t-16">
<view>
<text class="title">{{ item.couponInfo.title }}</text>
<text class="num">x{{ item.num }}</text>
</view>
<button class="lingqu" @click="handleReceive(item)">
立即领取
</button>
</view>
<!-- 有效期(替换硬编码,用接口返回数据) -->
<view class="u-m-t-10 time">
有效期至:{{ formatDate(item.couponInfo.validStartTime) }}-{{
formatDate(item.couponInfo.validEndTime)
}}
</view>
</view>
</view>
<!-- 分页控制(左右箭头+页码) -->
<view
class="u-flex u-row-center u-m-t-16"
v-if="allCoupons.length > 3"
>
<!-- 左箭头:当前页>1可点击 -->
<view
@click="handlePrevPage"
class="page-arrow"
:class="{ disabled: currentPage === 1 }"
>
<up-icon
name="arrow-left"
size="12"
:color="currentPage === 1 ? '#999' : '#000'"
></up-icon>
</view>
<!-- 页码列表:点击切换+当前页高亮 -->
<view class="u-flex page-nums">
<view
v-for="(num, index) in pageNums"
:key="index"
class="item"
:class="{ active: currentPage === num }"
@click="handleClickPage(num)"
>
{{ num }}
</view>
</view>
<!-- 右箭头:当前页<总页数可点击 -->
<view
@click="handleNextPage"
class="page-arrow"
:class="{ disabled: currentPage === totalPages }"
>
<up-icon
name="arrow-right"
size="12"
:color="currentPage === totalPages ? '#999' : '#000'"
></up-icon>
</view>
</view>
<!-- 底部一键领取按钮 -->
<view class="btn-wrap" :class="{ 'u-m-t-18': allCoupons.length > 3 }">
<image
@click="handleReceiveAll"
class="btn-img"
:src="imageList.btn"
mode="widthFix"
></image>
</view>
</view>
</view>
</up-popup>
</view>
</template>
<script setup>
import _ from "lodash";
import dayjs from "dayjs";
import { onMounted, ref, reactive, computed } from "vue";
import * as birthdayGiftApi from "@/common/api/market/birthdayGift.js";
// 1. 分页核心配置
const currentPage = ref(1); // 当前页码
const pageSize = ref(3); // 每页显示条数
const allCoupons = ref([]); // 存储全部优惠券(用于分页截取)
const couponList = ref([]); // 当前页优惠券列表
const pageNums = ref([]); // 页码数组(如[1,2,3]
const totalPages = computed(() => {
// 计算总页数向上取整如5条数据→2页
return Math.ceil(allCoupons.value.length / pageSize.value);
});
// 2. 图片资源修复bg2地址缺失的"g"
const imageList = reactive({
btn: "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/493b459f8c944057be72750c12c4cd1a.png",
gift: "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/112d2433378349b4a26ab311b8d3bac4.png",
kuang:
"https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/bb5e2d5ed73c455d9b6e9b4ac0e86192.png",
bg1: "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/847f9aea44d64b15b35caf8967f3d63f.png",
bg2: "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/2f704eef2e3d484d8862673131ae3989.png", // 修复:.pn→.png
bg3: "https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/7ab43d1ef2fc490d80165d18795a93f3.png",
});
// 3. 背景图(随当前页切换)
const bgUrl = ref(imageList.bg1);
const contentStyle = computed(() => ({
backgroundImage: `url(${bgUrl.value})`,
backgroundSize: "100% 100%", // 确保背景图铺满容器
}));
const kuangStyle = computed(() => ({
backgroundImage: `url(${imageList.kuang})`,
}));
// 4. 弹窗状态与props
const show = ref(false);
const props = defineProps({
getMode: {
type: String,
default: "eat",
},
});
// ---------------------- 分页核心逻辑 ----------------------
/**
* 1. 生成页码数组如总数据5条→[1,2]
*/
const generatePageNums = () => {
pageNums.value = Array.from({ length: totalPages.value }, (_, i) => i + 1);
};
/**
* 2. 更新当前页优惠券列表(根据当前页截取数据)
*/
const updateCouponList = () => {
const startIdx = (currentPage.value - 1) * pageSize.value;
const endIdx = startIdx + pageSize.value;
couponList.value = allCoupons.value.slice(startIdx, endIdx);
// 同步切换背景图当前页对应bg1/bg2/bg3
bgUrl.value = imageList[`bg${currentPage.value}`] || imageList.bg1;
};
/**
* 3. 上一页切换
*/
const handlePrevPage = () => {
if (currentPage.value > 1) {
currentPage.value--;
updateCouponList();
}
};
/**
* 4. 下一页切换
*/
const handleNextPage = () => {
if (currentPage.value < totalPages.value) {
currentPage.value++;
updateCouponList();
}
};
/**
* 5. 点击页码切换
*/
const handleClickPage = (num) => {
currentPage.value = num;
updateCouponList();
};
// ---------------------- 数据与交互逻辑 ----------------------
/**
* 1. 格式化日期YYYY.MM.DD
*/
const formatDate = (dateStr) => {
return dateStr ? dayjs(dateStr).format("YYYY.MM.DD") : ""; // 默认兜底日期
};
/**
* 2. 单个优惠券领取
*/
const handleReceive = async (item) => {
close();
uni.showToast({ title: "领取成功!去「我的优惠券」查看", icon: "none" });
};
/**
* 3. 底部一键领取(领取当前页所有优惠券)
*/
const handleReceiveAll = async () => {
if (couponList.value.length === 0) {
uni.showToast({ title: "当前页无优惠券可领", icon: "none" });
return;
}
close();
uni.showToast({ title: "领取成功!去「我的优惠券」查看", icon: "none" });
};
/**
* 4. 初始化获取优惠券数据
*/
const getCouponPopupAjax = async () => {
try {
const shopId = uni.cache.get("shopId");
const res = await birthdayGiftApi.config({ shopId });
if (res.length) {
// 处理有效期格式(固定有效期规则)
allCoupons.value = res.map((item) => {
if (item.validType === "fixed") {
item.validStartTime = dayjs()
.add(item.daysToTakeEffect, "day")
.format("YYYY-MM-DD HH:mm:ss");
item.validEndTime = dayjs()
.add(+item.daysToTakeEffect + +item.validDays, "day")
.format("YYYY-MM-DD HH:mm:ss");
}
return item;
});
// 初始化分页:生成页码→更新列表→显示弹窗
generatePageNums();
updateCouponList();
show.value = true;
}else{
close();
}
} catch (error) {
console.error("获取优惠券失败:", error);
}
};
// 页面挂载时初始化
onMounted(() => {
getCouponPopupAjax();
});
function returnTitle(coupon) {
if (coupon.couponType == 1) {
return `¥${coupon.discountAmount}`;
}
if (coupon.couponType == 2) {
return `商品兑换券`;
}
if (coupon.couponType == 3) {
const discountRate = coupon.discountRate / 10;
return `${discountRate}折券`;
}
if (coupon.couponType == 4) {
return `第二件半价券`;
}
if (coupon.couponType == 6) {
return `买一送一券`;
}
}
function returnSmallTitle(coupon) {
if (coupon.couponType == 1) {
return `满${coupon.fullAmount || 0}可用`;
}
if (coupon.couponType == 3) {
return `满${coupon.fullAmount || 0}可用`;
}
}
const emit = defineEmits(["close"]);
function close() {
show.value = false;
emit("close");
}
</script>
<style scoped lang="scss">
// 基础容器样式
.container {
width: 100vw;
height: 100vh;
position: relative;
display: flex;
align-items: center;
justify-content: center;
padding: 52rpx;
.content {
width: 100%;
position: relative;
margin: auto;
min-height: 836rpx;
padding: 0 28rpx 62rpx;
border-radius: 16rpx;
overflow: hidden;
// 分页箭头样式添加禁用态
.page-arrow {
cursor: pointer;
width: 64rpx;
height: 64rpx;
box-sizing: border-box;
color: #000;
background-color: #fff;
border: 1px solid #d9d9d9;
font-size: 14px;
line-height: 60rpx;
padding: 0 14rpx;
border-radius: 4rpx;
overflow: hidden;
cursor: pointer;
transition: all 0.2s;
margin: 0 16rpx;
display: flex;
justify-content: center;
align-content: center;
&.disabled {
cursor: not-allowed;
}
}
// 页码样式当前页高亮
.page-nums {
display: flex;
gap: 16rpx;
.item {
width: 64rpx;
height: 64rpx;
box-sizing: border-box;
color: #000;
background-color: #fff;
border: 1px solid #d9d9d9;
font-size: 14px;
line-height: 64rpx;
padding: 0 4rpx;
border-radius: 4rpx;
overflow: hidden;
cursor: pointer;
transition: all 0.2s;
text-align: center;
&.active {
border-color: #1890ff;
color: #1890ff;
font-weight: 500;
}
&:active:not(.active) {
background-color: #f5f5f5;
}
}
}
// 底部按钮容器
.btn-wrap {
margin: 28rpx 0 0;
margin-top: 30rpx;
.btn-img {
width: 100%;
height: 100%;
cursor: pointer;
&:active {
opacity: 0.9;
}
}
}
}
}
// 顶部标题图
.top {
position: absolute;
left: 0;
right: 0;
top: 0;
z-index: 1;
.image {
width: 100%;
}
}
// 优惠券列表样式
.list {
margin-top: 332rpx;
position: relative;
z-index: 2;
.item {
position: relative;
padding: 32rpx 12rpx 36rpx 36rpx;
background-size: 100% 100%;
background-position: center;
overflow: hidden;
margin-top: 36rpx;
box-sizing: border-box;
// 优惠券边框图
.kuang {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
z-index: -1;
.kuang-img {
width: 100%;
height: 100%;
}
}
// 金额样式
.big-title {
color: #f05a82;
font-size: 36px;
font-weight: 600;
}
.small-title {
color: #f05a82;
font-size: 16px;
font-weight: 600;
}
// 名称与数量
.title {
color: #333;
font-size: 16px;
font-weight: 400;
padding-bottom: 10rpx;
border-bottom: 4rpx dashed #fd8293;
}
.num {
color: #f05a82;
font-size: 20px;
font-weight: 400;
line-height: 22px;
margin-left: 16rpx;
}
// 有效期
.time {
color: #666; // 调整颜色更柔和
font-size: 14px;
font-weight: 400;
}
}
}
// 领取按钮样式
.lingqu {
padding: 12rpx 20rpx; // 加宽内边距点击区域更大
border-radius: 14rpx;
background: #fd8293;
color: #fff;
font-size: 28rpx;
font-weight: 400;
line-height: 1;
border: none;
outline: none;
margin: 0;
cursor: pointer;
&:active {
background: #f07080; // 点击深色反馈
}
}
// 工具类样式补充缺失的flex基础样式
.u-flex {
display: flex;
}
.u-row-center {
align-items: center;
justify-content: center;
}
.u-row-between {
justify-content: space-between;
}
.u-m-t-10 {
margin-top: 10rpx;
}
.u-m-t-16 {
margin-top: 16rpx;
}
.u-m-t-20 {
margin-top: 20rpx;
}
.u-m-t-30 {
margin-top: 30rpx;
}
.u-m-x-16 {
margin-left: 16rpx;
margin-right: 16rpx;
}
.u-m-l-12 {
margin-left: 12rpx;
}
</style>

View File

@@ -1,6 +1,6 @@
<!-- 首页优惠券弹窗 -->
<template>
<up-popup :show="show" bgColor="transparent">
<up-popup :show="show" bgColor="transparent" @close="close">
<view class="container">
<view class="content" :class="`content${currentNum}`">
<image class="bg" :src="bgUrl" mode="widthFix"></image>
@@ -141,6 +141,8 @@ async function getCouponPopupAjax() {
bgUrl.value = bgUrlList.value[1];
currentNum.value = 1;
}
}else{
close()
}
} catch (error) {
console.log(error);
@@ -167,6 +169,12 @@ async function getHandle() {
}
uni.hideLoading();
}
const emit=defineEmits(['close'])
function close() {
show.value = false;
emit('close');
}
onMounted(() => {
getCouponPopupAjax();

101
components/drainage.vue Normal file
View File

@@ -0,0 +1,101 @@
<template>
<view>
<!-- 私域引流 -->
<up-popup
:show="showPreview"
mode="center"
round="16rpx"
closeOnClickOverlay
@close="close"
:safeAreaInsetBottom="false"
>
<view class="preview-box">
<view class="u-flex" style="align-items: stretch">
<view
class="u-flex-1 u-p-r-24 u-flex u-flex-col"
style="align-items: start; justify-content: space-between"
>
<view>
<view class="font-14 font-bold color-333">{{
drainageConfig.title
}}</view>
<view class="u-m-t-16 font-12 color-666">{{
drainageConfig.content
}}</view>
</view>
<view class="color-999 font-12 u-m-t-16">{{
drainageConfig.note
}}</view>
</view>
<image
:show-menu-by-longpress="true"
:src="drainageConfig.qrCode"
style="width: 240rpx; height: 240rpx"
mode="aspectFit"
></image>
</view>
<view class="close" @click="close">
<up-icon name="close-circle" size="34" color="#fff"></up-icon>
</view>
</view>
</up-popup>
</view>
</template>
<script setup>
import * as drainageConfigApi from "@/common/api/market/drainageConfig.js";
import { ref, reactive, computed, watch, onMounted } from "vue";
const showPreview = defineModel({
type: Boolean,
default: false,
});
const emit = defineEmits(["close"]);
function close() {
showPreview.value = false;
emit("close");
}
const drainageConfig = ref({});
onMounted(async () => {
const shopId = uni.cache.get("shopId");
const drainageConfigRes = await drainageConfigApi.config({
shopId: shopId,
});
drainageConfig.value = drainageConfigRes;
if (drainageConfig.value.isEnable) {
showPreview.value = true;
} else {
close();
}
});
</script>
<style scoped lang="scss">
.u-flex-col {
flex-direction: column;
}
.preview {
padding: 8rpx 32rpx;
border-radius: 12rpx;
background: $my-main-color;
color: #ffffff;
font-size: 28rpx;
font-weight: 400;
line-height: 40rpx;
}
.preview-box {
width: 700rpx;
padding: 32rpx 28rpx;
position: relative;
.close {
position: absolute;
left: 50%;
bottom: -100rpx;
transform: translateX(-50%);
}
}
</style>

41
components/modal-list.vue Normal file
View File

@@ -0,0 +1,41 @@
<template>
<view>
<officialAccount
v-if="showOfficialAccount"
@close="modelClose($event, 'officialAccount')"
/>
<couponModal
v-if="showCoupon"
getMode="eat"
@close="modelClose($event, 'coupon')"
/>
<birthdayGift v-if="showBirthdayGift" @close="modelClose($event, 'birthdayGift')" />
</view>
</template>
<script setup>
import { ref, watch, computed, reactive, toRaw } from "vue";
import couponModal from "@/components/coupon-modal.vue";
import birthdayGift from "@/components/birthday-modal.vue";
import officialAccount from "@/components/official-account.vue";
//弹窗列表
const list = ref([]);
const showBirthdayGift = ref(true);
const showCoupon = ref(false);
const showOfficialAccount = ref(false);
function modelClose(e, type) {
console.log("modelClose", type);
if (type == "birthdayGift") {
showCoupon.value = true;
return;
}
if (type == "coupon") {
showOfficialAccount.value = true;
return;
}
if (type == "officialAccount") {
return;
}
}
</script>

View File

@@ -0,0 +1,116 @@
<!-- 首页优惠券弹窗 -->
<template>
<up-popup :show="show" bgColor="transparent" mode="center" @close="close">
<view class="container">
<view class="content">
<image class="bg" :src="bgUrl" mode="widthFix"></image>
<view class="info">
<view class="u-flex u-row-center">
<image
:show-menu-by-longpress="true"
:src="code"
style="height: 240rpx"
mode="heightFix"
></image>
</view>
<view
class="color-999 font-12 text-center u-m-t-10"
style="line-height: 36rpx"
>长按识别关注更多优惠不能错过</view
>
</view>
<view class="close" @click="close">
<up-icon name="close-circle" size="34" color="#fff"></up-icon>
</view>
</view>
</view>
</up-popup>
</template>
<script setup>
import _ from "lodash";
import dayjs from "dayjs";
import { onMounted, ref } from "vue";
const bgUrl = ref(
"https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/4/41239c8852874aa39d1f106e45456e10.png"
);
const show = ref(false);
const code = ref(
"https://cashier-oss.oss-cn-beijing.aliyuncs.com/upload/20240408/4d6e818a01f145a898d8c2368f4b5ad1.jpg"
);
const emit=defineEmits(['close'])
function close() {
show.value = false;
emit('close');
}
onMounted(() => {
show.value = true;
});
</script>
<style scoped lang="scss">
.u-row-center {
justify-content: center;
}
.container {
width: 100vw;
height: 100vh;
position: relative;
display: flex;
align-items: center;
justify-content: center;
padding: 54rpx;
.content {
width: 100%;
position: relative;
.close {
position: absolute;
left: 50%;
bottom: -100rpx;
transform: translateX(-50%);
}
.bg {
width: 100%;
height: 100%;
}
.info {
position: absolute;
bottom: 86rpx;
left: 60rpx;
right: 60rpx;
}
.btn-wrap {
width: 60%;
position: absolute;
left: 20%;
&.btn-wrap1 {
bottom: 74upx;
}
&.btn-wrap2 {
bottom: 74upx;
}
&.btn-wrap3 {
bottom: 38upx;
}
.btn-img {
width: 100%;
}
.t {
font-size: 42upx;
font-weight: bold;
color: #b43a14;
position: absolute;
top: 44%;
left: 54%;
white-space: nowrap;
transform: translate(-50%, -50%);
}
}
}
}
</style>

View File

@@ -0,0 +1,26 @@
<template>
<view>
<officialAccount
v-if="showOfficialAccount"
@close="modelClose($event, 'officialAccount')"
/>
<Drainage v-model="showDrainage" @close="modelClose($event, 'drainage')" />
</view>
</template>
<script setup>
import { ref, watch, computed, reactive, toRaw } from "vue";
import officialAccount from "@/components/official-account.vue";
import Drainage from "@/components/drainage.vue";
const showDrainage = ref(true);
const showOfficialAccount = ref(false);
function modelClose(e, type) {
console.log("modelClose", type);
if(type=='drainage'){
showOfficialAccount.value = true;
return
}
}
</script>

View File

@@ -0,0 +1,260 @@
<template>
<!-- 支付方式 -->
<view class="paymentMethod">
<view class="paymentMethod_content">
<view class="paymentMethod_title">支付方式</view>
<up-radio-group v-model="radiovalue" iconPlacement="right" @change="groupChanges" :size="28"
placement="column">
<block v-for="(item,index) in paymentMethodList" :key="index">
<view class="method_list" @click="groupChanges(item.type)" :class="{disabled:returnDisabled(item)}"
v-if="(index+1) == radiovalue?!changeFreeenable:true">
<view class="method_list_top">
<view class="method_list_top_left">
<image class="icon" :src="item.url" mode="aspectFill" />
<view class="method_list_top_cen">
<view class="name"> {{ item.name }} </view>
<view class="method_list_bom" v-if="item.type == 1">
<text class="balance">
当前余额{{orderVIP?(orderVIP.amount||0):0}}</text>
<text class="topUpNow" @click="goRecharge">去充值</text>
</view>
</view>
</view>
<up-radio :disabled="returnDisabled(item)" activeColor="#E8AD7B" icon-size="18" size="18" :name="item.type">
</up-radio>
</view>
</view>
</block>
</up-radio-group>
</view>
</view>
</template>
<script setup>
import {
ref,
reactive,
defineProps,
computed,
defineEmits,
watch,
watchEffect,
defineExpose
} from 'vue'
const props = defineProps({
rechargeFreeChecked: {
type: Boolean,
default: false
},
payAmount: {
type: Number,
default: 0
},
freeCheck: {
type: Boolean,
default: false
},
changeFreeenable: {
type: Boolean,
default: false
},
disablePayType: {
type: Array,
default: () => {
return []
}
}
});
function returnDisabled(item) {
if (props.disablePayType.includes(item.name)) {
return true
}else{
return false
}
}
const orderVIP = ref(null)
const emits = defineEmits(['customevent', 'groupChange']);
watchEffect(() => {
orderVIP.value = uni.cache.get('orderVIP')
})
const orderVIPfun = (data) => {
orderVIP.value = data
}
const paymentMethodList = ref([
// #ifdef MP-WEIXIN
{
name: "微信支付",
type: 2,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/weChat.png",
payType: 'wechatPay'
},
// #endif
// #ifdef MP-ALIPAY
{
name: "支付宝支付",
type: 3,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/alipay.png",
payType: 'aliPay'
},
// #endif
{
name: "余额支付",
type: 1,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/drder/wechat.png",
payType: 'accountPay'
}
])
const paymentMethodName = ref([{
name: "余额支付",
type: 1,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/drder/wechat.png",
payType: 'accountPay'
},
{
name: "微信支付",
type: 2,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/weChat.png",
payType: 'wechatPay'
},
{
name: "支付宝支付",
type: 3,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/alipay.png",
payType: 'aliPay'
},
])
const radiovalue = ref(2) // 支付方式
const ispws = ref(false) // 输入支付密码
const storeInfo = ref({})
// * 监听支付方式切换
const groupChanges = (type) => {
if (props.freeCheck && type == 1) {
return;
}
const item=paymentMethodList.value.find(v=>v.type==type)
if(item&&returnDisabled(item)){
uni.showToast({
title:"当前支付方式不可用",
icon:'none'
})
return
}
// if (props.payAmount <= 0 && type != 1) {
// return;
// }
radiovalue.value = type;
let name = paymentMethodName.value[type - 1].name;
emits("groupChange", paymentMethodName.value[type - 1])
}
// 去充值
const goRecharge = () => {
if (orderVIP.value.isVip) {
uni.navigateTo({
url: '/pages/user/member/czzx?shopId=' + orderVIP.value.shopId
})
return
}
uni.navigateTo({
url: '/user/vip/buy-vip?shopId=' + orderVIP.value.shopId
})
// uni.pro.navigateTo('user/member/index', {
// shopId: orderVIP.value.shopId
// })
}
// 将方法暴露给父组件
defineExpose({
groupChanges,
orderVIPfun
});
</script>
<style lang="scss">
.paymentMethod {
box-sizing: border-box;
margin-top: 30rpx;
border-radius: 18rpx;
.paymentMethod_content {
background-color: #fff;
border-radius: 22rpx;
padding: 30rpx 30rpx 0 30rpx;
box-sizing: border-box;
.paymentMethod_title {
font-weight: 500;
font-size: 32rpx;
color: #333333;
box-sizing: border-box;
}
.method_list {
padding: 40rpx 0;
box-sizing: border-box;
&.disabled{
opacity: .6;
}
.method_list_top {
display: flex;
justify-content: space-between;
.method_list_top_left {
display: flex;
align-items: center;
.icon {
width: 54.67rpx !important;
height: 48rpx !important;
margin-right: 22rpx;
}
.name {
font-size: 32rpx;
font-weight: 500;
color: #333;
}
.method_list_top_cen {
display: flex;
flex-direction: column;
}
}
}
.method_list_bom {
display: flex;
align-items: center;
.balance {
margin-right: 20rpx;
font-size: 24rpx;
}
.topUpNow {
color: #FF803D;
font-size: 28rpx;
}
}
}
.method_list:nth-child(odd) {
border-bottom: 2rpx solid #e5e5e5;
}
}
}
</style>

View File

@@ -3,11 +3,19 @@
<view class="paymentMethod">
<view class="paymentMethod_content">
<view class="paymentMethod_title">支付方式</view>
<up-radio-group v-model="radiovalue" iconPlacement="right" @change="groupChanges" :size="28"
placement="column">
<block v-for="(item,index) in paymentMethodList" :key="index">
<view class="method_list" @click="groupChanges(item.type)" :class="{disabled:returnDisabled(item)}"
v-if="(index+1) == radiovalue?!changeFreeenable:true">
<up-radio-group
v-model="radiovalue"
iconPlacement="right"
@change="groupChanges"
:size="28"
placement="column"
>
<block v-for="(item, index) in paymentMethodList" :key="index">
<view
class="method_list"
@click="groupChanges(item.type)"
:class="{ disabled: returnDisabled(item) }"
>
<view class="method_list_top">
<view class="method_list_top_left">
<image class="icon" :src="item.url" mode="aspectFill" />
@@ -15,12 +23,19 @@
<view class="name"> {{ item.name }} </view>
<view class="method_list_bom" v-if="item.type == 1">
<text class="balance">
当前余额{{orderVIP?(orderVIP.amount||0):0}}</text>
当前余额{{ orderVIP ? orderVIP.amount || 0 : 0 }}</text
>
<text class="topUpNow" @click="goRecharge">去充值</text>
</view>
</view>
</view>
<up-radio :disabled="returnDisabled(item)" activeColor="#E8AD7B" icon-size="18" size="18" :name="item.type">
<up-radio
:disabled="returnDisabled(item)"
activeColor="#E8AD7B"
icon-size="18"
size="18"
:name="item.type"
>
</up-radio>
</view>
</view>
@@ -31,7 +46,7 @@
</template>
<script setup>
import {
import {
ref,
reactive,
defineProps,
@@ -39,60 +54,59 @@
defineEmits,
watch,
watchEffect,
defineExpose
} from 'vue'
defineExpose,
} from "vue";
const props = defineProps({
const props = defineProps({
rechargeFreeChecked: {
type: Boolean,
default: false
default: false,
},
payAmount: {
type: Number,
default: 0
default: 0,
},
freeCheck: {
type: Boolean,
default: false
default: false,
},
changeFreeenable: {
type: Boolean,
default: false
default: false,
},
disablePayType: {
type: Array,
default: () => {
return []
}
}
return [];
},
},
});
});
function returnDisabled(item) {
function returnDisabled(item) {
if (props.disablePayType.includes(item.name)) {
return true
}else{
return false
}
return true;
} else {
return false;
}
}
const orderVIP = ref(null)
const emits = defineEmits(['customevent', 'groupChange']);
watchEffect(() => {
orderVIP.value = uni.cache.get('orderVIP')
})
const orderVIP = ref(null);
const emits = defineEmits(["customevent", "groupChange"]);
watchEffect(() => {
orderVIP.value = uni.cache.get("orderVIP");
});
const orderVIPfun = (data) => {
orderVIP.value = data
}
const orderVIPfun = (data) => {
orderVIP.value = data;
};
const paymentMethodList = ref([
const paymentMethodList = ref([
// #ifdef MP-WEIXIN
{
name: "微信支付",
type: 2,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/weChat.png",
payType: 'wechatPay'
payType: "wechatPay",
},
// #endif
// #ifdef MP-ALIPAY
@@ -100,56 +114,56 @@
name: "支付宝支付",
type: 3,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/alipay.png",
payType: 'aliPay'
payType: "aliPay",
},
// #endif
{
name: "余额支付",
type: 1,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/drder/wechat.png",
payType: 'accountPay'
}
])
payType: "accountPay",
},
]);
const paymentMethodName = ref([{
const paymentMethodName = ref([
{
name: "余额支付",
type: 1,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/drder/wechat.png",
payType: 'accountPay'
payType: "accountPay",
},
{
name: "微信支付",
type: 2,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/weChat.png",
payType: 'wechatPay'
payType: "wechatPay",
},
{
name: "支付宝支付",
type: 3,
url: "https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/alipay.png",
payType: 'aliPay'
payType: "aliPay",
},
])
]);
const radiovalue = ref(2) // 支付方式
const radiovalue = ref(2); // 支付方式
const ispws = ref(false) // 输入支付密码
const ispws = ref(false); // 输入支付密码
const storeInfo = ref({})
const storeInfo = ref({});
// * 监听支付方式切换
const groupChanges = (type) => {
// * 监听支付方式切换
const groupChanges = (type) => {
if (props.freeCheck && type == 1) {
return;
}
const item=paymentMethodList.value.find(v=>v.type==type)
if(item&&returnDisabled(item)){
const item = paymentMethodList.value.find((v) => v.type == type);
if (item && returnDisabled(item)) {
uni.showToast({
title:"当前支付方式不可用",
icon:'none'
})
return
title: "当前支付方式不可用",
icon: "none",
});
return;
}
// if (props.payAmount <= 0 && type != 1) {
// return;
@@ -157,34 +171,37 @@
radiovalue.value = type;
let name = paymentMethodName.value[type - 1].name;
emits("groupChange", paymentMethodName.value[type - 1])
}
emits("groupChange", paymentMethodName.value[type - 1]);
};
// 去充值
const goRecharge = () => {
// 去充值
const goRecharge = () => {
if (props.disablePayType.includes("余额支付")) {
return;
}
if (orderVIP.value.isVip) {
uni.navigateTo({
url: '/pages/user/member/czzx?shopId=' + orderVIP.value.shopId
})
return
url: "/pages/user/member/czzx?shopId=" + orderVIP.value.shopId,
});
return;
}
uni.navigateTo({
url: '/user/vip/buy-vip?shopId=' + orderVIP.value.shopId
})
url: "/user/vip/buy-vip?shopId=" + orderVIP.value.shopId,
});
// uni.pro.navigateTo('user/member/index', {
// shopId: orderVIP.value.shopId
// })
}
// 将方法暴露给父组件
defineExpose({
};
// 将方法暴露给父组件
defineExpose({
groupChanges,
orderVIPfun
});
orderVIPfun,
});
</script>
<style lang="scss">
.paymentMethod {
.paymentMethod {
box-sizing: border-box;
margin-top: 30rpx;
border-radius: 18rpx;
@@ -205,8 +222,8 @@
.method_list {
padding: 40rpx 0;
box-sizing: border-box;
&.disabled{
opacity: .6;
&.disabled {
opacity: 0.6;
}
.method_list_top {
display: flex;
@@ -233,7 +250,6 @@
flex-direction: column;
}
}
}
.method_list_bom {
@@ -246,7 +262,7 @@
}
.topUpNow {
color: #FF803D;
color: #ff803d;
font-size: 28rpx;
}
}
@@ -256,5 +272,5 @@
border-bottom: 2rpx solid #e5e5e5;
}
}
}
}
</style>

View File

@@ -1,5 +1,5 @@
// const debug = process.env.NODE_ENV == 'development' ? true : false;
const debug = false
const debug = true
// #ifdef H5
const proxyApi = "/api"
// #endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,29 @@
<template>
<!-- 充值免单 -->
<view class="rechargeFree">
<view class="rechargeFree_bg" @click="changeFree">
<view class="rechargeFree_bg" @click="itemClick">
<view class="left">
<view class="icon">优惠</view>
<view class="text">
充值消费{{freeDineConfig.rechargeTimes}}订单满{{freeDineConfig.rechargeThreshold}}元可用本单立享免单</view>
充值消费{{ freeDineConfig.rechargeTimes }}订单满{{
freeDineConfig.rechargeThreshold
}}元可用本单立享免单</view
>
</view>
<up-checkbox :disabled="!freeDineConfig.enable" @change="change" shape="circle" usedAlone v-model:checked="changeFreeenable" icon-size="20" size="20">
<view @click.stop="()=>{}">
<up-checkbox
:disabled="!freeDineConfig.enable"
@change="changeFree"
shape="circle"
activeColor="#E8AD7B"
usedAlone
v-model:checked="changeFreeenable"
icon-size="20"
size="20"
>
</up-checkbox>
</view>
<!-- <up-checkbox-group iconPlacement="right">
<up-checkbox : v-model="changeFreeenable"
:checked="freeDineConfig.enable" @change="change" activeColor="#E8AD7B" shape="circle"
@@ -20,38 +35,38 @@
</template>
<script setup>
import {
ref,
defineProps,
defineEmits
} from 'vue';
import { ref, defineProps, defineEmits } from "vue";
// 定义接收的属性
const props = defineProps({
// 定义接收的属性
const props = defineProps({
freeDineConfig: {
type: Object,
default: {}
default: {},
},
payAmount: {
type: Number,
default: 0
default: 0,
},
});
});
function itemClick(){
changeFreeenable.value = !changeFreeenable.value;
emits("changeFree", changeFreeenable.value);
const emits = defineEmits(['changeFree']);
}
const emits = defineEmits(["changeFree"]);
const changeFreeenable = ref(false)
const changeFreeenable = ref(false);
/**
/**
* 监听是否免单
*/
const change = (e) => {
emits('changeFree', e);
}
const changeFree = (e) => {
emits("changeFree", e);
};
</script>
<style lang="scss" scoped>
.rechargeFree {
.rechargeFree {
// padding: 0 20rpx;
margin-top: 32rpx;
@@ -72,11 +87,11 @@
height: 36rpx;
text-align: center;
line-height: 36rpx;
background: linear-gradient(180deg, #FEDE81 0%, #FEB263 100%);
background: linear-gradient(180deg, #fede81 0%, #feb263 100%);
border-radius: 12rpx 0rpx 12rpx 0rpx;
font-weight: 500;
font-size: 20rpx;
color: #FFFFFF;
color: #ffffff;
margin-right: 12rpx;
}
@@ -88,5 +103,5 @@
}
}
}
}
}
</style>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,65 +1,13 @@
<template>
<view class="u-p-30">
<view>
<up-button type="warning" @click="popupShow">初始化</up-button>
</view>
<view class="u-m-t-30">
<up-button type="primary" @click="toCreate">去下单</up-button>
</view>
<up-popup :show="show" mode="bottom" close-on-click-overlay @close="resetForm">
<view class="u-p-30">
<up-form label-width="80" ref="refForm">
<up-form-item label="台桌码">
<up-input v-model="form.tableCode" placeholder="请输入台桌码"></up-input>
</up-form-item>
</up-form>
<view class="u-flex gap-20 u-m-t-30">
<up-button @click="show=false">取消</up-button>
<up-button type="primary" @click="scanCodehandle">确定</up-button>
</view>
</view>
</up-popup>
<birthdayGift></birthdayGift>
</view>
</template>
<script setup>
import {onLoad} from '@dcloudio/uni-app'
import { reactive,ref} from 'vue'
import {
productStore
} from '@/stores/user.js';
const store = productStore();
const scanCodehandle = async (i) => {
await store.scanCodeactions(form)
}
const show=ref(false);
const options=ref({})
function popupShow(){
show.value=true;
}
const refForm=ref(null);
const form=reactive({
tableCode:"40963902920"
})
function resetForm(){
form.tableCode=""
}
onLoad((opt)=>{
console.log(opt);
options.value=opt
})
function toCreate(){
uni.navigateTo({
url:'/pages/index/index'
})
}
import birthdayGift from "@/components/birthday-modal.vue";
</script>
<style lang="scss" scoped>
.gap-20{
gap: 20rpx;
}
</style>

View File

@@ -1,59 +1,54 @@
import {
defineStore
} from 'pinia';
import yskUtils from 'ysk-utils'
const {
OrderPriceCalculator,
BaseCartItem,
BackendCoupon,
ActivityConfig,
OrderExtraConfig,
MerchantReductionConfig,
MerchantReductionType,
GoodsType
} = yskUtils
import { defineStore } from "pinia";
// import yskUtils from 'ysk-utils'
// const {
// OrderPriceCalculator,
// BaseCartItem,
// BackendCoupon,
// ActivityConfig,
// OrderExtraConfig,
// MerchantReductionConfig,
// MerchantReductionType,
// GoodsType
// } = yskUtils
import {
ref,
computed,
reactive,
watchEffect,
watch
} from 'vue';
import { OrderPriceCalculator } from "@/utils/goods";
import { ref, computed, reactive, watchEffect, watch } from "vue";
import {
productminiApphotsquery,
APIgroupquery,
} from "@/common/api/product/product.js";
export const useCartsStore = defineStore('cart',
() => {
export const useCartsStore = defineStore("cart", () => {
// 店铺信息
const shopInfo = ref(uni.cache.get('shopInfo') || {
const shopInfo = ref(
uni.cache.get("shopInfo") || {
isMemberPrice: 0,
isTableFee: 1
})
isTableFee: 1,
}
);
const consumeDiscount=ref({})
const consumeDiscount = ref({});
// 适配工具库 BaseCartItem 接口的商品数据转换函数
const convertToBaseCartItem = (item) => {
const skuData = item.skuData ? {
const skuData = item.skuData
? {
id: item.skuData.id || item.sku_id,
salePrice: item.skuData.salePrice || 0,
memberPrice: item.skuData.memberPrice || 0
} :
undefined;
memberPrice: item.skuData.memberPrice || 0,
}
: undefined;
const goods = getProductDetails({
...item,
product_id: item.product_id || item.productId,
sku_id:item.skuId||item.sku_id
})
sku_id: item.skuId || item.sku_id,
});
return {
...item,
id: item.id,
sku_id:item.skuId||item.sku_id,
sku_id: item.skuId || item.sku_id,
product_id: item.product_id || item.productId,
salePrice: item.salePrice || item.price,
number: item.number || item.num || 0,
@@ -62,23 +57,28 @@ export const useCartsStore = defineStore('cart',
is_gift: !!(item.is_gift || item.isGift),
returnNum: item.returnNum || 0,
memberPrice: item.memberPrice || 0,
discountSaleAmount: item.discount_sale_amount || item.discountSaleAmount || 0,
packFee: item.packFee || (goods?goods.packFee:0) || 0,
discountSaleAmount:
item.discount_sale_amount || item.discountSaleAmount || 0,
packFee: item.packFee || (goods ? goods.packFee : 0) || 0,
packNumber: item.pack_number || item.packNumber || 0,
activityInfo: item.activityInfo ? {
activityInfo: item.activityInfo
? {
type: item.activityInfo.type,
discountRate: OrderPriceCalculator.formatDiscountRate(item.activityInfo.discountRate),
vipPriceShare: !!item.activityInfo.vipPriceShare
} : undefined,
skuData
discountRate: OrderPriceCalculator.formatDiscountRate(
item.activityInfo.discountRate
),
vipPriceShare: !!item.activityInfo.vipPriceShare,
}
: undefined,
skuData,
};
};
// 合并所有商品列表
const allGoods = ref([])
const allGoods = ref([]);
function getAllGoodsList() {
const currentGoods = (carts.value).map(convertToBaseCartItem);
const currentGoods = carts.value.map(convertToBaseCartItem);
const giftGoods = [].map(convertToBaseCartItem);
// 扁平化历史订单商品
const oldOrderGoods = Object.values(oldOrder.value.detailMap || {})
@@ -87,64 +87,76 @@ export const useCartsStore = defineStore('cart',
return [...currentGoods, ...giftGoods, ...oldOrderGoods];
}
// 就餐类型 'dine-in' | 'take-out'
let dinnerType = ref('dine-in');
let dinnerType = ref("dine-in");
function setDinnerType(str) {
dinnerType.value = str
dinnerType.value = str;
}
//餐位费配置
const dinersNum = uni.cache.get('dinersNum') || 0
const dinersNum = uni.cache.get("dinersNum") || 0;
const seatFeeConfig = ref({
pricePerPerson: shopInfo.value.tableFee || 0,
personCount: dinersNum||0,
isEnabled: !shopInfo.value.isTableFee
})
watch(() => shopInfo.value.isTableFee, (newval) => {
seatFeeConfig.value.isEnabled = !shopInfo.value.isTableFee
seatFeeConfig.value.pricePerPerson = shopInfo.value.tableFee||0
},{
deep:true
})
personCount: dinersNum || 0,
isEnabled: !shopInfo.value.isTableFee,
});
watch(
() => shopInfo.value.isTableFee,
(newval) => {
seatFeeConfig.value.isEnabled = !shopInfo.value.isTableFee;
seatFeeConfig.value.pricePerPerson = shopInfo.value.tableFee || 0;
},
{
deep: true,
}
);
function setSeatFeeConfig(key, val) {
seatFeeConfig.value[key] = val;
}
watch(() => seatFeeConfig.value, (newval) => {
console.log('seatFeeConfig', seatFeeConfig.value);
}, {
deep: true
})
watch(
() => seatFeeConfig.value,
(newval) => {
console.log("seatFeeConfig", seatFeeConfig.value);
},
{
deep: true,
}
);
//积分规则
const pointDeductionRule = ref({
pointsPerYuan: 100,
maxDeductionAmount: Infinity
})
maxDeductionAmount: Infinity,
});
function setPointDeductionRule(pointsPerYuan, maxDeductionAmount) {
pointDeductionRule.value.pointsPerYuan = pointsPerYuan
pointDeductionRule.value.maxDeductionAmount = maxDeductionAmount
pointDeductionRule.value.pointsPerYuan = pointsPerYuan;
pointDeductionRule.value.maxDeductionAmount = maxDeductionAmount;
}
// 初始配置:默认无减免(固定金额 0 元)
const merchantReductionConfig = ref({
type: 'fixed_amount',
fixedAmount: 0
type: "fixed_amount",
fixedAmount: 0,
});
//使用积分数量
const userPoints = ref(0);
function setUserPoints(newval) {
userPoints.value = newval
userPoints.value = newval;
}
//新客立减
const newUserDiscount = ref(0);
//满减活动
const fullReductionActivities = ref([]);
//是否使用霸王餐
const isFreeDine = ref(false);
// 商家霸王餐配置
const freeDineConfig = ref(null);
// 订单额外配置
const orderExtraConfig = computed(() => ({
// 引用扩展后的商家减免配置
@@ -152,11 +164,15 @@ export const useCartsStore = defineStore('cart',
additionalFee: 0,
pointDeductionRule: pointDeductionRule.value,
seatFeeConfig: seatFeeConfig.value,
currentStoreId: '',
currentStoreId: "",
userPoints: userPoints.value,
isMember: useVipPrice.value,
memberDiscountRate: 1,
newUserDiscount: newUserDiscount.value
newUserDiscount: newUserDiscount.value,
fullReductionActivities: fullReductionActivities.value,
currentDinnerType: dinnerType.value,
isFreeDine: isFreeDine.value,
freeDineConfig: freeDineConfig.value,
}));
// 营销活动列表
@@ -164,18 +180,18 @@ export const useCartsStore = defineStore('cart',
return [];
});
// 优惠券列表
const backendCoupons = ref([])
const backendCoupons = ref([]);
function setCoupons(cps) {
console.log('setCoupons', cps);
console.log("setCoupons", cps);
backendCoupons.value = cps;
}
// 商品加入购物车顺序
const cartOrder = ref({});
// 订单费用汇总
const orderCostSummary = computed(() => {
allGoods.value = getAllGoodsList()
console.log('allGoods.value',allGoods.value);
allGoods.value = getAllGoodsList();
console.log("orderExtraConfig.value", orderExtraConfig.value);
const costSummary = OrderPriceCalculator.calculateOrderCostSummary(
allGoods.value,
dinnerType.value,
@@ -185,31 +201,32 @@ export const useCartsStore = defineStore('cart',
cartOrder.value,
new Date()
);
console.log(" 订单费用汇总", costSummary);
return costSummary;
});
const goodsIsloading = ref(true);
//商品数据Map
const goodsMap = reactive({})
const goodsMap = reactive({});
//获取商品数据
async function goodsInit() {
goodsIsloading.value = true;
//获取招牌菜商品
const hotres = await productminiApphotsquery();
for (let product of hotres) {
setGoodsMap(product.id, product)
setGoodsMap(product.id, product);
}
//获取分组商品
const groupres = await APIgroupquery()
const groupres = await APIgroupquery();
for (let group of groupres) {
for (let product of group.productList) {
setGoodsMap(product.id, product)
setGoodsMap(product.id, product);
}
}
allGoods.value = getAllGoodsList()
console.log('allGoods.value ',allGoods.value );
goodsIsloading.value = false
allGoods.value = getAllGoodsList();
console.log("allGoods.value ", allGoods.value);
goodsIsloading.value = false;
}
function setGoodsMap(product_id, data) {
@@ -218,15 +235,15 @@ export const useCartsStore = defineStore('cart',
//websocket回执
const websocketsendMessage = (data) => {
uni.$u.debounce(sendMessage(data), 500)
}
uni.$u.debounce(sendMessage(data), 500);
};
const isLoading = ref(true);
function getProductDetails(v) {
const goods = goodsMap[v.product_id]
const goods = goodsMap[v.product_id];
if (!goods) {
return undefined
return undefined;
}
let skuData = undefined;
skuData = goods?.skuList.find((sku) => sku.id == v.sku_id);
@@ -247,10 +264,10 @@ export const useCartsStore = defineStore('cart',
type: goods.type,
skuData,
skuName: skuData.name,
num: v.number * 1
}
num: v.number * 1,
};
} else {
return undefined
return undefined;
}
}
// 用于记录已经处理过的消息的 msg_id
@@ -258,48 +275,52 @@ export const useCartsStore = defineStore('cart',
//购物车商品信息补全初始化
function cartsGoodsInfoInit(arr) {
carts.value = arr.map(v => {
return getProductDetails(v)
}).filter(v => v)
carts.value = arr
.map((v) => {
return getProductDetails(v);
})
.filter((v) => v);
}
//收到socket消息时对购物车进行处理
async function onMessage(Message) {
if (Message) {
// 心跳返回 过滤
if (Message.type == "ping_interval" || Message.msg_id == "ping_interval") {
if (
Message.type == "ping_interval" ||
Message.msg_id == "ping_interval"
) {
isLoading.value = false;
return false
return false;
}
// 检查消息是否已经处理过
if (processedMessageIds.has(Message.msg_id)) {
return;
}
processedMessageIds.add(Message.msg_id);
const msgData = Message.data
const msgData = Message.data;
// 初始化
if (Message.operate_type == "init") {
console.log('carts init', msgData);
cartsGoodsInfoInit(msgData)
console.log("carts init", msgData);
cartsGoodsInfoInit(msgData);
uni.hideLoading();
isLoading.value = false;
}
// 清空购物车
if (Message.operate_type == 'cleanup') {
carts.value = []
if (Message.operate_type == "cleanup") {
carts.value = [];
}
// 删除除购物车
if (Message.operate_type == 'del' && Message.status == 1) {
if (Message.operate_type == "del" && Message.status == 1) {
// 优化:使用可选链操作符避免报错
carts.value = carts.value.filter(item => item.id !== msgData?.id);
carts.value = carts.value.filter((item) => item.id !== msgData?.id);
}
// 添加或者减少购物后返回
if (Message.operate_type == 'add' || Message.operate_type == 'edit') {
const index = carts.value.findIndex((v => v.id == msgData.id))
if (Message.operate_type == "add" || Message.operate_type == "edit") {
const index = carts.value.findIndex((v) => v.id == msgData.id);
if (index !== -1) {
carts.value[index] = getProductDetails(msgData);
} else {
@@ -308,164 +329,169 @@ export const useCartsStore = defineStore('cart',
}
// 历史订单
if (Message.operate_type == 'clearOrder') {}
if (Message.operate_type == "clearOrder") {
}
// 购物车数据更新从新请求
if (Message.type == 'product' && Message.data_type == 'product_update' && Message
.operate_type == 'product_update') {
await goodsInit()
await cartsGoodsInfoInit()
if (
Message.type == "product" &&
Message.data_type == "product_update" &&
Message.operate_type == "product_update"
) {
await goodsInit();
await cartsGoodsInfoInit();
}
// 提示
if (Message.status == 0 && Message.type != 'no_suit_num') {
if (Message.status == 0 && Message.type != "no_suit_num") {
uni.showToast({
title: Message.msg,
icon: "none"
})
icon: "none",
});
}
if (Message.type == 'no_suit_num') {
if (Message.type == "no_suit_num") {
uni.showModal({
title: '提示',
title: "提示",
showCancel: false,
content: '此商品库存不足起售数量!',
success: async (data) => {
}
content: "此商品库存不足起售数量!",
success: async (data) => {},
});
}
}
}
//购物车数据
const carts = ref([])
const carts = ref([]);
//历史订单数据
const oldOrder = ref({
detailMap: {},
originAmount: 0
})
originAmount: 0,
});
function setOldOrder(data) {
oldOrder.value = data
allGoods.value=getAllGoodsList()
oldOrder.value = data;
allGoods.value = getAllGoodsList();
}
// 会员信息
const orderVIP = ref(uni.cache.get('orderVIP') || {
isVip: false
})
const orderVIP = ref(
uni.cache.get("orderVIP") || {
isVip: false,
}
);
function updateData(key, newval) {
if (key === 'orderVIP') {
uni.cache.set('orderVIP', newval)
return orderVIP.value = newval
if (key === "orderVIP") {
uni.cache.set("orderVIP", newval);
return (orderVIP.value = newval);
}
if (key === 'shopInfo') {
uni.cache.set('shopInfo', newval)
return shopInfo.value = newval
if (key === "shopInfo") {
uni.cache.set("shopInfo", newval);
return (shopInfo.value = newval);
}
}
//是否使用会员价
const useVipPrice = computed(() => {
const isUse = (orderVIP.value.isVip && shopInfo.value.isMemberPrice) ? true : false
return isUse
})
const isUse =
orderVIP.value.isVip && shopInfo.value.isMemberPrice ? true : false;
return isUse;
});
function currentCalcMpneyNumber(item) {
const n = item.number - (item.returnNum || 0)
return n <= 0 ? 0 : n
const n = item.number - (item.returnNum || 0);
return n <= 0 ? 0 : n;
}
//历史订单商品价格总和
const oldOrderMoney = computed(() => {
let total = 0
let total = 0;
for (let i in oldOrder.value.detailMap) {
total += oldOrder.value.detailMap[i].reduce((prve, cur) => {
if (cur.isGift) {
return prve + 0
return prve + 0;
}
const discount_sale_amount = cur.discount_sale_amount * 1 || 0
const memberPrice = cur.skuData ? (cur.skuData.memberPrice || cur.skuData
.salePrice) : 0
const price = (discount_sale_amount || cur.salePrice || 0)
const number = currentCalcMpneyNumber(cur)
return prve + (number <= 0 ? 0 : number) * (discount_sale_amount || (useVipPrice
.value ? memberPrice : price))
}, 0)
const discount_sale_amount = cur.discount_sale_amount * 1 || 0;
const memberPrice = cur.skuData
? cur.skuData.memberPrice || cur.skuData.salePrice
: 0;
const price = discount_sale_amount || cur.salePrice || 0;
const number = currentCalcMpneyNumber(cur);
return (
prve +
(number <= 0 ? 0 : number) *
(discount_sale_amount || (useVipPrice.value ? memberPrice : price))
);
}, 0);
}
return total
})
return total;
});
//当前购物车总价格
const totalPrice = computed(() => {
const money = carts.value.reduce((prve, cur) => {
const memberPrice = cur.memberPrice || cur.salePrice
const memberPrice = cur.memberPrice || cur.salePrice;
const price = useVipPrice.value ? memberPrice : cur.salePrice;
const curMoney = price * currentCalcMpneyNumber(cur)
return prve + curMoney
}, 0)
return money
})
const curMoney = price * currentCalcMpneyNumber(cur);
return prve + curMoney;
}, 0);
return money;
});
// 霸王餐购物车原价,不享受任何优惠
const totalOriginPrice = computed(() => {
const money = carts.value.reduce((prve, cur) => {
const curMoney = cur.salePrice * currentCalcMpneyNumber(cur)
return prve + curMoney
}, 0)
return money
})
const curMoney = cur.salePrice * currentCalcMpneyNumber(cur);
return prve + curMoney;
}, 0);
return money;
});
//返回打包数量称重商品打包数量最大为1
function returnCartPackNumber(cur) {
const maxReturnNum = cur.number - (cur.returnNum || 0);
let pack_number = cur.number;
pack_number = (cur.product_type == 'weight' && pack_number > 1) ? 1 : pack_number;
pack_number =
cur.product_type == "weight" && pack_number > 1 ? 1 : pack_number;
pack_number = Math.min(maxReturnNum, pack_number);
pack_number = pack_number <= 0 ? 0 : pack_number
return pack_number * 1
pack_number = pack_number <= 0 ? 0 : pack_number;
return pack_number * 1;
}
//当前购物车打包费
const totalPackFee = computed(() => {
const money = carts.value.reduce((prve, cur) => {
const curMoney = (cur.packFee || 0) * currentCalcMpneyNumber(cur)
return prve + curMoney
}, 0)
return money
})
const curMoney = (cur.packFee || 0) * currentCalcMpneyNumber(cur);
return prve + curMoney;
}, 0);
return money;
});
//打包费
const packFee = computed(() => {
const nowPackFee = carts.value.reduce((acc, cur) => {
return acc + (cur.packFee || 0) * returnCartPackNumber(cur)
}, 0)
return acc + (cur.packFee || 0) * returnCartPackNumber(cur);
}, 0);
let oldPackfee = 0;
for (let i in oldOrder.value.detailMap) {
oldPackfee += oldOrder.value.detailMap[i].reduce((prve, cur) => {
return prve + (cur.packFee || 0) * returnCartPackNumber(cur)
}, 0)
return prve + (cur.packFee || 0) * returnCartPackNumber(cur);
}, 0);
}
return nowPackFee + oldPackfee
})
return nowPackFee + oldPackfee;
});
//购物车是否为空
const isEmpty = computed(() => {
return !carts.value || carts.value.length <= 0
})
return !carts.value || carts.value.length <= 0;
});
// 计算向上取整
const roundUpToTwoDecimals = (num, i) => {
// 先将数字乘以 100 并转换为字符串保留足够的小数位
let temp = (num * 100).toFixed(10);
// 向上取整
let rounded = null
if (i == 'upward') {
let rounded = null;
if (i == "upward") {
rounded = Math.ceil(parseFloat(temp));
} else {
rounded = Math.floor(parseFloat(temp));
@@ -491,31 +517,35 @@ export const useCartsStore = defineStore('cart',
return 0;
}
// 购物车总数价格
console.log('isBwc');
console.log(isBwc);
let cart = matchedProducts.reduce((total, item) => {
if (isBwc === true) {
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
return (
total + parseFloat(item.price) * parseFloat(item.num - item.returnNum)
);
}
// 是否启用会员价 0否1是
if (useVipPrice.value) {
// memberPrice会员价
return total + (parseFloat(item.memberPrice || item.price) * parseFloat(item
.num - item
.returnNum));
return (
total +
parseFloat(item.memberPrice || item.price) *
parseFloat(item.num - item.returnNum)
);
} else {
// salePrice销售价
return total + (parseFloat(item.price) * parseFloat(item.num - item.returnNum));
return (
total + parseFloat(item.price) * parseFloat(item.num - item.returnNum)
);
}
}, 0);
cart = cart.toFixed(2)
console.log(parseFloat(cart))
cart = cart.toFixed(2);
return parseFloat(cart);
};
// 计算商品卷所选择的总价格
const getTotalProductroll = (matchedProducts) => computed(() => {
const getTotalProductroll = (matchedProducts) =>
computed(() => {
if (!matchedProducts || !Array.isArray(matchedProducts)) {
return 0;
}
@@ -524,53 +554,61 @@ export const useCartsStore = defineStore('cart',
// 是否启用会员价 0否1是
if (useVipPrice.value) {
// memberPrice会员价
return total + parseFloat(item.memberPrice || item.price)
return total + parseFloat(item.memberPrice || item.price);
} else {
// salePrice销售价
return total + parseFloat(item.price)
return total + parseFloat(item.price);
}
}, 0);
// 向上取整并保留两位小数
let result = roundUpToTwoDecimals(cart, 'upward')
let result = roundUpToTwoDecimals(cart, "upward");
return result;
});
// 桌位置
const getTotalSeatcharge = (seatNum) => computed(() => {
const getTotalSeatcharge = (seatNum) =>
computed(() => {
// 是否免除桌位费 0 否 1 是
let cart = 0
let cart = 0;
if (uni.cache.get('ordershopUserInfo').isTableFee == 0 && seatNum) {
cart = parseFloat(seatNum) * parseFloat(uni.cache.get('ordershopUserInfo').tableFee)
if (uni.cache.get("ordershopUserInfo").isTableFee == 0 && seatNum) {
cart =
parseFloat(seatNum) *
parseFloat(uni.cache.get("ordershopUserInfo").tableFee);
}
// 向下取整并保留两位小数
let result = roundUpToTwoDecimals(cart, 'downward')
let result = roundUpToTwoDecimals(cart, "downward");
return result;
});
// 计算购物车总打包费用(向下取整并保留两位小数)
const getTotalPackFee = (cartList) => computed(() => {
const getTotalPackFee = (cartList) =>
computed(() => {
const total = cartList.reduce((sum, item) => {
return sum + (parseFloat(item.packAmount) * (parseFloat(item.packNumber) || (
parseFloat(item.num) - parseFloat(item.returnNum))));
return (
sum +
parseFloat(item.packAmount) *
(parseFloat(item.packNumber) ||
parseFloat(item.num) - parseFloat(item.returnNum))
);
}, 0);
// 向下取整并保留两位小数
let result = roundUpToTwoDecimals(total, 'downward')
let result = roundUpToTwoDecimals(total, "downward");
return result;
});
function clearOrderConfig(){
console.log('clearOrderConfig');
backendCoupons.value=[];
allGoods.value=[];
carts.value=[]
seatFeeConfig.value.personCount=uni.cache.get('dinersNum') || 0;
dinnerType.value='dine-in';
userPoints.value=0
function clearOrderConfig() {
console.log("clearOrderConfig");
backendCoupons.value = [];
allGoods.value = [];
carts.value = [];
seatFeeConfig.value.personCount = uni.cache.get("dinersNum") || 0;
dinnerType.value = "dine-in";
userPoints.value = 0;
fullReductionActivities.value = [];
isFreeDine.value = false;
}
return {
getTotalPackFee,
getTotalSeatcharge,
@@ -609,8 +647,11 @@ export const useCartsStore = defineStore('cart',
newUserDiscount,
getAllGoodsList,
//清空配置
clearOrderConfig
clearOrderConfig,
//满减活动
fullReductionActivities,
isFreeDine,//是否使用霸王餐
// 商家霸王餐配置
freeDineConfig,
};
}
);
});

View File

@@ -23,10 +23,7 @@ export const Memberpay = defineStore('memberpay', {
return new Promise(async (resolve, reject) => {
try {
let res = await APIpayltPayVip({
shopId: data.shopId,
shopUserId: data.shopUserId,
amount: data.amount,
activateId: data.activateId,
...data,
// #ifdef MP-WEIXIN
payType: 'wechatPay',
openId: uni.cache.get('userInfo').wechatOpenId,
@@ -35,11 +32,6 @@ export const Memberpay = defineStore('memberpay', {
payType: 'aliPay',
openId: uni.cache.get('userInfo').wechatOpenId,
// #endif
returnUrl: data.returnUrl ? data.returnUrl : '',
buyerRemark: data.buyerRemark ? data.buyerRemark : '',
orderId: data.orderId,
userAllPack: data.userAllPack,
seatNum:data.seatNum
})
if (res) {
uni.showLoading({
@@ -67,20 +59,20 @@ export const Memberpay = defineStore('memberpay', {
title: "支付成功"
})
console.log('支付成功')
setTimeout(() => {
uni.navigateBack()
}, 1000)
resolve(res)
// setTimeout(() => {
// uni.navigateBack()
// }, 1000)
resolve(true)
// #endif
// #ifdef MP-ALIPAY
if (res.resultCode == '9000') {
uni.showToast({
title: "支付成功"
})
setTimeout(() => {
uni.navigateBack()
}, 1000)
resolve(res)
// setTimeout(() => {
// uni.navigateBack()
// }, 1000)
resolve(true)
} else {
uni.showToast({
title: "支付失败"
@@ -163,14 +155,14 @@ export const Memberpay = defineStore('memberpay', {
title: "支付成功"
})
console.log('支付成功')
resolve(res)
resolve(true)
// #endif
// #ifdef MP-ALIPAY
if (res.resultCode == '9000') {
uni.showToast({
title: "支付成功"
})
resolve(res)
resolve(true)
} else {
uni.showToast({
title: "支付失败"

View File

@@ -104,6 +104,7 @@ export const productStore = defineStore('product', {
},
// 扫码请求
scanCodeactions(q) {
console.log('扫码内容', q)
return new Promise(async (resolve, reject) => {
if (q) {
console.log(q)
@@ -121,7 +122,7 @@ export const productStore = defineStore('product', {
// 储存卓玛
uni.cache.set('tableCode', tableCode)
if (tableCode) {
console.log(uni.cache.get('tableCode'));
console.log('台桌码', uni.cache.get('tableCode'));
let data = await this.actionsproductqueryShop(tableCode)
console.log('data', data)
@@ -194,6 +195,7 @@ export const productStore = defineStore('product', {
// /通过桌码获取当前店铺信息
actionsproductqueryShop(tableCode) {
console.log('台桌码',tableCode);
return new Promise(async (resolve, reject) => {
// try {
try {
@@ -213,7 +215,7 @@ export const productStore = defineStore('product', {
resolve(res)
} else {
console.log(res)
console.error('通过桌码获取当前店铺信息失败' ,res)
reject()
}

View File

@@ -295,6 +295,7 @@ export function calcDiscountGoodsArrPrice(discountGoodsArr, discountNum, user, s
* @param shopInfo 店铺信息
*/
export function returnCouponDiscount(arr, coupon, user, goodsOrderPrice, selCoupon, shopInfo) {
arr = returnCanDikouGoods(arr, user, shopInfo);
const canDikouGoodsArr = returnCanDikouGoodsArr(arr, selCoupon, user);
if (coupon.type == 2) {
return returnCouponProductDiscount(canDikouGoodsArr, coupon, user, shopInfo);
@@ -423,7 +424,6 @@ function returnCouponBuyOneGiveOneDiscount(canDikouGoodsArr, coupon, user, shopI
}
let discountPrice = 0;
let hasDiscountGoodsArr = [];
console.log("returnCouponBuyOneGiveOneDiscount:discountGoods", discountGoods);
if (discountGoods) {
discountPrice = returnGoodsPrice(discountGoods, user, shopInfo);
hasDiscountGoodsArr = [discountGoods];

1374
utils/goods.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,12 @@
export const pay = (res) => {
return new Promise((resolve, reject) => {
uni.showLoading({
title: '支付中...',
mask: true
})
title: "支付中...",
mask: true,
});
uni.requestPayment({
// #ifdef MP-WEIXIN
provider: 'wxpay', //支付类型-固定值
provider: "wxpay", //支付类型-固定值
partnerid: res.appId, // 微信支付商户号
timeStamp: res.timeStamp, // 时间戳(单位:秒)
nonceStr: res.nonceStr, // 随机字符串
@@ -15,43 +15,43 @@ export const pay = (res) => {
paySign: res.paySign, //签名
// #endif
// #ifdef MP-ALIPAY
provider: 'alipay', //支付类型-固定值
provider: "alipay", //支付类型-固定值
orderInfo: res.tradeNo, // 微信支付商户号
// #endif
success: (res) => {
console.log('pay');
console.log("pay");
console.log(res);
uni.hideLoading()
uni.hideLoading();
// #ifdef MP-WEIXIN
uni.showToast({
title: "支付成功",
icon:'none'
})
console.log('支付成功')
resolve(res)
icon: "none",
});
console.log("支付成功");
resolve(true);
// #endif
// #ifdef MP-ALIPAY
if (res.resultCode == '9000') {
if (res.resultCode == "9000") {
uni.showToast({
title: "支付成功",
icon:'none'
})
resolve(res)
icon: "none",
});
resolve(true);
} else {
uni.showToast({
title: "支付失败",
icon:'none'
})
icon: "none",
});
reject(false);
}
// #endif
},
fail: (res) => {
setTimeout(() => {
uni.hideLoading()
}, 1000)
reject(false)
uni.hideLoading();
}, 1000);
reject(false);
},
});
})
}
});
};