|
|
@@ -1,279 +0,0 @@
|
|
|
-<script setup lang="ts">
|
|
|
-import {computed, ref} from "vue";
|
|
|
-import {createCoupons, getCouponGroups, getCoupons, receiveCouponGroup} from "../../api/coupon.ts";
|
|
|
-import {userInfo} from "../../api/user.ts";
|
|
|
-
|
|
|
-const role = sessionStorage.getItem("role")
|
|
|
-const myCouponList = ref()
|
|
|
-const receiveCouponList = ref()
|
|
|
-const type = ref()
|
|
|
-const satisfaction = ref('')
|
|
|
-const minus = ref('')
|
|
|
-const rest = ref('')
|
|
|
-const storeName = ref()
|
|
|
-
|
|
|
-userInfo().then(res => {
|
|
|
- storeName.value = res.result.storeName
|
|
|
-})
|
|
|
-
|
|
|
-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);
|
|
|
- } else if (type.value === 'SPECIAL') {
|
|
|
- return !(hasTypeInput.value && hasRestInput.value);
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
-})
|
|
|
-
|
|
|
-const couponDialogVisible = ref(false)
|
|
|
-
|
|
|
-function toCreateCoupon() {
|
|
|
- couponDialogVisible.value = true
|
|
|
-}
|
|
|
-
|
|
|
-function handleCloseCouponDialog() {
|
|
|
- type.value = null
|
|
|
- satisfaction.value = ''
|
|
|
- minus.value = ''
|
|
|
- rest.value = ''
|
|
|
- couponDialogVisible.value = false
|
|
|
-}
|
|
|
-
|
|
|
-function handleCreateCoupon() {
|
|
|
- const payload = {
|
|
|
- type: type.value,
|
|
|
- satisfaction: satisfaction.value,
|
|
|
- minus: minus.value,
|
|
|
- rest: rest.value
|
|
|
- }
|
|
|
- couponDialogVisible.value = false
|
|
|
- createCoupons(payload).then(res => {
|
|
|
- if (res.code === '000') {
|
|
|
- ElMessage({
|
|
|
- message: '创建优惠券成功!',
|
|
|
- type: 'success',
|
|
|
- center: true,
|
|
|
- })
|
|
|
- getReceiveCouponList()
|
|
|
- type.value = ''
|
|
|
- satisfaction.value = null
|
|
|
- minus.value = null
|
|
|
- rest.value = null
|
|
|
- } else if (res.code === '400') {
|
|
|
- ElMessage({
|
|
|
- message: res.msg,
|
|
|
- type: 'error',
|
|
|
- center: true,
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-
|
|
|
-getCoupons().then(res => {
|
|
|
- myCouponList.value = res.result
|
|
|
-})
|
|
|
-
|
|
|
-getCouponGroups().then(res => {
|
|
|
- receiveCouponList.value = res.result
|
|
|
-})
|
|
|
-
|
|
|
-function parseType(type) {
|
|
|
- if (type === "FULL_REDUCTION") {
|
|
|
- return "满减"
|
|
|
- } else if (type === "SPECIAL") {
|
|
|
- return "折扣"
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function parseNull(value) {
|
|
|
- if (value === null) {
|
|
|
- return "/"
|
|
|
- } else {
|
|
|
- return value
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function receiveCoupon(couponGroupId) {
|
|
|
- receiveCouponGroup(couponGroupId).then(res => {
|
|
|
- if (res.code === '000') {
|
|
|
- ElMessage({
|
|
|
- message: '获取优惠券成功!',
|
|
|
- type: 'success',
|
|
|
- center: true,
|
|
|
- })
|
|
|
- getMyCouponList()
|
|
|
- getReceiveCouponList()
|
|
|
- } else if (res.code === '400') {
|
|
|
- ElMessage({
|
|
|
- message: res.msg,
|
|
|
- type: 'error',
|
|
|
- center: true,
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
-}
|
|
|
-</script>
|
|
|
-
|
|
|
-
|
|
|
-<template>
|
|
|
- <div>
|
|
|
- <el-button @click="toCreateCoupon()" v-if="role === 'MANAGER' || role === 'STAFF'"
|
|
|
- class="create-coupon-button" type="primary" plain>
|
|
|
- 新增优惠券
|
|
|
- </el-button>
|
|
|
-
|
|
|
- <el-dialog v-model="couponDialogVisible" title="创建优惠券" :before-close="handleCloseCouponDialog">
|
|
|
- <el-form label-width="100px" class="create-coupon-form">
|
|
|
- <el-form-item label="应用范围:">
|
|
|
- <span v-if="role === 'MANAGER'">全平台</span>
|
|
|
- <span v-if="role === 'STAFF'">{{ storeName }}</span>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="类型:" for="type">
|
|
|
- <el-select id="identity"
|
|
|
- v-model="type"
|
|
|
- placeholder="请选择"
|
|
|
- >
|
|
|
- <el-option value="FULL_REDUCTION" label="满减"/>
|
|
|
- <el-option value="SPECIAL" label="折扣"/>
|
|
|
- </el-select>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="满:" for="satisfaction" v-if="type === 'FULL_REDUCTION'">
|
|
|
- <el-input id="satisfaction" v-model="satisfaction"
|
|
|
- required placeholder="请输入金额" class="create-coupon-dialog-input">
|
|
|
- <template #append>元</template>
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-form-item label="减:" for="minus" v-if="type === 'FULL_REDUCTION'">
|
|
|
- <el-input id="minus" v-model="minus" required placeholder="请输入金额"
|
|
|
- class="create-coupon-dialog-input">
|
|
|
- <template #append>元</template>
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-alert v-if="type === 'SPECIAL'"
|
|
|
- title="“蓝鲸券”使用规则:" type="success" :closable="false" class="special-alert">
|
|
|
- * 0-100元区间打九五折;<br>
|
|
|
- * 200-300元区间打八五折;<br>
|
|
|
- * 300-400元区间打八折;<br>
|
|
|
- * 400-500元区间打七五折;<br>
|
|
|
- * 500元以上区间打七折。<br>
|
|
|
- </el-alert>
|
|
|
-
|
|
|
- <el-form-item label="数量:" for="rest">
|
|
|
- <el-input id="rest" v-model="rest" required placeholder="请输入数量"
|
|
|
- class="create-coupon-dialog-input">
|
|
|
- <template #append>张</template>
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
-
|
|
|
- <el-button @click.prevent="handleCreateCoupon()" :disabled="createCouponDisabled"
|
|
|
- type="primary" plain>
|
|
|
- 创建
|
|
|
- </el-button>
|
|
|
-
|
|
|
- </el-form>
|
|
|
- </el-dialog>
|
|
|
-
|
|
|
- <div class="all-coupon-main">
|
|
|
- <div v-if="role === 'CUSTOMER'">
|
|
|
- <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"/>
|
|
|
- <el-table-column prop="type" label="类型" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ parseType(scope.row.type) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="satisfaction" label="满(元)" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ parseNull(scope.row.satisfaction) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="minus" label="减(元)" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ parseNull(scope.row.minus) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="used" label="状态" width="180">
|
|
|
- <template #default="scope">
|
|
|
- <el-tag v-if="scope.row.used === false" type="success">待使用</el-tag>
|
|
|
- <el-tag v-if="scope.row.used === true" type="info">已使用</el-tag>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- </div>
|
|
|
-
|
|
|
- <div>
|
|
|
- <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">
|
|
|
- <el-table-column type="index" width="50"/>
|
|
|
- <el-table-column prop="storeName" label="所属商店" width="180"/>
|
|
|
- <el-table-column prop="type" label="类型" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ parseType(scope.row.type) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="satisfaction" label="满(元)" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ parseNull(scope.row.satisfaction) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="minus" label="减(元)" width="180">
|
|
|
- <template #default="scope">
|
|
|
- {{ parseNull(scope.row.minus) }}
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column prop="rest" label="剩余数量(张)" width="180"/>
|
|
|
- <el-table-column label="操作" v-if="role === 'CUSTOMER'">
|
|
|
- <template #default="scope">
|
|
|
- <el-button @click="receiveCoupon(scope.row.id)" type="primary" plain>领取</el-button>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
-</template>
|
|
|
-
|
|
|
-
|
|
|
-<style scoped>
|
|
|
-.create-coupon-button {
|
|
|
- width: 100px;
|
|
|
- margin-left: 20px;
|
|
|
- margin-top: 30px;
|
|
|
-}
|
|
|
-
|
|
|
-.create-coupon-form {
|
|
|
- width: 60%;
|
|
|
-}
|
|
|
-
|
|
|
-.special-alert {
|
|
|
- margin-bottom: 15px;
|
|
|
-}
|
|
|
-
|
|
|
-.all-coupon-main {
|
|
|
- margin-left: 20px;
|
|
|
- margin-top: 20px;
|
|
|
-}
|
|
|
-
|
|
|
-.this-title {
|
|
|
- font-size: large;
|
|
|
- margin-bottom: 20px;
|
|
|
-}
|
|
|
-
|
|
|
-.coupon-table {
|
|
|
- margin-bottom: 30px;
|
|
|
-}
|
|
|
-</style>
|