|
|
@@ -35,59 +35,66 @@
|
|
|
</template>
|
|
|
<!-- 表格操作 -->
|
|
|
<template #operation="scope">
|
|
|
+ <!-- 上架按钮 -->
|
|
|
<el-button
|
|
|
+ v-if="canShowButton(scope.row.status, currentOperationPermissions.上架)"
|
|
|
link
|
|
|
type="primary"
|
|
|
- @click="changeTypes(scope.row, 1)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.上架)"
|
|
|
+ @click="changeTypes(scope.row, isVoucher ? 1 : 5)"
|
|
|
>
|
|
|
上架
|
|
|
</el-button>
|
|
|
+ <!-- 下架按钮 -->
|
|
|
<el-button
|
|
|
+ v-if="canShowButton(scope.row.status, currentOperationPermissions.下架)"
|
|
|
link
|
|
|
type="primary"
|
|
|
@click="changeTypes(scope.row, 6)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.下架)"
|
|
|
>
|
|
|
下架
|
|
|
</el-button>
|
|
|
+ <!-- 修改库存按钮 -->
|
|
|
<el-button
|
|
|
+ v-if="canShowButton(scope.row.status, currentOperationPermissions.修改库存)"
|
|
|
link
|
|
|
type="primary"
|
|
|
@click="changeInventory(scope.row)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.修改库存)"
|
|
|
>
|
|
|
修改库存
|
|
|
</el-button>
|
|
|
+ <!-- 查看拒绝原因按钮(仅代金券) -->
|
|
|
<el-button
|
|
|
+ v-if="isVoucher && canShowButton(scope.row.status, VOUCHER_OPERATION_PERMISSIONS.查看拒绝原因)"
|
|
|
link
|
|
|
type="primary"
|
|
|
@click="viewRejectReason(scope.row)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.查看拒绝原因)"
|
|
|
>
|
|
|
查看拒绝原因
|
|
|
</el-button>
|
|
|
+ <!-- 查看详情按钮 -->
|
|
|
<el-button
|
|
|
- type="primary"
|
|
|
+ v-if="canShowButton(scope.row.status, currentOperationPermissions.查看详情) && (isCoupon || scope.row.dataType != 1)"
|
|
|
link
|
|
|
+ type="primary"
|
|
|
@click="toDetail(scope.row)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.查看详情) && scope.row.dataType != 1"
|
|
|
>
|
|
|
查看详情
|
|
|
</el-button>
|
|
|
+ <!-- 编辑按钮 -->
|
|
|
<el-button
|
|
|
+ v-if="canShowButton(scope.row.status, currentOperationPermissions.编辑) || (isVoucher && scope.row.dataType == 1)"
|
|
|
link
|
|
|
type="primary"
|
|
|
@click="editRow(scope.row)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.编辑) || scope.row.dataType == 1"
|
|
|
>
|
|
|
编辑
|
|
|
</el-button>
|
|
|
+ <!-- 删除按钮 -->
|
|
|
<el-button
|
|
|
+ v-if="canShowButton(scope.row.status, currentOperationPermissions.删除) || (isVoucher && scope.row.dataType == 1)"
|
|
|
link
|
|
|
type="primary"
|
|
|
@click="deleteRow(scope.row)"
|
|
|
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.删除) || scope.row.dataType == 1"
|
|
|
>
|
|
|
删除
|
|
|
</el-button>
|
|
|
@@ -138,14 +145,20 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="tsx" name="voucherManagement">
|
|
|
-import { computed, onActivated, onMounted, reactive, ref, watch } from "vue";
|
|
|
+import { computed, onActivated, onMounted, reactive, ref } from "vue";
|
|
|
import { useRouter } from "vue-router";
|
|
|
import type { FormInstance, FormRules } from "element-plus";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
import ProTable from "@/components/ProTable/index.vue";
|
|
|
import { ColumnProps, ProTableInstance } from "@/components/ProTable/interface";
|
|
|
import { Plus } from "@element-plus/icons-vue";
|
|
|
-import { delThaliById, getThaliList, updateNum, updateStatus } from "@/api/modules/voucherManagement";
|
|
|
+import {
|
|
|
+ delThaliById as delVoucherById,
|
|
|
+ getThaliList,
|
|
|
+ updateNum,
|
|
|
+ updateStatus as updateVoucherStatus
|
|
|
+} from "@/api/modules/voucherManagement";
|
|
|
+import { delThaliById as delCouponById, updateStatus as updateCouponStatus } from "@/api/modules/couponManagement";
|
|
|
import { ElMessageBox } from "element-plus/es";
|
|
|
import { localGet, usePermission } from "@/utils";
|
|
|
|
|
|
@@ -157,7 +170,6 @@ const formInventory: any = ref({
|
|
|
singleQty: "",
|
|
|
newInventory: ""
|
|
|
});
|
|
|
-const rowData = ref<any>();
|
|
|
const activeName = ref("1");
|
|
|
// 查看拒绝原因弹窗相关
|
|
|
const rejectReasonDialogVisible = ref(false);
|
|
|
@@ -241,12 +253,7 @@ const voucherColumns = reactive<ColumnProps<any>[]>([
|
|
|
},
|
|
|
{
|
|
|
prop: "status",
|
|
|
- label: "状态"
|
|
|
- },
|
|
|
- {
|
|
|
- prop: "reviewType",
|
|
|
- label: "审核状态",
|
|
|
- isShow: false,
|
|
|
+ label: "状态",
|
|
|
search: {
|
|
|
el: "select",
|
|
|
props: { placeholder: "请选择" }
|
|
|
@@ -286,18 +293,13 @@ const couponColumns = reactive<ColumnProps<any>[]>([
|
|
|
},
|
|
|
{
|
|
|
prop: "status",
|
|
|
- label: "状态"
|
|
|
- },
|
|
|
- {
|
|
|
- prop: "reviewType",
|
|
|
- label: "审核状态",
|
|
|
- isShow: false,
|
|
|
+ label: "状态",
|
|
|
search: {
|
|
|
el: "select",
|
|
|
props: { placeholder: "请选择" }
|
|
|
},
|
|
|
enum: statusEnum,
|
|
|
- fieldNames: { label: "label", value: "name" }
|
|
|
+ fieldNames: { label: "label", value: "value" }
|
|
|
},
|
|
|
{ prop: "operation", label: "操作", fixed: "right", width: 330 }
|
|
|
]);
|
|
|
@@ -324,8 +326,8 @@ const STATUS = {
|
|
|
已结束: 7
|
|
|
} as const;
|
|
|
|
|
|
-// 操作按钮权限配置:定义每个操作按钮在哪些状态下显示
|
|
|
-const OPERATION_PERMISSIONS = {
|
|
|
+// 代金券操作按钮权限配置:定义每个操作按钮在哪些状态下显示
|
|
|
+const VOUCHER_OPERATION_PERMISSIONS = {
|
|
|
// 查看详情:待审核、未开始、审核拒绝、进行中、已售罄、已下架
|
|
|
查看详情: [STATUS.待审核, STATUS.未开始, STATUS.审核拒绝, STATUS.进行中, STATUS.已售罄, STATUS.已下架],
|
|
|
// 上架:未开始、已下架
|
|
|
@@ -342,11 +344,38 @@ const OPERATION_PERMISSIONS = {
|
|
|
查看拒绝原因: [STATUS.审核拒绝]
|
|
|
} as const;
|
|
|
|
|
|
+// 优惠券操作按钮权限配置
|
|
|
+const COUPON_OPERATION_PERMISSIONS = {
|
|
|
+ // 查看详情:草稿、未开始、进行中、已下架、已结束、已售罄
|
|
|
+ 查看详情: [STATUS.草稿, STATUS.未开始, STATUS.进行中, STATUS.已下架, STATUS.已结束, STATUS.已售罄],
|
|
|
+ // 上架:未开始、已下架
|
|
|
+ 上架: [STATUS.未开始, STATUS.已下架],
|
|
|
+ // 下架:进行中
|
|
|
+ 下架: [STATUS.进行中],
|
|
|
+ // 修改库存:未开始、进行中、已售罄
|
|
|
+ 修改库存: [STATUS.未开始, STATUS.进行中, STATUS.已售罄],
|
|
|
+ // 编辑:草稿、未开始、进行中、已下架、已结束、已售罄
|
|
|
+ 编辑: [STATUS.草稿, STATUS.未开始, STATUS.进行中, STATUS.已下架, STATUS.已结束, STATUS.已售罄],
|
|
|
+ // 删除:草稿、已结束、已售罄
|
|
|
+ 删除: [STATUS.草稿, STATUS.已结束, STATUS.已售罄]
|
|
|
+} as const;
|
|
|
+
|
|
|
// 判断按钮是否显示的工具函数
|
|
|
const canShowButton = (status: number, allowedStatuses: readonly number[]) => {
|
|
|
return allowedStatuses.includes(status);
|
|
|
};
|
|
|
|
|
|
+// 根据当前tab获取操作权限配置
|
|
|
+const currentOperationPermissions = computed(() => {
|
|
|
+ return activeName.value === "1" ? VOUCHER_OPERATION_PERMISSIONS : COUPON_OPERATION_PERMISSIONS;
|
|
|
+});
|
|
|
+
|
|
|
+// 判断是否为代金券
|
|
|
+const isVoucher = computed(() => activeName.value === "1");
|
|
|
+
|
|
|
+// 判断是否为优惠券
|
|
|
+const isCoupon = computed(() => activeName.value === "2");
|
|
|
+
|
|
|
// 获取状态标签
|
|
|
const getStatusLabel = (status: number) => {
|
|
|
const statusMap: Record<number, string> = {
|
|
|
@@ -375,24 +404,7 @@ const getReviewStatusLabel = (reviewType: string | number) => {
|
|
|
return reviewStatusMap[String(reviewType)] || "";
|
|
|
};
|
|
|
|
|
|
-// 获取当前审核状态
|
|
|
-const currentAuditStatus = computed(() => {
|
|
|
- if (!proTable.value?.searchParam) return "";
|
|
|
- return proTable.value.searchParam.reviewType || "";
|
|
|
-});
|
|
|
-
|
|
|
-// 根据审核状态过滤 tabOptions:如果审核状态为空,只显示草稿;审核通过时,显示除草稿外的所有标签页
|
|
|
-const filteredTabOptions = computed(() => {
|
|
|
- const status = currentAuditStatus.value;
|
|
|
- if (!status) {
|
|
|
- return allTabOptions;
|
|
|
- } else if (status == "1") {
|
|
|
- // 审核通过时,显示除草稿外的所有标签页
|
|
|
- return allTabOptions.filter(tab => tab.name != "0");
|
|
|
- }
|
|
|
- return [];
|
|
|
-});
|
|
|
-
|
|
|
+// 数据类型:1-草稿,0-已发布,2-全部
|
|
|
const dataType = computed(() => {
|
|
|
if (!activeName.value) return 2;
|
|
|
return activeName.value === "0" ? 1 : 0;
|
|
|
@@ -441,74 +453,102 @@ const newCoupon = () => {
|
|
|
router.push(`/ticketManagement/newCoupon?type=add`);
|
|
|
};
|
|
|
// 跳转详情页 - 根据类型跳转不同页面
|
|
|
-const toDetail = row => {
|
|
|
- if (activeName.value === "1") {
|
|
|
- // 代金券跳转到代金券详情页
|
|
|
- router.push(`/ticketManagement/detail?id=${row.id}`);
|
|
|
- } else {
|
|
|
- // 优惠券跳转到优惠券详情页
|
|
|
- router.push(`/couponManagement/detail?id=${row.id}`);
|
|
|
- }
|
|
|
+const toDetail = (row: any) => {
|
|
|
+ const path = isVoucher.value ? `/ticketManagement/detail?id=${row.id}` : `/ticketManagement/couponDetail?id=${row.id}`;
|
|
|
+ router.push(path);
|
|
|
};
|
|
|
-const editRow = row => {
|
|
|
- if (activeName.value === "1") {
|
|
|
- // 代金券编辑
|
|
|
- router.push(`/ticketManagement/newVoucher?id=${row.id}&type=edit`);
|
|
|
- } else {
|
|
|
- // 优惠券编辑
|
|
|
- router.push(`/ticketManagement/newCoupon?id=${row.id}&type=edit`);
|
|
|
- }
|
|
|
+// 编辑行数据
|
|
|
+const editRow = (row: any) => {
|
|
|
+ const path = isVoucher.value
|
|
|
+ ? `/ticketManagement/newVoucher?id=${row.id}&type=edit`
|
|
|
+ : `/ticketManagement/newCoupon?id=${row.id}&type=edit`;
|
|
|
+ router.push(path);
|
|
|
};
|
|
|
-const deleteRow = row => {
|
|
|
+// 删除行数据
|
|
|
+const deleteRow = (row: any) => {
|
|
|
ElMessageBox.confirm("确定要删除吗?", "提示", {
|
|
|
confirmButtonText: "确定",
|
|
|
cancelButtonText: "取消",
|
|
|
type: "warning"
|
|
|
- }).then(() => {
|
|
|
- const params = {
|
|
|
- id: row.id,
|
|
|
- groupType: localGet("businessSection")
|
|
|
- };
|
|
|
- delThaliById(params).then(() => {
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ if (isVoucher.value) {
|
|
|
+ // 代金券删除逻辑
|
|
|
+ const params = {
|
|
|
+ id: row.id,
|
|
|
+ groupType: localGet("businessSection")
|
|
|
+ };
|
|
|
+ return delVoucherById(params);
|
|
|
+ } else {
|
|
|
+ // 优惠券删除逻辑
|
|
|
+ const params = {
|
|
|
+ id: row.id,
|
|
|
+ groupType: localGet("businessSection")
|
|
|
+ };
|
|
|
+ return delCouponById(params);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
ElMessage.success("删除成功");
|
|
|
proTable.value?.getTableList();
|
|
|
+ })
|
|
|
+ .catch(() => {
|
|
|
+ // 用户取消删除,不做任何操作
|
|
|
});
|
|
|
- });
|
|
|
};
|
|
|
+// Tab切换处理
|
|
|
const handleClick = () => {
|
|
|
- // tab切换时刷新表格
|
|
|
proTable.value?.getTableList();
|
|
|
};
|
|
|
-const changeTypes = async (row, status) => {
|
|
|
- rowData.value = row;
|
|
|
- let res = await updateStatus({ id: row.id, status: status, approvalComments: "" });
|
|
|
- if (res && res.code == 200) {
|
|
|
- ElMessage.success("操作成功");
|
|
|
- proTable.value?.getTableList();
|
|
|
+
|
|
|
+// 修改状态(上架/下架)
|
|
|
+const changeTypes = async (row: any, status: number) => {
|
|
|
+ if (isVoucher.value) {
|
|
|
+ // 代金券上架/下架逻辑
|
|
|
+ const res = await updateVoucherStatus({ id: row.id, status: status, approvalComments: "" });
|
|
|
+ if (res && res.code == 200) {
|
|
|
+ ElMessage.success("操作成功");
|
|
|
+ proTable.value?.getTableList();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 优惠券上架/下架逻辑
|
|
|
+ const res = await updateCouponStatus({ id: row.id, status: status, approvalComments: "" });
|
|
|
+ if (res && res.code == 200) {
|
|
|
+ ElMessage.success("操作成功");
|
|
|
+ proTable.value?.getTableList();
|
|
|
+ }
|
|
|
}
|
|
|
};
|
|
|
+// 修改库存
|
|
|
const changeInventory = (row: any) => {
|
|
|
- formInventory.value.id = row.id;
|
|
|
- formInventory.value.name = row.name;
|
|
|
- formInventory.value.singleQty = row.singleQty;
|
|
|
- formInventory.value.newInventory = "";
|
|
|
+ formInventory.value = {
|
|
|
+ id: row.id,
|
|
|
+ name: row.name,
|
|
|
+ singleQty: row.singleQty,
|
|
|
+ newInventory: ""
|
|
|
+ };
|
|
|
dialogFormVisible.value = true;
|
|
|
};
|
|
|
-// 弹窗提交
|
|
|
+
|
|
|
+// 提交修改库存
|
|
|
const handleSubmit = async () => {
|
|
|
if (!ruleFormRef.value) return;
|
|
|
- await ruleFormRef.value.validate(async (valid, fields) => {
|
|
|
+ await ruleFormRef.value.validate(async valid => {
|
|
|
if (valid) {
|
|
|
- let res = await updateNum({ id: formInventory.value.id, singleQty: formInventory.value.newInventory });
|
|
|
+ const res = await updateNum({
|
|
|
+ id: formInventory.value.id,
|
|
|
+ singleQty: formInventory.value.newInventory
|
|
|
+ });
|
|
|
if (res && res.code == 200) {
|
|
|
ElMessage.success("修改成功");
|
|
|
- dialogFormVisible.value = false;
|
|
|
+ closeDialog();
|
|
|
proTable.value?.getTableList();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
-// 关闭弹窗;
|
|
|
+
|
|
|
+// 关闭弹窗
|
|
|
const closeDialog = () => {
|
|
|
dialogFormVisible.value = false;
|
|
|
formInventory.value = {
|