|
|
@@ -1,8 +1,9 @@
|
|
|
+<!--Lab4新增,全部优惠券界面-->
|
|
|
<script setup lang="ts">
|
|
|
-import {computed, ref} from "vue";
|
|
|
-import {createCoupons, getCouponGroups, getCoupons, receiveCouponGroup} from "../../api/coupon";
|
|
|
-import {userInfo} from "../../api/user";
|
|
|
-import {parseCouponType, parseOrderType} from "../../utils";
|
|
|
+import {computed, ref} from "vue"
|
|
|
+import {createCoupons, getCouponGroups, getCoupons, receiveCouponGroup} from "../../api/coupon"
|
|
|
+import {userInfo} from "../../api/user"
|
|
|
+import {parseCouponType} from "../../utils"
|
|
|
|
|
|
const role = sessionStorage.getItem("role")
|
|
|
const myCouponList = ref()
|
|
|
@@ -13,18 +14,13 @@ const minus = ref(undefined)
|
|
|
const rest = ref(undefined)
|
|
|
const storeName = ref()
|
|
|
|
|
|
+//从用户信息中获取到当前用户的店铺名(可能为空)
|
|
|
userInfo().then(res => {
|
|
|
storeName.value = res.data.result.storeName
|
|
|
})
|
|
|
|
|
|
-getMyCouponList()
|
|
|
getReceiveCouponList()
|
|
|
-
|
|
|
-function getMyCouponList() {
|
|
|
- getCoupons().then(res => {
|
|
|
- myCouponList.value = res.data.result
|
|
|
- })
|
|
|
-}
|
|
|
+getMyCouponList()
|
|
|
|
|
|
function getReceiveCouponList() {
|
|
|
getCouponGroups().then(res => {
|
|
|
@@ -32,11 +28,17 @@ function getReceiveCouponList() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+function getMyCouponList() {
|
|
|
+ getCoupons().then(res => {
|
|
|
+ myCouponList.value = res.data.result
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
const hasTypeInput = computed(() => type.value != null)
|
|
|
const hasSatisfactionInput = computed(() => satisfaction.value != '')
|
|
|
const hasMinusInput = computed(() => minus.value != '')
|
|
|
const hasRestInput = computed(() => rest.value != '')
|
|
|
-
|
|
|
+//确定创建优惠券按钮是否可用
|
|
|
const createCouponDisabled = computed(() => {
|
|
|
if (type.value === 'FULL_REDUCTION') {
|
|
|
return !(hasTypeInput.value && hasSatisfactionInput.value && hasMinusInput.value && hasRestInput.value);
|
|
|
@@ -49,10 +51,12 @@ const createCouponDisabled = computed(() => {
|
|
|
|
|
|
const couponDialogVisible = ref(false)
|
|
|
|
|
|
+//打开创建优惠券弹窗
|
|
|
function toCreateCoupon() {
|
|
|
couponDialogVisible.value = true
|
|
|
}
|
|
|
|
|
|
+//关闭创建优惠券弹窗,需要将这些参数都置为默认值
|
|
|
function handleCloseCouponDialog() {
|
|
|
type.value = null
|
|
|
satisfaction.value = undefined
|
|
|
@@ -61,6 +65,7 @@ function handleCloseCouponDialog() {
|
|
|
couponDialogVisible.value = false
|
|
|
}
|
|
|
|
|
|
+//确定创建优惠券
|
|
|
function handleCreateCoupon() {
|
|
|
const payload = {
|
|
|
type: type.value,
|
|
|
@@ -76,6 +81,7 @@ function handleCreateCoupon() {
|
|
|
type: 'success',
|
|
|
center: true,
|
|
|
})
|
|
|
+ //更新可获取优惠券列表
|
|
|
getReceiveCouponList()
|
|
|
type.value = ''
|
|
|
satisfaction.value = undefined
|
|
|
@@ -91,6 +97,7 @@ function handleCreateCoupon() {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+//顾客获取优惠券
|
|
|
function receiveCoupon(couponGroupId: number) {
|
|
|
receiveCouponGroup(couponGroupId).then(res => {
|
|
|
if (res.data.code === '000') {
|
|
|
@@ -99,7 +106,9 @@ function receiveCoupon(couponGroupId: number) {
|
|
|
type: 'success',
|
|
|
center: true,
|
|
|
})
|
|
|
+ //更新我的优惠券列表
|
|
|
getMyCouponList()
|
|
|
+ //更新可获取优惠券列表
|
|
|
getReceiveCouponList()
|
|
|
} else if (res.data.code === '400') {
|
|
|
ElMessage({
|
|
|
@@ -177,7 +186,7 @@ function receiveCoupon(couponGroupId: number) {
|
|
|
|
|
|
<div class="all-coupon-main">
|
|
|
<div>
|
|
|
- <span class="this-title" v-if="role === 'CUSTOMER'">可获取优惠券</span>
|
|
|
+ <span class="this-title" v-if="role === 'CUSTOMER'">可领优惠券(按发放时间排序)</span>
|
|
|
<span class="this-title" v-if="role === 'MANAGER'">全部优惠券</span>
|
|
|
<span class="this-title" v-if="role === 'STAFF'">门店下优惠券</span>
|
|
|
<el-table :data="receiveCouponList" stripe class="coupon-table">
|
|
|
@@ -216,7 +225,7 @@ function receiveCoupon(couponGroupId: number) {
|
|
|
</div>
|
|
|
|
|
|
<div v-if="role === 'CUSTOMER'">
|
|
|
- <span class="this-title">我的优惠券</span>
|
|
|
+ <span class="this-title">我的优惠券(按领取时间排序)</span>
|
|
|
<el-table :data="myCouponList" stripe class="coupon-table">
|
|
|
<el-table-column type="index" width="50"/>
|
|
|
<el-table-column prop="storeName" label="所属商店" width="180"/>
|