优惠卷和商品卷

This commit is contained in:
wwz
2025-03-10 16:33:43 +08:00
parent 70edc6756d
commit 5342133cbd
30 changed files with 2820 additions and 3338 deletions

View File

@@ -3,9 +3,8 @@
<view class="headStatus"
v-if="listinfo.status == 'unpaid' || listinfo.status == 'paying'||listinfo.status=='closed'">
<view class="status">
<u-icon name="checkmark-circle-fill" color="#03C061" size="46"></u-icon>
<up-icon name="checkmark-circle-fill" color="#03C061" size="23"></up-icon>
<view class="statusName" v-if="listinfo.status == 'unpaid' || listinfo.status == 'paying'">
<!-- {{listinfo.registerType == 'munchies'?'待支付':'下单成功'}} -->
待支付
</view>
<view class="statusName" v-if="listinfo.status=='closed'">已完成</view>
@@ -33,11 +32,10 @@
</view>
<!-- 先下单后支付 -->
<!-- <orderInfoAfter ref="orderInfoAfterRef" :amountVIP="amountVIP" :rechargeFreeChecked="rechargeFreeChecked"
:freeCheck="freeCheck" :listinfo="listinfo" @setPayAmount="setPayAmount"
v-if="listinfo.useType == 'dine-in-after'"></orderInfoAfter> -->
<orderInfoAfter ref="orderInfoAfterRef" :rechargeFreeChecked="rechargeFreeChecked" :freeCheck="freeCheck"
:listinfo="listinfo"></orderInfoAfter>
:listinfo="listinfo" :orderVIP="orderVIP" :ordershopUserInfo='ordershopUserInfo' @istype="istype">
</orderInfoAfter>
<!-- 先支付后下单 -->
<!-- <orderInfoBefore ref="orderInfoBefore" :listinfo="listinfo" v-else></orderInfoBefore> -->
<!-- 充值免单 -->
@@ -48,7 +46,7 @@
ref="rechargeFree"
:freeDisabled="freeDisabled"
:payAmount="listinfo.payAmount"
:freeDingConfig="listinfo.freeDingConfig" :shopUserInfo="amountVIP" @changeFree="changeFree"></rechargeFree>
:freeDingConfig="listinfo.freeDingConfig" :shopUserInfo="orderVIP" @changeFree="changeFree"></rechargeFree>
</block>
<block v-else>
<rechargeFree
@@ -57,42 +55,33 @@
ref="rechargeFree"
:freeDisabled="freeDisabled"
:payAmount="listinfo.payAmount"
:freeDingConfig="listinfo.freeDingConfig" :shopUserInfo="amountVIP" @changeFree="changeFree"></rechargeFree>
:freeDingConfig="listinfo.freeDingConfig" :shopUserInfo="orderVIP" @changeFree="changeFree"></rechargeFree>
</block>
<paymentMethod ref="paymentMethod" :rechargeFreeChecked="rechargeFreeChecked" v-if="amountVIP&&listinfo.status == 'unpaid' || listinfo.status == 'paying'" :freeCheck="freeCheck" :payAmount="listinfo.payAmount" :amountVIP="amountVIP" @groupChange="groupChange"></paymentMethod>
-->
</block> -->
<!-- 支付方式 -->
<paymentMethodes ref="paymentMethodref" :orderVIP="orderVIP" @groupChange="groupChange">
</paymentMethodes>
<!-- <paymentMethodes ref="paymentMethodes" :rechargeFreeChecked="rechargeFreeChecked"
v-if="orderVIP&&listinfo.status == 'unpaid' || listinfo.status == 'paying'" :freeCheck="freeCheck"
:payAmount="listinfo.payAmount" :orderVIP="orderVIP" @groupChange="groupChange"></paymentMethodes> -->
<view class="fixedview">
<view class="flex-between" v-if="listinfo.status == 'unpaid' || listinfo.status == 'paying'">
<view class="flex-between" v-if="listinfo.status == 'unpaid'">
<view class="fixedview_one flex-start">
<view class="fixedview_oneone"> 实付金额 </view>
<view class="fixedview_onetow">
<text>¥</text>{{listinfo.payAmount}}
<text>¥</text>{{listinfo.totalCost}}
</view>
</view>
<view class="fixedview_tow" @tap="$u.debounce(goToPay,1000)">
{{11}}
{{paymentmethod.paymentBtnText}}
</view>
</view>
</view>
<view style="width: 100%;height: 200rpx;"> </view>
<u-popup :show="ispws" :round="20" mode="bottom" @close="payClose" height="500" :safeAreaInsetBottom="false">
<view class="pay-info-wrap">
<view class="info-wrap flex-between">
<view class="close" @click="payClose">
<u-icon name="close" color="#999999" size="40"></u-icon>
</view>
<text class="title">请输入支付密码</text>
<view></view>
</view>
<view class="info-content">
<payPasswordtwo ref="payPwd" :payAmount="listinfo.payAmount" @accountPayevent="accountPayevent"
v-if="ispws"></payPasswordtwo>
</view>
</view>
</u-popup>
<payPassword :isShow="ispws" @inputComplete="accountPayevent" @close="ispws = false" />
</view>
</template>
@@ -100,7 +89,9 @@
import {
ref,
reactive,
onMounted
onMounted,
onUnmounted,
watchEffect
} from 'vue';
import {
@@ -108,6 +99,7 @@
} from '@/common/api/order/index.js'
import {
APIusershopInfodetail,
APIshopUserInfo
} from '@/common/api/member.js'
@@ -117,24 +109,30 @@
const cartStore = useCartStore()
// import payPasswordtwo from '@/components/payPasswordtwo.vue'
// 结账管理
import {
Memberpay
} from '@/stores/pay.js';
const storeMemberpay = Memberpay();
import payPassword from '@/components/payPassword.vue'
import orderInfoAfter from './components/orderInfoAfter.vue'
// import orderInfoBefore from '../components/orderInfoBefore.vue'
// import rechargeFree from '../components/rechargeFree.vue'
// import paymentMethod from '../components/paymentMethod.vue'
import paymentMethodes from '@/components/paymentMethod.vue'; //支付方式
// 输入支付密码
const ispws = ref(false)
// 支付方式切换
const paymentmethod = reactive({
radiovalue: 1,
paymentBtnText: "余额支付",
payType: ''
// 商品订单会员
const ordershopUserInfo = ref({
isTableFee: 0
})
// 是否显示商家二维码信息
try {
const shopQrcode = uni.cache.get('shopInfo').shopQrcode
const shopQrcode = ref(uni.cache.get('shopInfo').shopQrcode)
} catch (error) {
//TODO handle the exception
}
@@ -144,117 +142,87 @@
// 订单详情
const listinfo = reactive({
})
const listinfoId = ref('')
// 会员信息?
const amountVIP = reactive({})
//优惠卷信息
const couopnInfo = reactive({
combinedArray: {},
Productroll: 0,
coupondiscountAmount: "",
couponInfoList: ''
})
const freeDisabled = ref(false)
// 会员信息
const orderVIP = ref()
//判断是否是打包商品
const is_type = ref(0)
//打包商品切换
const istype = (newValue) => {
is_type.value = newValue;
};
//积分
const freeCheck = ref(false)
const rechargeFreeChecked = ref(false)
// * 获取订单详情接口
const orderorderInfo = async () => {
let res = await APIgetOrderById({
orderId: orderId.value
})
console.log(res)
if (res) {
Object.assign(listinfo, res);
console.log(listinfo)
if (listinfo.couponInfoList) {
listinfo.couponInfoList = JSON.parse(listinfo.couponInfoList)
}
// this.listinfoId = res.data.orderId;
// this.shopId = res.data.shopId;
// if (listinfo.useType == " ") {
// //堂食先付费
// }
// if (listinfo.freeDingConfig && listinfo.payAmount < listinfo.freeDingConfig
// .rechargeThreshold) {
// this.freeDisabled = true
// }
// console.log(listinfo)
// if (listinfo.useType == "dine-in-after") {
// console.log(this.$refs.orderInfoAfterRef)
// this.$nextTick(() => {
// this.$refs.orderInfoAfterRef.childOnShow();
// })
// }
// this.getAount();
}
}
const setPayAmount = (data) => {
console.log(data)
listinfo.payAmount = data.payAmount
this.couopnInfo = data;
this.freeDisabled = data.freeDisabled
this.freeCheck = data.freeCheck
if (listinfo.freeDingConfig && listinfo.payAmount < listinfo.freeDingConfig
.rechargeThreshold) {
this.freeDisabled = true
} else {
this.freeDisabled = false
}
}
// * 免单状态监听
const changeFree = (val) => {
// this.freeCheck = val;
this.rechargeFreeChecked = !val
if (this.rechargeFreeChecked) {
if (this.couopnInfo) {
if (this.couopnInfo.isPointsChecked) {
listinfo.payAmount = (Number(listinfo.payAmount) + (this.couopnInfo
.calcUsablePointsData.pointsNum / this.couopnInfo.calcUsablePointsData
.equivalentPoints)).toFixed(2);
}
let couponList = this.couopnInfo.userCouponInfos.filter(v => v.type == 1);
if (couponList.length > 0) {
listinfo.payAmount = (couponList.length > 0 ? Number(listinfo.payAmount) +
couponList[0].discountAmount : listinfo.payAmount)
}
let productList = this.couopnInfo.userCouponInfos.filter(v => v.type == 2);
if (productList.length > 0) {
productList.map(item => {
listinfo.payAmount = Number(listinfo.payAmount) + item.discountAmount
if (listinfo.status == 'unpaid') {
try {
let res = await APIhistoryOrder({
orderId: orderId.value
})
}
} catch (error) {}
// if (listinfo.couponInfoList) {
// listinfo.couponInfoList = JSON.parse(listinfo.couponInfoList)
// }
}
listinfo.payAmount = (listinfo.payAmount * listinfo.freeDingConfig.rechargeTimes)
.toFixed(2)
} else {
listinfo.payAmount = (listinfo.payAmount / listinfo.freeDingConfig.rechargeTimes)
.toFixed(2)
if (this.couopnInfo) {
this.couopnInfo.isPointsChecked = false;
let couponList = this.couopnInfo.userCouponInfos.filter(v => v.type == 1);
if (couponList.length > 0) {
listinfo.payAmount = (couponList.length > 0 ? Number(listinfo.payAmount) -
couponList[0].discountAmount : listinfo.payAmount)
}
let productList = this.couopnInfo.userCouponInfos.filter(v => v.type == 2);
if (productList.length > 0) {
productList.map(item => {
listinfo.payAmount = Number(listinfo.payAmount) - item.discountAmount
})
}
// 历史订单
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
setTimeout(async () => {
listinfo.packFee = await cartStore.getTotalPackFee(listinfo.combinedArray)
// 计算购物车商品费用
listinfo.totalPrices = await cartStore.getTotalTotalPrices(listinfo.combinedArray)
// 餐位费listinfo.seatNum
listinfo.Seatcharge = await cartStore.getTotalSeatcharge(listinfo.seatNum)
})
}
}
}
// 监听价格算法
watchEffect(async () => {
if (listinfo.combinedArray.length > 0) {
//总价格
console.log(listinfo.combinedArray, listinfo.packFee, listinfo.totalPrices, listinfo.Seatcharge,
listinfo.Productroll, listinfo.coupondiscountAmount)
// 打包费packFee 计算购物车商品费用totalPrices 餐位费Seatcharge
let sum = (is_type.value != 0 ? listinfo.packFee : 0) + listinfo.totalPrices + (is_type.value ==
0 ? listinfo.Seatcharge : 0);
listinfo.originAmount = Math.round(sum * 100) / 100;
// 打包费packFee 计算购物车商品费用totalPrices 餐位费Seatcharge 商品卷Productroll 优惠卷coupondiscountAmount
let sums = (is_type.value != 0 ? listinfo.packFee : 0) + listinfo.totalPrices + (is_type.value ==
0 ? listinfo.Seatcharge : 0) - (listinfo.Productroll || 0) - (listinfo
.coupondiscountAmount || 0);
listinfo.totalCost = Math.round(sums * 100) / 100;
console.log(listinfo.totalCost)
// totalCost.value = Math.round(sums * 100) / 100;
}
});
const saveImage = (url) => {
uni.saveImage({
url: url,
@@ -267,22 +235,17 @@
});
}
// * 获取会员信息
const getAount = async () => {
let res = await this.api.shopUserInfo({
"shopId": listinfo.shopId,
"userId": uni.cache.get('userInfo').id,
})
if (res.code == 0) {
console.log("会员信息===", res)
this.amountVIP = res.data;
}
}
// 支付方式切换
const paymentmethod = reactive({
radiovalue: 1,
paymentBtnText: "余额支付",
payType: ''
})
// * 获取会员信息
const groupChange = async (e) => {
this.radiovalue = e.type;
this.paymentBtnText = e.name;
paymentmethod.radiovalue = e.type;
paymentmethod.paymentBtnText = e.name;
paymentmethod.payType = e.payType;
}
// * 去充值
@@ -292,250 +255,83 @@
})
}
// 操作下单时候
const orderInfoAfterRef = ref(null)
// 商品卷的id储存
const uniqueIds = ref([])
// 这是优惠卷传的值
const handleReturnData = async (data) => {
console.log(data)
// 这是优惠卷
if (data.typeOrder == 1) {
// 优惠卷减去的金额
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))]
// 商品卷总价价格
listinfo.Productroll = await cartStore.getTotalProductroll(data)
let res = {
Productroll: listinfo.Productroll,
uniqueIds: uniqueIds.value.length
}
orderInfoAfterRef.value.dataprocessing(res)
}
};
// * 去支付
const goToPay = async () => {
if ((this.radiovalue == 2 || this.radiovalue == 3) && listinfo.payAmount <= 0) {
uni.showToast({
title: "支付金额必须大于0",
icon: 'none'
})
return;
// 余额支付
if (paymentmethod.payType == '') {
ispws.value = true
return false
}
if (this.couopnInfo) {
let params = {
shopId: listinfo.shopId,
orderId: listinfo.orderId,
userCouponInfos: this.couopnInfo.userCouponInfos,
}
if (this.couopnInfo.isPointsChecked && this.couopnInfo.calcUsablePointsData.pointsNum && this
.couopnInfo.calcUsablePointsData.pointsNum > 0) {
params.pointsNum = this.couopnInfo.calcUsablePointsData.pointsNum;
}
let res = await this.api.useCoupon(params)
let checkOrderPay = {
orderId: orderId.value,
vipPrice: orderVIP.value.isVip == 1 && ordershopUserInfo.value.isMemberPrice == 1 ? 1 :
0, //是否使用会员价0否1是
allPack: is_type.value == 0 ? 0 : 1, //是否整单打包
seatNum: is_type.value == 0 ? listinfo.seatNum : 0, //用餐人数
originAmount: listinfo.originAmount, //订单原金额(包含打包费+餐位费) 不含折扣价格
discountRatio: 1, //折扣比例(计算时 向上取整保留 两位小数) 写死1
discountAmount: 0, //手动优惠金额 写死0
productCouponDiscountAmount: listinfo.Productroll, //商品优惠券抵扣金额
fullCouponDiscountAmount: listinfo.coupondiscountAmount, //满减优惠券抵扣金额
couponList: uniqueIds.value, //用户使用的卡券
orderAmount: listinfo.totalCost, // 最中订单金额
roundAmount: 0, //抹零金额 减免多少钱
pointsDiscountAmount: 0, //积分抵扣金额(tb_points_basic_setting表)
pointsNum: 0, //(扣除各类折扣 enable_deduction后使用)
remark: '', //用户备注
}
if (this.radiovalue == 2 || this.radiovalue == 3) {
this.wechatPay() //微信支付
} else {
// 先判断是否设置支付密码。0是没设置。没设置的情况下跳转到设置页面。有的话输入支付密码
// console.log(isPwd,'是否设置了支付密码')
if (this.amountVIP.isVip == 0) { //非会员情况
this.goRecharge();
} else {
if (uni.cache.get('userInfo').isPwd == 0) {
uni.navigateTo({
url: '/pages/member/setPassword?shopUserInfo=' + JSON.stringify(this.amountVIP)
})
} else {
uni.hideLoading()
// this.payPasswordShow = false;
this.ispws = true
}
}
}
}
// * 取消支付
const payClose = async () => {
this.ispws = false;
console.log(2)
uni.showToast({
icon: 'none',
title: '取消支付'
let res = await storeMemberpay.actionsltPayOrder({
checkOrderPay,
payType: paymentmethod.payType,
buyerRemark: '',
returnUrl: ''
})
setTimeout(res => {
uni.switchTab({
url: '/pages/order/order'
});
}, 500)
if (res) {
await orderorderInfo()
// uni.redirectTo({
// url: '/order/detail?orderId=' + res.id
// });
}
}
// * 余额支付
// 余额支付
const accountPayevent = async (pwd) => {
this.ispws = false;
let res = await this.api.accountPay({
orderId: this.listinfoId,
memberId: this.amountVIP.id,
pwd: pwd
})
if (res.code == 0) {
// data ->1 支付成功
// ->2 余额不足
// ->3 未设置支付密码,
// ->4 不是会员,
if (res.data == 1) {
uni.showToast({
title: "支付成功",
icon: 'none'
})
let _this = this
uni.requestSubscribeMessage({
tmplIds: ["z0fUG7-jhSfYCrw6poOvSRzh4_hgnPkm_5C7E5s5bCQ",
"AV-KybUHaK3KtFVLqpy6PHccHBS7XeX__mOM4RbufnQ"
],
complete() {
uni.redirectTo({
url: '/pagesOrder/order_detail/index?orderId=' + _this.listinfoId
});
},
})
} else if (res.data == 2) {
uni.showToast({
title: "余额不足",
icon: 'none'
})
setTimeout(() => {
// 去充值
this.goRecharge()
}, 1500)
} else if (res.data == 3) {
uni.showToast({
title: "未设置支付密码",
icon: 'none'
})
setTimeout(() => {
uni.navigateTo({
url: '/pages/member/setPassword?shopUserInfo=' + JSON.stringify(this
.amountVIP)
})
}, 1500)
} else if (res.data == 4) {
uni.showToast({
title: "非会员请充值",
icon: 'none'
})
setTimeout(() => {
// 去充值
this.goRecharge()
}, 1500)
}
}
console.log('输入的密码是:', pwd);
ispws.value = false;
}
/**
* 微信支付
*/
const wechatPay = async () => {
let res;
console.log(this.rechargeFreeChecked)
if (!this.rechargeFreeChecked) {
res = await this.api.orderPay({
orderId: orderId.value,
// #ifdef MP-WEIXIN
payType: 'wechatPay',
// #endif
// #ifdef MP-ALIPAY
payType: 'aliPay',
// #endif
// payType: this.radiovalue == 2 ? 'wechatPay' : 'aliPay'
}) //判断是否支付成功
} else {
console.log(listinfo.payAmount)
res = await this.api.paymemeberIn({
shopId: listinfo.shopId,
amount: listinfo.payAmount,
orderId: orderId.value,
// #ifdef MP-WEIXIN
payType: 'wechatPay',
// #endif
// #ifdef MP-ALIPAY
payType: 'aliPay',
// #endif
// payType: this.radiovalue == 2 ? 'wechatPay' : 'aliPay'
}) //判断是否支付成功
}
if (res.code == 0) {
uni.showLoading({
title: '加载中',
mask: true
})
uni.requestPayment({
// #ifdef MP-WEIXIN
provider: 'wxpay', //支付类型-固定值
partnerid: res.data.appId, // 微信支付商户号
timeStamp: res.data.timeStamp, // 时间戳(单位:秒)
nonceStr: res.data.nonceStr, // 随机字符串
package: res.data.package, // 固定值
signType: res.data.signType, //固定值
paySign: res.data.paySign, //签名
// #endif
// #ifdef MP-ALIPAY
provider: 'alipay', //支付类型-固定值
orderInfo: res.data.tradeNo, // 微信支付商户号
// #endif
success: (res) => {
let _this = this
uni.showToast({
title: "支付成功"
})
// #ifdef MP-WEIXIN
uni.requestSubscribeMessage({
tmplIds: ['z0fUG7-jhSfYCrw6poOvSRzh4_hgnPkm_5C7E5s5bCQ'],
complete() {
_this.paymodfiyOrderInfo()
setTimeout(res => {
uni.hideLoading()
uni.switchTab({
url: '/pages/order/order'
});
}, 500)
},
})
// #endif
// #ifdef MP-ALIPAY
_this.paymodfiyOrderInfo()
uni.switchTab({
url: '/pages/order/order'
});
// #endif
},
fail: async (err) => {
let res = await this.api.cancelOrderPay({
orderId: orderId.value,
}) //判断是否支付成功
uni.showToast({
icon: 'none',
title: '支付失败'
})
setTimeout(res => {
uni.hideLoading()
uni.switchTab({
url: '/pages/order/order'
});
}, 500)
}
});
}
}
// * 支付完成后请求
const paymodfiyOrderInfo = async () => {
let res = await this.api.paymodfiyOrderInfo({
orderId: listinfo.orderId,
})
}
// * 复制订单号
const copyHandle = async (e) => {
uni.setClipboardData({
data: e,
success() {
uni.showToast({
title: '复制成功',
icon: 'none'
});
}
});
}
onUnmounted(() => {
uni.$off('returnData', handleReturnData);
});
onMounted(async () => {
// 获取当前页面栈
@@ -545,16 +341,25 @@
// 获取页面参数
const options = currentPage.options;
orderId.value = options.orderId
let res = await APIshopUserInfo({
shopId: options.shopId
})
cartStore.shopInfo = res.shopInfo
orderorderInfo()
if (options.shopId) {
// 每次进来全局更新shopId
uni.cache.set('shopId', options.shopId, 30)
uni.$on('returnData', handleReturnData);
// * 获取会员信息
let res = await APIshopUserInfo({
shopId: options.shopId
})
uni.cache.set('orderVIP', res)
uni.cache.set('ordershopUserInfo', res.shopInfo)
orderVIP.value = res
ordershopUserInfo.value = res.shopInfo
}
await orderorderInfo()
})
</script>
<style scoped lang="scss">
::v-deep page {
<style lang="scss">
page {
background-color: #F7F7F7;
}