uview-plus组件库全面升级更新,订单结算判断支付方式是否可用代码调整,公众号关注二维码修改

This commit is contained in:
2025-10-21 10:44:31 +08:00
parent 5d98b7efc2
commit 5f3a307fec
395 changed files with 31264 additions and 2477 deletions

View File

@@ -77,7 +77,6 @@
:ordershopUserInfo="ordershopUserInfo"
@istype="istype"
@clickPointsamount="clickPointsamount"
@learcoupons="learcoupons"
:isBwc="isBwc"
>
</orderInfo>
@@ -106,9 +105,15 @@
</rechargeFree>
<!-- 充值享优惠 -->
<view v-if="!showFreeDine && (listinfo.status == 'unpaid' || !listinfo.id)">
<view
v-if="
!showFreeDine &&
(listinfo.status == 'unpaid' || !listinfo.id) &&
cartStore.orderCostSummary.finalPayAmount > 0
"
>
<ChargeVue
@updateChargeSel="updateChargeSel"
@updateChargeSel="(e) => updateChargeSel(e)"
@updateRechargeId="updateRechargeId"
v-if="listinfo.status == 'unpaid' || !listinfo.id"
></ChargeVue>
@@ -120,6 +125,7 @@
@groupChange="groupChange"
:disablePayType="disablePayType"
:changeFreeenable="isBwc"
v-model="paymentmethod"
v-if="listinfo.status == 'unpaid' || !listinfo.id"
>
</paymentMethodes>
@@ -160,7 +166,7 @@
shape="circle"
v-if="listinfo.id && listinfo.status == 'unpaid'"
plain
@tap="cancelOrder"
@tap="cancelOrder()"
:custom-style="customStyle"
>
<view class="u-flex u-flex-y-center">
@@ -200,7 +206,7 @@
</template>
</view>
<view class="fixedview_tow" @tap="$u.debounce(istoricalorders, 1000)">
{{ paymentmethod.paymentBtnText }}
{{ paymentmethod.name }}
</view>
<!-- <view class="fixedview_tows" @tap="$u.debounce(APIputuserorderclick,1000)">
取消订单
@@ -212,34 +218,19 @@
<payPassword
ref="payPasswordref"
:isShow="ispws"
@inputComplete="accountPayevent"
@inputComplete="(e) => accountPayevent(e)"
@close="ispws = false"
/>
<!-- 私域引流配置 -->
<OrderFinshModal v-if="showDrainage"></OrderFinshModal>
<OrderFinshModal v-model="showDrainage" ></OrderFinshModal>
</view>
</template>
<script setup>
import { back } from "@/utils/uniapp.js";
import { onLoad } from "@dcloudio/uni-app";
import { BigNumber } from "bignumber.js";
import ChargeVue from "./components/charge.vue";
import { pay } from "@/utils/pay.js";
import Drainage from "@/components/drainage.vue";
import * as drainageConfigApi from "@/common/api/market/drainageConfig.js";
import OrderFinshModal from "@/components/order-finish-modal.vue";
function onback() {
closeSocket();
back();
}
const customStyle = {
width: "180rpx",
height: "70rpx",
background: "FFFFFF",
"border-radius": "106rpx",
border: "2rpx solid #E8AD7B",
};
import _ from "lodash";
import {
ref,
@@ -247,12 +238,12 @@ import {
computed,
onMounted,
onUnmounted,
watchEffect,
nextTick,
watch,
onBeforeMount,
onBeforeUnmount,
} from "vue";
import { getTableInfo } from "@/common/api/shop/index.js";
import {
APIgetOrderById,
@@ -269,9 +260,21 @@ import {
import { useCartsStore } from "@/stores/carts.js";
import { useWebSocket } from "@/stores/carts-websocket.js";
function onback() {
closeSocket();
console.log("返回");
back();
}
const customStyle = {
width: "180rpx",
height: "70rpx",
background: "FFFFFF",
"border-radius": "106rpx",
border: "2rpx solid #E8AD7B",
};
const cartStore = useCartsStore();
const disablePayType = ref([]);
//充值相关
const rechargeItem = ref({
id: "",
@@ -285,32 +288,6 @@ function updateRechargeId(e) {
function updateChargeSel(newval) {
rechargeItem.value = newval;
console.log("updateChargeSel", newval);
//充值并付款时只能微信支付
if (newval && newval.id) {
disablePayType.value = ["余额支付"];
paymentMethodref.value.groupChanges(2);
return;
}
console.log("orderVIP.value.amount", orderVIP.value.amount);
if (!orderVIP.value.amount) {
disablePayType.value = ["余额支付"];
if (paymentMethodref.value) {
paymentMethodref.value.groupChanges(2);
}
return;
}
if (orderVIP.value.amount < newval) {
disablePayType.value = ["余额支付"];
if (paymentMethodref.value) {
paymentMethodref.value.groupChanges(2);
}
return;
}
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
disablePayType.value = ["微信支付"];
} else {
disablePayType.value = [];
}
}
async function onMessage(Message) {
@@ -386,7 +363,6 @@ function youhuiReset() {
listinfo.pointsNum = 0;
listinfo.pointsDiscountAmount = 0;
listinfo.Productroll = 0;
uniqueIds.value = [];
try {
orderInfoAfterRef.value?.IntegralInputclose();
} catch {}
@@ -437,7 +413,6 @@ const listinfo = reactive({
packFeess: 0,
totalPrices: 0,
Seatcharge: 0,
pointsNum: 0,
id: null,
});
@@ -544,82 +519,17 @@ function getOrderInfoAfterCalcInit(res) {
// },1000)
}
// 监听价格算法
watchEffect(async () => {
if (listinfo.combinedArray.length > 0 || cartStore.carts.length > 0) {
// 打包费packFeess 计算购物车商品费用totalPrices 餐位费Seatcharge
// try {
let historyOrderPackFee = is_type.value != 0 ? listinfo.packFeess : 0;
let nowCartPackFee = is_type.value != 0 ? cartStore.totalPackFee * 1 : 0;
let seatFee = is_type.value == 0 ? listinfo.Seatcharge : 0;
let sum =
cartStore.totalPackFee * 1 +
historyOrderPackFee +
listinfo.totalPrices +
seatFee;
listinfo.originAmount = Math.round(sum * 100) / 100;
// 打包费packFeess 计算购物车商品费用totalPrices 餐位费Seatcharge 商品卷Productroll 优惠卷coupondiscountAmount 积分listinfo.pointsDiscountAmount
let sums =
nowCartPackFee +
historyOrderPackFee +
listinfo.totalPrices +
seatFee -
(listinfo.Productroll || 0) -
(listinfo.coupondiscountAmount || 0) -
(listinfo.pointsDiscountAmount || 0);
listinfo.totalCost = Math.round(sums * 100) / 100;
// 总价格
// console.log(listinfo.combinedArray, listinfo.packFeess, listinfo.totalPrices, listinfo
// .Seatcharge, listinfo.Productroll, listinfo.coupondiscountAmount, sums) // 霸王餐
// console.log(orderVIP.value.freeDineConfig.enable, changeFreeenable.value)
if (orderVIP.value.freeDineConfig.enable && isBwc.value) {
listinfo.totalCost = (
parseFloat(listinfo.totalCost) *
parseFloat(orderVIP.value.freeDineConfig.rechargeTimes)
).toFixed(2);
}
// 积分
if (
listinfo.totalCost &&
(listinfo.status == "unpaid" || !listinfo.id) &&
orderVIP.value.id
) {
uni.$u.debounce(memberPointscalcUsablePoints, 500);
}
// } catch (error) {
// //TODO handle the exception
// }
}
});
const changeFree = (e) => {
if (JSON.stringify(e) == "{}") {
return;
}
isBwc.value = e;
cartStore.isFreeDine = e;
if (e) {
disablePayType.value = ["余额支付"];
} else {
disablePayType.value = [];
}
orderInfoAfterRef.value.bwcclear();
uniqueIds.value = []; // 筛选出商品卷的id
listinfo.coupondiscountAmount = 0; // 优惠卷减去的金额
listinfo.pointsNum = 0; // 商品卷总价价格
// 商品价格
// listinfo.totalPrices = cartStore.getTotalTotalPrices(
// listinfo.combinedArray,
// isBwc.value
// );
console.log("changeFree", e);
// 支付方式切换
// #ifdef MP-WEIXIN
paymentMethodref.value.groupChanges(2);
// #endif
// #ifdef MP-ALIPAY
paymentMethodref.value.groupChanges(3);
// #endif
};
@@ -637,71 +547,35 @@ const saveImage = (url) => {
//
const paymentMethodref = ref(null);
// 支付方式切换
const paymentmethod = reactive({
radiovalue: 2,
paymentBtnText: "微信支付",
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;
}
console.log("groupChange", e);
paymentmethod.radiovalue = e.type;
paymentmethod.paymentBtnText = e.name;
paymentmethod.payType = e.payType;
paymentmethod.value = e;
};
// 操作下单时候
const orderInfoAfterRef = ref(null);
// 商品卷的id储存
const uniqueIds = ref([]);
// 这是优惠卷传的值
const handleReturnData = async (data) => {
// 这是优惠卷
if (data.typeOrder == 1) {
if (data.item) {
// 优惠卷减去的金额
listinfo.coupondiscountAmount = data.item.discountAmount;
uniqueIds.value.push(data.item.id);
orderInfoAfterRef.value.dataprocessing(data);
}
} else {
// 筛选出商品卷的id
// 商品卷总价价格
// uniqueIds.value = [...uniqueIds.value, ...new Set(data.map(item => item.id))]
uniqueIds.value = [...uniqueIds.value, ...data.map((item) => item.id)];
console.log(uniqueIds.value);
listinfo.Productroll = cartStore.getTotalProductroll(data).value;
// TODO handle the exception
let res = {
Productroll: listinfo.Productroll,
uniqueIds: uniqueIds.value.length,
};
orderInfoAfterRef.value.dataprocessing(res);
}
};
const learcoupons = (data) => {
if (data == "product") {
uniqueIds.value = []; // 筛选出商品卷的id
listinfo.coupondiscountAmount = 0; // 优惠卷减去的金额
listinfo.Productroll = 0; // 商品卷总价价格
listinfo.pointsNum = 0; // 积分总价格
} else {
// 每次点击优惠卷删除优惠卷里的id
if (listinfo.coupondiscountAmount != 0) {
uniqueIds.value.pop();
}
listinfo.coupondiscountAmount = 0; // 优惠卷减去的金额
}
};
//取消订单
const cancelOrder = async () => {
uni.showModal({
@@ -821,7 +695,9 @@ function returnPayParams() {
cartStore.orderCostSummary.productCouponDeduction, //商品优惠券抵扣金额
otherCouponDiscountAmount: cartStore.orderCostSummary.fullCouponDeduction, //其他优惠券抵扣金额
couponList: cartStore.backendCoupons.map((v) => v.id), //用户使用的卡券
orderAmount:isBwc.value? cartStore.orderCostSummary.orderOriginFinalPayAmount: cartStore.orderCostSummary.finalPayAmount, // 最终订单金额
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后使用)
@@ -837,7 +713,7 @@ function returnPayParams() {
return {
isBwc: isBwc.value,
checkOrderPay,
payType: paymentmethod.payType,
payType: paymentmethod.value.payType,
buyerRemark: "",
returnUrl: "",
rechargeId: rechargeId.value,
@@ -926,7 +802,7 @@ const istoricalorders = async () => {
// * 去支付
const goToPay = async (payParams) => {
console.log("goToPay:payParams", payParams);
// 余额支付
if (payParams.payType == "accountPay") {
if (orderVIP.value.payPwd == "") {
@@ -1035,22 +911,7 @@ const goToPay = async (payParams) => {
orderorderInfo();
};
//002-获取订单可用积分及抵扣金额(支付页面使用)
const memberPointscalcUsablePoints = async () => {
let res = await APImemberPointscalcUsablePoints({
shopUserId: orderVIP.value.id,
orderAmount: listinfo.totalCost,
});
console.log('获取订单可用积分及抵扣金额(支付页面使用)')
if(res){
cartStore.setPointDeductionRule(
res.equivalentPoints,
res.maxDeductionAmount
);
}
orderInfoAfterRef.value?.getCalcUsablePoints(res);
};
//
const clickPointsamount = (Pointsamount) => {
listinfo.pointsDiscountAmount = Pointsamount.pointsDiscountAmount;
@@ -1060,6 +921,10 @@ const clickPointsamount = (Pointsamount) => {
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;
@@ -1079,46 +944,8 @@ const accountPayevent = async (pwd) => {
}
orderorderInfo();
};
watch(
() => cartStore.orderCostSummary.orderOriginFinalPayAmount,
(newval) => {
console.log("orderOriginFinalPayAmount", newval);
if (newval <= 0) {
disablePayType.value = ["微信支付"];
paymentMethodref.value.groupChanges(1);
}
if (
newval <= 0 ||
newval < orderVIP.value.freeDineConfig.rechargeThreshold
) {
isBwc.value = false;
showFreeDine.value = false;
return;
}
disablePayType.value = [];
if (
(listinfo.status == "unpaid" || !listinfo.id) &&
orderVIP.value.freeDineConfig.enable &&
newval >= orderVIP.value.freeDineConfig.rechargeThreshold
) {
showFreeDine.value = true;
}
},
{
immediate: true,
}
);
watch(
() => isBwc.value,
(newval) => {
cartStore.isFreeDine = newval;
}
);
onBeforeUnmount(() => {
uni.$off("returnData", handleReturnData);
clearTimeout(backtimer);
clearInterval(payStatusTimer);
closeSocket();
@@ -1153,7 +980,6 @@ onShow(() => {
uni.$off("selCoupon");
uni.$on("selCoupon", function (data) {
console.log("selCoupon", data);
orderInfoAfterRef.value.dataprocessing(_.cloneDeep(data));
cartStore.setCoupons(_.cloneDeep(data));
});
});
@@ -1161,6 +987,7 @@ let options = {};
// 跳转到加菜页面
function toJiacai() {
console.log("跳转到加菜页面");
back();
return;
uni.navigateTo({
@@ -1200,6 +1027,7 @@ const navTitle = computed(() => {
//支付成功后的处理
function paySucessCallback() {
console.log("paySucessCallback");
showDrainage.value = true;
}
@@ -1208,6 +1036,8 @@ const drainageConfig = ref({});
//私域引流弹窗
const showDrainage = ref(false);
async function init(opt) {
await storeuser.actionsproductqueryProduct();
console.log("init");
cartStore.clearOrderConfig();
Object.assign(options, opt);
@@ -1216,7 +1046,6 @@ async function init(opt) {
if (options.shopId) {
// 每次进来全局更新shopId
uni.cache.set("shopId", options.shopId, 30);
uni.$on("returnData", handleReturnData);
}
//如果已经生成订单,根据历史订信息设置相关配置
if (options.orderId) {
@@ -1242,7 +1071,6 @@ async function init(opt) {
}
await cartStore.goodsInit();
// * 获取会员信息
await storeuser.actionsproductqueryProduct();
await nextTick();
orderVIP.value = uni.cache.get("orderVIP");
@@ -1257,6 +1085,78 @@ async function init(opt) {
onLoad((opt) => {
init(opt);
});
watch(
() => cartStore.orderCostSummary.orderOriginFinalPayAmount,
(newval) => {
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 (rechargeItem.value.id) {
arr.add("余额支付");
}
if (!orderVIP.value.amount) {
arr.add("余额支付");
}
if (
orderVIP.value.amount < cartStore.orderCostSummary.orderOriginFinalPayAmount
) {
arr.add("余额支付");
}
if (cartStore.orderCostSummary.orderOriginFinalPayAmount <= 0) {
arr.add("微信支付");
}
return Array.from(arr);
});
</script>
<style lang="scss">