You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
5.4 KiB
Vue

2 years ago
<script setup lang="ts">
import Card from "./components/Card.vue";
import { getCardList } from "@/api/list";
import { message } from "@/utils/message";
import { ElMessageBox } from "element-plus";
import { ref, onMounted, nextTick } from "vue";
import dialogForm from "./components/DialogForm.vue";
import { useRouter } from "vue-router";
import { isString } from "@pureadmin/utils";
import { useMultiTagsStoreHook } from "@/store/modules/multiTags";
2 years ago
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Search from "@iconify-icons/ep/search";
import AddFill from "@iconify-icons/ri/add-circle-line";
defineOptions({
name: "ProjectList"
});
const svg = `
<path class="path" d="
M 30 15
L 28 17
M 25.61 25.61
A 15 15, 0, 0, 1, 15 30
A 15 15, 0, 1, 1, 27.99 7.5
L 15 15
" style="stroke-width: 4px; fill: rgba(0, 0, 0, 0)"/>
`;
const INITIAL_DATA = {
name: "",
status: "",
description: "",
type: "",
mark: "",
leader: "",
phone: ""
2 years ago
};
const pagination = ref({ current: 1, pageSize: 12, total: 0 });
const productList = ref([]);
const dataLoading = ref(true);
const getCardListData = async () => {
try {
const { data } = await getCardList();
productList.value = data.list;
pagination.value = {
...pagination.value,
total: data.list.length
};
} catch (e) {
console.log(e);
} finally {
setTimeout(() => {
dataLoading.value = false;
}, 500);
}
};
onMounted(() => {
getCardListData();
});
const formDialogVisible = ref(false);
const formData = ref({ ...INITIAL_DATA });
const searchValue = ref("");
const onPageSizeChange = (size: number) => {
pagination.value.pageSize = size;
pagination.value.current = 1;
};
const onCurrentChange = (current: number) => {
pagination.value.current = current;
};
const handleDeleteItem = product => {
ElMessageBox.confirm(
product
? `确认删除后${product.name}的所有产品信息将被清空, 且无法恢复`
: "",
"提示",
{
type: "warning"
}
)
.then(() => {
message("删除成功", { type: "success" });
})
.catch(() => {});
};
const handleManageProduct = product => {
formDialogVisible.value = true;
nextTick(() => {
formData.value = { ...product, status: product?.isSetup ? "1" : "0" };
});
};
const router = useRouter();
2 years ago
const handleProductDetail = product => {
Object.keys(product).forEach(param => {
if (!isString(product[param])) {
product[param] = product[param].toString();
}
});
// 保存信息到标签页
useMultiTagsStoreHook().handleTags("push", {
path: `/project/details`,
name: "ProjectDetails",
query: product,
meta: {
title: `项目详情`,
showLink: false
}
});
router.push({ name: "ProjectDetails", query: product });
2 years ago
// formDialogVisible.value = true;
// nextTick(() => {
// formData.value = { ...product, status: product?.isSetup ? "1" : "0" };
// });
};
</script>
<template>
<div class="main">
<div class="w-full flex justify-between mb-4">
<el-button
:icon="useRenderIcon(AddFill)"
@click="formDialogVisible = true"
>
新建项目
2 years ago
</el-button>
<el-input
style="width: 300px"
v-model="searchValue"
placeholder="请输入项目名称"
2 years ago
clearable
v-if="false"
>
<template #suffix>
<el-icon class="el-input__icon">
<IconifyIconOffline
v-show="searchValue.length === 0"
:icon="Search"
/>
</el-icon>
</template>
</el-input>
</div>
<div
v-loading="dataLoading"
:element-loading-svg="svg"
element-loading-svg-view-box="-10, -10, 50, 50"
>
<el-empty
description="暂无数据"
v-show="
productList
.slice(
pagination.pageSize * (pagination.current - 1),
pagination.pageSize * pagination.current
)
.filter(v =>
v.name.toLowerCase().includes(searchValue.toLowerCase())
).length === 0
"
/>
<template v-if="pagination.total > 0">
<el-row :gutter="16">
<el-col
v-for="(product, index) in productList
.slice(
pagination.pageSize * (pagination.current - 1),
pagination.pageSize * pagination.current
)
.filter(v =>
v.name.toLowerCase().includes(searchValue.toLowerCase())
)"
:key="index"
:xs="48"
:sm="36"
:md="24"
:lg="12"
:xl="8"
>
<Card
:product="product"
@delete-item="handleDeleteItem"
@manage-product="handleManageProduct"
@product-detail="handleProductDetail"
/>
</el-col>
</el-row>
<el-pagination
class="float-right"
v-model:currentPage="pagination.current"
:page-size="pagination.pageSize"
:total="pagination.total"
:page-sizes="[12, 24, 36]"
:background="true"
layout="total, sizes, prev, pager, next, jumper"
@size-change="onPageSizeChange"
@current-change="onCurrentChange"
/>
</template>
</div>
<dialogForm v-model:visible="formDialogVisible" :data="formData" />
</div>
</template>