合并扫码点餐

This commit is contained in:
魏啾
2024-05-10 10:59:34 +08:00
parent 09661b8b0b
commit b1e0dfb352
6 changed files with 320 additions and 44 deletions

View File

@@ -111,4 +111,7 @@ export default {
loginOut(data) { //退出登录
return uni.api.post("/loginOut", data);
},
productqueryShopIdByTableCode(data) { //通过桌码获取shopId
return uni.api.get("/product/queryShopIdByTableCode", data);
},
}

View File

@@ -38,42 +38,35 @@
});
break;
case 'relative':
uni.pro.navigateTo(item.absUrl,item);
uni.pro.navigateTo(item.absUrl, item);
break;
case 'scan':
if (!uni.utils.pluschooseImage()) {
return false
}
// #ifdef H5
if (this.wxSdk) {
wx.scanQRCode({
needResult: 1, // 默认为0扫描结果由微信处理1则直接返回扫描结果
scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
success: res => {
// 当needResult 为 1 时,扫码返回的结果
console.log(res.resultStr, res)
}
});
} else {
uni.showModal({
title: '注意',
content: '微信sdk初始化失败请重新加载',
success: res => {
window.location.reload();
}
});
}
// #endif
// #ifdef APP || MP-WEIXIN
uni.scanCode({
success: res => {
console.log(res.result, res)
success: (res) => {
let tableCode = this.getQueryString(decodeURIComponent(res.result), 'code')
if (tableCode) {
uni.pro.navigateTo('order_food/order_food', {
tableCode: tableCode,
})
}
}
});
// #endif
break;
}
}
},
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
},
}
};
</script>

View File

@@ -0,0 +1,267 @@
<template>
<view>
<view class="banner-wrap">
<u-swiper :list="banners" height="440" radius="0" :indicator="banners.length > 1"
imgMode="widthFix"></u-swiper>
</view>
<view class="container">
<view class="user-info">
<view class="top">
<view class="col">
<view style="width: 36px; height: 36px;border-radius: 10rpx;">
<button open-type="chooseAvatar" @chooseavatar='onChooseAvatar'
style="padding: 0;margin: 0; width: 36px; height: 36px;border-radius: 10rpx;">
<image style="width: 36px; height: 36px;" v-if="userInfo.avatar" :src="userInfo.avatar" mode="aspectFill">
</image>
<image style="width: 36px; height: 36px;" v-else src="@/static/avatar.png" mode="aspectFill">
</image>
</button>
</view>
<text class="t">{{userInfo.nickName}}</text>
</view>
<navigator class="ewm-wrap" url="/pages/pay_code/pay_code" hover-class="none">
<image class="ewm" src="../../static/ewm.png" mode="aspectFit"></image>
<text class="t">会员码</text>
</navigator>
</view>
<view class="bottom">
<view class="col">
<text class="t1 num">{{shopUser.amount || '0'}}</text>
<text class="t2">余额</text>
</view>
<view class="col">
<text class="t1 num">{{shopUser.levelConsume || '0'}}</text>
<text class="t2">积分</text>
</view>
</view>
</view>
<view class="menu-wrap">
<view class="top-wrap">
<view class="item" @click="scanCodehandle">
<image class="bg" src="../../static/index_m2.png" mode="widthFix"></image>
<view class="btn">
<text class="t">扫码点餐</text>
</view>
</view>
<view class="item" @click="memberindex">
<image class="bg" src="../../static/index_m1.png" mode="widthFix"></image>
<view class="btn">
<text class="t">会员充值</text>
</view>
</view>
</view>
</view>
<view class="footer-banner">
<u-swiper :list="footerBanners" radius="20" height="160" :indicator="banners.length > 1"
imgMode="widthFix"></u-swiper>
</view>
</view>
</view>
</template>
<script>
import uploadImage from "@/js_sdk/yushijie-ossutil/ossutil/uploadFile.js";
export default {
data() {
return {
banners: [require('@/static/banner1.png')],
footerBanners: [require('@/static/footer_banner1.png')],
shopUser: {},
userInfo: {},
shopInfo:{}
};
},
onLoad() {
// #ifdef MP-WEIXIN
if (!uni.cache.get('token')) {
uni.reLaunch({
url: '/pages/login/login'
})
}
// #endif
},
onShow() {
if (uni.cache.get('token')) {
this.loginwxuserInfo()
}else{
uni.reLaunch({
url: '/pages/login/login'
})
}
},
methods: {
async loginwxuserInfo() {
let res = await this.api.loginwxuserInfo({
userId: uni.cache.get('userInfo').id,
shopId: uni.cache.get('shopUser')
})
if (res.code == 0) {
uni.cache.set('userInfo', res.data.userInfo);
uni.cache.set('shopUser', res.data.shopUser);
uni.cache.set('shopInfo', res.data.shopInfo);
this.shopUser = uni.cache.get('shopUser')
this.userInfo = uni.cache.get('userInfo')
this.shopInfo = uni.cache.get('shopInfo')
}
},
scanCodehandle() {
uni.scanCode({
success: (res) => {
let tableCode = this.getQueryString(decodeURIComponent(res.result), 'code')
if (tableCode) {
uni.pro.navigateTo('order_food/order_food', {
tableCode: tableCode,
})
}
}
})
},
memberindex() {
uni.pro.navigateTo('member/index')
},
getQueryString(url, name) { //解码
var reg = new RegExp('(^|&|/?)' + name + '=([^&|/?]*)(&|/?|$)', 'i')
var r = url.substr(1).match(reg)
if (r != null) {
return r[2]
}
return null;
},
// / 更换头像
onChooseAvatar(e) {
uni.showLoading({
title: '上传中',
mask: true
})
console.log(e.detail.avatarUrl)
let file = e.detail.avatarUrl;
uploadImage(file, 'avatar',
result => {
//将上传后的图片以对象官方要求的格式的形式存入uni-file-picker的value值imageValueimageValue值的结构为数组包对象用于图片回显
// let objAge = {
// 'url': result,
// 'extname': 'png',
// 'name': 'imgss.png'
// };
// this.userlist.avatar.push(objAge)
this.userInfo.avatar = result
console.log(this.userInfo.avatar)
uni.hideLoading()
}, result => {
uni.hideLoading()
})
},
}
};
</script>
<style scoped lang="scss">
.container {
padding: 40upx;
}
.user-info {
background-color: #fff;
padding: 40upx;
border-radius: 20upx;
.top {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1upx solid #ececec;
padding-bottom: 42upx;
.col {
display: flex;
align-items: center;
.t {
margin-left: 20upx;
}
}
.ewm-wrap {
display: flex;
flex-direction: column;
align-items: center;
.ewm {
$size: 50upx;
width: $size;
height: $size;
}
.t {
font-size: 20upx;
padding-top: 8upx;
}
}
}
.bottom {
padding-top: 40upx;
display: flex;
.col {
flex: 1;
display: flex;
align-items: center;
flex-direction: column;
.t1 {
font-size: 38upx;
}
}
}
}
.menu-wrap {
padding: 40upx 0 0 0;
$gap: 20upx;
.top-wrap {
display: flex;
gap: $gap;
.item {
flex: auto;
display: flex;
align-items: center;
flex-direction: column;
background-color: #fff;
border-radius: 20upx;
position: relative;
.bg {
width: 100%;
height: auto;
border-radius: $gap;
}
.btn {
margin-top: $gap;
padding: $gap $gap * 2;
border-radius: 100upx;
display: flex;
justify-content: center;
font-size: 32upx;
background-color: #fff;
box-shadow: 0 12upx 12upx rgba(0, 0, 0, 0.05);
position: absolute;
bottom: $gap * 2;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
}
}
}
}
.footer-banner {
padding-top: 20upx;
}
</style>

View File

@@ -78,7 +78,7 @@
return false;
}
let res = await this.api.paymemeberIn({
shopId: uni.cache.get('shopUser').shopId, // 判断显示哪家的作品,
shopId: uni.cache.get('shopUser'), // 判断显示哪家的作品,
amount: this.amount // 判断显示哪家的作品,
})
if (res) {

View File

@@ -15,7 +15,7 @@
<text>订单完成</text>
</text>
<text class="status" v-if="listinfo.status == 'send'">
<text> 已发</text>
<text>已发</text>
</text>
<text class="status" v-if="listinfo.status == 'refunding'">
<text>申请退单</text>

View File

@@ -267,15 +267,33 @@
}
this.countScrollTitle(e.scrollTop);
},
onLoad(e) {
uni.$on('message', this.getMessage)
async onLoad(e) {
if (e.q) {
this.scanCodehandle(e.q)
this.tableCode = this.getQueryString(decodeURIComponent(e.q), 'code')
uni.cache.set('tableCode', this.tableCode)
// this.scanCodehandle()
} else {
this.tableCode = e.tableCode
uni.cache.set('tableCode', this.tableCode)
this.handlemessage()
// this.handlemessage()
}
let res = await this.api.productqueryShopIdByTableCode({
code: uni.cache.get('tableCode')
})
try {
if (res.data) {
uni.cache.set('shopUser', res.data)
if (e.q) {
this.scanCodehandle()
} else {
this.handlemessage()
}
}
} catch (e) {
//TODO handle the exception
}
uni.$on('message', this.getMessage)
this.$nextTick(() => {
this.countTitleTopNum();
});
@@ -326,18 +344,15 @@
this.productqueryProduct() //list 数据
break;
case 'createOrder': //去结算
// uni.$emit('createOrdermessage', msg.data)
let item = JSON.stringify(msg.data)
uni.redirectTo({
url: '/pages/order_detail/order_detail?tableId=' + item
});
break;
case 'addcart':
console.log('addcart', 315)
this.cartLists = msg
if (msg.data.length != 0) {
msg.data.forEach((item, index, arr) => { //初始化skuidname的数据 选择第一个
console.log(item.skuId, 111111, this.skuidsearch)
if (item.skuId == this.skuidsearch) {
this.$set(this, 'amountcartNumber', item.number)
} else {
@@ -350,7 +365,6 @@
this.productqueryProduct() //list 数据
break;
default:
console.log('default', 320)
this.cartLists = msg
this.productqueryProduct() //list 数据
}
@@ -359,7 +373,7 @@
handlemessage() {
this.socketTicket ? this.socketTicket.Close() : null //调用前先判断是否有socket正在进行 先关闭后链接
this.socketTicket = new webSocketUtils(
`${uni.conf.baseUrlwws}/websocket/table/${this.tableCode}/${uni.cache.get('shopUser').shopId}/${uni.cache.get('userInfo').id}`,
`${uni.conf.baseUrlwws}/websocket/table/${this.tableCode}/${uni.cache.get('shopUser')}/${uni.cache.get('userInfo').id}`,
5000)
},
@@ -370,8 +384,7 @@
}
},
scanCodehandle(e) {
this.tableCode = this.getQueryString(decodeURIComponent(e), 'code')
uni.cache.set('tableCode', this.tableCode)
// #ifdef MP-WEIXIN || MP-ALIPAY
uni.login({ //alipay weixin
provider: 'weixin',
@@ -395,7 +408,7 @@
uni.cache.set('miniAppOpenId', res.data.userInfo
.miniAppOpenId)
uni.cache.set('userInfo', res.data.userInfo);
uni.cache.set('shopUser', res.data.shopUser);
// uni.cache.set('shopUser', res.data.shopUser);
this.handlemessage()
}
},
@@ -435,7 +448,7 @@
"num": a == '-' ? -1 : 1, //skuId
"type": "addcart", //“addcart:添加购物车create0rder:生成订单clearCart:清空购物车”,
"productId": item.id, //商品id
"shopId": uni.cache.get('shopUser').shopId,
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id
};
uni.$u.debounce(this.socketSendMsg(data), 500)
@@ -499,7 +512,7 @@
async hodgepodge(item, a, c) { //去获取商品id 库存等
try {
let res = await this.api.productqueryProductSku({
shopId: uni.cache.get('shopUser').shopId,
shopId: uni.cache.get('shopUser'),
productId: item.id, //商品id
spec_tag: this.skuidname.join(",")
})
@@ -518,7 +531,7 @@
"num": c == '-' ? -1 : 1, //数量
"type": "addcart", //“addcart:添加购物车create0rder:生成订单clearCart:庆康购物车”,
"productId": item.id, //商品id
"shopId": uni.cache.get('shopUser').shopId,
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id
};
} else {
@@ -527,7 +540,7 @@
"num": '', //数量
"type": "sku", //“addcart:添加购物车create0rder:生成订单clearCart:庆康购物车”,
"productId": item.id, //商品id
"shopId": uni.cache.get('shopUser').shopId,
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id
};
}
@@ -546,7 +559,7 @@
"num": '', //数量
"type": "createOrder", //“addcart:添加购物车create0rder:生成订单clearCart:庆康购物车”,
"productId": '', //商品id
"shopId": uni.cache.get('shopUser').shopId,
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id
}
uni.$u.debounce(this.socketSendMsg(data), 500)
@@ -559,7 +572,7 @@
"num": '', //skuId
"type": "clearCart", //“addcart:添加购物车create0rder:生成订单clearCart:清空购物车”,
"productId": '', //商品id
"shopId": uni.cache.get('shopUser').shopId,
"shopId": uni.cache.get('shopUser'),
"userId": uni.cache.get('userInfo').id
};
uni.$u.debounce(this.socketSendMsg(data), 500)