修改公众号关注逻辑,增加电子围栏
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -24,11 +24,18 @@ onMounted(() => {
|
||||
// 页面加载完成后生成二维码
|
||||
const userInfo = uni.cache.get("userInfo") || {};
|
||||
const wechatAcQrcode = userInfo.wechatAcQrcode || "";
|
||||
codeOptions.value.code = wechatAcQrcode;
|
||||
if(!userInfo.isAc){
|
||||
codeOptions.value.code = wechatAcQrcode;
|
||||
}
|
||||
});
|
||||
const emit = defineEmits(["generate"]);
|
||||
function qrcodeResult(e) {
|
||||
emit("generate", e.img.tempFilePath);
|
||||
const userInfo = uni.cache.get("userInfo") || {};
|
||||
if(!userInfo.isAc){
|
||||
emit("generate", e.img.tempFilePath);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
// 登录
|
||||
proxy.$isResolve();
|
||||
}
|
||||
},
|
||||
fail(error) {
|
||||
console.error('获取经纬度失败',error);
|
||||
}
|
||||
});
|
||||
|
||||
await storeuser.getLocation()
|
||||
proxy.$isResolve();
|
||||
const shopId=uni.cache.get('shopId')
|
||||
if(shopId){
|
||||
indexsRef.value.getVipConfig();
|
||||
|
||||
@@ -1227,6 +1227,10 @@ const disablePayType = computed(() => {
|
||||
arr.add("余额支付");
|
||||
}
|
||||
}
|
||||
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
|
||||
arr.add("微信支付");
|
||||
}
|
||||
|
||||
//充值并付款时只能微信支付
|
||||
if (rechargeItem.value.id) {
|
||||
arr.add("余额支付");
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -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
59
pnpm-lock.yaml
generated
@@ -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
|
||||
|
||||
608
stores/user.js
608
stores/user.js
@@ -1,273 +1,365 @@
|
||||
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', {
|
||||
state: () => ({
|
||||
token: '',
|
||||
miniAppOpenId: '',
|
||||
userInfo: '',
|
||||
shopInfo: {}
|
||||
}),
|
||||
actions: {
|
||||
async getShopInfo(shopId) {
|
||||
const shopRes = await APIusershopInfodetail({
|
||||
shopId
|
||||
})
|
||||
console.log(shopRes);
|
||||
},
|
||||
actionslogin() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.login({
|
||||
provider: 'weixin',
|
||||
success: (data) => {
|
||||
// 微信小程序环境
|
||||
uni.getUserInfo({
|
||||
provider: 'weixin',
|
||||
success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.code, //临时登录凭证
|
||||
rawData: infoRes.rawData,
|
||||
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||'');
|
||||
}
|
||||
resolve(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
my.getAuthCode({
|
||||
scopes: 'auth_base',
|
||||
success: async (data) => {
|
||||
// 支付宝小程序环境
|
||||
// my.getAuthUserInfo({
|
||||
// success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.authCode, //临时登录凭证
|
||||
// rawData: JSON.stringify(infoRes),
|
||||
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);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
}
|
||||
})
|
||||
// #endif
|
||||
})
|
||||
}
|
||||
}
|
||||
APIproductqueryShop,
|
||||
APIusershopInfodetail,
|
||||
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: {},
|
||||
}),
|
||||
actions: {
|
||||
async getShopInfo(shopId) {
|
||||
const shopRes = await APIusershopInfodetail({
|
||||
shopId,
|
||||
});
|
||||
console.log(shopRes);
|
||||
},
|
||||
actionslogin() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// #ifdef MP-WEIXIN
|
||||
uni.login({
|
||||
provider: "weixin",
|
||||
success: (data) => {
|
||||
// 微信小程序环境
|
||||
uni.getUserInfo({
|
||||
provider: "weixin",
|
||||
success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.code, //临时登录凭证
|
||||
rawData: infoRes.rawData,
|
||||
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 || "");
|
||||
}
|
||||
resolve(true);
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(false);
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
my.getAuthCode({
|
||||
scopes: "auth_base",
|
||||
success: async (data) => {
|
||||
// 支付宝小程序环境
|
||||
// my.getAuthUserInfo({
|
||||
// success: async (infoRes) => {
|
||||
let res = await APIuserlogin({
|
||||
code: data.authCode, //临时登录凭证
|
||||
// rawData: JSON.stringify(infoRes),
|
||||
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);
|
||||
resolve(true);
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
reject(false);
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const productStore = defineStore('product', {
|
||||
actions: {
|
||||
getQueryString(url, name) { //解码
|
||||
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
|
||||
var r = url.substr(1).match(reg)
|
||||
if (r != null) {
|
||||
return r[2]
|
||||
}
|
||||
return null;
|
||||
},
|
||||
// 扫码请求
|
||||
scanCodeactions(q) {
|
||||
console.log('扫码内容', q)
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (q) {
|
||||
console.log(q)
|
||||
let tableCode = ""
|
||||
// #ifdef MP-WEIXIN
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), 'code')
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
tableCode = q
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
tableCode = q.tableCode
|
||||
// #endif
|
||||
console.log(tableCode);
|
||||
// 储存卓玛
|
||||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
console.log('台桌码', uni.cache.get('tableCode'));
|
||||
let data = await this.actionsproductqueryShop(tableCode)
|
||||
|
||||
console.log('data', data)
|
||||
// -4请求登录
|
||||
if (data.code == '500') {
|
||||
if (await this.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
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'
|
||||
});
|
||||
}
|
||||
export const productStore = defineStore("product", {
|
||||
state: () => ({
|
||||
location: {
|
||||
latitude: "",
|
||||
longitude: "",
|
||||
},
|
||||
shopInfo: {
|
||||
shopId: "",
|
||||
isOrderFence: 0,
|
||||
},
|
||||
}),
|
||||
actions: {
|
||||
getLocation() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("获取经纬度");
|
||||
uni.getLocation({
|
||||
type: "wgs84",
|
||||
altitude: true,
|
||||
isHighAccuracy: true,
|
||||
success: (res) => {
|
||||
console.log("获取经纬度成功", res);
|
||||
|
||||
}
|
||||
} else {
|
||||
// #ifdef APP || MP-WEIXIN || MP-ALIPAY
|
||||
uni.scanCode({
|
||||
success: async (res) => {
|
||||
let tableCode = this.getQueryString(
|
||||
decodeURIComponent(res.result), 'code')
|
||||
// 储存卓玛
|
||||
uni.cache.set('tableCode', tableCode)
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop()
|
||||
if (!data) {
|
||||
uni.showToast({
|
||||
title: '店铺已过期或其他问题,请联系商家',
|
||||
icon:'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
// -4请求登录
|
||||
const store = Storelogin()
|
||||
if (data.code == '-4') {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
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'
|
||||
});
|
||||
}
|
||||
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 null;
|
||||
},
|
||||
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log(res)
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
/**
|
||||
* 扫码请求
|
||||
* @param {*} q
|
||||
* @returns
|
||||
*/
|
||||
async scanCodeactions(q) {
|
||||
console.log("扫码内容", q);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
if (q) {
|
||||
console.log(q);
|
||||
let tableCode = "";
|
||||
// #ifdef MP-WEIXIN
|
||||
tableCode = this.getQueryString(decodeURIComponent(q), "code");
|
||||
// #endif
|
||||
// #ifdef MP-ALIPAY
|
||||
tableCode = q;
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
tableCode = q.tableCode;
|
||||
// #endif
|
||||
console.log(tableCode);
|
||||
// 储存卓玛
|
||||
uni.cache.set("tableCode", tableCode);
|
||||
if (tableCode) {
|
||||
console.log("台桌码", uni.cache.get("tableCode"));
|
||||
let data = await this.actionsproductqueryShop(tableCode);
|
||||
|
||||
})
|
||||
},
|
||||
console.log("data", data);
|
||||
// -4请求登录
|
||||
if (data.code == "500") {
|
||||
if (await this.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop();
|
||||
}
|
||||
}
|
||||
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"
|
||||
);
|
||||
// 储存卓玛
|
||||
uni.cache.set("tableCode", tableCode);
|
||||
if (tableCode) {
|
||||
let data = await this.actionsproductqueryShop();
|
||||
if (!data) {
|
||||
uni.showToast({
|
||||
title: "店铺已过期或其他问题,请联系商家",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
// -4请求登录
|
||||
const store = Storelogin();
|
||||
if (data.code == "-4") {
|
||||
if (await store.actionslogin()) {
|
||||
// 成功 接着在调用
|
||||
await this.actionsproductqueryShop();
|
||||
}
|
||||
}
|
||||
const canOrder = await this.computedDistance();
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
console.log(res);
|
||||
},
|
||||
});
|
||||
// #endif
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// /通过桌码获取当前店铺信息
|
||||
actionsproductqueryShop(tableCode) {
|
||||
console.log('台桌码',tableCode);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// try {
|
||||
try {
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: tableCode ? tableCode : uni.cache.get('tableCode'),
|
||||
})
|
||||
if (res) {
|
||||
res.shopInfo.isVip = res.vip ? '1' : '0'
|
||||
res.shopTable.shopExtendMap = res.shopExtendMap
|
||||
// 店铺信息
|
||||
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)
|
||||
//计算距离判断是否可以点餐
|
||||
async computedDistance() {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log("店铺经纬度", this.shopInfo.lat, this.shopInfo.lng);
|
||||
console.log(
|
||||
"用户经纬度",
|
||||
this.location.latitude,
|
||||
this.location.longitude
|
||||
);
|
||||
|
||||
resolve(res)
|
||||
} else {
|
||||
console.error('通过桌码获取当前店铺信息失败' ,res)
|
||||
reject()
|
||||
}
|
||||
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);
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
reject()
|
||||
//TODO handle the exception
|
||||
}
|
||||
console.log("距离", juli);
|
||||
|
||||
// } catch (e) {
|
||||
// reject(false)
|
||||
// }
|
||||
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);
|
||||
return new Promise(async (resolve, reject) => {
|
||||
// try {
|
||||
try {
|
||||
let res = await APIproductqueryShop({
|
||||
tableCode: tableCode ? tableCode : uni.cache.get("tableCode"),
|
||||
});
|
||||
if (res) {
|
||||
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("shopInfo", res.shopInfo);
|
||||
uni.cache.set("shopId", res.shopTable.shopId, 30);
|
||||
|
||||
// 通过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)
|
||||
} catch (e) {
|
||||
reject(false)
|
||||
}
|
||||
resolve(res);
|
||||
} else {
|
||||
uni.showToast({
|
||||
title: "通过桌码获取当前店铺信息失败",
|
||||
icon: "none",
|
||||
});
|
||||
console.error("通过桌码获取当前店铺信息失败", res);
|
||||
reject();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
reject();
|
||||
//TODO handle the exception
|
||||
}
|
||||
|
||||
})
|
||||
},
|
||||
// } catch (e) {
|
||||
// reject(false)
|
||||
// }
|
||||
});
|
||||
},
|
||||
|
||||
// 用户信息获取
|
||||
actionsAPIuser() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = null
|
||||
// 获取店铺用户会员信息
|
||||
if (uni.cache.get('shopId')) {
|
||||
res = await this.actionsproductqueryProduct()
|
||||
} else {
|
||||
res = await APIuser()
|
||||
uni.cache.set('userInfo', res);
|
||||
}
|
||||
console.log('actionsAPIuser res', res);
|
||||
resolve(res)
|
||||
} 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);
|
||||
} catch (e) {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
});
|
||||
// 用户信息获取
|
||||
actionsAPIuser() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let res = null;
|
||||
// 获取店铺用户会员信息
|
||||
if (uni.cache.get("shopId")) {
|
||||
res = await this.actionsproductqueryProduct();
|
||||
} else {
|
||||
res = await APIuser();
|
||||
uni.cache.set("userInfo", res);
|
||||
}
|
||||
console.log("actionsAPIuser res", res);
|
||||
resolve(res);
|
||||
} catch (e) {
|
||||
reject(false);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
13
utils/address.js
Normal file
13
utils/address.js
Normal 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user