修改公众号关注逻辑,增加电子围栏

This commit is contained in:
2025-11-25 13:24:35 +08:00
parent 26f5beb660
commit 4d78311aaf
10 changed files with 1315 additions and 1057 deletions

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

View File

@@ -24,11 +24,18 @@ onMounted(() => {
// 页面加载完成后生成二维码
const userInfo = uni.cache.get("userInfo") || {};
const wechatAcQrcode = userInfo.wechatAcQrcode || "";
if(!userInfo.isAc){
codeOptions.value.code = wechatAcQrcode;
}
});
const emit = defineEmits(["generate"]);
function qrcodeResult(e) {
const userInfo = uni.cache.get("userInfo") || {};
if(!userInfo.isAc){
emit("generate", e.img.tempFilePath);
}
}
</script>

View File

@@ -7,6 +7,6 @@
"lodash": "^4.17.21",
"pinia": "^2.3.1",
"pinia-plugin-unistorage": "^0.1.2",
"ysk-utils": "^1.0.45"
"ysk-utils": "^1.0.78"
}
}

View File

@@ -326,33 +326,8 @@ const indexsRef = ref(null);
onShow(async () => {
try {
uni.getLocation({
type: 'wgs84',
success: async (res) => {
console.log('getLocation',res);
let successres = await APIgeocodelocation({
lng: res.longitude,
lat: res.latitude
});
if (successres) {
let datastorage = {
country: successres.addressComponent.country, // "中国"
province: successres.addressComponent.province, //province: "陕西省"
address: successres.addressComponent.city, //district: "西安市"
district: successres.addressComponent.district, //district: "未央区"
lng: res.longitude,
lat: res.latitude
};
uni.cache.set('getLocationstorage', datastorage);
// 登录
await storeuser.getLocation()
proxy.$isResolve();
}
},
fail(error) {
console.error('获取经纬度失败',error);
}
});
const shopId=uni.cache.get('shopId')
if(shopId){
indexsRef.value.getVipConfig();

View File

@@ -1227,6 +1227,10 @@ const disablePayType = computed(() => {
arr.add("余额支付");
}
}
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
arr.add("微信支付");
}
//充值并付款时只能微信支付
if (rechargeItem.value.id) {
arr.add("余额支付");

View File

@@ -16,14 +16,28 @@
</view>
</view> -->
<view class="status-wrap">
<view class="item" :class="{ active: querForm.statusActiveIndex == 0 }" @click="tabChange(0)">
<view
class="item"
:class="{ active: querForm.statusActiveIndex == 0 }"
@click="tabChange(0)"
>
<text class="t">商品兑换券 {{ returnSelNumber(0) }}</text>
</view>
<view class="item" :class="{ active: querForm.statusActiveIndex == 1 }" @click="tabChange(1)">
<view
class="item"
:class="{ active: querForm.statusActiveIndex == 1 }"
@click="tabChange(1)"
>
<text class="t">折扣优惠券{{ returnSelNumber(1) }}</text>
</view>
<view class="icon-wrap" :style="{ width: `${100 / statusList.length}%`, left: `${(100 / statusList.length) * querForm.statusActiveIndex}%` }">
<view
class="icon-wrap"
:style="{
width: `${100 / statusList.length}%`,
left: `${(100 / statusList.length) * querForm.statusActiveIndex}%`,
}"
>
<image
class="active-icon"
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAMCAYAAAB4MH11AAACKUlEQVR4AaRTS2sTURT+MpkxUzNtRpuYpBsrqbgQH6BYRHGllloQN+5cuNeV6MKfoj9BwYUgIsXHRqE+SluliFLbBqmENJNMMpMm87qecw1NglJse+HMPeee833nce8oIgpFq7wsGt/fCb9eFrtdfmNd1L+9Jc4Vog6E4jcqqM0/R+3zNOwv09jtshdfSx7mDJwKqAMfIvAAEaFVWkLgWjvOEbVdtNa+Epf4wxmFUNTkfqiDGUkqogDu8icKiKS9nQ9jnR8fqM5AwuJJE/G9JhRF05E8dAqIKeDlrsyiWVxg9f+Fum+uzsFZmtnEGIVxKHsGIFn1bAF6ZlQ6I28D9uIrmYSrkodbfETgw6GubZo9Yzk0kR4Fc7IuE8QUFebJKSTSB/kM4UYd1scnKL18QInm4Vk/6W6qiNoOwpZDuoX2elFWXHrzELW5Z+RzJVbPHca+09doIKq0ZQLW+C44iWbm2ZQSNMqozj5F5f1jWCSVGd4fwerstYUXCOplGcsfxponJqHS7Nlm2UyAWAza0AFkzt1A6uhFqEYaoHsR9BLCpg2vukZVr5IU4dV+yU7oRikkTrHDMI9PIHPhJrhQ9Kxugs6hkkhi8Mh5DI9flyCep6ImOt7uxnF6dgypYxMy1hg7S0/yH3FdSL+mpbIw6CVwVSNX7yM/eQfZS7eQu3wb+St3MTJ1D2nq1iicgZbK9YN7rL866PH1qfGBIWj0v/Do4rrR59vK+A0AAP//GfTndQAAAAZJREFUAwCu+SjIaSGpLwAAAABJRU5ErkJggg=="
@@ -33,13 +47,20 @@
</view>
<view class="list-wrap">
<view class="tips">
<text class="t">使用商品兑换券的商品不再计入同享优惠券门槛和折扣计算</text>
<text class="t"
>使用商品兑换券的商品不再计入同享优惠券门槛和折扣计算</text
>
</view>
<view class="title-wrap">
<text class="t">可用红包</text>
<text class="n">{{ list.canUseCoupons.length }}</text>
</view>
<view class="item" v-for="item in list.canUseCoupons" :key="item.id" @click="changeSelCoupon(item)">
<view
class="item"
v-for="item in list.canUseCoupons"
:key="item.id"
@click="changeSelCoupon(item)"
>
<view class="top">
<view class="icon">
<couponIcon :item="item" />
@@ -49,18 +70,29 @@
<text class="t">{{ item.name }}</text>
</view>
<view class="view time">
<text class="t">{{ dayjs(item.effectStartTime).format('YYYY.M.D') }} - {{ dayjs(item.effectEndTime).format('YYYY.M.D') }}</text>
<text class="t"
>{{ dayjs(item.effectStartTime).format("YYYY.M.D") }} -
{{ dayjs(item.effectEndTime).format("YYYY.M.D") }}</text
>
</view>
</view>
<view class="btn">
<view class="active" v-if="isActive(item)">
<up-icon name="checkmark-circle-fill" size="24" color="#FF3232"></up-icon>
<up-icon
name="checkmark-circle-fill"
size="24"
color="#FF3232"
></up-icon>
</view>
<view class="round" v-else></view>
</view>
</view>
<view class="btm">
<view class="left">1可适用门店{{ item.useShops }} 2可适用商品{{ item.foods }}3可使用类型{{ convertValuesToLabels(item.useType) }}</view>
<view class="left"
>1可适用门店{{ item.useShops }} 2可适用商品{{
item.foods
}}3可使用类型{{ convertValuesToLabels(item.useType) }}</view
>
<view class="right" @click.stop="showDetailHandle(item)">
<text class="t">查看详情</text>
</view>
@@ -70,7 +102,11 @@
<text class="t">不可用红包</text>
<text class="n">{{ list.noCanUseCoupons.length }}</text>
</view>
<view class="item disabled" v-for="item in list.noCanUseCoupons" :key="item.id">
<view
class="item disabled"
v-for="item in list.noCanUseCoupons"
:key="item.id"
>
<view class="top">
<view class="icon">
<couponIcon :item="item" />
@@ -80,7 +116,10 @@
<text class="t">{{ item.name }}</text>
</view>
<view class="view time">
<text class="t">{{ dayjs(item.effectStartTime).format('YYYY.M.D') }} - {{ dayjs(item.effectEndTime).format('YYYY.M.D') }}</text>
<text class="t"
>{{ dayjs(item.effectStartTime).format("YYYY.M.D") }} -
{{ dayjs(item.effectEndTime).format("YYYY.M.D") }}</text
>
</view>
</view>
<view class="btn">
@@ -105,8 +144,17 @@
<view class="title">
<text class="t">店铺列表</text>
</view>
<scroll-view class="popup-list" direction="vertical" @scrollend="scrollBottom">
<view class="item" v-for="item in shopList" :key="item.shopId" @click="selectShopHandle(item)">
<scroll-view
class="popup-list"
direction="vertical"
@scrollend="scrollBottom"
>
<view
class="item"
v-for="item in shopList"
:key="item.shopId"
@click="selectShopHandle(item)"
>
<text class="t">{{ item.shopName }}</text>
<text class="intro">地址{{ item.shopAddress }}</text>
</view>
@@ -114,14 +162,24 @@
</scroll-view>
</view>
</u-popup>
<u-popup :show="showDetail" round="20" closeable @close="showDetail = false">
<u-popup
:show="showDetail"
round="20"
closeable
@close="showDetail = false"
>
<view class="shoplist-popup">
<view class="title">
<text class="t">详情说明</text>
</view>
<scroll-view class="popup-list" direction="vertical">
<view class="ul">
<view class="li" v-for="(item, index) in selectListItemDetails" :key="index">{{ index + 1 }}{{ item }}</view>
<view
class="li"
v-for="(item, index) in selectListItemDetails"
:key="index"
>{{ index + 1 }}{{ item }}</view
>
</view>
</scroll-view>
</view>
@@ -130,14 +188,27 @@
</template>
<script setup>
import dayjs from 'dayjs';
import { ref, reactive, onMounted, computed, watch } from 'vue';
import { onLoad, onReady, onShow, onPageScroll, onReachBottom, onBackPress } from '@dcloudio/uni-app';
import { APIcouponfindByUserId, APIfindCoupon, getCouponShops } from '@/common/api/member.js';
import { findCoupon } from '@/common/api/market/coupon.js';
import couponIcon from '@/pages/user/components/coupon-icon.vue';
import * as UTILS from '@/utils/goods-utils.js';
import { useCartsStore } from '@/stores/carts.js';
import dayjs from "dayjs";
import { ref, reactive, onMounted, computed, watch } from "vue";
import {
onLoad,
onReady,
onShow,
onPageScroll,
onReachBottom,
onBackPress,
} from "@dcloudio/uni-app";
import {
APIcouponfindByUserId,
APIfindCoupon,
getCouponShops,
} from "@/common/api/member.js";
import { findCoupon } from "@/common/api/market/coupon.js";
import couponIcon from "@/pages/user/components/coupon-icon.vue";
// import * as UTILS from '@/utils/goods-utils.js';
import yskUtils from "ysk-utils";
const UTILS = yskUtils.couponUtils;
import { useCartsStore } from "@/stores/carts.js";
const cartStore = useCartsStore();
//返回不可用原因
@@ -148,43 +219,43 @@ function returnNoUseRestrictions(item) {
if (item.canuseResult) {
return item.canuseResult.reason;
}
return '';
return "";
}
const show = ref(false);
const querForm = ref({
searchValue: '',
shopId: '',
shopName: '',
statusActiveIndex: 0
searchValue: "",
shopId: "",
shopName: "",
statusActiveIndex: 0,
});
const statusList = ref([
{
value: 0,
label: '商品兑换券',
bg: '#333333',
color: '#ffffff'
label: "商品兑换券",
bg: "#333333",
color: "#ffffff",
},
{
value: 1,
label: '折扣优惠券',
bg: '#F8F8F8',
color: '#999999'
}
label: "折扣优惠券",
bg: "#F8F8F8",
color: "#999999",
},
]);
const list = reactive({
page: 1,
size: 10,
status: 'nomore',
status: "nomore",
data: [],
noCanUseCoupons: [],
canUseCoupons: []
canUseCoupons: [],
});
const showDetail = ref(false);
const selectListItem = ref('');
const selectListItem = ref("");
const selectListItemDetails = ref([]);
function showDetailHandle(item) {
@@ -194,32 +265,52 @@ function showDetailHandle(item) {
const ruleList = [];
// 规则1限时折扣同享始终显示
const discountRule = item.discountShare ? '与限时折扣同享' : '不与限时折扣同享';
const discountRule = item.discountShare
? "与限时折扣同享"
: "不与限时折扣同享";
ruleList.push(discountRule);
// 规则2会员价/会员折扣同享(始终显示)
const vipRule = item.vipPriceShare ? '与会员价/会员折扣同享' : '不与会员价/会员折扣同享';
const vipRule = item.vipPriceShare
? "与会员价/会员折扣同享"
: "不与会员价/会员折扣同享";
ruleList.push(vipRule);
// 规则3其他优惠券同享仅item.type=2时显示
if (item.type === 2) {
const otherCouponRule = item.otherCouponShare ? '与其他优惠券同享' : '不与其他优惠券同享';
const otherCouponRule = item.otherCouponShare
? "与其他优惠券同享"
: "不与其他优惠券同享";
ruleList.push(otherCouponRule);
}
const shareRuleText = `${ruleList.join('、')}`;
let foods=item.foods;
const shareRuleText = `${ruleList.join("、")}`;
let foods = item.foods;
selectListItemDetails.value = [
`可适用门店:${item.useShops}`,
`可适用商品:${foods}`,
`可使用类型:${convertValuesToLabels(item.useType)}`,
`可用时间段:${item.useTimeType == 'all' ? '全段时间可用' : `${item.useStartTime} - ${item.useEndTime}`}`,
`限量规则:每人限领${item.getLimit == -10086 ? `无限张` : `${item.getLimit}`},每日最多可使用${item.useLimit == -10086 ? `无限张` : `${item.useLimit}`}`,
`可用时间段:${
item.useTimeType == "all"
? "全段时间可用"
: `${item.useStartTime} - ${item.useEndTime}`
}`,
`限量规则:每人限领${
item.getLimit == -10086 ? `无限张` : `${item.getLimit}`
},每日最多可使用${
item.useLimit == -10086 ? `无限张` : `${item.useLimit}`
}`,
`同享规则:${shareRuleText}`,
`其它说明:${item.ruleDetails || '无'}`
`其它说明:${item.ruleDetails || "无"}`,
];
if (item.type == 2 || item.type == 4 || item.type == 6) {
selectListItemDetails.value.splice(2, 0, `使用规则:${item.useRule == 'price_asc' ? '从最低价开始抵扣' : '从最高价开始抵扣'}`);
selectListItemDetails.value.splice(
2,
0,
`使用规则:${
item.useRule == "price_asc" ? "从最低价开始抵扣" : "从最高价开始抵扣"
}`
);
}
if (item.type == 3) {
@@ -230,22 +321,22 @@ function showDetailHandle(item) {
function returnSelNumber(index) {
if (index) {
if (couponSel.value.id) {
return '(1)';
return "(1)";
} else {
return '(0)';
return "(0)";
}
} else {
if (goodsCouponSel.value.id) {
return '(1)';
return "(1)";
} else {
return '(0)';
return "(0)";
}
}
}
// 搜索
function searchHandle() {
list.page = 1;
list.status = 'nomore';
list.status = "nomore";
getCouponList();
}
@@ -253,7 +344,7 @@ function searchHandle() {
function tabChange(index) {
querForm.value.statusActiveIndex = index;
list.page = 1;
list.status = 'nomore';
list.status = "nomore";
formatCoupon();
}
@@ -261,7 +352,7 @@ function changeSelCoupon(item) {
if (querForm.value.statusActiveIndex) {
if (couponSel.value.id == item.id) {
couponSel.value = {
id: ''
id: "",
};
} else {
couponSel.value = item;
@@ -269,7 +360,7 @@ function changeSelCoupon(item) {
} else {
if (goodsCouponSel.value.id == item.id) {
goodsCouponSel.value = {
id: ''
id: "",
};
} else {
goodsCouponSel.value = item;
@@ -277,22 +368,27 @@ function changeSelCoupon(item) {
}
}
const couponSel = ref({
id: ''
id: "",
});
const goodsCouponSel = ref({
id: ''
id: "",
});
const quansSelArr = computed(() => {
return [couponSel.value, goodsCouponSel.value].filter((v) => v.id);
});
watch(()=>couponSel.value.id,(newval)=>{
formatCoupon()
})
watch(()=>goodsCouponSel.value.id,(newval)=>{
formatCoupon()
})
watch(
() => couponSel.value.id,
(newval) => {
formatCoupon();
}
);
watch(
() => goodsCouponSel.value.id,
(newval) => {
formatCoupon();
}
);
function isActive(item) {
if (querForm.value.statusActiveIndex) {
return couponSel.value.id == item.id;
@@ -301,35 +397,40 @@ function isActive(item) {
}
}
const couponList=ref([])
function formatCoupon(){
const couponList = ref([]);
function formatCoupon() {
let canUseGoodsCoupon = [];
let canUseDiscountCoupon = [];
let noUseGoodsCoupon = [];
let noUseDiscountCoupon = [];
const user = uni.cache.get('shopUserInfo');
let shopInfo = uni.cache.get('shopInfo') || {};
const user = uni.cache.get("shopUserInfo");
let shopInfo = uni.cache.get("shopInfo") || {};
if (!shopInfo.isMemberPrice) {
shopInfo = {};
}
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
const goodsOrderPrice = uni.getStorageSync("goodsOrderPrice") || 0;
const dinnerType = cartStore.dinnerType;
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
const shopId = uni.cache.get('shopId');
const canDikouGoodsArr = UTILS.returnCanDikouGoods(
cartStore.allGoods,
[],
user
);
const shopId = uni.cache.get("shopId");
for (let i = 0; i < couponList.value.length; i++) {
const coupon = couponList.value[i];
const selCoupon=querForm.value.statusActiveIndex!=1?quansSelArr.value.filter(v=>v.type!=2):quansSelArr.value.filter(v=>v.type==2)
const selCoupon =
querForm.value.statusActiveIndex != 1
? quansSelArr.value.filter((v) => v.type != 2)
: quansSelArr.value.filter((v) => v.type == 2);
const canuseResult = UTILS.returnCouponCanUse({
canDikouGoodsArr,
coupon,
goodsOrderPrice,
user,
selCoupon:selCoupon,
selCoupon: selCoupon,
shopInfo,
limitTimeDiscount:cartStore.limitTimeDiscount
limitTimeDiscount: cartStore.limitTimeDiscount,
});
const { canUse, reason } = canuseResult;
if (coupon.type == 2) {
@@ -338,7 +439,7 @@ function formatCoupon(){
} else {
noUseGoodsCoupon.push({
...coupon,
canuseResult
canuseResult,
});
}
} else {
@@ -347,27 +448,43 @@ function formatCoupon(){
} else {
noUseDiscountCoupon.push({
...coupon,
canuseResult
canuseResult,
});
}
}
}
//商品券
canUseGoodsCoupon = canUseGoodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo,cartStore.limitTimeDiscount);
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
quansSelArr.value,
shopInfo,
cartStore.limitTimeDiscount
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
//非商品券
canUseDiscountCoupon = canUseDiscountCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, quansSelArr.value, shopInfo,cartStore.limitTimeDiscount);
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
quansSelArr.value,
shopInfo,
cartStore.limitTimeDiscount
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
@@ -379,25 +496,24 @@ function formatCoupon(){
list.canUseCoupons = canUseDiscountCoupon;
}
console.log('canUseGoodsCoupon', canUseGoodsCoupon);
console.log('noUseGoodsCoupon', noUseGoodsCoupon);
console.log('canUseDiscountCoupon', canUseDiscountCoupon);
console.log('noUseDiscountCoupon', noUseDiscountCoupon);
console.log("canUseGoodsCoupon", canUseGoodsCoupon);
console.log("noUseGoodsCoupon", noUseGoodsCoupon);
console.log("canUseDiscountCoupon", canUseDiscountCoupon);
console.log("noUseDiscountCoupon", noUseDiscountCoupon);
}
// 获取优惠券列表
async function getCouponList() {
try {
uni.showLoading({
title: '加载中...',
mask: true
title: "加载中...",
mask: true,
});
const res = await findCoupon({
shopUserId: uni.cache.get('shopUserInfo').id
shopUserId: uni.cache.get("shopUserInfo").id,
});
couponList.value=res
formatCoupon()
couponList.value = res;
formatCoupon();
} catch (error) {
console.log(error);
}
@@ -406,7 +522,7 @@ async function getCouponList() {
// 店铺列表滚动到底部了
function scrollBottom() {
console.log('店铺列表滚动到底部了');
console.log("店铺列表滚动到底部了");
}
/**
@@ -416,56 +532,62 @@ function scrollBottom() {
* @param {string} separator - 标签拼接分隔符,默认值为'、'
* @returns {string} 拼接后的label字符串如"堂食、自取"
*/
function convertValuesToLabels(valueStr, options, separator = '、') {
function convertValuesToLabels(valueStr, options, separator = "、") {
try {
options = [
{
value: 'dine',
label: '堂食'
value: "dine",
label: "堂食",
},
{
value: 'pickup',
label: '自取'
value: "pickup",
label: "自取",
},
{
value: 'deliv',
label: '配送'
value: "deliv",
label: "配送",
},
{
value: 'express',
label: '快递'
}
value: "express",
label: "快递",
},
];
// 验证输入参数
if (!Array.isArray(options)) {
throw new Error('options必须是数组');
throw new Error("options必须是数组");
}
if (typeof valueStr !== 'string') {
throw new Error('valueStr必须是字符串');
if (typeof valueStr !== "string") {
throw new Error("valueStr必须是字符串");
}
// 解析value数组字符串
const values = JSON.parse(valueStr);
if (!Array.isArray(values)) {
throw new Error('解析后的valueStr必须是数组');
throw new Error("解析后的valueStr必须是数组");
}
// 构建value到label的映射表
const valueLabelMap = new Map();
options.forEach((item) => {
if (item && typeof item.value !== 'undefined' && typeof item.label !== 'undefined') {
if (
item &&
typeof item.value !== "undefined" &&
typeof item.label !== "undefined"
) {
valueLabelMap.set(item.value, item.label);
}
});
// 匹配并收集label
const labels = values.map((value) => valueLabelMap.get(value)).filter(Boolean); // 过滤未匹配到的项
const labels = values
.map((value) => valueLabelMap.get(value))
.filter(Boolean); // 过滤未匹配到的项
// 拼接结果
return labels.join(separator);
} catch (error) {
console.error('转换失败:', error.message);
return ''; // 出错时返回空字符串
console.error("转换失败:", error.message);
return ""; // 出错时返回空字符串
}
}
@@ -507,37 +629,57 @@ watch(
() => quansSelArr.value,
(newval) => {
// getCouponList()
const user = uni.cache.get('shopUserInfo');
let shopInfo = uni.cache.get('shopInfo') || {};
const user = uni.cache.get("shopUserInfo");
let shopInfo = uni.cache.get("shopInfo") || {};
if (!shopInfo.isMemberPrice) {
shopInfo = {};
}
const goodsOrderPrice = uni.getStorageSync('goodsOrderPrice') || 0;
const goodsOrderPrice = uni.getStorageSync("goodsOrderPrice") || 0;
const dinnerType = cartStore.dinnerType;
const canDikouGoodsArr = UTILS.returnCanDikouGoods(cartStore.allGoods, [], user);
const shopId = uni.cache.get('shopId');
const canDikouGoodsArr = UTILS.returnCanDikouGoods(
cartStore.allGoods,
[],
user
);
const shopId = uni.cache.get("shopId");
let goodsCoupon = newval.filter((v) => v.type == 2);
let otherCoupon = newval.filter((v) => v.type != 2);
goodsCoupon = goodsCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, [], shopInfo,cartStore.limitTimeDiscount);
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
[],
shopInfo,
cartStore.limitTimeDiscount
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
otherCoupon = otherCoupon.map((v) => {
const discount = UTILS.returnCouponDiscount(canDikouGoodsArr, v, user, goodsOrderPrice, goodsCoupon, shopInfo,cartStore.limitTimeDiscount);
const discount = UTILS.returnCouponDiscount(
canDikouGoodsArr,
v,
user,
goodsOrderPrice,
goodsCoupon,
shopInfo,
cartStore.limitTimeDiscount
);
return {
...v,
discount,
discountAmount: discount ? discount.discountPrice : v.discountAmount
discountAmount: discount ? discount.discountPrice : v.discountAmount,
};
});
uni.$emit('selCoupon', [...goodsCoupon, ...otherCoupon]);
uni.$emit("selCoupon", [...goodsCoupon, ...otherCoupon]);
},
{
deep: true
deep: true,
}
);
</script>
@@ -691,7 +833,7 @@ page {
position: relative;
&::after {
content: '';
content: "";
width: 100%;
height: 100%;
position: absolute;
@@ -732,7 +874,7 @@ page {
&::after {
$height: 100upx;
content: '';
content: "";
height: $height;
border-left: 1upx solid #f7f7f7;
position: absolute;

View File

@@ -250,7 +250,7 @@
></view>
</view>
<text class="num">{{ ifcartNumber(item) }}</text>
<view class="btn">
<view class="btn" >
<up-icon
name="plus-circle-fill"
color="#E9AB7A"
@@ -495,7 +495,7 @@
</view>
<text class="num">{{ ifcartNumber(item1) }}</text>
<view class="btn">
<view class="btn" >
<up-icon
name="plus-circle-fill"
color="#E9AB7A"
@@ -1674,15 +1674,33 @@ const isProductAvailable = async (sellDaysStr, startTimeStr, endTimeStr) => {
return isInRange;
};
// 单规格
const singleclick = async (item, i) => {
console.log("单规格商品点击事件:", item, i);
/**
* 判断商品是否可售
* @param {Object} item
*/
function juageProductAvailable(item) {
if (!isProductAvailable(item.days, item.startTime, item.endTime)) {
uni.showToast({
title: "不在可售时间内",
});
return false;
}
if(item.isStock&&item.stockNumber<item.suitNum){
uni.showToast({
title: "库存不足",
icon: "none",
});
return false;
}
return true
}
// 单规格
const singleclick = async (item, i) => {
console.log("单规格商品点击事件:", item, i);
if(!juageProductAvailable(item)){
return false;
}
// 判断购物车是否有该选中商品
let res = null;
try {
@@ -3055,7 +3073,7 @@ function toHistory() {
}
.shop_sku_box:last-child {
padding-bottom: 60rpx;
padding-bottom: 140rpx;
}
.shop_sku_box {

59
pnpm-lock.yaml generated
View File

@@ -30,8 +30,8 @@ importers:
specifier: ^0.1.2
version: 0.1.2
ysk-utils:
specifier: ^1.0.40
version: 1.0.40
specifier: ^1.0.78
version: 1.0.78
packages:
@@ -39,17 +39,17 @@ packages:
resolution: {integrity: sha512-qMlSxKbpRlAridDExk92nSobyDdpPijUq2DW6oDnUqd0iOGxmQjyqhMIihI9+zv4LPyZdRje2cavWPbCbWm3eA==}
engines: {node: '>=6.9.0'}
'@babel/helper-validator-identifier@7.27.1':
resolution: {integrity: sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==}
'@babel/helper-validator-identifier@7.28.5':
resolution: {integrity: sha512-qSs4ifwzKJSV39ucNjsvc6WVHs6b7S03sOh2OcHF9UHfVPqWWALUsNUVzhSBiItjRZoLHx7nIarVjqKVusUZ1Q==}
engines: {node: '>=6.9.0'}
'@babel/parser@7.28.4':
resolution: {integrity: sha512-yZbBqeM6TkpP9du/I2pUZnJsRMGGvOuIrhjzC1AwHwW+6he4mni6Bp/m8ijn0iOuZuPI2BfkCoSRunpyjnrQKg==}
'@babel/parser@7.28.5':
resolution: {integrity: sha512-KKBU1VGYR7ORr3At5HAtUQ+TV3SzRCXmA/8OdDZiLDBIZxVyzXuztPjfLd3BV1PRAQGCMWWSHYhL0F8d5uHBDQ==}
engines: {node: '>=6.0.0'}
hasBin: true
'@babel/types@7.28.4':
resolution: {integrity: sha512-bkFqkLhh3pMBUQQkpVgWDWq/lqzc2678eUyDlTBhRqhCHFguYYGM0Efga7tYk4TogG/3x0EEl66/OQ+WGbWB/Q==}
'@babel/types@7.28.5':
resolution: {integrity: sha512-qQ5m48eI/MFLQ5PxQj4PFaprjyCTLI37ElWMmNs0K8Lk3dVeOdNpB3ks8jc7yM5CDmVC73eMVk/trk3fgmrUpA==}
engines: {node: '>=6.9.0'}
'@dcloudio/types@3.4.21':
@@ -104,8 +104,8 @@ packages:
bignumber.js@9.3.1:
resolution: {integrity: sha512-Ko0uX15oIUS7wJ3Rb30Fs6SkVbLmPBAKdlm7q9+ak9bbIeFf0MwuBsQV6z7+X768/cHsfg+WlysDWJcmthjsjQ==}
csstype@3.1.3:
resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==}
csstype@3.2.3:
resolution: {integrity: sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==}
dayjs@1.11.18:
resolution: {integrity: sha512-zFBQ7WFRvVRhKcWoUh+ZA1g2HVgUbsZm9sbddh8EC5iv93sui8DVVz1Npvz+r6meo9VKfa8NyLWBsQK1VvIKPA==}
@@ -120,11 +120,15 @@ packages:
jsbarcode@3.12.1:
resolution: {integrity: sha512-QZQSqIknC2Rr/YOUyOkCBqsoiBAOTYK+7yNN3JsqfoUtJtkazxNw1dmPpxuv7VVvqW13kA3/mKiLq+s/e3o9hQ==}
loadsh@0.0.4:
resolution: {integrity: sha512-U+wLL8InpfRalWrr+0SuhWgGt10M4OyAk6G8xCYo2rwpiHtxZkWiFpjei0vO463ghW8LPCdhqQxXlMy2qicAEw==}
deprecated: This is a typosquat on the popular Lodash package. This is not maintained nor is the original Lodash package.
lodash@4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
magic-string@0.30.19:
resolution: {integrity: sha512-2N21sPY9Ws53PZvsEpVtNuSW+ScYbQdp4b9qUaL+9QkHUrGFKo56Lg9Emg5s9V/qrtNBmiR01sYhUOwu3H+VOw==}
magic-string@0.30.21:
resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==}
nanoid@3.3.11:
resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==}
@@ -173,23 +177,23 @@ packages:
typescript:
optional: true
ysk-utils@1.0.40:
resolution: {integrity: sha512-Hi+XI7sykGJizExMY5kVWIBhPvO3wudp2q92Vqv6zI6eDtquLz4CwxIfOLEXFfn5crYXVu/yfJQVjK3WAyNYDQ==}
ysk-utils@1.0.78:
resolution: {integrity: sha512-Bgr5B3WWiy0nbgL91QVKoVPYm4wt13Rlav757zEjMVRHbmTjwFEhi3wJlYus0JGd52mbknSxXHMazAPHXwA7uQ==}
snapshots:
'@babel/helper-string-parser@7.27.1': {}
'@babel/helper-validator-identifier@7.27.1': {}
'@babel/helper-validator-identifier@7.28.5': {}
'@babel/parser@7.28.4':
'@babel/parser@7.28.5':
dependencies:
'@babel/types': 7.28.4
'@babel/types': 7.28.5
'@babel/types@7.28.4':
'@babel/types@7.28.5':
dependencies:
'@babel/helper-string-parser': 7.27.1
'@babel/helper-validator-identifier': 7.27.1
'@babel/helper-validator-identifier': 7.28.5
'@dcloudio/types@3.4.21': {}
@@ -202,7 +206,7 @@ snapshots:
'@vue/compiler-core@3.5.22':
dependencies:
'@babel/parser': 7.28.4
'@babel/parser': 7.28.5
'@vue/shared': 3.5.22
entities: 4.5.0
estree-walker: 2.0.2
@@ -215,13 +219,13 @@ snapshots:
'@vue/compiler-sfc@3.5.22':
dependencies:
'@babel/parser': 7.28.4
'@babel/parser': 7.28.5
'@vue/compiler-core': 3.5.22
'@vue/compiler-dom': 3.5.22
'@vue/compiler-ssr': 3.5.22
'@vue/shared': 3.5.22
estree-walker: 2.0.2
magic-string: 0.30.19
magic-string: 0.30.21
postcss: 8.5.6
source-map-js: 1.2.1
@@ -250,7 +254,7 @@ snapshots:
'@vue/reactivity': 3.5.22
'@vue/runtime-core': 3.5.22
'@vue/shared': 3.5.22
csstype: 3.1.3
csstype: 3.2.3
'@vue/server-renderer@3.5.22(vue@3.5.22)':
dependencies:
@@ -262,7 +266,7 @@ snapshots:
bignumber.js@9.3.1: {}
csstype@3.1.3: {}
csstype@3.2.3: {}
dayjs@1.11.18: {}
@@ -272,9 +276,11 @@ snapshots:
jsbarcode@3.12.1: {}
loadsh@0.0.4: {}
lodash@4.17.21: {}
magic-string@0.30.19:
magic-string@0.30.21:
dependencies:
'@jridgewell/sourcemap-codec': 1.5.5
@@ -314,7 +320,8 @@ snapshots:
'@vue/server-renderer': 3.5.22(vue@3.5.22)
'@vue/shared': 3.5.22
ysk-utils@1.0.40:
ysk-utils@1.0.78:
dependencies:
bignumber.js: 9.3.1
loadsh: 0.0.4
lodash: 4.17.21

View File

@@ -1,68 +1,63 @@
import {
defineStore
} from 'pinia';
import {
ref
} from 'vue';
import {
APIuserlogin,
APIuser
} from '@/common/api/api.js'
import { defineStore } from "pinia";
import { ref } from "vue";
import { APIuserlogin, APIuser } from "@/common/api/api.js";
import {
APIproductqueryShop,
APIusershopInfodetail,
APIshopUserInfo
} from '@/common/api/member.js'
export const Storelogin = defineStore('login', {
APIshopUserInfo,
} from "@/common/api/member.js";
import { getDistance } from "@/utils/address.js";
import { APIgeocodelocation } from "@/common/api/api.js";
export const Storelogin = defineStore("login", {
state: () => ({
token: '',
miniAppOpenId: '',
userInfo: '',
shopInfo: {}
token: "",
miniAppOpenId: "",
userInfo: "",
shopInfo: {},
}),
actions: {
async getShopInfo(shopId) {
const shopRes = await APIusershopInfodetail({
shopId
})
shopId,
});
console.log(shopRes);
},
actionslogin() {
return new Promise(async (resolve, reject) => {
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin',
provider: "weixin",
success: (data) => {
// 微信小程序环境
uni.getUserInfo({
provider: 'weixin',
provider: "weixin",
success: async (infoRes) => {
let res = await APIuserlogin({
code: data.code, //临时登录凭证
rawData: infoRes.rawData,
source: 'wechat'
})
source: "wechat",
});
if (res) {
this.token = res.token
this.miniAppOpenId = res.userInfo
.miniAppOpenId
this.userInfo = res.userInfo
uni.cache.set('token', res.token);
uni.cache.set('userInfo', res.userInfo);
uni.cache.set('followIndex', res.followIndex||'');
this.token = res.token;
this.miniAppOpenId = res.userInfo.miniAppOpenId;
this.userInfo = res.userInfo;
uni.cache.set("token", res.token);
uni.cache.set("userInfo", res.userInfo);
uni.cache.set("followIndex", res.followIndex || "");
}
resolve(true);
},
fail: (err) => {
reject(false);
}
},
});
}
},
});
// #endif
// #ifdef MP-ALIPAY
my.getAuthCode({
scopes: 'auth_base',
scopes: "auth_base",
success: async (data) => {
// 支付宝小程序环境
// my.getAuthUserInfo({
@@ -70,204 +65,301 @@ export const Storelogin = defineStore('login', {
let res = await APIuserlogin({
code: data.authCode, //临时登录凭证
// rawData: JSON.stringify(infoRes),
source: 'alipay'
})
source: "alipay",
});
if (res) {
this.token = res.token
this.miniAppOpenId = res.userInfo.miniAppOpenId
this.userInfo = res.userInfo
uni.cache.set('token', res.token);
uni.cache.set('openId', res.userInfo
.alipayOpenId)
uni.cache.set('userInfo', res.userInfo);
this.token = res.token;
this.miniAppOpenId = res.userInfo.miniAppOpenId;
this.userInfo = res.userInfo;
uni.cache.set("token", res.token);
uni.cache.set("openId", res.userInfo.alipayOpenId);
uni.cache.set("userInfo", res.userInfo);
resolve(true);
}
},
fail: () => {
reject(false);
}
})
},
});
// #endif
})
}
}
});
},
},
});
export const productStore = defineStore('product', {
export const productStore = defineStore("product", {
state: () => ({
location: {
latitude: "",
longitude: "",
},
shopInfo: {
shopId: "",
isOrderFence: 0,
},
}),
actions: {
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
getLocation() {
return new Promise((resolve, reject) => {
console.log("获取经纬度");
uni.getLocation({
type: "wgs84",
altitude: true,
isHighAccuracy: true,
success: (res) => {
console.log("获取经纬度成功", res);
this.location = res;
this.APIgeocodelocation();
resolve(res);
},
fail: (err) => {
console.error("获取经纬度失败", err);
reject(err);
},
});
});
},
async APIgeocodelocation() {
let successres = await APIgeocodelocation({
lng: this.location.longitude,
lat: this.location.latitude,
});
if (successres) {
let datastorage = {
country: successres.addressComponent.country, // "中国"
province: successres.addressComponent.province, //province: "陕西省"
address: successres.addressComponent.city, //district: "西安市"
district: successres.addressComponent.district, //district: "未央区"
lng: this.location.longitude,
lat: this.location.latitude,
};
uni.cache.set("getLocationstorage", datastorage);
}
},
getQueryString(url, name) {
//解码
var reg = new RegExp("(^|&|/?)" + name + "=([^&|/?]*)(&|/?|$)", "i");
var r = url.substr(1).match(reg);
if (r != null) {
return r[2]
return r[2];
}
return null;
},
// 扫码请求
scanCodeactions(q) {
console.log('扫码内容', q)
/**
* 扫码请求
* @param {*} q
* @returns
*/
async scanCodeactions(q) {
console.log("扫码内容", q);
return new Promise(async (resolve, reject) => {
if (q) {
console.log(q)
let tableCode = ""
console.log(q);
let tableCode = "";
// #ifdef MP-WEIXIN
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
tableCode = this.getQueryString(decodeURIComponent(q), "code");
// #endif
// #ifdef MP-ALIPAY
tableCode = q
tableCode = q;
// #endif
// #ifdef H5
tableCode = q.tableCode
tableCode = q.tableCode;
// #endif
console.log(tableCode);
// 储存卓玛
uni.cache.set('tableCode', tableCode)
uni.cache.set("tableCode", tableCode);
if (tableCode) {
console.log('台桌码', uni.cache.get('tableCode'));
let data = await this.actionsproductqueryShop(tableCode)
console.log("台桌码", uni.cache.get("tableCode"));
let data = await this.actionsproductqueryShop(tableCode);
console.log('data', data)
console.log("data", data);
// -4请求登录
if (data.code == '500') {
if (data.code == "500") {
if (await this.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop()
await this.actionsproductqueryShop();
}
}
// 是否免除桌位费 0否1是
if (uni.cache.get('shopInfo').isTableFee == 0) {
uni.reLaunch({
url: '/pages/product/choosetable'
});
} else {
uni.reLaunch({
url: '/pages/product/index'
});
}
const canOrder = await this.computedDistance();
}
} else {
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
uni.scanCode({
success: async (res) => {
let tableCode = this.getQueryString(
decodeURIComponent(res.result), 'code')
decodeURIComponent(res.result),
"code"
);
// 储存卓玛
uni.cache.set('tableCode', tableCode)
uni.cache.set("tableCode", tableCode);
if (tableCode) {
let data = await this.actionsproductqueryShop()
let data = await this.actionsproductqueryShop();
if (!data) {
uni.showToast({
title: '店铺已过期或其他问题,请联系商家',
icon:'none'
})
return
title: "店铺已过期或其他问题,请联系商家",
icon: "none",
});
return;
}
// -4请求登录
const store = Storelogin()
if (data.code == '-4') {
const store = Storelogin();
if (data.code == "-4") {
if (await store.actionslogin()) {
// 成功 接着在调用
await this.actionsproductqueryShop()
await this.actionsproductqueryShop();
}
}
// 是否免除桌位费 0否1是
if (uni.cache.get('shopInfo').isTableFee == 0) {
uni.navigateTo({
url: '/pages/product/choosetable'
});
} else {
uni.reLaunch({
url: '/pages/product/index'
});
}
const canOrder = await this.computedDistance();
}
},
fail: (res) => {
console.log(res)
}
console.log(res);
},
});
// #endif
}
});
},
})
//计算距离判断是否可以点餐
async computedDistance() {
return new Promise((resolve, reject) => {
console.log("店铺经纬度", this.shopInfo.lat, this.shopInfo.lng);
console.log(
"用户经纬度",
this.location.latitude,
this.location.longitude
);
if (this.shopInfo.isOrderFence == 0) {
this.jumpToOrderPage();
resolve(true);
return;
}
const juli = getDistance(
this.location.latitude,
this.location.longitude,
this.shopInfo.lat,
this.shopInfo.lng
);
const orderFenceDistance = (
(this.shopInfo.orderFenceDistance || 2000) / 2000
).toFixed(2);
console.log("距离", juli);
if (this.shopInfo.isOrderFence && juli > orderFenceDistance) {
uni.showModal({
title: "提示",
confirmText: "重新定位",
content:
"抱歉,您当前距离店铺过远,为保障您的用餐体验,请您到店后或在门店附近再下单。若您已在店铺附近,可尝试重新定位",
success: async(res) => {
if (res.confirm) {
console.log("用户点击了确认");
await this.getLocation();
this.computedDistance();
} else if (res.cancel) {
console.log("用户点击了取消");
}
},
});
reject();
return;
}
this.jumpToOrderPage();
resolve(juli);
});
},
// 跳转点餐页面
jumpToOrderPage() {
// 是否免除桌位费 0否1是
if (this.shopInfo.isTableFee == 0) {
uni.reLaunch({
url: "/pages/product/choosetable",
});
} else {
uni.reLaunch({
url: "/pages/product/index",
});
}
},
// /通过桌码获取当前店铺信息
actionsproductqueryShop(tableCode) {
console.log('台桌码',tableCode);
console.log("台桌码", tableCode);
return new Promise(async (resolve, reject) => {
// try {
try {
let res = await APIproductqueryShop({
tableCode: tableCode ? tableCode : uni.cache.get('tableCode'),
})
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
});
if (res) {
res.shopInfo.isVip = res.vip ? '1' : '0'
res.shopTable.shopExtendMap = res.shopExtendMap
res.shopInfo.isVip = res.vip ? "1" : "0";
res.shopTable.shopExtendMap = res.shopExtendMap;
this.shopInfo = res.shopInfo;
// 店铺信息
uni.cache.set('shopTable', res.shopTable)
uni.cache.set("shopTable", res.shopTable);
// 台桌信息
uni.cache.set('shopInfo', res.shopInfo)
uni.cache.set('shopId', res.shopTable.shopId, 30)
// 当前用户距离店铺的米数
uni.cache.set('distance', res.distance)
uni.cache.set("shopInfo", res.shopInfo);
uni.cache.set("shopId", res.shopTable.shopId, 30);
resolve(res)
resolve(res);
} else {
console.error('通过桌码获取当前店铺信息失败' ,res)
reject()
uni.showToast({
title: "通过桌码获取当前店铺信息失败",
icon: "none",
});
console.error("通过桌码获取当前店铺信息失败", res);
reject();
}
} catch (error) {
console.log(error);
reject()
reject();
//TODO handle the exception
}
// } catch (e) {
// reject(false)
// }
})
});
},
// 通过shopId 获取店铺会员信息
actionsproductqueryProduct() {
return new Promise(async (resolve, reject) => {
try {
let res = await APIshopUserInfo()
uni.cache.set('shopUserInfo', res);
uni.cache.set('orderVIP', res)
uni.cache.set('ordershopUserInfo', res.shopInfo)
resolve(res)
let res = await APIshopUserInfo();
uni.cache.set("shopUserInfo", res);
uni.cache.set("orderVIP", res);
uni.cache.set("ordershopUserInfo", res.shopInfo);
resolve(res);
} catch (e) {
reject(false)
reject(false);
}
})
});
},
// 用户信息获取
actionsAPIuser() {
return new Promise(async (resolve, reject) => {
try {
let res = null
let res = null;
// 获取店铺用户会员信息
if (uni.cache.get('shopId')) {
res = await this.actionsproductqueryProduct()
if (uni.cache.get("shopId")) {
res = await this.actionsproductqueryProduct();
} else {
res = await APIuser()
uni.cache.set('userInfo', res);
res = await APIuser();
uni.cache.set("userInfo", res);
}
console.log('actionsAPIuser res', res);
resolve(res)
console.log("actionsAPIuser res", res);
resolve(res);
} catch (e) {
reject(false)
}
})
}
reject(false);
}
});
},
},
});

13
utils/address.js Normal file
View File

@@ -0,0 +1,13 @@
// 计算距离
export const getDistance = (la1, lo1, la2, lo2) => { // 当前的纬度,当前的经度,接口拿到的纬度,接口拿到的经度
let La1 = la1 * Math.PI / 180.0;
let La2 = la2 * Math.PI / 180.0;
let La3 = La1 - La2;
let Lb3 = lo1 * Math.PI / 180.0 - lo2 * Math.PI / 180.0;
let distance = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) *
Math.pow(Math.sin(Lb3 / 2), 2)));
distance = distance * 6378.137;
distance = Math.round(distance * 10000) / 10000;
return distance;
}