Files
cashier_wx/pages/order/confirm-order.vue
2025-12-03 15:26:41 +08:00

1604 lines
39 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<view class="container">
<up-navbar :title="navTitle" @leftClick="onback" placeholder></up-navbar>
<view class="headStatus">
<view class="status">
<up-icon v-if="listinfo.status == 'done' || listinfo.status == 'unpaid' || !listinfo.id" name="checkmark-circle-fill" color="#03C061" size="23"></up-icon>
<view class="statusName" v-if="listinfo.status == 'unpaid' || !listinfo.id">待支付</view>
<view class="statusName" v-if="listinfo.status == 'done'">已完成</view>
<view class="statusName" v-if="listinfo.status == 'refund'">退单</view>
<view class="statusName" v-if="listinfo.status == 'part-refund'">部分退单</view>
<view class="statusName" v-if="listinfo.status == 'cancelled'">取消订单</view>
</view>
<view class="time" v-if="listinfo.createTime">下单时间{{ listinfo.createTime }}</view>
<view class="time" v-if="listinfo.paidTime && (listinfo.status != 'cancelled' || listinfo.status != 'unpaid')">付款时间{{ listinfo.paidTime }}</view>
</view>
<view class="wxQrcode" v-if="shopQrcode">
<view class="left">
<text class="title">扫码加好友优惠多多</text>
<text>优惠活动多</text>
<text>充值有好礼</text>
<text>会员享低价</text>
<text>长按保存微信内扫一扫加好友</text>
</view>
<!-- #ifdef MP-WEIXIN -->
<u-image width="152" height="152" radius="16" :src="shopQrcode"></u-image>
<!-- #endif -->
<!-- #ifdef MP-ALIPAY -->
<image style="height: 150rpx; width: 150rpx" :src="shopQrcode" @longpress="saveImage(shopQrcode)" mode="aspectFill"></image>
<!-- #endif -->
</view>
<!-- {{cartStore.orderCostSummary}} -->
<!-- 详情 -->
<orderInfo
:useVipPrice="cartStore.useVipPrice"
:packfee="packfee"
:shifu="shifu"
:nowCarts="cartStore.carts"
ref="orderInfoAfterRef"
:freeCheck="freeCheck"
:listinfo="listinfo"
:orderVIP="orderVIP"
:ordershopUserInfo="ordershopUserInfo"
@istype="istype"
@clickPointsamount="clickPointsamount"
:isBwc="isBwc"
></orderInfo>
<!-- 订单备注 -->
<view class="orderInfo">
<view class="">
<view class="t">订单备注</view>
<view class="u-m-t-18">
<up-textarea border="none" placeholder="请填写口味、偏好等要求" type="textarea" v-model="orderRemarker" :clearable="true" />
</view>
</view>
</view>
<!-- 霸王餐 -->
<rechargeFree
:freeDineConfig="orderVIP.freeDineConfig"
:payAmount="listinfo.totalPrices"
v-if="showFreeDine && (listinfo.status == 'unpaid' || !listinfo.id)"
@changeFree="changeFree"
></rechargeFree>
<!-- 充值享优惠 -->
<view v-if="!showFreeDine && (listinfo.status == 'unpaid' || !listinfo.id) && cartStore.orderCostSummary.finalPayAmount > 0">
<ChargeVue
@updateChargeSel="(e) => updateChargeSel(e)"
@updateRechargeId="updateRechargeId"
@updateIsShow="updateIsShow"
v-if="listinfo.status == 'unpaid' || !listinfo.id"
></ChargeVue>
</view>
<!-- 支付方式 -->
<paymentMethodes
ref="paymentMethodref"
:orderVIP="orderVIP"
@groupChange="groupChange"
:disablePayType="disablePayType"
:changeFreeenable="isBwc"
v-model="paymentmethod"
v-if="listinfo.status == 'unpaid' || !listinfo.id"
></paymentMethodes>
<view class="fixedview">
<view class="flex-between" v-if="listinfo.status == 'unpaid' || !listinfo.id">
<view class="fixedview_one flex-start">
<view class="fixedview_oneone">实付金额</view>
<view class="fixedview_onetow" v-if="rechargeItem.id">
<text>¥</text>
{{ rechargeItem.amount }}
</view>
<view class="fixedview_onetow" v-else>
<text>¥</text>
{{ cartStore.orderCostSummary.finalPayAmount }}
</view>
</view>
<view class="flex-colum-end u-flex u-flex-y-center">
<view class="u-m-r-30 u-flex u-flex-y-center">
<template v-if="ordershopUserInfo.registerType == 'before'">
<up-button shape="circle" v-if="!listinfo.id" @click="toJiacai" plain :custom-style="customStyle">
<view class="u-flex u-flex-y-center">
<image style="width: 40rpx; height: 40rpx" src="@/static/icon/add-goods.png" mode=""></image>
<text class="u-font-32 color-main u-m-l-16">加菜</text>
</view>
</up-button>
<up-button shape="circle" v-if="listinfo.id && listinfo.status == 'unpaid'" plain @tap="cancelOrder()" :custom-style="customStyle">
<view class="u-flex u-flex-y-center">
<text class="u-font-32 color-main u-m-l-16">取消订单</text>
</view>
</up-button>
</template>
<template v-else>
<up-button v-if="!cartStore.isEmpty" shape="circle" @click="onlyCreateOrder" plain :custom-style="customStyle">
<view class="u-flex u-flex-y-center">
<!-- <image style="width: 40rpx;height: 40rpx;" src="@/static/icon/add-goods.png" mode=""></image> -->
<text class="u-font-32 color-main">仅下单</text>
</view>
</up-button>
<up-button v-else shape="circle" @click="toJiacai" plain :custom-style="customStyle">
<view class="u-flex u-flex-y-center">
<image style="width: 40rpx; height: 40rpx" src="@/static/icon/add-goods.png" mode=""></image>
<text class="u-font-32 color-main u-m-l-16">加菜</text>
</view>
</up-button>
</template>
</view>
<view class="fixedview_tow" @tap="$u.debounce(istoricalorders, 1000)">
{{ paymentmethod.name }}
</view>
<!-- <view class="fixedview_tows" @tap="$u.debounce(APIputuserorderclick,1000)">
取消订单
</view> -->
</view>
</view>
</view>
<view style="width: 100%; height: 200rpx; color: #fff; color: #fff"></view>
<payPassword ref="payPasswordref" :isShow="ispws" @inputComplete="(e) => accountPayevent(e)" @close="pwdClose" />
<!-- 私域引流配置 -->
<OrderFinshModal v-model="showDrainage"></OrderFinshModal>
</view>
</template>
<script setup>
import { back } from '@/utils/uniapp.js';
import { onLoad, onUnload } from '@dcloudio/uni-app';
import ChargeVue from './components/charge.vue';
import { pay } from '@/utils/pay.js';
import OrderFinshModal from '@/components/order-finish-modal.vue';
import _ from 'lodash';
import { ref, reactive, computed, onMounted, onUnmounted, nextTick, watch, onBeforeMount, onBeforeUnmount, provide } from 'vue';
provide('shopUserInfo', ref(uni.cache.get('shopUserInfo')));
provide('shopInfo', ref(uni.cache.get('shopInfo')));
import { getTableInfo } from '@/common/api/shop/index.js';
import { APIgetOrderById, APIputuserorder, APIhistoryOrder, rechargePayOrder, APIcancelOrder } from '@/common/api/order/index.js';
import { APIusershopInfodetail, APIshopUserInfo } from '@/common/api/member.js';
import { APImemberPointsmyPoints, APImemberPointscalcUsablePoints } from '@/common/api/shop/index.js';
import { useCartsStore } from '@/stores/carts.js';
import { useWebSocket } from '@/stores/carts-websocket.js';
function pwdClose() {
ispws.value = false;
pay_unlock();
}
onUnload(() => {
console.log('onUnload');
closeSocket();
});
onBackPress(() => {
console.log('返回拦截');
closeSocket();
});
function onback() {
closeSocket();
console.log('返回');
back();
}
const customStyle = {
width: '180rpx',
height: '70rpx',
background: 'FFFFFF',
'border-radius': '106rpx',
border: '2rpx solid #E8AD7B'
};
const cartStore = useCartsStore();
//充值相关start
//充值和余额支付是否可用
const isCanUseCharge = ref(true);
function updateIsShow(e) {
isCanUseCharge.value = e;
}
const rechargeItem = ref({
id: ''
});
const rechargeId = ref(null);
function updateRechargeId(e) {
rechargeId.value = e;
}
function updateChargeSel(newval) {
rechargeItem.value = newval;
console.log('updateChargeSel', newval);
}
//充值相关end
async function onMessage(Message) {
cartStore.onMessage(Message, cartsSocket);
listinfo.totalPrices = historyTotalPrices * 1 + cartStore.totalPrice * 1;
if (Message.operate_type == 'init') {
youhuiReset();
}
if (Message.operate_type == 'cleanup') {
console.log('onMessage:cleanup', Message);
console.log('onMessage:options', options);
console.log('onMessage:listinfo', listinfo);
youhuiReset();
if (listinfo.id || options.tableCode) {
let res = listinfo.id
? await APIgetOrderById({
orderId: listinfo.id
})
: await APIhistoryOrder({
tableCode: options.tableCode || ''
});
console.log('onMessage:APIgetOrderById', res);
Object.assign(listinfo, res);
if (res) {
orderRemarker.value = res.remark;
cartStore.setOldOrder(res);
}
if (noPayStatus[res.status]) {
uni.showToast({
title: noPayStatus[res.status],
icon: 'none'
});
setTimeout(() => {
uni.navigateBack();
}, 1000);
return;
}
}
}
if (Message.operate_type == 'del') {
youhuiReset();
}
if (Message.operate_type == 'edit') {
youhuiReset();
}
if (Message.operate_type == 'clearOrder') {
youhuiReset();
}
if (Message.type == 'product' && Message.data_type == 'product_update' && Message.operate_type == 'product_update') {
youhuiReset();
}
return Message;
}
let cartsSocket = null;
cartStore.goodsInit();
const socketInitPar = {
type: 'shopping',
operate_type: 'init',
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId')
};
function socketInit() {
cartsSocket = useWebSocket();
cartsSocket.connect(socketInitPar, onMessage);
}
const noPayStatus = {
cancelled: '订单已取消',
done: '订单已关闭'
};
function youhuiReset() {
listinfo.pointsDiscountAmount = 0;
listinfo.pointsNum = 0;
listinfo.pointsDiscountAmount = 0;
listinfo.Productroll = 0;
try {
orderInfoAfterRef.value?.IntegralInputclose();
} catch {}
}
// 结账管理
import { Memberpay } from '@/stores/pay.js';
const storeMemberpay = Memberpay();
import { productStore } from '@/stores/user.js';
const storeuser = productStore();
import payPassword from '@/components/payPassword.vue';
import orderInfo from './components/orderInfo.vue';
// import orderInfoBefore from '../components/orderInfoBefore.vue'
import rechargeFree from './components/rechargeFree.vue';
import paymentMethodes from '@/components/paymentMethod.vue'; //支付方式
import { onShow, onBackPress } from '@dcloudio/uni-app';
import { onHide } from '@dcloudio/uni-app';
// 输入支付密码
const ispws = ref(false);
let userInfo = uni.cache.get('userInfo');
// 会员信息
const orderVIP = ref(uni.cache.get('orderVIP'));
// 商品订单关联的店铺信息
const ordershopUserInfo = ref(uni.cache.get('shopInfo'));
cartStore.updateData('orderVIP', orderVIP.value);
cartStore.updateData('shopInfo', ordershopUserInfo.value);
// 是否显示商家二维码信息
const shopQrcode = ref(ordershopUserInfo.shopInfo || false);
// 霸王餐
const isBwc = ref(false);
//是否显示霸王餐
const showFreeDine = ref(false);
//订单备注
const orderRemarker = ref('');
// 订单详情
const listinfo = reactive({
combinedArray: [],
Productroll: 0,
coupondiscountAmount: 0,
pointsDiscountAmount: 0,
packFeess: 0,
totalPrices: 0,
Seatcharge: 0,
id: null
});
//判断是否是打包商品
const is_type = ref(0);
//打包商品切换
const istype = (newValue) => {
is_type.value = newValue;
};
//积分
const freeCheck = ref(false);
let backtimer = null;
let historyTotalPrices = 0;
// * 获取订单详情接口
const orderorderInfo = async (isNpwGetOrderDetail = false) => {
console.log('listinfo.id', listinfo.id);
if (!listinfo.id && !options.tableCode) {
return;
}
if (!isNpwGetOrderDetail) {
if (isPayBefor() && !listinfo.id) {
return;
}
}
let res = listinfo.id
? await APIgetOrderById({
orderId: listinfo.id
})
: await APIhistoryOrder({
tableCode: options.tableCode || ''
});
orderRemarker.value = res.remark;
Object.assign(listinfo, res);
if (res && res.tableCode) {
socketInitPar.table_code = res.tableCode;
let tableRes = await getTableInfo({
tableCode: options.tableCode || ''
});
console.log(tableRes);
listinfo.tableName = tableRes.name;
} else {
if (options.tableCode) {
socketInitPar.table_code = options.tableCode;
let tableRes = await getTableInfo({
tableCode: options.tableCode || ''
});
console.log(tableRes);
listinfo.tableName = tableRes.name;
}
}
cartStore.setOldOrder(res);
socketInit();
console.log(res);
getOrderInfoAfterCalcInit(res);
};
//拿到订单数据后续初始化处理
function getOrderInfoAfterCalcInit(res) {
console.log('getOrderInfoAfterCalcInit', res);
if (res && res.id) {
Object.assign(listinfo, res);
// 历史订单
if (listinfo.detailMap) {
let combinedArray = [];
for (const key in listinfo.detailMap) {
if (listinfo.detailMap.hasOwnProperty(key)) {
let subArray = listinfo.detailMap[key];
combinedArray = [...combinedArray, ...subArray];
}
}
listinfo.combinedArray = combinedArray;
listinfo.packFeess = cartStore.getTotalPackFee(listinfo.combinedArray);
// 计算购物车商品费用
historyTotalPrices = cartStore.getTotalTotalPrices(listinfo.combinedArray, isBwc.value) * 1;
listinfo.totalPrices = historyTotalPrices + cartStore.totalPrice * 1;
// 餐位费listinfo.seatNum
listinfo.Seatcharge = cartStore.getTotalSeatcharge(listinfo.seatNum);
}
if (listinfo.discountInfo) {
const discountObj = JSON.parse(listinfo.discountInfo);
const tempArray = [];
for (const [key, value] of Object.entries(discountObj)) {
tempArray.push({
name: key,
amount: value
});
}
listinfo.discountInfo = tempArray;
}
// 回填先质控
listinfo.pointsDiscountAmount = 0;
// console.log(listinfo)
} else {
listinfo.totalPrices = cartStore.totalPrice * 1;
}
// uni.showToast({
// title:'订单已取消或已付款',
// icon:'none'
// })
// backtimer=setTimeout(()=>{
// const arr=getCurrentPages()
// if(arr.length<=1){
// toJiacai()
// }else{
// uni.navigateBack({delta:1})
// }
// },1000)
}
const changeFree = (e) => {
if (JSON.stringify(e) == '{}') {
return;
}
isBwc.value = e;
console.log('changeFree', e);
// 支付方式切换
// #ifdef MP-WEIXIN
// #endif
// #ifdef MP-ALIPAY
// #endif
};
const saveImage = (url) => {
uni.saveImage({
url: url,
success: () => {
uni.showToast({
title: '保存成功',
icon: 'none'
});
}
});
};
//
const paymentMethodref = ref(null);
const paymentmethod = ref({});
// 支付方式
// #ifdef MP-WEIXIN
paymentmethod.value = {
name: '微信支付',
type: 2,
url: 'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/weChat.png',
payType: 'wechatPay'
};
// #endif
// #ifdef MP-ALIPAY
paymentmethod.value = {
name: '支付宝支付',
type: 3,
url: 'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/confirmOrder/alipay.png',
payType: 'aliPay'
};
// #endif
const groupChange = async (e) => {
if (e == 5) {
return;
}
paymentmethod.value = e;
};
// 操作下单时候
const orderInfoAfterRef = ref(null);
//取消订单
const cancelOrder = async () => {
uni.showModal({
title: '取消订单',
content: '是否取消订单?',
showCancel: true,
success: async (res) => {
if (res.confirm) {
await APIcancelOrder({
shopId: listinfo.shopId,
orderId: listinfo.id
});
uni.showToast({
title: '取消订单成功',
icon: 'none'
});
setTimeout(() => {
uni.pro.switchTab('order/index');
}, 1000);
}
}
});
};
// 删除订单
const APIputuserorderclick = async () => {
await APIputuserorder(listinfo.id);
uni.showToast({
title: '删除成功',
icon: 'none'
});
uni.pro.switchTab('order/index');
};
async function onlyCreateOrder() {
await createOrder();
orderorderInfo();
}
// 生成订单
const createOrder = async () => {
// cartStore.carts = [];
const res = await storeMemberpay.actionscreateOrder({
dineMode: is_type.value == 0 ? 'dine-in' : 'take-out', //堂食 dine-in 外带 take-out 外卖 take-away
seatNum: uni.cache.get('dinersNum') ? uni.cache.get('dinersNum') : '', //用餐人数
// packFee: packFee.value, //打包费
packFee: packfee.value, //打包费
originAmount: shifu.value, //订单原金额(包含打包费) 不含折扣价格 不含餐位费
remark: orderRemarker.value, //备注
placeNum: listinfo.id ? listinfo.placeNum * 1 + 1 : 1, //当前订单下单次数
waitCall: '', //是否等叫 0 否 1 等叫
orderId: listinfo.id || '',
tableCode: options.tableCode || '',
userId: uni.cache.get('userInfo').id || '', //
limitRate:
cartStore.limitTimeDiscount && cartStore.limitTimeDiscount.id
? {
id: cartStore.limitTimeDiscount.id,
discountRate: cartStore.limitTimeDiscount.discountRate,
discountPriority: cartStore.limitTimeDiscount.discountPriority,
foodType: cartStore.limitTimeDiscount.foodType,
foods: cartStore.limitTimeDiscount.foods
}
: null
});
// 清空购物车
if (res) {
Object.assign(listinfo, res);
// cartStore.setOldOrder(res)
getOrderInfoAfterCalcInit(res);
cartsSocket.sendMessage({
type: 'shopping',
table_code: uni.cache.get('tableCode'),
shop_id: uni.cache.get('shopId'),
operate_type: 'cleanup'
});
return res;
} else {
uni.showToast({
title: '生成订单失败'
});
}
};
function isPayBefor() {
return ordershopUserInfo.value.registerType == 'before' ? true : false;
}
function pay_lock() {
cartsSocket.sendMessage({
...socketInitPar,
operate_type: 'pay_lock'
});
}
function pay_unlock() {
console.log('pay_unlock');
clearInterval(payStatusTimer);
cartsSocket.sendMessage({
...socketInitPar,
operate_type: 'pay_unlock'
});
}
async function search_pay_lock() {
cartsSocket.sendMessage({
...socketInitPar,
operate_type: 'search_pay_lock'
});
return new Promise((relove, reject) => {
cartsSocket.socketTask.onMessage((res) => {
relove(JSON.parse(res.data));
});
});
}
let payStatusTimer = null;
let orderIsLock = true;
function returnPayParams() {
const checkOrderPay = {
orderId: '',
vipPrice: cartStore.useVipPrice ? 1 : 0, //是否使用会员价0否1是
userAllPack: is_type.value == 0 ? 0 : 1, //是否整单打包
seatNum: is_type.value == 0 ? cartStore.seatFeeConfig.personCount : 0, //用餐人数
originAmount: cartStore.orderCostSummary.goodsRealAmount, //订单原金额(不包含打包费+餐位费)
discountRatio: 1, //折扣比例(计算时 向上取整保留 两位小数) 写死1
discountAmount: 0, //手动优惠金额 写死0
productCouponDiscountAmount: cartStore.orderCostSummary.productCouponDeduction, //商品优惠券抵扣金额
otherCouponDiscountAmount: cartStore.orderCostSummary.fullCouponDeduction, //其他优惠券抵扣金额
couponList: cartStore.backendCoupons.map((v) => v.id), //用户使用的卡券
orderAmount: isBwc.value ? cartStore.orderCostSummary.orderOriginFinalPayAmount : cartStore.orderCostSummary.finalPayAmount, // 最终订单金额
roundAmount: 0, //抹零金额 减免多少钱
pointsDiscountAmount: cartStore.orderCostSummary.pointDeductionAmount, //积分抵扣金额(tb_points_basic_setting表)
pointsNum: cartStore.orderCostSummary.pointUsed, //(扣除各类折扣 enable_deduction后使用)
newCustomerDiscountAmount: cartStore.orderCostSummary.newUserDiscount, //新客立减
newCustomerDiscountId: cartStore.orderCostSummary.newUserDiscount > 0 ? cartStore.consumeDiscount.id : '',
remark: orderRemarker.value, //用户备注
discountActAmount: cartStore.orderCostSummary.fullReduction.actualAmount, //满减抵扣金额
discountActId: cartStore.orderCostSummary.fullReduction.usedActivity ? cartStore.orderCostSummary.fullReduction.usedActivity.id : null,
userId: uni.cache.get('userInfo').id || '', //
limitRate:
cartStore.limitTimeDiscount && cartStore.limitTimeDiscount.id
? {
id: cartStore.limitTimeDiscount.id,
discountRate: cartStore.limitTimeDiscount.discountRate,
discountPriority: cartStore.limitTimeDiscount.discountPriority,
foodType: cartStore.limitTimeDiscount.foodType,
foods: cartStore.limitTimeDiscount.foods
}
: null,
vipDiscountAmount: cartStore.orderCostSummary.vipDiscountAmount //会员折扣减免金额
};
return {
isBwc: isBwc.value,
checkOrderPay,
payType: paymentmethod.value.payType,
buyerRemark: '',
returnUrl: '',
rechargeId: rechargeId.value,
rechargeDetailId: rechargeItem.value.id,
shopUserId: orderVIP.value.id,
shopId: orderVIP.value.shopId,
pwd: '',
userId: uni.cache.get('userInfo').id || '', //
discountActld: cartStore.orderCostSummary.fullReduction.usedActivity ? cartStore.orderCostSummary.fullReduction.usedActivity.id : '' //满减活动id
};
}
const istoricalorders = async () => {
const payParams = returnPayParams();
console.log('istoricalorders:payParams', payParams);
//先付
if (isPayBefor()) {
// 购物车有数据
if (!cartStore.isEmpty) {
const res = await createOrder();
//历史订单数据
const res1 = await APIgetOrderById({
orderId: res.id
});
Object.assign(listinfo, res1);
orderRemarker.value = res1.remark;
cartStore.setOldOrder(res1);
}
goToPay(payParams);
// goToPay()
} else {
//后付
// 购物车有数据
if (!cartStore.isEmpty) {
const res = await createOrder();
//历史订单数据
const res1 = await APIgetOrderById({
orderId: res.id
});
Object.assign(listinfo, res1);
orderRemarker.value = res1.remark;
cartStore.setOldOrder(res1);
goToPay(payParams);
return;
}
// 先调用历史订单
let APIhistoryOrderres = await APIhistoryOrder({
tableCode: listinfo.tableCode
});
// 判断是否有历史订单
if (APIhistoryOrderres.detailMap) {
let combinedArray = [];
for (const key in APIhistoryOrderres.detailMap) {
if (APIhistoryOrderres.detailMap.hasOwnProperty(key)) {
let subArray = APIhistoryOrderres.detailMap[key];
combinedArray = [...combinedArray, ...subArray];
}
}
// 判断支付之前是是否还有新加订单
if (listinfo.combinedArray.length === combinedArray.length) {
goToPay(payParams);
} else {
uni.showToast({
title: '你的订单已更新!',
icon: 'none'
});
orderorderInfo();
}
} else {
uni.showToast({
title: '你的小伙伴已提交订单~',
icon: 'none'
});
setTimeout(() => {
orderorderInfo();
}, 1000);
}
}
};
//开始锁单
function start_lock_order() {
clearInterval(payStatusTimer);
pay_lock();
payStatusTimer = setInterval(() => {
pay_lock();
}, 1000);
}
// * 去支付
const goToPay = async (payParams) => {
console.log('goToPay:payParams', payParams);
const canPayRes = await search_pay_lock();
const canPay = canPayRes.status == 1 ? true : false;
if (!canPay) {
uni.showToast({
title: '有人正在付款中!',
icon: 'none'
});
const shopUserInfo = uni.cache.get('shopUserInfo');
console.log('shopUserInfo', shopUserInfo);
console.log('listinfo', listinfo);
if (shopUserInfo) {
if (shopUserInfo.userId == listinfo.userId) {
pay_unlock();
}
}
return;
}
// 余额支付
if (payParams.payType == 'accountPay') {
console.log('orderVIP.value', orderVIP.value);
if (orderVIP.value.payPwd == '' && userInfo.usePayPwd) {
uni.showModal({
title: '提示',
content: '您还未设置支付密码,是否去设置?',
success: (res) => {
if (res.confirm) {
uni.pro.navigateTo('user/member/setPassword', {
shopId: orderVIP.value.shopId,
type: 'detail'
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
return;
}
start_lock_order();
if (userInfo.usePayPwd) {
ispws.value = true;
return;
}
accountPayevent();
return;
}
console.log('canPay:goToPay:payParams', payParams);
start_lock_order();
console.log('霸王餐前payParams', payParams);
if (payParams.isBwc) {
payParams.checkOrderPay.orderId = listinfo.id;
console.log('霸王餐支付参数:', payParams);
try {
const isPaySuccess = await storeMemberpay.actionspayltPayVip({
...payParams,
shopId: orderVIP.value.shopId,
shopUserId: orderVIP.value.id,
orderId: listinfo.id,
userAllPack: is_type.value == 0 ? 0 : 1, //是否整单打包
amount: cartStore.orderCostSummary.finalPayAmount, // 最终订单金额
orderAmount: cartStore.orderCostSummary.orderOriginFinalPayAmount, // 最终订单原金额
originAmount: cartStore.orderCostSummary.goodsRealAmount, //订单原金额(不包含打包费+餐位费)
returnUrl: '', //跳转地址
buyerRemark: '',
seatNum: is_type.value == 0 ? cartStore.seatFeeConfig.personCount : 0 //用餐人数
});
if (isPaySuccess) {
paySucessCallback();
orderorderInfo();
pay_unlock();
}
} catch (error) {
console.log('error', error);
pay_unlock();
}
return false;
} else {
payParams.checkOrderPay.orderId = listinfo.id;
try {
if (rechargeItem.value.id && rechargeId.value) {
//充值并且支付
const payRes = await rechargePayOrder(payParams);
const isPaySuccess = await pay(payRes);
if (isPaySuccess) {
paySucessCallback();
}
pay_unlock();
} else {
console.log('微信支付');
const isPaySuccess = await storeMemberpay.actionsltPayOrder(payParams);
if (isPaySuccess) {
paySucessCallback();
}
}
} catch (error) {
console.log('error', error);
pay_unlock();
//TODO handle the exception
}
}
pay_unlock();
console.log('orderorderInfo');
orderorderInfo();
};
//
const clickPointsamount = (Pointsamount) => {
listinfo.pointsDiscountAmount = Pointsamount.pointsDiscountAmount;
listinfo.pointsNum = Pointsamount.pointsNum;
};
const payPasswordref = ref(null);
// 余额支付
const accountPayevent = async (pwd) => {
console.log('账户支付', pwd);
if (JSON.stringify(pwd) === '{}') {
return;
}
const payParams = returnPayParams();
ispws.value = false;
payParams.checkOrderPay.userId = uni.cache.get('userInfo').id;
payParams.checkOrderPay.orderId = listinfo.id;
payParams.pwd = pwd;
try {
const isPaySuccess = await storeMemberpay.balancePayOrder(payParams);
if (isPaySuccess) {
uni.showToast({
title: '支付成功',
icon: 'none'
});
pay_unlock();
paySucessCallback();
}
} catch (error) {
//TODO handle the exception
pay_unlock();
}
orderorderInfo();
};
onBeforeUnmount(() => {
clearTimeout(backtimer);
clearInterval(payStatusTimer);
closeSocket();
});
onHide(() => {
closeSocket();
clearInterval(payStatusTimer);
});
function closeSocket() {
// cartsSocket.closeExistingConnection()
}
onShow(() => {
userInfo = uni.cache.get('userInfo');
if (cartsSocket) {
cartsSocket.connect();
}
try {
// 更新数据
if (orderVIP.value) {
orderVIP.value = uni.cache.get('orderVIP');
paymentMethodref.value.orderVIPfun(uni.cache.get('orderVIP'));
if (listinfo.id && ordershopUserInfo.value.registerType != 'before') {
orderorderInfo();
}
}
} catch (error) {
//TODO handle the exception
}
orderorderInfo();
uni.$off('selCoupon');
uni.$on('selCoupon', function (data) {
console.log('selCoupon', data);
cartStore.setCoupons(_.cloneDeep(data));
});
});
let options = {};
// 跳转到加菜页面
function toJiacai() {
console.log('跳转到加菜页面');
back();
}
const packfee = computed(() => {
return cartStore.orderCostSummary.packFee;
});
//不计算各种折扣前的实付金额
const shifu = computed(() => {
const payAmount = listinfo.payAmount ? listinfo.payAmount * 1 : 0;
return payAmount + cartStore.totalPrice * 1 + packfee.value * 1;
});
//减去各种折扣后的金额
const lastPayMoney = computed(() => {
return shifu.value * 1;
});
const payStatus = {
unpaid: '待支付',
done: '已完成',
refund: '已退款',
'part-refund': '部分退款',
cancelled: '已取消'
};
const navTitle = computed(() => {
if (!listinfo.id && !cartStore.isEmpty) {
return '待确认';
}
if (cartStore.isEmpty && listinfo.id) {
return payStatus[listinfo.status] || '待确认';
} else {
return '待确认';
}
});
//支付成功后的处理
function paySucessCallback() {
console.log('paySucessCallback');
cartsSocket.closeSocket();
showDrainage.value = true;
}
//私域引流配置
const drainageConfig = ref({});
//私域引流弹窗
const showDrainage = ref(false);
async function init(opt) {
await storeuser.actionsproductqueryProduct();
console.log('init');
cartStore.clearOrderConfig();
Object.assign(options, opt);
listinfo.id = options.orderId;
console.log('options', options);
if (options.shopId) {
// 每次进来全局更新shopId
// uni.cache.set("shopId", options.shopId, 30);
uni.cache.set('shopId', options.shopId);
}
//如果已经生成订单,根据历史订信息设置相关配置
if (options.orderId) {
let res = await APIgetOrderById({
orderId: listinfo.id
});
if (res) {
uni.cache.set('tableCode', res.tableCode);
uni.cache.set('tableCode', res.seatNum);
options.tableCode = res.tableCode || '';
cartStore.setSeatFeeConfig('personCount', res.seatNum);
cartStore.setDinnerType(res.dineMode || 'dine-in');
cartStore.setOldOrder(res);
if (res.limitRate) {
cartStore.limitTimeDiscount = res.limitRate;
}
orderRemarker.value = res.remark;
Object.assign(listinfo, res);
}
}
//获取店铺信息
const shopInfoRes = await APIusershopInfodetail({
shopId: options.shopId
});
if (shopInfoRes) {
cartStore.shopInfo = shopInfoRes.shopInfo;
}
await cartStore.goodsInit();
// * 获取会员信息
await nextTick();
orderVIP.value = uni.cache.get('orderVIP');
cartStore.freeDineConfig = orderVIP.value.freeDineConfig;
const shopUserInfo = uni.cache.get('shopUserInfo');
cartStore.shopUserInfo = shopUserInfo;
if (options.tableCode) {
socketInitPar.table_code = options.tableCode;
socketInit();
} else {
orderorderInfo();
}
}
onLoad((opt) => {
init(opt);
});
watch(
() => cartStore.orderCostSummary.orderOriginFinalPayAmount,
(newval) => {
console.log('cartStore.orderCostSummary.orderOriginFinalPayAmount', orderVIP.value);
if (JSON.stringify(orderVIP.value) == '{}') {
return;
}
if (!orderVIP.value) {
return;
}
if (!orderVIP.value.freeDineConfig || !orderVIP.value.freeDineConfig.enable) {
//未开始霸王餐后面代码不执行
isBwc.value = false;
showFreeDine.value = false;
return;
}
const bwc_fullaniunt_money = newval + cartStore.orderCostSummary.fullReduction.actualAmount;
if (bwc_fullaniunt_money <= 0 || bwc_fullaniunt_money < orderVIP.value.freeDineConfig.rechargeThreshold) {
isBwc.value = false;
showFreeDine.value = false;
return;
}
if ((listinfo.status == 'unpaid' || !listinfo.id) && orderVIP.value.freeDineConfig.enable && bwc_fullaniunt_money >= orderVIP.value.freeDineConfig.rechargeThreshold) {
showFreeDine.value = true;
}
},
{
immediate: true
}
);
watch(
() => isBwc.value,
(newval) => {
cartStore.isFreeDine = newval;
}
);
const disablePayType = computed(() => {
const arr = new Set([]);
if (isBwc.value) {
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
arr.add('微信支付');
} else {
arr.add('余额支付');
}
}
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
arr.add('微信支付');
}
//充值并付款时只能微信支付
if (rechargeItem.value.id) {
arr.add('余额支付');
}
if (!orderVIP.value || !orderVIP.value.amount) {
arr.add('余额支付');
}
if (orderVIP.value) {
if (orderVIP.value.amount < cartStore.orderCostSummary.orderOriginFinalPayAmount) {
arr.add('余额支付');
}
}
// if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
// arr.add("微信支付");
// }
if (!isCanUseCharge.value) {
arr.add('余额支付');
}
return Array.from(arr);
});
</script>
<style lang="scss">
page {
background-color: #f7f7f7;
}
.container {
padding: 32rpx 28rpx 32rpx 28rpx;
}
.headStatus {
display: flex;
flex-direction: column;
margin-bottom: 32rpx;
align-items: center;
.status {
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
font-size: 36rpx;
color: #333333;
.statusName {
margin-left: 16rpx;
}
}
.time {
font-weight: 400;
font-size: 24rpx;
color: #999999;
margin-top: 18rpx;
}
}
.wxQrcode {
background: #ffffff;
border-radius: 18rpx 18rpx 18rpx 18rpx;
padding: 32rpx 24rpx;
font-weight: 400;
font-size: 24rpx;
color: #999999;
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 32rpx;
.left {
display: flex;
flex-direction: column;
}
.title {
font-weight: bold;
font-size: 28rpx;
color: #333333;
margin-bottom: 16rpx;
}
}
.card_box {
background-color: #fff;
// box-shadow: 0rpx 8rpx 12rpx 2rpx rgba(87,86,86,0.35);
position: relative;
width: 100%;
height: 100%;
// box-shadow: 0rpx 4rpx 12rpx 2rpx rgba(87, 86, 86, 0.35);
border-radius: 18rpx;
.card_head_box {
width: 100%;
display: flex;
justify-content: space-between;
position: absolute;
top: -22.5rpx;
padding: 0 44rpx;
.card_head_item {
width: 45rpx;
height: 45rpx;
background-color: #f9f9f9;
border-radius: 50%;
box-shadow: inset 0rpx -13rpx 18rpx -16rpx rgba(87, 86, 86, 0.35);
}
}
}
.card {
// background-color: #fff;
border-radius: 20upx;
margin-bottom: 28upx;
position: relative;
.head {
display: flex;
justify-content: space-between;
padding: 50rpx 0 32rpx 0;
border-bottom: 2rpx dashed #e3e3e3;
.head_left {
.shopName {
font-weight: bold;
font-size: 32rpx;
color: #333333;
}
.tableName {
font-weight: 400;
font-size: 28rpx;
color: #333333;
}
}
.status {
text {
font-weight: 500;
font-size: 28rpx;
color: #333333;
}
}
}
.number-wrap {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 32rpx;
.t {
font-weight: 400;
font-size: 28rpx;
color: #333333;
}
.number {
font-weight: bold;
font-size: 56rpx;
color: #333333;
}
}
.price {
.i {
font-size: 20upx;
}
.num {
font-size: 38upx;
}
}
.shop-box {
padding: 36rpx 34rpx 30rpx 34rpx;
border-bottom: 2rpx dashed #e3e3e3;
.shop-head {
display: flex;
justify-content: space-between;
align-items: center;
.shop-head-left {
display: flex;
align-items: center;
.tag-wrap {
width: 80rpx;
height: 48rpx;
background: #ffffff;
border-radius: 10rpx 10rpx 10rpx 10rpx;
border: 2rpx solid #e3ad7f;
margin-right: 18rpx;
display: flex;
align-items: center;
justify-content: center;
.tag {
font-weight: 400;
font-size: 24rpx;
color: #e3ad7f;
}
}
.title {
font-weight: bold;
font-size: 28rpx;
color: #333333;
}
}
}
.shop-info {
margin-top: 32rpx;
.item:nth-child(1) {
margin-top: 0;
}
.item {
padding: 32rpx 0 !important;
display: flex;
.cover {
}
.info {
flex: 1;
display: flex;
flex-direction: column;
padding-left: 16upx;
.productName {
font-weight: bold;
font-size: 28rpx;
color: #333333;
margin-top: 20rpx;
}
.productSkuName {
font-weight: 400;
font-size: 24rpx;
color: #999999;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
overflow: hidden;
text-overflow: ellipsis;
}
.n {
font-size: 24upx;
color: #999;
}
}
.price {
display: flex;
flex-direction: column;
align-items: flex-end;
padding-left: 68rpx;
.priceAmount {
font-weight: 500;
font-size: 28rpx;
color: #333333;
margin-top: 26rpx;
}
.num {
font-weight: 400;
font-size: 24rpx;
color: #999999;
margin-top: 22rpx;
}
}
}
}
.total-wrap {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: 500;
font-size: 28rpx;
.price {
font-weight: bold;
font-size: 32rpx;
}
}
}
.order_footer {
display: flex;
flex-direction: column;
padding: 34rpx;
position: relative;
.order_footer_icon {
width: 100%;
position: absolute;
top: -22.5rpx;
left: 0;
display: flex;
justify-content: space-between;
.order_footer_left_icon {
width: 45rpx;
height: 45rpx;
margin-left: -22.5rpx;
background-color: #f9f9f9;
border-radius: 50%;
box-shadow: inset -20rpx 0rpx 22rpx -20rpx rgba(87, 86, 86, 0.35);
}
.order_footer_right_icon {
width: 45rpx;
height: 45rpx;
margin-right: -22.5rpx;
background-color: #f9f9f9;
border-radius: 50%;
box-shadow: inset 13rpx 0rpx 16rpx -9rpx rgba(87, 86, 86, 0.35);
}
}
.title {
font-weight: bold;
font-size: 28rpx;
color: #333333;
}
.order-info {
.row {
display: flex;
justify-content: space-between;
padding-top: 32upx;
.t {
font-weight: normal;
font-size: 28rpx;
color: #333333;
}
.info {
font-weight: 400;
font-size: 24rpx;
color: #666666;
}
}
}
}
}
.pay-info-wrap {
padding: 0;
box-sizing: border-box;
.info-wrap {
padding: 64rpx 30rpx 30rpx 30rpx;
box-sizing: border-box;
.title {
align-self: center;
font-size: 32rpx;
color: #333;
font-weight: bold;
}
}
.info-content {
.pay-title {
display: flex;
align-items: flex-end;
justify-content: center;
font-weight: bold;
width: 100%;
font-size: 48rpx;
color: #333;
margin-top: 48rpx;
text {
font-size: 60rpx;
color: #333;
}
}
.pay-password {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 64rpx;
.list {
width: 88rpx;
height: 88rpx;
display: flex;
align-items: center;
justify-content: center;
border: 2rpx solid #999;
border-radius: 8rpx;
text {
font-size: 32rpx;
}
}
}
.hint {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100rpx;
text {
font-size: 28rpx;
color: #ccc;
}
}
}
}
.fixedview {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
z-index: 999;
// height: 80rpx;
.flex-between {
width: 100%;
padding: 36rpx 36rpx 70rpx 36rpx;
background: #ffffff;
.fixedview_one {
display: flex;
align-items: flex-end;
.fixedview_oneone {
font-weight: 400;
font-size: 28rpx;
color: #666666;
}
.fixedview_onetow {
font-weight: bold;
font-size: 32rpx;
color: #333333;
text {
font-size: 24rpx;
}
}
}
.flex-colum-end {
.fixedview_tow {
background: #e3ad7f;
border-radius: 36rpx;
font-weight: 400;
font-size: 32rpx;
color: #ffffff;
padding: 14rpx 44rpx;
}
.fixedview_tows {
margin-top: 10rpx;
background: #c3c3c3;
border-radius: 36rpx;
font-weight: 400;
font-size: 32rpx;
color: #ffffff;
padding: 14rpx 44rpx;
}
}
}
}
.orderInfo {
background: #ffffff;
border-radius: 18rpx 18rpx 18rpx 18rpx;
margin-top: 32rpx;
padding: 32rpx 34rpx;
.t {
font-weight: bold;
font-size: 28rpx;
color: #333333;
flex-shrink: 0;
}
.info {
font-weight: 400;
font-size: 28rpx;
color: #666666;
}
}
</style>