2025-06-03 17:35:22 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div class="app-container customer-control">
|
|
|
|
|
<div class="container-custom">
|
|
|
|
|
<!-- 搜索栏 -->
|
|
|
|
|
<div ref="searchBarRef" class="search-box">
|
|
|
|
|
<div class="search-bar">
|
|
|
|
|
<div class="search-bar-left">
|
|
|
|
|
<div class="order-tab" style="margin-top: -10px">
|
|
|
|
|
<el-tabs v-model="activeCurrent" @tab-click="tabChange">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-tab-pane
|
|
|
|
|
v-for="t in bottomList"
|
|
|
|
|
:key="t.id"
|
|
|
|
|
:label="t.title + t.value"
|
|
|
|
|
:name="t.id"
|
|
|
|
|
>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</el-tab-pane>
|
|
|
|
|
</el-tabs>
|
|
|
|
|
</div>
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-form
|
|
|
|
|
ref="searchForm"
|
|
|
|
|
:inline="true"
|
|
|
|
|
:model="formInline"
|
|
|
|
|
class="demo-form-inline"
|
|
|
|
|
:label-width="'auto'"
|
|
|
|
|
>
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<el-form-item label="商品名称" prop="goodName">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-input
|
|
|
|
|
v-model="formInline.goodName"
|
|
|
|
|
placeholder="请输入商品名称"
|
|
|
|
|
clearable
|
|
|
|
|
/>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</el-form-item>
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-form-item
|
|
|
|
|
label="商品分类"
|
|
|
|
|
prop="goodCategoryId"
|
|
|
|
|
class="custom-form-inline"
|
|
|
|
|
>
|
|
|
|
|
<!-- <el-select v-model="formInline.goodCategoryId" placeholder="请选择" clearable>
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<el-option v-for="item in goodsCategoryList" :key="item.id" :value="item.id" :label="item.name" />
|
2025-06-09 18:49:32 +08:00
|
|
|
|
</el-select> -->
|
|
|
|
|
<el-cascader
|
|
|
|
|
v-model="formInline.goodCategoryId"
|
|
|
|
|
:options="goodsOptions"
|
|
|
|
|
:props="cascaderProps"
|
|
|
|
|
placeholder="请选择省市区"
|
|
|
|
|
clearable
|
|
|
|
|
/>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</el-form-item>
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<!-- <el-form-item label="商品品牌" prop="storeId">
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<el-select v-model="formInline.storeId" placeholder="请选择" clearable>
|
|
|
|
|
<el-option v-for="item in goodsBrandList" :key="item.id" :value="item.id" :label="item.name" />
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</el-select>
|
2025-06-09 18:49:32 +08:00
|
|
|
|
</el-form-item> -->
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</el-form>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="search-bar-right">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-button type="primary" icon="Search" @click="onSubmit"
|
|
|
|
|
>查询</el-button
|
|
|
|
|
>
|
|
|
|
|
<el-button
|
|
|
|
|
icon="Refresh"
|
|
|
|
|
style="margin: 16px 0 0 0"
|
|
|
|
|
@click="resetForm"
|
|
|
|
|
>重置</el-button
|
|
|
|
|
>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- 表格 -->
|
|
|
|
|
<div class="table-cont" :style="{ height: tableViewportHeight + 'px' }">
|
|
|
|
|
<div class="table-toolbar">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-button
|
|
|
|
|
icon="delete"
|
|
|
|
|
@click="batchDelete"
|
|
|
|
|
:disabled="btnStatus"
|
|
|
|
|
style="margin-right: 10px"
|
|
|
|
|
>批量删除</el-button
|
|
|
|
|
>
|
2025-06-06 19:00:59 +08:00
|
|
|
|
<router-link to="/goods/goodsManage/addGoods">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-button type="primary" icon="plus" @click="onSubmit"
|
|
|
|
|
>新增商品</el-button
|
|
|
|
|
>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</router-link>
|
|
|
|
|
</div>
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<tableComponent
|
|
|
|
|
:table-data="tableData"
|
|
|
|
|
:columns="columns"
|
|
|
|
|
:show-border="false"
|
|
|
|
|
:show-selection="true"
|
|
|
|
|
:header-cell-class-name="getHeaderClass"
|
|
|
|
|
@page-change="handlePaginationChange"
|
|
|
|
|
:loading="tableLoading"
|
|
|
|
|
@selection-change="handleSelectionChange"
|
|
|
|
|
:total="tableTotal"
|
|
|
|
|
:current-page="formInline.current"
|
|
|
|
|
:page-size="formInline.size"
|
|
|
|
|
:showSort="true"
|
|
|
|
|
:rowkey="'goodId'"
|
|
|
|
|
>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
<!-- 自定义-图片 -->
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<template #goodUrl="slotProps">
|
2025-06-03 17:35:22 +08:00
|
|
|
|
<div class="table-cell-img-box">
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<img :src="slotProps.row.goodUrl" class="table-cell-img" alt="" />
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<!-- 自定义 - 序号 -->
|
|
|
|
|
<template #sort="slotProps">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<span v-if="slotProps.row.goodPrice"
|
|
|
|
|
>¥{{ slotProps.row.goodPrice }}</span
|
|
|
|
|
>
|
2025-06-05 18:29:47 +08:00
|
|
|
|
</template>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
|
|
|
|
|
<!-- 自定义-状态 -->
|
2025-06-05 18:29:47 +08:00
|
|
|
|
<template #isListed="slotProps">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<span v-if="slotProps.row.isListed == 0" class="color-blue"
|
|
|
|
|
>待上架</span
|
|
|
|
|
>
|
|
|
|
|
<span v-else-if="slotProps.row.isListed == 1" class="color-black"
|
|
|
|
|
>已上架</span
|
|
|
|
|
>
|
|
|
|
|
<span v-else-if="slotProps.row.isListed == 2" class="color-green"
|
|
|
|
|
>上架</span
|
|
|
|
|
>
|
|
|
|
|
<span v-else-if="slotProps.row.isListed == 3" class="color-red"
|
|
|
|
|
>下架</span
|
|
|
|
|
>
|
|
|
|
|
<span v-else-if="slotProps.row.isListed == 4" class="color-orange"
|
|
|
|
|
>审核中</span
|
|
|
|
|
>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<!-- 自定义-操作 -->
|
|
|
|
|
<template #action="slotProps">
|
2025-06-09 18:49:32 +08:00
|
|
|
|
<el-button
|
|
|
|
|
text
|
|
|
|
|
class="el-button-custom"
|
|
|
|
|
@click="seeDetails(slotProps.row)"
|
|
|
|
|
>详情</el-button
|
|
|
|
|
>
|
|
|
|
|
<el-button
|
|
|
|
|
text
|
|
|
|
|
v-if="slotProps.row.isListed == 0"
|
|
|
|
|
class="el-button-custom"
|
|
|
|
|
@click="toUpload(slotProps.row)"
|
|
|
|
|
>上架</el-button
|
|
|
|
|
>
|
|
|
|
|
<el-button
|
|
|
|
|
text
|
|
|
|
|
v-if="slotProps.row.isListed == 1"
|
|
|
|
|
class="el-button-custom"
|
|
|
|
|
@click="toDownload(slotProps.row)"
|
|
|
|
|
>下架</el-button
|
|
|
|
|
>
|
|
|
|
|
<el-button
|
|
|
|
|
text
|
|
|
|
|
class="el-button-custom"
|
|
|
|
|
@click="handleEdit(slotProps.row)"
|
|
|
|
|
>编辑</el-button
|
|
|
|
|
>
|
|
|
|
|
<el-button
|
|
|
|
|
text
|
|
|
|
|
class="el-button-delete"
|
|
|
|
|
@click="handleDelete(slotProps.row)"
|
|
|
|
|
>删除</el-button
|
|
|
|
|
>
|
2025-06-03 17:35:22 +08:00
|
|
|
|
</template>
|
|
|
|
|
</tableComponent>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, reactive, computed, onMounted, onBeforeUnmount } from "vue";
|
|
|
|
|
import tableComponent from "@/components/tableComponent.vue";
|
|
|
|
|
import Mock from "mockjs";
|
2025-06-09 18:49:32 +08:00
|
|
|
|
import {
|
|
|
|
|
getGoodManageInfo,
|
|
|
|
|
getGoodType,
|
|
|
|
|
goodDelete,
|
|
|
|
|
getGoodManageCount,
|
|
|
|
|
goodUpAndDown,
|
|
|
|
|
} from "@/api/goods/info";
|
2025-06-06 19:00:59 +08:00
|
|
|
|
import { id } from "element-plus/es/locales.mjs";
|
2025-06-09 18:49:32 +08:00
|
|
|
|
import { ElMessage } from "element-plus";
|
|
|
|
|
const route = useRoute();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const { proxy } = getCurrentInstance();
|
2025-06-03 17:35:22 +08:00
|
|
|
|
|
|
|
|
|
const formInline = reactive({
|
2025-06-05 18:29:47 +08:00
|
|
|
|
goodName: "",
|
2025-06-09 18:49:32 +08:00
|
|
|
|
goodCategoryId: [],
|
2025-06-05 18:29:47 +08:00
|
|
|
|
storeId: "",
|
|
|
|
|
type: "1",
|
2025-06-03 17:35:22 +08:00
|
|
|
|
current: 1,
|
|
|
|
|
size: 10,
|
|
|
|
|
});
|
|
|
|
|
const goodsCategoryList = ref([
|
|
|
|
|
{ name: "蔬菜", id: 1 },
|
|
|
|
|
{ name: "肥料", id: 2 },
|
|
|
|
|
{ name: "农药", id: 3 },
|
|
|
|
|
]);
|
|
|
|
|
const goodsBrandList = ref([
|
|
|
|
|
{ name: "品牌1", id: 1 },
|
|
|
|
|
{ name: "品牌2", id: 2 },
|
|
|
|
|
{ name: "品牌3", id: 3 },
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
const searchForm = ref(null);
|
|
|
|
|
const onSubmit = () => {
|
|
|
|
|
console.log("submit!");
|
|
|
|
|
formInline.current = 1;
|
|
|
|
|
console.log(formInline);
|
|
|
|
|
loadData();
|
|
|
|
|
};
|
|
|
|
|
const resetForm = () => {
|
|
|
|
|
searchForm.value.resetFields();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let activeCurrent = ref("1");
|
|
|
|
|
let bottomList = reactive([
|
2025-06-09 18:49:32 +08:00
|
|
|
|
{ title: "全部", id: "1", value: "" },
|
|
|
|
|
{ title: "已上架", id: "2", value: "" },
|
|
|
|
|
{ title: "已下架", id: "3", value: "" },
|
2025-06-03 17:35:22 +08:00
|
|
|
|
]);
|
|
|
|
|
const tabChange = (Event) => {
|
|
|
|
|
console.log(Event.index);
|
|
|
|
|
if (Event.index == "0") {
|
|
|
|
|
// 请求全部
|
2025-06-05 18:29:47 +08:00
|
|
|
|
formInline.type = "1";
|
2025-06-03 17:35:22 +08:00
|
|
|
|
} else if (Event.index == "1") {
|
|
|
|
|
// 请求已上架
|
2025-06-05 18:29:47 +08:00
|
|
|
|
formInline.type = "2";
|
2025-06-06 19:00:59 +08:00
|
|
|
|
} else if (Event.index == "2") {
|
2025-06-03 17:35:22 +08:00
|
|
|
|
// 请求已下架
|
2025-06-05 18:29:47 +08:00
|
|
|
|
formInline.type = "3";
|
2025-06-03 17:35:22 +08:00
|
|
|
|
}
|
|
|
|
|
loadData();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 表格数据
|
|
|
|
|
const tableData = ref([]);
|
|
|
|
|
const selectedIds = ref([]);
|
|
|
|
|
const btnStatus = computed(() => {
|
|
|
|
|
return selectedIds.value.length <= 0;
|
|
|
|
|
});
|
|
|
|
|
const tableLoading = ref(false);
|
|
|
|
|
const tableTotal = ref(0);
|
|
|
|
|
let nowClickRow = ref({});
|
|
|
|
|
// 列配置
|
|
|
|
|
const columns = ref([]);
|
|
|
|
|
const columns1 = ref([
|
2025-06-05 18:29:47 +08:00
|
|
|
|
{ prop: "goodId", label: "ID", width: "150" },
|
|
|
|
|
{ prop: "goodUrl", label: "商品图片", slotName: "goodUrl" },
|
|
|
|
|
{ prop: "goodName", label: "商品名称", width: "120" },
|
2025-06-03 17:35:22 +08:00
|
|
|
|
{ prop: "categoryName", label: "分类名称" },
|
2025-06-05 18:29:47 +08:00
|
|
|
|
{ prop: "goodPrice", label: "商品售价" },
|
2025-06-03 17:35:22 +08:00
|
|
|
|
{ prop: "salesVolume", label: "销量" },
|
|
|
|
|
{ prop: "pageView", label: "浏览量" },
|
2025-06-05 18:29:47 +08:00
|
|
|
|
{ prop: "stock", label: "库存" },
|
|
|
|
|
{ prop: "isListed", label: "状态", slotName: "isListed" },
|
2025-06-09 18:49:32 +08:00
|
|
|
|
{
|
|
|
|
|
prop: "action",
|
|
|
|
|
label: "操作",
|
|
|
|
|
slotName: "action",
|
|
|
|
|
width: 200,
|
|
|
|
|
fixed: "right",
|
|
|
|
|
},
|
2025-06-03 17:35:22 +08:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
// 生成食物主题昵称
|
|
|
|
|
const generateFoodNickname = () => {
|
|
|
|
|
// 食物名词(仅限食物)
|
|
|
|
|
const foods = [
|
|
|
|
|
"辣椒",
|
|
|
|
|
"西瓜",
|
|
|
|
|
"土豆",
|
|
|
|
|
"番茄",
|
|
|
|
|
"黄瓜",
|
|
|
|
|
"苹果",
|
|
|
|
|
"蛋糕",
|
|
|
|
|
"面包",
|
|
|
|
|
"披萨",
|
|
|
|
|
"冰淇淋",
|
|
|
|
|
"奶茶",
|
|
|
|
|
"咖啡",
|
|
|
|
|
"啤酒",
|
|
|
|
|
"炸鸡",
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 随机组合:形容词 + 食物
|
|
|
|
|
return Mock.mock(`@pick(${foods})`);
|
|
|
|
|
};
|
|
|
|
|
// 生成模拟数据
|
|
|
|
|
const generateMockData = () => {
|
|
|
|
|
return Mock.mock({
|
|
|
|
|
"list|10": [
|
|
|
|
|
{
|
2025-06-06 19:00:59 +08:00
|
|
|
|
"id|+1": 10000,
|
2025-06-05 18:29:47 +08:00
|
|
|
|
"goodId|+1": 10000,
|
2025-06-03 17:35:22 +08:00
|
|
|
|
"sort|+1": 1,
|
2025-06-05 18:29:47 +08:00
|
|
|
|
goodUrl: " @image", //商品图片
|
|
|
|
|
goodName: () => generateFoodNickname(), //商品名称
|
2025-06-03 17:35:22 +08:00
|
|
|
|
categoryName: '@pick(["蔬菜", "肥料", "农药"])', //分类名称
|
2025-06-05 18:29:47 +08:00
|
|
|
|
goodPrice: "@float(10, 200, 2, 2)", //商品售价
|
2025-06-03 17:35:22 +08:00
|
|
|
|
salesVolume: "@integer(1000, 20000)", //销量
|
|
|
|
|
pageView: Mock.mock("@id").toString().slice(0, 6), //浏览量
|
2025-06-05 18:29:47 +08:00
|
|
|
|
stock: "@integer(5000, 90000)", //库存
|
2025-06-09 18:49:32 +08:00
|
|
|
|
isListed: "@pick([0, 1, 2, 3, 4])", //状态
|
2025-06-03 17:35:22 +08:00
|
|
|
|
ordersNums: "@integer(10, 200)",
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
}).list;
|
|
|
|
|
};
|
|
|
|
|
// 加载数据
|
|
|
|
|
const loadData = async () => {
|
|
|
|
|
tableLoading.value = true;
|
2025-06-06 19:00:59 +08:00
|
|
|
|
// 测试
|
2025-06-05 18:29:47 +08:00
|
|
|
|
// tableData.value = generateMockData();
|
|
|
|
|
// tableTotal.value = tableData.value.length;
|
2025-06-06 19:00:59 +08:00
|
|
|
|
// console.log(tableData.value);
|
2025-06-09 18:49:32 +08:00
|
|
|
|
|
|
|
|
|
let prams = { ...formInline };
|
|
|
|
|
prams.goodCategoryId =
|
|
|
|
|
formInline.goodCategoryId[prams.goodCategoryId.length - 1];
|
|
|
|
|
|
2025-06-05 18:29:47 +08:00
|
|
|
|
try {
|
2025-06-09 18:49:32 +08:00
|
|
|
|
let response = await getGoodManageInfo(prams);
|
2025-06-05 18:29:47 +08:00
|
|
|
|
console.log(response);
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
|
tableData.value = response.data.records;
|
|
|
|
|
tableTotal.value = response.data.total;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
2025-06-03 17:35:22 +08:00
|
|
|
|
tableLoading.value = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 自定义表头类名,也可以在columns指定列中添加headerClassName: 'custom-header'
|
|
|
|
|
const getHeaderClass = ({ column }) => {
|
|
|
|
|
return "custom-header";
|
|
|
|
|
};
|
|
|
|
|
// 分页变化
|
|
|
|
|
const handlePaginationChange = ({ page, pageSize }) => {
|
|
|
|
|
console.log("分页变化:", page, pageSize);
|
|
|
|
|
formInline.current = page;
|
|
|
|
|
formInline.size = pageSize;
|
|
|
|
|
// 这里可以调用API获取新数据
|
|
|
|
|
loadData();
|
|
|
|
|
};
|
|
|
|
|
// 多选框变化
|
|
|
|
|
const handleSelectionChange = (selection, ids) => {
|
|
|
|
|
console.log("选中项:", selection, ids);
|
|
|
|
|
selectedIds.value = ids;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 查看详情
|
|
|
|
|
const seeDetails = (row) => {
|
|
|
|
|
nowClickRow.value = row;
|
|
|
|
|
console.log("要查看详情的行:", row);
|
|
|
|
|
};
|
2025-06-09 18:49:32 +08:00
|
|
|
|
const toUpload = async (row) => {
|
|
|
|
|
console.log("上架:", row);
|
|
|
|
|
goodsUpAndDown(row.goodId, 2);
|
|
|
|
|
};
|
|
|
|
|
const toDownload = (row) => {
|
|
|
|
|
console.log("下架:", row);
|
|
|
|
|
goodsUpAndDown(row.goodId, 3);
|
2025-06-03 17:35:22 +08:00
|
|
|
|
};
|
2025-06-09 18:49:32 +08:00
|
|
|
|
const goodsUpAndDown = async (id, isListed) => {
|
|
|
|
|
// 2->上架,3->下架
|
|
|
|
|
let res = await goodUpAndDown({ id: id, isListed: isListed });
|
|
|
|
|
let text = isListed == 2 ? "上架" : "下架";
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
ElMessage.success(`${text}成功`);
|
|
|
|
|
loadData();
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error(res.msg);
|
|
|
|
|
}
|
2025-06-03 17:35:22 +08:00
|
|
|
|
};
|
|
|
|
|
// 编辑操作
|
|
|
|
|
const handleEdit = (row) => {
|
|
|
|
|
nowClickRow.value = row;
|
|
|
|
|
console.log("要编辑的行:", row);
|
2025-06-06 19:00:59 +08:00
|
|
|
|
// 跳转路由并携带参数,行数据,和query的值edit
|
|
|
|
|
router.push({
|
|
|
|
|
path: "/goods/goodsManage/editGoods",
|
2025-06-09 18:49:32 +08:00
|
|
|
|
query: { goodId: row.goodId },
|
|
|
|
|
});
|
2025-06-03 17:35:22 +08:00
|
|
|
|
};
|
|
|
|
|
// 删除操作
|
2025-06-09 18:49:32 +08:00
|
|
|
|
const handleDelete = async (row) => {
|
|
|
|
|
deleteGoods(row.goodId)
|
2025-06-03 17:35:22 +08:00
|
|
|
|
};
|
|
|
|
|
// 批量删除
|
2025-06-09 18:49:32 +08:00
|
|
|
|
const batchDelete = async () => {
|
|
|
|
|
console.log("要删除的行:", selectedIds.value);
|
|
|
|
|
deleteGoods(selectedIds.value.join(","))
|
|
|
|
|
};
|
|
|
|
|
const deleteGoods = async (param) => {
|
|
|
|
|
try {
|
|
|
|
|
tableLoading.value = true;
|
|
|
|
|
let res = await goodDelete(param);
|
|
|
|
|
tableLoading.value = false;
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
ElMessage.success("删除成功");
|
|
|
|
|
loadData();
|
|
|
|
|
} else {
|
|
|
|
|
ElMessage.error(res.msg);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
tableLoading.value = false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 级联选择器配置
|
|
|
|
|
const cascaderProps = ref({
|
|
|
|
|
label: "name", // 选项标签字段名
|
|
|
|
|
value: "id", // 选项值字段名
|
|
|
|
|
children: "children", // 子选项字段名
|
|
|
|
|
emitPath: true,
|
|
|
|
|
expandTrigger: "hover",
|
|
|
|
|
});
|
|
|
|
|
const goodsOptions = ref([]);
|
|
|
|
|
const getGoodTypeList = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let response = await getGoodType();
|
|
|
|
|
console.log(response);
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
|
goodsOptions.value = response.data;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getGoodsManageCount = async () => {
|
|
|
|
|
try {
|
|
|
|
|
let response = await getGoodManageCount();
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
|
bottomList[0].value = `(${response.data?.allGoodCount ?? ""})`;
|
|
|
|
|
bottomList[1].value = `(${response.data?.alreadyListedCount ?? ""})`;
|
|
|
|
|
bottomList[2].value = `(${response.data?.removedCount ?? ""})`;
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log(error);
|
|
|
|
|
}
|
2025-06-03 17:35:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const titleRef = ref(null);
|
|
|
|
|
const searchBarRef = ref(null);
|
|
|
|
|
const tableViewportHeight = ref(0);
|
|
|
|
|
// 精确计算可用高度
|
|
|
|
|
const calculateTableHeight = () => {
|
|
|
|
|
// 获取窗口总高度
|
|
|
|
|
const windowHeight = window.innerHeight;
|
|
|
|
|
|
|
|
|
|
// 获取各组件高度
|
|
|
|
|
const headerHeight = titleRef.value?.$el?.offsetHeight || 0;
|
|
|
|
|
const searchBarHeight = searchBarRef.value?.offsetHeight || 0;
|
|
|
|
|
|
|
|
|
|
// 计算容器内边距补偿(根据实际样式调整)
|
|
|
|
|
const paddingCompensation = 130;
|
|
|
|
|
|
|
|
|
|
// 最终计算
|
|
|
|
|
tableViewportHeight.value =
|
|
|
|
|
windowHeight - headerHeight - searchBarHeight - paddingCompensation;
|
|
|
|
|
// console.log(tableViewportHeight.value);
|
|
|
|
|
};
|
|
|
|
|
// 组件挂载时加载数据
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
columns.value = columns1.value;
|
|
|
|
|
loadData();
|
2025-06-09 18:49:32 +08:00
|
|
|
|
getGoodTypeList();
|
|
|
|
|
getGoodsManageCount();
|
2025-06-03 17:35:22 +08:00
|
|
|
|
|
|
|
|
|
calculateTableHeight();
|
|
|
|
|
|
|
|
|
|
// 添加响应式监听
|
|
|
|
|
window.addEventListener("resize", calculateTableHeight);
|
|
|
|
|
|
|
|
|
|
// 监听DOM变化(适用于动态变化的header/searchbar)
|
|
|
|
|
const observer = new ResizeObserver(calculateTableHeight);
|
|
|
|
|
if (titleRef.value?.$el) observer.observe(titleRef.value.$el);
|
|
|
|
|
if (searchBarRef.value) observer.observe(searchBarRef.value);
|
|
|
|
|
});
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
window.removeEventListener("resize", calculateTableHeight);
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.table-toolbar {
|
|
|
|
|
width: 300px;
|
|
|
|
|
height: 50px;
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: end;
|
|
|
|
|
padding: 14px 16px 0 0;
|
|
|
|
|
}
|
|
|
|
|
</style>
|