style: purchase
This commit is contained in:
@@ -1,9 +1,383 @@
|
||||
<script setup lang="ts">
|
||||
import dayjs from "dayjs";
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ElMessage, ElMessageBox } from "element-plus";
|
||||
import { request, bizApi } from "@/api/utils";
|
||||
|
||||
defineOptions({
|
||||
name: "purchase"
|
||||
});
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
height?: string;
|
||||
}>(),
|
||||
{
|
||||
height: undefined
|
||||
}
|
||||
);
|
||||
|
||||
// 定义查询参数
|
||||
const queryParams = ref({
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
userId: "",
|
||||
isCompany: "",
|
||||
companyId: "",
|
||||
purchasesType: "",
|
||||
isUsed: ""
|
||||
});
|
||||
|
||||
// 定义表格数据
|
||||
const tableData = ref([]);
|
||||
const loading = ref(false);
|
||||
const total = ref(0);
|
||||
|
||||
// 前端用户列表数据
|
||||
const frontendUserOptions = ref([]);
|
||||
// 获取前端用户列表
|
||||
const getFrontendUserList = async () => {
|
||||
try {
|
||||
const res = await request(bizApi("getFrontendUserPrimaryInfo"), {
|
||||
method: "POST"
|
||||
});
|
||||
if (res.status === 200) {
|
||||
frontendUserOptions.value = res.data.map(item => ({
|
||||
value: item.id,
|
||||
label: item.name
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取用户列表失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// 公司列表数据
|
||||
const companyOptions = ref([]);
|
||||
// 获取公司列表
|
||||
const getCompanyList = async () => {
|
||||
try {
|
||||
const res = await request(bizApi("getCompanyPrimaryInfo"), {
|
||||
method: "POST"
|
||||
});
|
||||
if (res.status === 200) {
|
||||
companyOptions.value = res.data.map(item => ({
|
||||
value: item.id,
|
||||
label: item.companyName
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取公司列表失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// 道具类型选项
|
||||
const purchaseTypeOptions = [
|
||||
{ value: 1, label: "实时达卡" },
|
||||
{ value: 2, label: "排他卡" },
|
||||
{ value: 3, label: "插队卡" },
|
||||
{ value: 4, label: "直通卡" },
|
||||
{ value: 5, label: "加量卡" },
|
||||
{ value: 6, label: "置顶卡" }
|
||||
];
|
||||
|
||||
// 获取道具列表
|
||||
const getPurchaseList = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params = { ...queryParams.value };
|
||||
const data = await request(bizApi("inappPurchasePage"), {
|
||||
method: "POST",
|
||||
body: JSON.stringify(params)
|
||||
});
|
||||
|
||||
if (data.status === 200) {
|
||||
tableData.value = data.data.rows;
|
||||
total.value = data.data.records;
|
||||
} else {
|
||||
ElMessage.error(data.msg || "获取数据失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取道具列表失败:", error);
|
||||
ElMessage.error(error.message || "获取数据失败");
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 搜索方法
|
||||
const handleSearch = () => {
|
||||
queryParams.value.pageNum = 1;
|
||||
getPurchaseList();
|
||||
};
|
||||
|
||||
// 重置方法
|
||||
const handleReset = () => {
|
||||
queryParams.value = {
|
||||
pageNum: 1,
|
||||
pageSize: 20,
|
||||
userId: "",
|
||||
isCompany: "",
|
||||
companyId: "",
|
||||
purchasesType: "",
|
||||
isUsed: ""
|
||||
};
|
||||
getPurchaseList();
|
||||
};
|
||||
|
||||
// 分页改变
|
||||
const handleSizeChange = (val: number) => {
|
||||
queryParams.value.pageSize = val;
|
||||
getPurchaseList();
|
||||
};
|
||||
|
||||
const handleCurrentChange = (val: number) => {
|
||||
queryParams.value.pageNum = val;
|
||||
getPurchaseList();
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
label: "用户名称",
|
||||
prop: "userId",
|
||||
width: "120",
|
||||
formatter: row => {
|
||||
const user = frontendUserOptions.value.find(
|
||||
item => item.value === row.userId
|
||||
);
|
||||
return user ? user.label : "";
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "是否公司",
|
||||
prop: "isCompany",
|
||||
width: "90",
|
||||
align: "center",
|
||||
formatter: row => {
|
||||
return row.isCompany === 1 ? "是" : "否";
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "公司名称",
|
||||
prop: "companyId",
|
||||
width: "150",
|
||||
formatter: row => {
|
||||
const company = companyOptions.value.find(
|
||||
item => item.value === row.companyId
|
||||
);
|
||||
return company ? company.label : "";
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "类型",
|
||||
prop: "purchasesType",
|
||||
width: "120",
|
||||
align: "center",
|
||||
formatter: row => {
|
||||
const type = purchaseTypeOptions.find(
|
||||
item => item.value === row.purchasesType
|
||||
);
|
||||
return type ? type.label : "-";
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "使用",
|
||||
prop: "isUsed",
|
||||
width: "90",
|
||||
align: "center",
|
||||
formatter: row => {
|
||||
return row.isUsed === 1 ? "是" : "否";
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "创建时间",
|
||||
prop: "createTime",
|
||||
width: "160",
|
||||
formatter: row => {
|
||||
return row.createTime
|
||||
? dayjs(row.createTime).format("YYYY-MM-DD HH:mm:ss")
|
||||
: "";
|
||||
}
|
||||
},
|
||||
{
|
||||
label: "操作",
|
||||
fixed: "right",
|
||||
width: 160,
|
||||
slot: "operation",
|
||||
align: "center"
|
||||
}
|
||||
];
|
||||
|
||||
// 添加删除方法
|
||||
const handleDelete = async (row: any) => {
|
||||
try {
|
||||
await ElMessageBox.confirm("确认要删除该道具记录吗?", "提示", {
|
||||
type: "warning"
|
||||
});
|
||||
|
||||
const res = await request(bizApi("deletePurchase"), {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ id: row.id })
|
||||
});
|
||||
|
||||
if (res.status === 200) {
|
||||
ElMessage.success("删除成功");
|
||||
getPurchaseList();
|
||||
} else {
|
||||
ElMessage.error(res.msg || "删除失败");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("删除失败:", error);
|
||||
}
|
||||
};
|
||||
|
||||
// 添加编辑方法
|
||||
const handleEdit = (row: any) => {
|
||||
// TODO: 实现编辑功能
|
||||
console.log("编辑行:", row);
|
||||
};
|
||||
|
||||
// 页面加载时获取数据
|
||||
onMounted(() => {
|
||||
getPurchaseList();
|
||||
getFrontendUserList();
|
||||
getCompanyList();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>道具管理</h1>
|
||||
<div class="purchase-container">
|
||||
<div class="search-box">
|
||||
<el-form ref="queryForm" :model="queryParams" :inline="true">
|
||||
<el-form-item label="用户" prop="userId">
|
||||
<el-select
|
||||
v-model="queryParams.userId"
|
||||
placeholder="请选择用户"
|
||||
clearable
|
||||
class="user-select"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in frontendUserOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="公司名称" prop="companyId">
|
||||
<el-select
|
||||
v-model="queryParams.companyId"
|
||||
placeholder="请选择公司"
|
||||
clearable
|
||||
class="company-select"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in companyOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="道具类型" prop="purchasesType">
|
||||
<el-select
|
||||
v-model="queryParams.purchasesType"
|
||||
placeholder="请选择类型"
|
||||
clearable
|
||||
class="type-select"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in purchaseTypeOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="使用状态" prop="isUsed">
|
||||
<el-select
|
||||
v-model="queryParams.isUsed"
|
||||
placeholder="请选择"
|
||||
clearable
|
||||
class="type-select"
|
||||
>
|
||||
<el-option label="是" :value="1" />
|
||||
<el-option label="否" :value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch">搜索</el-button>
|
||||
<el-button @click="handleReset">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<pure-table
|
||||
v-loading="loading"
|
||||
:data="tableData"
|
||||
:columns="columns"
|
||||
:height="height"
|
||||
row-key="id"
|
||||
>
|
||||
<template #operation="{ row }">
|
||||
<el-button type="primary" link @click="handleEdit(row)">
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</pure-table>
|
||||
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="queryParams.pageNum"
|
||||
v-model:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 20, 30, 50]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.purchase-container {
|
||||
padding: 20px;
|
||||
|
||||
.search-box {
|
||||
padding: 20px;
|
||||
margin-bottom: 20px;
|
||||
background: #fff;
|
||||
border-radius: 4px;
|
||||
|
||||
:deep(.el-form-item) {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.user-select {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.company-select {
|
||||
width: 180px;
|
||||
}
|
||||
|
||||
.type-select {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user