fix: 修改订单计算逻辑
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<el-switch v-model="isOpen" v-if="props.showSwitch" />
|
||||
<el-switch v-model="isOpen" active-value="1" inactive-value="0" v-if="props.showSwitch" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<el-form-item label="周期价格" required>
|
||||
<el-input v-model="form.price" placeholder="周期价格" type="number" />
|
||||
</el-form-item>
|
||||
<el-form-item label="赠送成长值" required>
|
||||
<el-form-item label="赠送成长值">
|
||||
<el-input v-model="form.reward" placeholder="开通后立刻获得经验" type="number" />
|
||||
</el-form-item>
|
||||
<el-form-item label="赠送优惠券">
|
||||
@@ -117,6 +117,9 @@ function submit() {
|
||||
ElMessage.error("请选择会员周期");
|
||||
return;
|
||||
}
|
||||
if (!form.value.circleUnit) {
|
||||
ElMessage.error("请选择会员周期单位");
|
||||
}
|
||||
const ispass = form.value.couponList.every((item) => item.num && item.coupon.id);
|
||||
if (!ispass) {
|
||||
ElMessage.error("请选择优惠券并输入数量");
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
intro="用户会员管理设置"
|
||||
icon="super_vip"
|
||||
showSwitch
|
||||
v-model:isOpen="isOpenSuperVip"
|
||||
v-model:isOpen="basicForm.isOpen"
|
||||
></HeaderCard>
|
||||
<el-tabs class="mt-4" v-model="activeTab" type="border-card">
|
||||
<el-tab-pane :label="item.label" v-for="item in configs" :key="item.name" :name="item.name">
|
||||
@@ -68,6 +68,10 @@
|
||||
style="margin-left: 20px"
|
||||
v-if="item.label != '绑定手机号' && item.checked"
|
||||
v-model="item.value"
|
||||
:step="item.step"
|
||||
:precision="item.precision || 0"
|
||||
:step-strictly="item.stepStrictly || false"
|
||||
:min="item.min || 0"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -96,8 +100,8 @@
|
||||
</el-form-item>
|
||||
<el-form-item label="享受会员价">
|
||||
<el-radio-group v-model="basicForm.isMemberPrice">
|
||||
<el-radio :value="1">所有支付方式</el-radio>
|
||||
<el-radio :value="0">仅余额支付</el-radio>
|
||||
<el-radio :value="1">是</el-radio>
|
||||
<el-radio :value="0">否</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="规则说明">
|
||||
@@ -113,23 +117,31 @@
|
||||
<h3>升级规则</h3>
|
||||
<el-form-item label="获取成长值升级">
|
||||
<div class="color-666">
|
||||
<div class="m-b-4">
|
||||
<span>每消费1元获得</span>
|
||||
<el-input-number
|
||||
class="m-x-2"
|
||||
v-model="basicForm.costReward"
|
||||
placeholder="请输入内容"
|
||||
/>
|
||||
<span>成长值</span>
|
||||
</div>
|
||||
<div>
|
||||
<span>每充值1元获得</span>
|
||||
<el-input-number
|
||||
class="m-x-2"
|
||||
v-model="basicForm.rechargeReward"
|
||||
placeholder="请输入内容"
|
||||
/>
|
||||
<span>成长值</span>
|
||||
<div class="flex">
|
||||
<div>
|
||||
<div class="m-b-4">
|
||||
<span>每消费1元获得</span>
|
||||
<el-input-number
|
||||
class="m-x-2"
|
||||
v-model="basicForm.costReward"
|
||||
placeholder="请输入内容"
|
||||
/>
|
||||
<span>成长值</span>
|
||||
</div>
|
||||
<div>
|
||||
<span>每充值1元获得</span>
|
||||
<el-input-number
|
||||
class="m-x-2"
|
||||
v-model="basicForm.rechargeReward"
|
||||
placeholder="请输入内容"
|
||||
/>
|
||||
<span>成长值</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span class="ml-4" style="color: red; font-size: 12px">
|
||||
*两个条件必选有一条是大于0的数值
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
@@ -152,6 +164,7 @@
|
||||
style="margin-top: 20px"
|
||||
@tab-remove="removeLevel"
|
||||
@tab-add="addLevel"
|
||||
@tab-change="levelTabChange"
|
||||
editable
|
||||
>
|
||||
<el-tab-pane
|
||||
@@ -162,7 +175,7 @@
|
||||
>
|
||||
<!-- 编辑会员等级参数 -->
|
||||
<el-form :model="level" label-width="150px">
|
||||
<el-form-item label="会员标题">
|
||||
<el-form-item label="会员标题" required>
|
||||
<el-input
|
||||
v-model="level.name"
|
||||
:style="inputStyle"
|
||||
@@ -170,18 +183,24 @@
|
||||
placeholder="请输入会员标题"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="所需成长值">
|
||||
<el-input
|
||||
<el-form-item label="所需成长值" required>
|
||||
<el-input-number
|
||||
:disabled="index == 0"
|
||||
v-model="level.experienceValue"
|
||||
type="number"
|
||||
placeholder="请输入所需成长值"
|
||||
:style="inputStyle"
|
||||
:min="levelExperienceValueMin(index, level)"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="会员折扣">
|
||||
<el-input
|
||||
<el-form-item label="会员折扣" required>
|
||||
<el-input-number
|
||||
v-model="level.discount"
|
||||
:style="inputStyle"
|
||||
:step="1"
|
||||
step-strictly
|
||||
:min="1"
|
||||
:max="100"
|
||||
type="number"
|
||||
placeholder="请输入会员折扣"
|
||||
/>
|
||||
@@ -210,8 +229,11 @@
|
||||
style="margin-top: 10px"
|
||||
class="color-666 flex"
|
||||
>
|
||||
<span class="no-wrap">每消耗</span>
|
||||
<el-input
|
||||
<span class="no-wrap">每消费</span>
|
||||
<el-input-number
|
||||
:min="0.01"
|
||||
:precision="2"
|
||||
:controls="false"
|
||||
class="m-x-2"
|
||||
v-model="level.costRewardPoints"
|
||||
type="number"
|
||||
@@ -221,16 +243,17 @@
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="等级说明">
|
||||
<el-form-item label="等级说明" required>
|
||||
<el-input
|
||||
v-model="level.remark"
|
||||
style="width: 400px"
|
||||
:maxlength="250"
|
||||
:autosize="{ minRows: 4, maxRows: 5 }"
|
||||
type="textarea"
|
||||
placeholder="请输入等级说明,最多 250 字"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="周期时间">
|
||||
<!-- <el-form-item label="周期时间">
|
||||
<div class="flex w-full gap-2">
|
||||
<el-input
|
||||
style="width: 140px"
|
||||
@@ -244,7 +267,7 @@
|
||||
<el-option label="年" value="年" />
|
||||
</el-select>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form-item> -->
|
||||
<el-form-item label="自动发放">
|
||||
<div>
|
||||
<el-switch
|
||||
@@ -257,7 +280,7 @@
|
||||
<el-radio :value="false">已禁用</el-radio>
|
||||
</el-radio-group> -->
|
||||
<div v-if="level.isCycleReward" style="margin-top: 10px">
|
||||
<!-- <div class="flex">
|
||||
<div class="flex">
|
||||
<span class="color-666 no-wrap mr-4">周期时间</span>
|
||||
<el-input
|
||||
v-model="level.cycleTime"
|
||||
@@ -269,10 +292,13 @@
|
||||
<el-option label="月" value="月" />
|
||||
<el-option label="年" value="年" />
|
||||
</el-select>
|
||||
</div> -->
|
||||
</div>
|
||||
<div class="flex mt-4">
|
||||
<span class="color-666 no-wrap mr-4">赠送积分</span>
|
||||
<el-input
|
||||
<el-input-number
|
||||
:step="1"
|
||||
step-strictly
|
||||
:min="1"
|
||||
v-model="level.cycleRewardPoints"
|
||||
type="number"
|
||||
placeholder="赠送积分"
|
||||
@@ -332,9 +358,6 @@ const inputStyle = {
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
//是否开启超级会员
|
||||
const isOpenSuperVip = ref(false);
|
||||
|
||||
const refDialogPlans = ref();
|
||||
const configs = [
|
||||
{ name: "basic", label: "会员基础设置" },
|
||||
@@ -344,9 +367,31 @@ const configs = [
|
||||
const activeTab = ref("basic");
|
||||
const conditionLists = ref([
|
||||
{ label: "绑定手机号", checked: false, code: "BIND_PHONE" },
|
||||
{ label: "订单达成指定次数", checked: false, value: "", code: "ORDER" },
|
||||
{ label: "消费达到指定金额", checked: false, value: "", code: "COST_AMOUNT" },
|
||||
{ label: "充值达到指定金额", checked: false, value: "", code: "RECHARGE_AMOUNT" },
|
||||
{
|
||||
label: "订单达成指定次数",
|
||||
checked: false,
|
||||
value: "",
|
||||
code: "ORDER",
|
||||
step: 1,
|
||||
stepStrictly: true,
|
||||
min: 1,
|
||||
},
|
||||
{
|
||||
label: "消费达到指定金额",
|
||||
checked: false,
|
||||
value: "",
|
||||
code: "COST_AMOUNT",
|
||||
precision: 2,
|
||||
min: 0.01,
|
||||
},
|
||||
{
|
||||
label: "充值达到指定金额",
|
||||
checked: false,
|
||||
value: "",
|
||||
code: "RECHARGE_AMOUNT",
|
||||
precision: 2,
|
||||
min: 0.01,
|
||||
},
|
||||
]);
|
||||
const basicForm = reactive({
|
||||
isSubmitInfo: 1,
|
||||
@@ -358,6 +403,7 @@ const basicForm = reactive({
|
||||
rechargeReward: 0,
|
||||
memberPriceShopIdList: [],
|
||||
isMemberPrice: 1,
|
||||
isOpen: 0,
|
||||
});
|
||||
function deletePlan(row) {
|
||||
const index = basicForm.configList.indexOf(row);
|
||||
@@ -384,6 +430,27 @@ function basicSubmit() {
|
||||
// if (data.openType == "CONDITION") {
|
||||
// data.configList = null;
|
||||
// }
|
||||
console.log(data);
|
||||
if (basicForm.openType == "PAY" && (!basicForm.configList || basicForm.configList.length <= 0)) {
|
||||
return ElMessage.error("请添加会员方案");
|
||||
}
|
||||
data.conditionList = conditionLists.value
|
||||
.filter((v) => v.checked)
|
||||
.map((v) => {
|
||||
return {
|
||||
code: v.code,
|
||||
value: v.value,
|
||||
};
|
||||
});
|
||||
if (
|
||||
basicForm.openType == "CONDITION" &&
|
||||
(!data.conditionList || data.conditionList.length <= 0)
|
||||
) {
|
||||
return ElMessage.error("请选择成为会员条件");
|
||||
}
|
||||
if (basicForm.costReward <= 0 && basicForm.rechargeReward <= 0) {
|
||||
return ElMessage.error("获取成长值升级规则两个条件必选有一条是大于0的数值");
|
||||
}
|
||||
data.conditionList = conditionLists.value
|
||||
.filter((v) => v.checked)
|
||||
.map((v) => {
|
||||
@@ -404,11 +471,6 @@ const levels = ref([]);
|
||||
// 当前选中的会员等级
|
||||
const selectedLevel = ref(null);
|
||||
|
||||
// 优惠券列表
|
||||
const couponList = ref([
|
||||
{ id: 1, name: "满100减10" },
|
||||
{ id: 2, name: "满200减30" },
|
||||
]);
|
||||
let activeLevelId = ref(null);
|
||||
// 添加会员等级
|
||||
function addLevel() {
|
||||
@@ -425,15 +487,16 @@ function addLevel() {
|
||||
const newLevel = {
|
||||
name,
|
||||
experienceValue: 0,
|
||||
discount: 1,
|
||||
discount: 100,
|
||||
logo: "",
|
||||
costRewardPoints: 1,
|
||||
isCostRewardPoints: 1,
|
||||
isCostRewardPoints: 0,
|
||||
isCycleReward: 0,
|
||||
cycleTime: 1,
|
||||
cycleUnit: "月",
|
||||
cycleRewardPoints: 1,
|
||||
cycleRewardCouponList: [],
|
||||
remark: "",
|
||||
};
|
||||
console.log(newLevel);
|
||||
levels.value.push(newLevel);
|
||||
@@ -476,10 +539,36 @@ async function removeLevel(index) {
|
||||
}
|
||||
// 保存会员等级
|
||||
async function saveLevel(level) {
|
||||
const isPass = level.cycleRewardCouponList.every((item) => item.num && item.coupon.id);
|
||||
if (!isPass) {
|
||||
ElMessage.error("请选择优惠券并输入数量");
|
||||
return;
|
||||
if (level.isCycleReward) {
|
||||
if (level.cycleRewardCouponList && level.cycleRewardCouponList.length) {
|
||||
const isPass = (level.cycleRewardCouponList || []).every(
|
||||
(item) => item.num && item.coupon.id
|
||||
);
|
||||
if (!isPass) {
|
||||
ElMessage.error("请选择优惠券并输入数量");
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (
|
||||
(!level.cycleRewardCouponList || level.cycleRewardCouponList.length <= 0) &&
|
||||
level.cycleRewardPoints <= 0
|
||||
) {
|
||||
ElMessage.error("赠送积分和送优惠券必须填充一项");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (level.name.trim() === "") {
|
||||
return ElMessage.error("请输入会员标题");
|
||||
}
|
||||
if (level.experienceValue === "") {
|
||||
return ElMessage.error("请输入所需成长值");
|
||||
}
|
||||
if (level.discount === "") {
|
||||
return ElMessage.error("请输入会员折扣");
|
||||
}
|
||||
if (level.remark.trim() === "") {
|
||||
return ElMessage.error("请输入等级说明");
|
||||
}
|
||||
const res = level.id ? await memberApi.levelEdit(level) : await memberApi.levelAdd(level);
|
||||
if (res) {
|
||||
@@ -509,6 +598,8 @@ async function init() {
|
||||
});
|
||||
memberApi.getConfig().then((res) => {
|
||||
Object.assign(basicForm, res);
|
||||
res.conditionList = res.conditionList || [];
|
||||
res.configList = res.configList || [];
|
||||
conditionLists.value = conditionLists.value.map((v) => {
|
||||
const findItem = res.conditionList.find((cond) => cond.code == v.code);
|
||||
if (findItem) {
|
||||
@@ -538,10 +629,19 @@ function totalCount(arr) {
|
||||
return total + item.num * 1;
|
||||
}, 0);
|
||||
}
|
||||
//
|
||||
function levelExperienceValueMin(index, level) {
|
||||
if (index == 0) {
|
||||
return 0;
|
||||
}
|
||||
return levels.value[index - 1].experienceValue + 1;
|
||||
}
|
||||
//返回
|
||||
function close() {
|
||||
router.back();
|
||||
}
|
||||
//
|
||||
function levelTabChange(index) {}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
@@ -206,9 +206,7 @@ const proGroupInfo = computed(() => {
|
||||
return [];
|
||||
}
|
||||
});
|
||||
const discountNewPrice = computed(() => {
|
||||
return 0;
|
||||
});
|
||||
|
||||
const vipAllPrice = computed(() => {
|
||||
const n = (props.item.memberPrice || props.item.salePrice) * props.item.number;
|
||||
return n;
|
||||
|
||||
@@ -255,9 +255,6 @@ function itemClick(item) {
|
||||
function changeNumber(step, item) {
|
||||
carts.changeNumber(step * 1, item);
|
||||
}
|
||||
// const totalMoney = computed(() => {
|
||||
// return (carts.payMoney * 1 + (carts.oldOrder.originAmount || 0) * 1).toFixed(2);
|
||||
// });
|
||||
|
||||
defineExpose({
|
||||
carts,
|
||||
|
||||
@@ -161,19 +161,25 @@
|
||||
<div class="order-info">
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">订单号:</span>
|
||||
|
||||
<span class="u-m-l-10 value">{{ orderInfo.orderNo }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">餐位费</span>
|
||||
<span class="u-m-l-10 value">¥{{ seatAmount }}</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.orderCostSummary.seatFee }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">打包费</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.packFee }}</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.orderCostSummary.packFee }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">商品订单金额</span>
|
||||
<span class="u-m-l-10 value">¥{{ carts.goodsTotal }}</span>
|
||||
<span class="u-m-l-10 value">
|
||||
¥{{
|
||||
carts.orderCostSummary.goodsOriginalAmount -
|
||||
carts.orderCostSummary.goodsDiscountAmount
|
||||
}}
|
||||
</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">商品优惠券</span>
|
||||
@@ -186,11 +192,13 @@
|
||||
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">整单改价</span>
|
||||
<span class="u-m-l-10 value color-red">-¥{{ discountAmount }}</span>
|
||||
<span class="u-m-l-10 value color-red">
|
||||
-¥{{ carts.orderCostSummary.merchantReduction.actualAmount }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">积分抵扣</span>
|
||||
<span class="u-m-l-10 value">-¥{{ pointsDiscountAmount }}</span>
|
||||
<span class="u-m-l-10 value">-¥{{ carts.orderCostSummary.pointDeductionAmount }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">抹零</span>
|
||||
@@ -198,11 +206,11 @@
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">总价(商品订单金额-商品优惠券-满减券-整单改价-积分抵扣)</span>
|
||||
<span class="u-m-l-10 value color-red">¥{{ totalMoney }}</span>
|
||||
<span class="u-m-l-10 value color-red">¥{{ totalPrice }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-m-b-10 u-row-between">
|
||||
<span class="title">应付金额(总价+客座费+打包费)</span>
|
||||
<span class="u-m-l-10 value price">¥{{ currentpayMoney }}</span>
|
||||
<span class="u-m-l-10 value price">¥{{ carts.orderCostSummary.finalPayAmount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -228,13 +236,12 @@
|
||||
|
||||
<script setup>
|
||||
import * as quanUtil from "../quan_util.js";
|
||||
|
||||
import { OrderPriceCalculator } from "@/utils/goods";
|
||||
import { useCartsStore } from "@/store/modules/carts";
|
||||
import { useUserStore } from "@/store/modules/user";
|
||||
import chooseGuaZahng from "./popup-choose-guazhang.vue";
|
||||
const shopUser = useUserStore();
|
||||
const carts = useCartsStore();
|
||||
|
||||
import popupCoupon from "./popup-coupon.vue";
|
||||
import PointsApi from "@/api/account/points";
|
||||
|
||||
@@ -244,7 +251,13 @@ import scanPay from "./scan-pay.vue";
|
||||
import discount from "./discount.vue";
|
||||
import { ElLoading } from "element-plus";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { BigNumber } from "bignumber.js";
|
||||
|
||||
// 配置BigNumber精度
|
||||
BigNumber.set({
|
||||
DECIMAL_PLACES: 2,
|
||||
ROUNDING_MODE: BigNumber.ROUND_DOWN, // 向下取整,符合业务需求
|
||||
});
|
||||
//挂账
|
||||
const refGuaZhang = ref();
|
||||
function refGuaZhangConfirm(guazhangRen) {
|
||||
@@ -312,17 +325,40 @@ function discountConfirm(e) {
|
||||
console.log(e);
|
||||
Object.assign(checkOrderPay, e);
|
||||
if (e.discount) {
|
||||
checkOrderPay.discountAmount = carts.goodsTotal - (carts.goodsTotal * (100 - e.discount)) / 100;
|
||||
carts.setMerchantDiscountReduction(e.discount);
|
||||
} else {
|
||||
carts.setMerchantFixedReduction(e.discountAmount);
|
||||
checkOrderPay.discount = 0;
|
||||
}
|
||||
|
||||
score.sel = -1;
|
||||
usePointsNumber.value = 0;
|
||||
}
|
||||
|
||||
//计算商家减免前金额
|
||||
function returnMerchantReductionDiscount() {
|
||||
const {
|
||||
goodsOriginalAmount, // 商品原价总和
|
||||
goodsDiscountAmount, // 减去商品折扣
|
||||
couponDeductionAmount, // 减去优惠券抵扣
|
||||
pointDeductionAmount, // 减去积分抵扣
|
||||
merchantReductionActualAmount, // 减去商家实际减免金额
|
||||
seatFee, // 加上餐位费(不参与减免)
|
||||
packFee, // 加上打包费(不参与减免)
|
||||
additionalFee,
|
||||
} = carts.orderCostSummary;
|
||||
const total =
|
||||
goodsOriginalAmount - // 商品原价总和
|
||||
goodsDiscountAmount - // 减去商品折扣
|
||||
couponDeductionAmount - // 减去优惠券抵扣
|
||||
pointDeductionAmount; // 减去积分抵扣
|
||||
|
||||
return total <= 0 ? 0 : total;
|
||||
}
|
||||
function discountShow(e) {
|
||||
refDiscount.value.open({
|
||||
amount: carts.goodsTotal - productCouponDiscountAmount.value,
|
||||
// amount: carts.goodsTotal - productCouponDiscountAmount.value,
|
||||
amount: returnMerchantReductionDiscount(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -392,17 +428,25 @@ watch(
|
||||
}
|
||||
);
|
||||
|
||||
// 返回积分抵扣前金额
|
||||
function returnPointsDiscountAmount() {
|
||||
const total = currentpayMoney.value * 1 + carts.orderCostSummary.pointDeductionAmount * 1;
|
||||
return total <= 0 ? 0 : total;
|
||||
}
|
||||
|
||||
async function pointsInit() {
|
||||
if (!props.user.id || score.sel == -1) {
|
||||
return;
|
||||
}
|
||||
const orderAmount = currentpayMoney.value * 1 + pointsDiscountAmount.value * 1;
|
||||
const res = await PointsApi.calcOrderUsablePoints({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: orderAmount <= 0 ? 0 : orderAmount,
|
||||
orderAmount: returnPointsDiscountAmount(),
|
||||
});
|
||||
pointsRes.value = res;
|
||||
carts.pointDeductionRule.pointsPerYuan = res.equivalentPoints;
|
||||
|
||||
usePointsNumber.value = res.usable ? res.maxUsablePoints : 0;
|
||||
carts.userPoints = usePointsNumber.value;
|
||||
if (res.usable) {
|
||||
pointsToMoney();
|
||||
} else {
|
||||
@@ -412,12 +456,20 @@ async function pointsInit() {
|
||||
}
|
||||
// 根据积分计算可抵扣金额
|
||||
async function pointsToMoney() {
|
||||
const res = await PointsApi.calcPointsToMoney({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: currentpayMoney.value * 1 + pointsDiscountAmount.value * 1,
|
||||
points: usePointsNumber.value,
|
||||
});
|
||||
pointsDiscountAmount.value = res;
|
||||
try {
|
||||
const res = await PointsApi.calcPointsToMoney({
|
||||
shopUserId: props.user.id,
|
||||
orderAmount: returnPointsDiscountAmount(),
|
||||
points: usePointsNumber.value,
|
||||
});
|
||||
if (!res) {
|
||||
score.sel = -1;
|
||||
return;
|
||||
}
|
||||
pointsDiscountAmount.value = res;
|
||||
} catch (e) {
|
||||
score.sel = -1;
|
||||
}
|
||||
}
|
||||
const emits = defineEmits(["chooseUser", "paysuccess"]);
|
||||
function chooseUser() {
|
||||
@@ -483,6 +535,8 @@ function returnPayParams() {
|
||||
originAmount: carts.payMoney * 1 + seatAmount.value * 1,
|
||||
discountAmount: discountAmount.value,
|
||||
productCouponDiscountAmount: productCouponDiscountAmount.value * 1,
|
||||
otherCouponDiscountAmount:
|
||||
carts.orderCostSummary.couponDeductionAmount - productCouponDiscountAmount.value * 1,
|
||||
orderAmount: currentpayMoney.value * 1,
|
||||
roundAmount: props.orderInfo.roundAmount,
|
||||
pointsDiscountAmount: pointsDiscountAmount.value * 1,
|
||||
@@ -616,19 +670,18 @@ const discountAmount = computed(() => {
|
||||
});
|
||||
//满减优惠券
|
||||
const fullCouponDiscountAmount = computed(() => {
|
||||
return quansSelArr.value
|
||||
.reduce((pre, cur) => {
|
||||
return pre + cur.discountAmount;
|
||||
}, 0)
|
||||
.toFixed(2);
|
||||
return (
|
||||
carts.orderCostSummary.fullCouponDeduction || props.orderInfo.fullCouponDiscountAmount || 0
|
||||
);
|
||||
});
|
||||
//商品券抵扣金额
|
||||
const productCouponDiscountAmount = computed(() => {
|
||||
let index = -1;
|
||||
return quansSelArr.value.reduce((pre, cur) => {
|
||||
index++;
|
||||
return pre + returnProDiscount(cur, index) * 1;
|
||||
}, 0);
|
||||
// 优先从 Store 扩展字段取,若无则用 props 数据(过渡方案)
|
||||
return (
|
||||
carts.orderCostSummary.productCouponDeduction ||
|
||||
props.orderInfo.productCouponDiscountAmount ||
|
||||
0
|
||||
);
|
||||
});
|
||||
//除开客座费,打包费总金额
|
||||
const totalMoney = computed(() => {
|
||||
@@ -640,9 +693,30 @@ const totalMoney = computed(() => {
|
||||
pointsDiscountAmount.value
|
||||
).toFixed(2);
|
||||
});
|
||||
|
||||
const totalPrice = computed(() => {
|
||||
// 使用bignumber.js处理高精度计算
|
||||
const originalAmount = new BigNumber(carts.orderCostSummary.goodsOriginalAmount);
|
||||
const discountAmount = new BigNumber(carts.orderCostSummary.goodsDiscountAmount);
|
||||
const couponDeduction = new BigNumber(carts.orderCostSummary.couponDeductionAmount);
|
||||
const merchantReduction = new BigNumber(carts.orderCostSummary.merchantReduction.actualAmount);
|
||||
const pointDeduction = new BigNumber(carts.orderCostSummary.pointDeductionAmount);
|
||||
|
||||
// 逐步计算:原价 - 商品折扣 - 优惠券 - 商家减免 - 积分抵扣
|
||||
const total = originalAmount
|
||||
.minus(discountAmount)
|
||||
.minus(couponDeduction)
|
||||
.minus(merchantReduction)
|
||||
.minus(pointDeduction)
|
||||
.decimalPlaces(2, BigNumber.ROUND_DOWN); // 保持与工具库一致的舍入策略
|
||||
|
||||
return total.toNumber();
|
||||
});
|
||||
|
||||
//应付金额
|
||||
const currentpayMoney = computed(() => {
|
||||
return (totalMoney.value * 1 + carts.packFee * 1 + seatAmount.value * 1).toFixed(2);
|
||||
return carts.orderCostSummary.finalPayAmount;
|
||||
// return (totalMoney.value * 1 + carts.packFee * 1 + seatAmount.value * 1).toFixed(2);
|
||||
});
|
||||
watch(
|
||||
() => currentpayMoney.value,
|
||||
|
||||
456
src/views/tool/Instead/components/popup-coupon-back.vue
Normal file
456
src/views/tool/Instead/components/popup-coupon-back.vue
Normal file
@@ -0,0 +1,456 @@
|
||||
<template>
|
||||
<el-dialog width="700px" :title="title" v-model="show" top="20px" @close="reset">
|
||||
<div class="u-p-15">
|
||||
<div class="">
|
||||
<el-tabs v-model="activeName" @tab-click="tabClick">
|
||||
<el-tab-pane label="优惠券(单选)" name="youhui">
|
||||
<el-table
|
||||
ref="refTable"
|
||||
empty-text="无可用优惠券"
|
||||
:data="quans.fullReductionCoupon"
|
||||
@cell-click="fullReductionCouponClick"
|
||||
>
|
||||
<el-table-column type="index" label="">
|
||||
<template v-slot="scope">
|
||||
<el-checkbox
|
||||
@change="fullReductionCouponClick(scope.row)"
|
||||
:model-value="scope.row.id == fullReductionCouponSel.id"
|
||||
></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column type="index" label="#"></el-table-column>
|
||||
<el-table-column prop="name" label="券名称"></el-table-column>
|
||||
<!-- <el-table-column label="券类型" width="80">
|
||||
<template v-slot="scope">
|
||||
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
<el-table-column prop="discountAmount" label="抵扣">
|
||||
<template v-slot="scope">
|
||||
<span class="color-red">¥{{ scope.row.discountAmount }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="discountAmount" label="限制" width="180">
|
||||
<template v-slot="scope">
|
||||
<div class="u-flex">
|
||||
<span>支付满</span>
|
||||
<span class="color-red no-wrap">
|
||||
{{ scope.row.fullAmount }}
|
||||
</span>
|
||||
<span>元可用</span>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="useRestrictions" label="描述"></el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="商品券(多选)" name="goods">
|
||||
<el-table
|
||||
ref="refTable1"
|
||||
empty-text="无可用商品券"
|
||||
:data="quans.productCoupon"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column width="80">
|
||||
<template v-slot="scope">
|
||||
<el-checkbox
|
||||
@change="productCouponClick($event, scope.row)"
|
||||
v-model="scope.row.checked"
|
||||
></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column type="index" width="50" label="#"></el-table-column>
|
||||
<el-table-column prop="name" label="券名称"></el-table-column>
|
||||
|
||||
<el-table-column label="商品信息" width="220">
|
||||
<template v-slot="scope">
|
||||
<div class="u-flex">
|
||||
<div class="u-flex">
|
||||
<el-image
|
||||
:src="scope.row.productImg"
|
||||
fit="cover"
|
||||
style="width: 40px; height: 40px"
|
||||
:preview-src-list="[scope.row.productImg]"
|
||||
></el-image>
|
||||
</div>
|
||||
<div class="u-p-l-10">
|
||||
<div class="">{{ scope.row.productName }}</div>
|
||||
<div class="">x{{ scope.row.num || 1 }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<!-- <el-table-column prop="discountAmount" label="抵扣">
|
||||
<template v-slot="scope">
|
||||
<span class="color-red">
|
||||
¥{{ scope.row.discountAmount }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
<!-- <el-table-column label="券类型">
|
||||
<template v-slot="scope">
|
||||
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
<el-table-column prop="useRestrictions" label="描述"></el-table-column>
|
||||
<!-- <el-table-column prop="useRestrictions" label="是否可用">
|
||||
<template v-slot="scope">
|
||||
{{ scope.row.use ? "可以" : "不可用" }}
|
||||
</template>
|
||||
</el-table-column> -->
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<div v-if="quansSelArr.length > 0">
|
||||
<div class="font-bold u-m-b-10">已选优惠券</div>
|
||||
<el-table empty-text="未选择优惠券" :data="quansSelArr">
|
||||
<el-table-column type="index" width="50" label="#"></el-table-column>
|
||||
<el-table-column prop="name" label="券名称"></el-table-column>
|
||||
<el-table-column label="券类型" width="80">
|
||||
<template v-slot="scope">
|
||||
{{ scope.row.type == 1 ? "优惠券" : "商品券" }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="商品信息" width="120">
|
||||
<template v-slot="scope">
|
||||
<div class="u-flex" v-if="scope.row.type == 2">
|
||||
<div class="u-flex">
|
||||
<el-image
|
||||
:src="scope.row.productImg"
|
||||
fit="cover"
|
||||
style="width: 40px; height: 40px"
|
||||
></el-image>
|
||||
</div>
|
||||
<div class="u-p-l-10">
|
||||
<div class="">{{ scope.row.productName }}</div>
|
||||
<div class="">x{{ scope.row.num || 1 }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="discountAmount" label="抵扣">
|
||||
<template v-slot="scope">
|
||||
<span class="color-red" v-if="scope.row.type == 1">
|
||||
¥{{ scope.row.discountAmount }}
|
||||
</span>
|
||||
<span class="color-red" v-if="scope.row.type == 2">
|
||||
¥{{ returnProDiscount(scope.row, scope.row.index) }}
|
||||
</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="useRestrictions" label="描述"></el-table-column>
|
||||
<el-table-column prop="useRestrictions" label="">
|
||||
<template v-slot="scope">
|
||||
<el-button type="danger" size="small" @click="delQuan(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<div class="u-flex u-row-between u-m-t-20">
|
||||
<div class="u-flex">
|
||||
<span>抵扣金额:</span>
|
||||
<span class="color-red">¥{{ AllCouponPrice }}</span>
|
||||
</div>
|
||||
<div class="u-flex u-relative">
|
||||
<span>支付金额:</span>
|
||||
<span class="color-red">¥{{ payPrice }}</span>
|
||||
<div
|
||||
class="u-absolute u-flex line-th color-999"
|
||||
style="right: 0; bottom: 100%"
|
||||
v-if="orderPrice * 1 != payPrice * 1"
|
||||
>
|
||||
<span class="">¥{{ orderPrice }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="u-flex u-row-center u-m-t-50">
|
||||
<el-button size="large" @click="close">取消</el-button>
|
||||
<el-button size="large" type="primary" @click="confirm">确定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script setup>
|
||||
import couponApi from "@/api/account/coupon";
|
||||
import { ElMessageBox } from "element-plus";
|
||||
import * as quanUtil from "../quan_util.js";
|
||||
const props = defineProps({
|
||||
title: {
|
||||
type: String,
|
||||
default: "选择优惠券",
|
||||
},
|
||||
goodsArr: {
|
||||
type: Array,
|
||||
default: [],
|
||||
},
|
||||
user: {
|
||||
type: Object,
|
||||
default: () => {
|
||||
return {
|
||||
isVip: false,
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
function tabClick() {}
|
||||
|
||||
const state = reactive({
|
||||
discount: 1,
|
||||
fullReductionCouponSel: {
|
||||
id: "",
|
||||
},
|
||||
quansSelArr: [],
|
||||
quans: {
|
||||
fullReductionCoupon: [],
|
||||
productCoupon: [],
|
||||
},
|
||||
currentRow: null,
|
||||
multipleSelection: null,
|
||||
fullReductionCouponSelId: "",
|
||||
activeName: "youhui",
|
||||
form: {},
|
||||
show: false,
|
||||
isSetProductCoup: false,
|
||||
});
|
||||
|
||||
const {
|
||||
discount,
|
||||
fullReductionCouponSel,
|
||||
quansSelArr,
|
||||
quans,
|
||||
currentRow,
|
||||
multipleSelection,
|
||||
activeName,
|
||||
form,
|
||||
show,
|
||||
isSetProductCoup,
|
||||
} = toRefs(state);
|
||||
|
||||
const refTable = ref();
|
||||
const refTable1 = ref();
|
||||
|
||||
let orderPrice = ref(0);
|
||||
let $originFullReductionCoupon = [];
|
||||
//可以抵扣的商品列表
|
||||
let canDikouGoodsArr = [];
|
||||
//商品数量从0到n每一个对应的价格
|
||||
let $goodsPayPriceMap = {};
|
||||
let goodsArr = [];
|
||||
|
||||
function open(money, orderInfo) {
|
||||
let arr = [];
|
||||
for (let i in orderInfo.detailMap) {
|
||||
arr.push(...orderInfo.detailMap[i]);
|
||||
}
|
||||
goodsArr = arr;
|
||||
$goodsPayPriceMap = quanUtil.returnGoodsPayPriceMap(goodsArr || []);
|
||||
canDikouGoodsArr = quanUtil.returnNewGoodsList(goodsArr);
|
||||
console.log(canDikouGoodsArr);
|
||||
getcoup();
|
||||
orderPrice.value = money;
|
||||
show.value = true;
|
||||
}
|
||||
|
||||
async function getcoup() {
|
||||
const res = await couponApi.findCoupon({ shopUserId: props.user.id });
|
||||
quans.value.fullReductionCoupon = res.filter(
|
||||
(v) => v.type == 1 && orderPrice.value * 1 >= v.fullAmount * 1
|
||||
);
|
||||
quans.value.productCoupon = res
|
||||
.filter((v) => v.type == 2 && canDikouGoodsArr.find((goods) => v.proId == goods.productId))
|
||||
.map((v) => {
|
||||
const findGoods = goodsArr.find((goods) => goods.productId == v.proId);
|
||||
return {
|
||||
...v,
|
||||
productImg: findGoods ? findGoods.productImg : "",
|
||||
productName: findGoods ? findGoods.productName : "",
|
||||
};
|
||||
});
|
||||
}
|
||||
function fullReductionCouponClick(row) {
|
||||
if (row.id == fullReductionCouponSel.value.id) {
|
||||
fullReductionCouponSel.value = { id: "" };
|
||||
quansSelArr.value.splice(0, 1);
|
||||
return;
|
||||
}
|
||||
const dikouQuan = quansSelArr.value[0];
|
||||
fullReductionCouponSel.value = row;
|
||||
if (dikouQuan && dikouQuan.type == 1) {
|
||||
quansSelArr.value[0] = row;
|
||||
} else {
|
||||
quansSelArr.value.unshift(row);
|
||||
}
|
||||
if (!fullReductionCouponSel.value.id) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
const AllCouponPrice = computed(() => {
|
||||
return quanUtil.returnCouponAllPrice(quansSelArr.value, canDikouGoodsArr, props.user);
|
||||
});
|
||||
|
||||
const payPrice = computed(() => {
|
||||
return (orderPrice.value - AllCouponPrice.value).toFixed(2);
|
||||
});
|
||||
function productCouponClick(checked, item) {
|
||||
console.log(checked);
|
||||
if (!item.use) {
|
||||
return;
|
||||
}
|
||||
const hasSelNum = quansSelArr.value
|
||||
.filter((v) => v.type == 2 && v.proId == item.proId)
|
||||
.reduce((a, b) => {
|
||||
return a + (b.num || 1);
|
||||
}, 0);
|
||||
console.log($goodsPayPriceMap[item.proId]);
|
||||
const maxSelNum = $goodsPayPriceMap[item.proId].length;
|
||||
const coupMaxUseNum = Math.min(item.num || 1, maxSelNum - hasSelNum);
|
||||
const canUseNum = Math.min(maxSelNum, coupMaxUseNum);
|
||||
console.log("maxSelNum", maxSelNum);
|
||||
console.log("coupMaxUseNum", coupMaxUseNum);
|
||||
console.log("canUseNum", canUseNum);
|
||||
if (checked && canUseNum <= 0) {
|
||||
ElMessage.error("购物车该商品券可使用最大数量为" + maxSelNum);
|
||||
setTimeout(() => {
|
||||
item.checked = !checked;
|
||||
}, 100);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fullReductionCouponSel.value.id && !item.checked) {
|
||||
const goodsQuan = quans.value.productCoupon.filter((v) => v.checked);
|
||||
const fullReductionCoupon = fullReductionCouponSel.value.id
|
||||
? [fullReductionCouponSel.value]
|
||||
: [];
|
||||
|
||||
let coupArr = [...goodsQuan, { ...item, num: canUseNum }];
|
||||
const payPrice =
|
||||
orderPrice.value - quanUtil.returnCouponAllPrice(coupArr, canDikouGoodsArr, props.user);
|
||||
console.log(payPrice);
|
||||
if (payPrice <= 0) {
|
||||
return ElMessageBox.confirm(
|
||||
"选择该商品券后支付金额将为0,继续选择将取消选择的满减券",
|
||||
"提示",
|
||||
{
|
||||
confirmButtonText: "继续选择",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
fullReductionCouponSel.value = {
|
||||
id: "",
|
||||
};
|
||||
quansSelArr.value.splice(0, 1);
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
if (fullReductionCouponSel.value.fullAmount > payPrice) {
|
||||
ElMessageBox.confirm(
|
||||
"选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券",
|
||||
"提示",
|
||||
{
|
||||
confirmButtonText: "继续选择",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning",
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
fullReductionCouponSel.value = {
|
||||
id: "",
|
||||
};
|
||||
})
|
||||
.catch(() => {
|
||||
item.checked = false;
|
||||
const index = quansSelArr.value.findIndex((v) => v.id == item.id);
|
||||
quansSelArr.value.splice(index, 1);
|
||||
});
|
||||
}
|
||||
}
|
||||
item.checked = checked;
|
||||
if (!item.checked) {
|
||||
const index = quansSelArr.value.findIndex((v) => v.id == item.id);
|
||||
quansSelArr.value.splice(index, 1);
|
||||
} else {
|
||||
quansSelArr.value.push({ ...item, num: canUseNum });
|
||||
}
|
||||
const CheckedArr = quans.value.productCoupon.filter((v) => v.checked);
|
||||
if (CheckedArr.length <= 0) {
|
||||
return quans.value.productCoupon.map((v) => {
|
||||
v.use = true;
|
||||
});
|
||||
}
|
||||
const noCheckedArr = quans.value.productCoupon.filter((v) => !v.checked);
|
||||
noCheckedArr.map((v) => {
|
||||
v.use = quanUtil.returnCoupCanUse(canDikouGoodsArr, v, CheckedArr);
|
||||
});
|
||||
}
|
||||
//返回商品券抵扣金额
|
||||
function returnProDiscount(row) {
|
||||
//相同商品抵扣券数组
|
||||
const arr = quansSelArr.value.filter((v) => v.type == 2 && v.proId == row.proId);
|
||||
const index = arr.findIndex((v) => v.id == row.id);
|
||||
const item = goodsArr.find((v) => v.productId == row.proId);
|
||||
if (index != -1) {
|
||||
const n = quanUtil.returnProductCoupAllPrice(
|
||||
$goodsPayPriceMap[row.proId],
|
||||
index,
|
||||
row.num,
|
||||
props.user.id && props.user.isVip
|
||||
);
|
||||
return n.toFixed(2);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
//删除选中的优惠券
|
||||
function delQuan(row) {
|
||||
const index = quansSelArr.value.findIndex((item) => item.id == row.id);
|
||||
if (row.type == 2 && index != -1) {
|
||||
quansSelArr.value.splice(index, 1);
|
||||
const proIndex = quans.value.productCoupon.findIndex((v) => v.id == row.id);
|
||||
quans.value.productCoupon[proIndex].checked = false;
|
||||
}
|
||||
if (row.type == 1 && index != -1) {
|
||||
fullReductionCouponSel.value = { id: "" };
|
||||
quansSelArr.value.splice(0, 1);
|
||||
}
|
||||
}
|
||||
function close() {
|
||||
show.value = false;
|
||||
}
|
||||
const emits = defineEmits(["confirm"]);
|
||||
function reset() {
|
||||
quansSelArr.value = [];
|
||||
fullReductionCouponSel.value = { id: "" };
|
||||
quans.value.productCoupon = [];
|
||||
}
|
||||
function confirm() {
|
||||
emits("confirm", [...quansSelArr.value], $goodsPayPriceMap, goodsArr);
|
||||
close();
|
||||
}
|
||||
defineExpose({
|
||||
close,
|
||||
open,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.line-th {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
.codeImg {
|
||||
width: 160px;
|
||||
border: 1px solid rgb(220, 223, 230);
|
||||
height: 160px;
|
||||
}
|
||||
:deep(.el-input .el-input__inner::-webkit-inner-spin-button) {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
:deep(.el-input .el-input__inner::-webkit-outer-spin-button) {
|
||||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
@@ -44,7 +44,7 @@
|
||||
<el-table-column prop="useRestrictions" label="描述"></el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="商品券(多选)" name="goods">
|
||||
<el-tab-pane label="商品券(单选)" name="goods">
|
||||
<el-table
|
||||
ref="refTable1"
|
||||
empty-text="无可用商品券"
|
||||
@@ -254,11 +254,18 @@ function open(money, orderInfo) {
|
||||
|
||||
async function getcoup() {
|
||||
const res = await couponApi.findCoupon({ shopUserId: props.user.id });
|
||||
console.log(res);
|
||||
quans.value.fullReductionCoupon = res.filter(
|
||||
(v) => v.type == 1 && orderPrice.value * 1 >= v.fullAmount * 1
|
||||
);
|
||||
quans.value.productCoupon = res
|
||||
.filter((v) => v.type == 2 && canDikouGoodsArr.find((goods) => v.proId == goods.productId))
|
||||
.filter((v) => {
|
||||
//是否抵扣全部商品
|
||||
const isDikouAll = v.useFoods.length === 0;
|
||||
//是否包含抵扣商品
|
||||
const isDikou = v.useFoods.some((v) => v.id == goods.value.id);
|
||||
return v.type == 2 && (isDikouAll || isDikou);
|
||||
})
|
||||
.map((v) => {
|
||||
const findGoods = goodsArr.find((goods) => goods.productId == v.proId);
|
||||
return {
|
||||
|
||||
@@ -882,6 +882,12 @@ watch(
|
||||
}
|
||||
}
|
||||
);
|
||||
watch(
|
||||
() => perpole.value,
|
||||
(newval) => {
|
||||
carts.seatFeeConfig.personCount = newval;
|
||||
}
|
||||
);
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
113
src/views/user/list/components/give-coupon.vue
Normal file
113
src/views/user/list/components/give-coupon.vue
Normal file
@@ -0,0 +1,113 @@
|
||||
<template>
|
||||
<div>
|
||||
<el-dialog title="赠送优惠券" v-model="show" @close="reset" width="400px">
|
||||
<el-form :model="form" label-width="120px">
|
||||
<el-form-item label="赠送用户">
|
||||
<div class="flex" v-if="user">
|
||||
<el-avatar :src="form.name" :size="60" shape="square" />
|
||||
<div class="ml-[18px]">
|
||||
<p class="text-size-lg">{{ user.nickName }}</p>
|
||||
<p class="color-999 mt-1">id:{{ user.userId }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号:">
|
||||
<span>{{ user.phone }}</span>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="选择优惠券" required>
|
||||
<el-select v-model="form.couponId" placeholder="请选择优惠券">
|
||||
<el-option
|
||||
v-for="coupon in couponList"
|
||||
:key="coupon.id"
|
||||
:label="coupon.title"
|
||||
:value="coupon.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="数量" required>
|
||||
<el-input-number
|
||||
style="width: 160px"
|
||||
v-model="form.num"
|
||||
:min="1"
|
||||
:step="1"
|
||||
placeholder="请输入数量"
|
||||
></el-input-number>
|
||||
<span class="ml-2">张</span>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div style="text-align: right; margin-top: 20px">
|
||||
<el-button @click="close">取消</el-button>
|
||||
<el-button type="primary" @click="submit">{{ isedit ? "更新" : "提交" }}</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import couponApi from "@/api/market/coupon";
|
||||
|
||||
import { ref, toRaw } from "vue";
|
||||
import { ElMessage } from "element-plus";
|
||||
// 控制主弹窗显示
|
||||
const show = ref(false);
|
||||
|
||||
// 表单数据
|
||||
const form = ref({
|
||||
userId: "",
|
||||
couponId: "",
|
||||
num: 1,
|
||||
});
|
||||
|
||||
// 优惠券列表
|
||||
const couponList = ref([]);
|
||||
|
||||
// 重置表单
|
||||
function reset() {
|
||||
form.value = {
|
||||
userId: "",
|
||||
couponId: "",
|
||||
num: 1,
|
||||
};
|
||||
}
|
||||
|
||||
const emits = defineEmits(["submitSuccess"]);
|
||||
// 提交表单
|
||||
function submit() {
|
||||
console.log("提交表单数据:", form.value);
|
||||
if (!form.value.couponId) {
|
||||
return ElMessage.error("请选择优惠券");
|
||||
}
|
||||
if (form.value.num <= 0) {
|
||||
return ElMessage.error("请输入数量");
|
||||
}
|
||||
couponApi.giveCoupon(form.value).then((res) => {
|
||||
if (res) {
|
||||
ElMessage.success("优惠券发放成功");
|
||||
emits("submitSuccess", form.value);
|
||||
close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const user = ref("");
|
||||
function open(data) {
|
||||
console.log("打开表单:", data);
|
||||
user.value = data;
|
||||
form.value.userId = data.userId;
|
||||
show.value = true;
|
||||
}
|
||||
function close() {
|
||||
show.value = false;
|
||||
reset();
|
||||
}
|
||||
defineExpose({ open, close, reset, submit });
|
||||
|
||||
onMounted(() => {
|
||||
couponApi.getList({ size: 999 }).then((res) => {
|
||||
if (res) {
|
||||
couponList.value = res.records || [];
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -47,14 +47,21 @@
|
||||
<el-table-column label="操作">
|
||||
<template #default="scope">
|
||||
<el-link :underline="false" type="primary" size="mini">查看</el-link>
|
||||
<el-button :underline="false" type="danger" size="mini">删除</el-button>
|
||||
<el-link
|
||||
:underline="false"
|
||||
type="danger"
|
||||
class="ml-4"
|
||||
@click="deleteCoupon(scope.row)"
|
||||
size="mini"
|
||||
>
|
||||
删除
|
||||
</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.currentPage"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
v-model:current-page="pagination.page"
|
||||
v-model:page-size="pagination.size"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@current-change="getList"
|
||||
@@ -82,11 +89,16 @@ const form = reactive({
|
||||
userId: "",
|
||||
page: 1,
|
||||
});
|
||||
|
||||
const tableData = ref([]);
|
||||
const pagination = reactive({
|
||||
total: 0,
|
||||
size: 10,
|
||||
page: 1,
|
||||
});
|
||||
function open(data) {
|
||||
console.log(data);
|
||||
data.userId = form.userId;
|
||||
form.page = 1;
|
||||
form.userId = data.userId;
|
||||
pagination.page = 1;
|
||||
visible.value = true;
|
||||
getList();
|
||||
}
|
||||
@@ -94,19 +106,25 @@ function close() {
|
||||
visible.value = false;
|
||||
}
|
||||
function getList() {
|
||||
couponApi.getDetail(form).then((res) => {
|
||||
couponApi.getDetail({ ...form, ...pagination }).then((res) => {
|
||||
console.log(res);
|
||||
tableData.value = res.records;
|
||||
pagination.total = res.totalRow;
|
||||
});
|
||||
}
|
||||
|
||||
const tableData = ref([]);
|
||||
const pagination = ref({
|
||||
total: 0,
|
||||
pageSize: 10,
|
||||
currentPage: 1,
|
||||
});
|
||||
function deleteCoupon(row) {
|
||||
couponApi
|
||||
.delete({
|
||||
id: row.id,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.code === 200) {
|
||||
ElMessage.success("删除成功");
|
||||
getList();
|
||||
}
|
||||
});
|
||||
}
|
||||
defineExpose({
|
||||
open,
|
||||
close,
|
||||
|
||||
@@ -106,6 +106,7 @@ const contentConfig: IContentConfig<any> = {
|
||||
options: [
|
||||
{ label: '增减余额', command: 'change-money' },
|
||||
{ label: '充值记录', command: 'charge-list' },
|
||||
{ label: '赠送券', command: 'give-coupon' },
|
||||
]
|
||||
},
|
||||
],
|
||||
|
||||
@@ -120,11 +120,14 @@
|
||||
|
||||
<!-- 用户优惠券详情 -->
|
||||
<UserCouponDialog ref="userCouponDialogRef"></UserCouponDialog>
|
||||
<!-- 赠送券 -->
|
||||
<GiveCoupon ref="GiveCouponRef"></GiveCoupon>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup >
|
||||
import UserCouponDialog from "./components/user-coupon-dialog.vue";
|
||||
import GiveCoupon from "./components/give-coupon.vue";
|
||||
import usePage from "@/components/CURD/usePage";
|
||||
import addModalConfig from "./config/add";
|
||||
import contentConfig from "./config/content";
|
||||
@@ -135,7 +138,7 @@ import { returnOptionsLabel } from "./config/config";
|
||||
import shopUserApi from "@/api/account/shopUser";
|
||||
const editMoneyModalRef = ref(null);
|
||||
const userCouponDialogRef = ref(null);
|
||||
|
||||
const GiveCouponRef = ref(null);
|
||||
//查看用户优惠券
|
||||
function handleViewCoupon(row) {
|
||||
userCouponDialogRef.value.open(row);
|
||||
@@ -214,6 +217,8 @@ function handleToolbarClick(name) {
|
||||
}
|
||||
}
|
||||
|
||||
// 赠送券
|
||||
function toGiveCoupon() {}
|
||||
// 其他操作列
|
||||
async function handleOperatClick(data) {
|
||||
const row = data.row;
|
||||
@@ -228,6 +233,10 @@ async function handleOperatClick(data) {
|
||||
toCharge({ userId: data.row.userId });
|
||||
return;
|
||||
}
|
||||
if (data.command === "give-coupon") {
|
||||
GiveCouponRef.value.open(row);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user