| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- <template>
- <div class="table-box">
- <ProTable ref="proTable" :columns="columns" :request-api="getTableList" :init-param="initParam" :data-callback="dataCallback">
- <!-- 表格 header 按钮 -->
- <template #tableHeader="scope">
- <div class="table-header-btn">
- <el-button :icon="Plus" class="button" type="primary" @click="newGroupBuying"> 新建团购 </el-button>
- <el-tabs v-if="showTabs" v-model="activeName" class="tabs" @tab-click="handleClick">
- <el-tab-pane v-for="tab in filteredTabOptions" :key="tab.name" :label="tab.label" :name="tab.name" />
- </el-tabs>
- </div>
- </template>
- <template #Information="scope">
- <div class="information">
- <el-image
- v-if="scope.row.imageValueStr"
- :src="scope.row.imageValueStr[0]"
- :preview-src-list="scope.row.imageValueStr"
- preview-teleported
- />
- <el-image v-else src="/src/assets/images/groupPackageManagement/aboutUsLogo.png" />
- <div class="information-right">
- <p>团购名称:{{ scope.row.groupName }}</p>
- <p>团购编号:{{ scope.row.groupNo }}</p>
- <p>结束时间:{{ scope.row.endTime }}</p>
- </div>
- </div>
- </template>
- <template #status="scope">
- <p>团购状态:{{ scope.row.statusName ?? "--" }}</p>
- <p>审核状态:{{ scope.row.reviewType ?? "--" }}</p>
- </template>
- <!-- 表格操作 -->
- <template #operation="scope">
- <el-button
- link
- type="primary"
- @click="changeTypes(scope.row, 'on')"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.上架)"
- >
- 上架
- </el-button>
- <el-button
- link
- type="primary"
- @click="changeTypes(scope.row, 'off')"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.下架)"
- >
- 下架
- </el-button>
- <el-button
- link
- type="primary"
- @click="changeInventory(scope.row)"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.修改库存)"
- >
- 修改库存
- </el-button>
- <el-button
- link
- type="primary"
- @click="viewRejectReason(scope.row)"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.查看拒绝原因)"
- >
- 查看拒绝原因
- </el-button>
- <el-button
- type="primary"
- link
- @click="toDetail(scope.row)"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.查看详情)"
- >
- 查看详情
- </el-button>
- <el-button
- link
- type="primary"
- @click="editRow(scope.row)"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.编辑)"
- >
- 编辑
- </el-button>
- <el-button
- link
- type="primary"
- @click="deleteRow(scope.row)"
- v-if="canShowButton(scope.row.status, OPERATION_PERMISSIONS.删除)"
- >
- 删除
- </el-button>
- </template>
- </ProTable>
- <el-dialog v-model="dialogFormVisible" title="修改库存" width="500">
- <el-form ref="ruleFormRef" :model="formInventory" :rules="rules" @submit.prevent>
- <el-form-item label="套餐名">
- {{ formInventory.groupName }}
- </el-form-item>
- <el-form-item label="剩余库存">
- {{ formInventory.inventoryNum }}
- </el-form-item>
- <el-form-item label="修改库存" prop="newInventory">
- <el-input v-model="formInventory.newInventory" placeholder="请输入库存数量" />
- </el-form-item>
- </el-form>
- <template #footer>
- <div class="dialog-footer">
- <el-button @click="closeDialog"> 取消 </el-button>
- <el-button type="primary" @click="handleSubmit"> 确定 </el-button>
- </div>
- </template>
- </el-dialog>
- <!-- 查看拒绝原因弹窗 -->
- <el-dialog v-model="rejectReasonDialogVisible" title="查看拒绝原因" width="600px">
- <div class="reject-reason-content">
- <div class="reject-reason-item">
- <div class="reject-reason-label">团购名称:</div>
- <div class="reject-reason-value">
- {{ rejectReasonData.groupName || "--" }}
- </div>
- </div>
- <div class="reject-reason-item">
- <div class="reject-reason-label">团购编号:</div>
- <div class="reject-reason-value">
- {{ rejectReasonData.groupNo || "--" }}
- </div>
- </div>
- <div class="reject-reason-item">
- <div class="reject-reason-label">拒绝原因:</div>
- <div class="reject-reason-value reject-reason-text">
- {{
- rejectReasonData.rejectReason ||
- rejectReasonData.rejectionReason ||
- rejectReasonData.refuseReason ||
- rejectReasonData.auditReason ||
- "暂无拒绝原因"
- }}
- </div>
- </div>
- </div>
- <template #footer>
- <div class="dialog-footer">
- <el-button type="primary" @click="closeRejectReasonDialog"> 确定 </el-button>
- </div>
- </template>
- </el-dialog>
- </div>
- </template>
- <script setup lang="tsx" name="groupPackageManagement">
- import { computed, onActivated, onMounted, reactive, ref, watch } from "vue";
- import { useRouter } from "vue-router";
- import { ElMessageBox, 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 { deleteThali, getThaliList, sjxj, updateNum } from "@/api/modules/groupPackageManagement";
- const router = useRouter();
- const dialogFormVisible = ref(false);
- const formInventory: any = ref({
- id: "",
- groupName: "",
- inventoryNum: "",
- newInventory: ""
- });
- const rowData = ref<any>();
- const activeName = ref("");
- // 查看拒绝原因弹窗相关
- const rejectReasonDialogVisible = ref(false);
- const rejectReasonData = ref<any>({
- groupName: "",
- groupNo: "",
- rejectReason: "",
- rejectionReason: "",
- refuseReason: "",
- auditReason: ""
- });
- // 定义表单类型
- interface RuleForm {
- newInventory: string;
- }
- const ruleFormRef = ref<FormInstance>();
- const rules = reactive<FormRules<RuleForm>>({
- newInventory: [
- { required: true, message: "请输入库存数量", trigger: "blur" },
- {
- pattern: /^(0|[1-9][0-9]*)$/,
- message: "请输入正整数",
- trigger: "blur"
- }
- ]
- });
- const statusEnum = [
- { value: "0", label: "待审核" },
- { value: "1", label: "审核通过" },
- { value: "2", label: "审核驳回" }
- ];
- const allTabOptions = [
- { label: "全部", name: "" },
- { label: "草稿", name: "0" },
- { label: "进行中", name: "5" },
- { label: "未开始", name: "2" },
- { label: "已下架", name: "6" },
- { label: "已售罄", name: "4" },
- { label: "已结束", name: "7" }
- ];
- // 状态枚举:0草稿 1待审核 2未开始 3审核拒绝 4已售罄 5进行中 6已下架 7已结束
- const STATUS = {
- 草稿: 0,
- 待审核: 1,
- 未开始: 2,
- 审核拒绝: 3,
- 已售罄: 4,
- 进行中: 5,
- 已下架: 6,
- 已结束: 7
- } as const;
- // 操作按钮权限配置:定义每个操作按钮在哪些状态下显示
- const OPERATION_PERMISSIONS = {
- // 查看详情:待审核、未开始、审核拒绝、进行中、已售罄、已下架
- 查看详情: [STATUS.待审核, STATUS.未开始, 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);
- };
- // ProTable 实例(需要在使用它的地方之前定义)
- const proTable = ref<ProTableInstance>();
- // 表格配置项
- const columns = reactive<ColumnProps<any>[]>([
- {
- prop: "index",
- label: "序号",
- width: 100,
- render: (scope: any) => {
- return scope.$index + (proTable.value!.pageable.pageNum - 1) * proTable.value!.pageable.pageSize + 1;
- }
- },
- {
- prop: "groupName",
- label: "团购名称",
- isShow: false,
- search: {
- el: "input"
- }
- },
- {
- prop: "groupNo",
- label: "团购编号",
- isShow: false,
- search: {
- el: "input"
- }
- },
- {
- prop: "Information",
- label: "团购信息",
- width: 400
- },
- {
- prop: "saleNum",
- label: "已售"
- },
- {
- prop: "inventoryNum",
- label: "剩余库存"
- },
- {
- prop: "goodsId",
- label: "优惠价",
- render: (scope: any) => {
- return scope.row.preferentialPrice ? `¥${scope.row.preferentialPrice}` : "--";
- }
- },
- {
- prop: "costPrice",
- label: "成本价",
- render: (scope: any) => {
- return scope.row.costPrice ? `¥${scope.row.costPrice}` : "--";
- }
- },
- {
- prop: "profit",
- label: "利润",
- render: (scope: any) => {
- return scope.row.profit ? `¥${scope.row.profit}` : "--";
- }
- },
- {
- prop: "reviewType",
- label: "审核状态",
- isShow: false,
- render: scope => {
- const statusObj = statusEnum.find(item => item.value === scope.row.reviewType);
- return statusObj ? statusObj.label : "--";
- },
- search: {
- el: "select"
- },
- enum: statusEnum,
- fieldNames: { label: "label", value: "value" }
- },
- {
- prop: "status",
- label: "状态",
- width: 200
- },
- { prop: "operation", label: "操作", fixed: "right", width: 330 }
- ]);
- // 获取当前审核状态
- const currentAuditStatus = computed(() => {
- if (!proTable.value?.searchParam) return "";
- return proTable.value.searchParam.reviewType || "";
- });
- // 控制 el-tabs 是否显示:当审核状态为空或审核通过时显示
- const showTabs = computed(() => {
- const status = currentAuditStatus.value;
- return !status || status === "-2";
- });
- // 根据审核状态过滤 tabOptions:如果审核状态为空,只显示草稿;审核通过时,显示除草稿外的所有标签页
- const filteredTabOptions = computed(() => {
- const status = currentAuditStatus.value;
- if (!status) {
- // 审核状态为空时,只显示草稿
- return allTabOptions;
- } else if (status === "-2") {
- // 审核通过时,显示除草稿外的所有标签页
- return allTabOptions.filter(tab => tab.name !== "1");
- }
- return [];
- });
- // 监听审核状态变化
- watch(
- currentAuditStatus,
- newStatus => {
- if (!newStatus || newStatus === "-2") {
- // 审核状态为空时,确保 activeName 为草稿
- activeName.value = "";
- }
- },
- { immediate: true }
- );
- // 如果表格需要初始化请求参数,直接定义传给 ProTable (之后每次请求都会自动带上该参数,此参数更改之后也会一直带上,改变此参数会自动刷新表格数据)
- const initParam = reactive({
- storeId: "104",
- groupType: "1",
- status: activeName
- });
- // 页面加载时触发查询
- onMounted(() => {
- proTable.value?.getTableList();
- });
- // 从其他页面返回时触发查询
- onActivated(() => {
- proTable.value?.getTableList();
- });
- // dataCallback 是对于返回的表格数据做处理,如果你后台返回的数据不是 list && total 这些字段,可以在这里进行处理成这些字段
- // 或者直接去 hooks/useTable.ts 文件中把字段改为你后端对应的就行
- const dataCallback = (data: any) => {
- return {
- list: data.records,
- total: data.total
- };
- };
- // 如果你想在请求之前对当前请求参数做一些操作,可以自定义如下函数:params 为当前所有的请求参数(包括分页),最后返回请求列表接口
- // 默认不做操作就直接在 ProTable 组件上绑定 :requestApi="getUserList"
- const getTableList = (params: any) => {
- let newParams = JSON.parse(JSON.stringify(params));
- return getThaliList(newParams);
- };
- const newGroupBuying = () => {
- router.push(`/groupPackageManagement/newGroup?type=add`);
- };
- // 跳转详情页
- const toDetail = row => {
- router.push(`/groupPackageManagement/detail?id=${row.id}`);
- };
- const editRow = row => {
- router.push(`/groupPackageManagement/newGroup?id=${row.id}&type=edit`);
- };
- const deleteRow = row => {
- ElMessageBox.confirm("确定要删除吗?", "提示", {
- confirmButtonText: "OK",
- cancelButtonText: "Cancel",
- type: "warning"
- }).then(() => {
- deleteThali(row.id).then(() => {
- ElMessage.success("删除成功");
- proTable.value?.getTableList();
- });
- });
- };
- const handleClick = () => {};
- const changeTypes = async (row: any, status: string) => {
- rowData.value = row;
- let res = await sjxj({ id: row.id, status: status });
- if (res && res.code == 200) {
- ElMessage.success("操作成功");
- proTable.value?.getTableList();
- }
- };
- const changeInventory = (row: any) => {
- formInventory.value.id = row.id;
- formInventory.value.groupName = row.groupName;
- formInventory.value.inventoryNum = row.inventoryNum;
- formInventory.value.newInventory = "";
- dialogFormVisible.value = true;
- };
- // 弹窗提交
- const handleSubmit = async () => {
- if (!ruleFormRef.value) return;
- await ruleFormRef.value.validate(async (valid, fields) => {
- if (valid) {
- let res = await updateNum({ id: formInventory.value.id, num: formInventory.value.newInventory });
- if (res && res.code == 200) {
- ElMessage.success("库存修改成功");
- dialogFormVisible.value = false;
- proTable.value?.getTableList();
- }
- }
- });
- };
- // 关闭弹窗
- const closeDialog = () => {
- dialogFormVisible.value = false;
- formInventory.value = {
- id: "",
- groupName: "",
- inventoryNum: "",
- newInventory: ""
- };
- };
- // 查看拒绝原因
- const viewRejectReason = (row: any) => {
- rejectReasonData.value = {
- groupName: row.groupName || "",
- groupNo: row.groupNo || "",
- rejectReason: row.rejectReason || "",
- rejectionReason: row.rejectionReason || "",
- refuseReason: row.refuseReason || "",
- auditReason: row.auditReason || ""
- };
- rejectReasonDialogVisible.value = true;
- };
- // 关闭拒绝原因弹窗
- const closeRejectReasonDialog = () => {
- rejectReasonDialogVisible.value = false;
- rejectReasonData.value = {
- groupName: "",
- groupNo: "",
- rejectReason: "",
- rejectionReason: "",
- refuseReason: "",
- auditReason: ""
- };
- };
- </script>
- <style lang="scss" scoped>
- // 在组件样式中添加
- .date-range {
- display: block; // 确保换行生效
- padding: 0 8px; // 可选:增加内边距
- word-wrap: break-word; // 长单词内换行
- white-space: normal; // 允许自然换行
- }
- .table-header-btn {
- .tabs {
- margin-top: 10px;
- :deep(.el-tabs__nav-wrap::after) {
- height: 0;
- }
- }
- }
- .information {
- display: flex;
- column-gap: 5px;
- align-items: center;
- .information-right {
- display: flex;
- flex-direction: column;
- row-gap: 5px;
- align-items: flex-start;
- }
- }
- .reject-reason-content {
- padding: 20px 0;
- .reject-reason-item {
- display: flex;
- margin-bottom: 20px;
- &:last-child {
- margin-bottom: 0;
- }
- .reject-reason-label {
- flex-shrink: 0;
- min-width: 100px;
- font-size: 14px;
- font-weight: 500;
- color: #606266;
- }
- .reject-reason-value {
- flex: 1;
- font-size: 14px;
- color: #303133;
- word-break: break-word;
- &.reject-reason-text {
- min-height: 80px;
- padding: 12px;
- line-height: 1.6;
- white-space: pre-wrap;
- background-color: #f5f7fa;
- border-radius: 4px;
- }
- }
- }
- }
- </style>
|