<template>
|
<div class="app-container">
|
<el-form :model="filters" :inline="true">
|
<el-form-item label="资产编号:">
|
<el-input v-model="filters.assetCode" placeholder="请输入资产编号" clearable style="width: 200px;" />
|
</el-form-item>
|
<el-form-item label="资产名称:">
|
<el-input v-model="filters.assetName" placeholder="请输入资产名称" clearable style="width: 200px;" />
|
</el-form-item>
|
<el-form-item label="资产类别:">
|
<el-select v-model="filters.category" placeholder="请选择类别" clearable style="width: 150px;">
|
<el-option label="房屋建筑" value="building" />
|
<el-option label="机器设备" value="machine" />
|
<el-option label="运输工具" value="vehicle" />
|
<el-option label="电子设备" value="electronic" />
|
<el-option label="办公家具" value="furniture" />
|
</el-select>
|
</el-form-item>
|
<el-form-item label="状态:">
|
<el-select v-model="filters.status" placeholder="请选择状态" clearable style="width: 150px;">
|
<el-option label="在用" value="in_use" />
|
<el-option label="闲置" value="idle" />
|
<el-option label="报废" value="scrapped" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="getTableData">搜索</el-button>
|
<el-button @click="resetFilters">重置</el-button>
|
</el-form-item>
|
</el-form>
|
<div class="table_list">
|
<div class="actions">
|
<div>
|
<el-statistic title="资产原值合计" :value="totalOriginalValue" precision="2" prefix="¥" />
|
<el-statistic title="累计折旧合计" :value="totalDepreciation" precision="2" prefix="¥" style="margin-left: 30px;" />
|
<el-statistic title="净值合计" :value="totalNetValue" precision="2" prefix="¥" style="margin-left: 30px;" />
|
</div>
|
<div>
|
<el-button type="primary" @click="add" icon="Plus">新增资产</el-button>
|
<el-button type="warning" @click="handleDepreciation" icon="Money">折旧计提</el-button>
|
<el-button @click="handleOut" icon="Download">导出</el-button>
|
</div>
|
</div>
|
<PIMTable
|
rowKey="id"
|
:column="columns"
|
:tableData="dataList"
|
:page="{
|
current: pagination.currentPage,
|
size: pagination.pageSize,
|
total: pagination.total,
|
}"
|
@pagination="changePage"
|
>
|
<template #originalValue="{ row }">
|
<span class="text-primary">¥{{ formatMoney(row.originalValue) }}</span>
|
</template>
|
<template #accumulatedDepreciation="{ row }">
|
<span class="text-warning">¥{{ formatMoney(row.accumulatedDepreciation) }}</span>
|
</template>
|
<template #netValue="{ row }">
|
<span class="text-success">¥{{ formatMoney(row.netValue) }}</span>
|
</template>
|
<template #category="{ row }">
|
<el-tag>{{ getCategoryLabel(row.category) }}</el-tag>
|
</template>
|
<template #status="{ row }">
|
<el-tag :type="getStatusType(row.status)">{{ getStatusLabel(row.status) }}</el-tag>
|
</template>
|
<template #operation="{ row }">
|
<el-button type="primary" link @click="view(row)">查看</el-button>
|
<el-button type="primary" link @click="edit(row)">编辑</el-button>
|
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
</template>
|
</PIMTable>
|
</div>
|
|
<FormDialog :title="dialogTitle" v-model="dialogVisible" width="800px" @confirm="submitForm" @cancel="dialogVisible = false">
|
<el-form :model="form" :rules="rules" ref="formRef" label-width="120px">
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="资产编号" prop="assetCode">
|
<el-input v-model="form.assetCode" placeholder="系统自动生成" disabled />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="资产名称" prop="assetName">
|
<el-input v-model="form.assetName" placeholder="请输入资产名称" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="资产类别" prop="category">
|
<el-select v-model="form.category" placeholder="请选择资产类别" style="width: 100%;">
|
<el-option label="房屋建筑" value="building" />
|
<el-option label="机器设备" value="machine" />
|
<el-option label="运输工具" value="vehicle" />
|
<el-option label="电子设备" value="electronic" />
|
<el-option label="办公家具" value="furniture" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="规格型号" prop="specification">
|
<el-input v-model="form.specification" placeholder="请输入规格型号" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="购置日期" prop="purchaseDate">
|
<el-date-picker v-model="form.purchaseDate" type="date" placeholder="选择日期" value-format="YYYY-MM-DD" style="width: 100%;" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="资产原值" prop="originalValue">
|
<el-input-number v-model="form.originalValue" :min="0" :precision="2" style="width: 100%;" @change="calculateNetValue" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="使用年限" prop="usefulLife">
|
<el-input-number v-model="form.usefulLife" :min="1" :max="50" style="width: 100%;" />
|
<span style="margin-left: 10px;">年</span>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="残值率" prop="residualRate">
|
<el-input-number v-model="form.residualRate" :min="0" :max="10" :precision="2" style="width: 100%;" />
|
<span style="margin-left: 10px;">%</span>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="累计折旧">
|
<el-input v-model="form.accumulatedDepreciation" disabled />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="资产净值">
|
<el-input v-model="form.netValue" disabled />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="存放地点" prop="location">
|
<el-input v-model="form.location" placeholder="请输入存放地点" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="使用部门" prop="department">
|
<el-input v-model="form.department" placeholder="请输入使用部门" />
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row :gutter="20">
|
<el-col :span="12">
|
<el-form-item label="保管人" prop="keeper">
|
<el-input v-model="form.keeper" placeholder="请输入保管人" />
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="状态" prop="status">
|
<el-select v-model="form.status" placeholder="请选择状态" style="width: 100%;">
|
<el-option label="在用" value="in_use" />
|
<el-option label="闲置" value="idle" />
|
<el-option label="报废" value="scrapped" />
|
</el-select>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="form.remark" type="textarea" :rows="3" placeholder="请输入备注" />
|
</el-form-item>
|
</el-form>
|
<template #footer>
|
<el-button type="primary" @click="submitForm">确定</el-button>
|
<el-button @click="dialogVisible = false">取消</el-button>
|
</template>
|
</FormDialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, onMounted, computed } from "vue";
|
import { ElMessage, ElMessageBox } from "element-plus";
|
import FormDialog from "@/components/Dialog/FormDialog.vue";
|
|
defineOptions({
|
name: "固定资产",
|
});
|
|
const filters = reactive({
|
assetCode: "",
|
assetName: "",
|
category: "",
|
status: "",
|
});
|
|
const pagination = reactive({
|
currentPage: 1,
|
pageSize: 10,
|
total: 0,
|
});
|
|
const columns = [
|
{ label: "资产编号", prop: "assetCode", width: "130" },
|
{ label: "资产名称", prop: "assetName", width: "150" },
|
{ label: "资产类别", prop: "category", slot: "category" },
|
{ label: "规格型号", prop: "specification", width: "120" },
|
{ label: "资产原值", prop: "originalValue", slot: "originalValue" },
|
{ label: "累计折旧", prop: "accumulatedDepreciation", slot: "accumulatedDepreciation" },
|
{ label: "资产净值", prop: "netValue", slot: "netValue" },
|
{ label: "状态", prop: "status", slot: "status" },
|
{ label: "操作", prop: "operation", slot: "operation", width: "180", fixed: "right" },
|
];
|
|
const dataList = ref([]);
|
const dialogVisible = ref(false);
|
const dialogTitle = ref("");
|
const formRef = ref(null);
|
const isEdit = ref(false);
|
const currentId = ref(null);
|
|
const form = reactive({
|
assetCode: "",
|
assetName: "",
|
category: "",
|
specification: "",
|
purchaseDate: "",
|
originalValue: 0,
|
usefulLife: 5,
|
residualRate: 5,
|
accumulatedDepreciation: 0,
|
netValue: 0,
|
location: "",
|
department: "",
|
keeper: "",
|
status: "in_use",
|
remark: "",
|
});
|
|
const rules = {
|
assetName: [{ required: true, message: "请输入资产名称", trigger: "blur" }],
|
category: [{ required: true, message: "请选择资产类别", trigger: "change" }],
|
purchaseDate: [{ required: true, message: "请选择购置日期", trigger: "change" }],
|
originalValue: [{ required: true, message: "请输入资产原值", trigger: "blur" }],
|
usefulLife: [{ required: true, message: "请输入使用年限", trigger: "blur" }],
|
};
|
|
const mockData = [
|
{ id: 1, assetCode: "GD2024001", assetName: "办公电脑", category: "electronic", specification: "联想ThinkPad X1", purchaseDate: "2023-01-15", originalValue: 8000, usefulLife: 5, residualRate: 5, accumulatedDepreciation: 1520, netValue: 6480, location: "办公室", department: "财务部", keeper: "张三", status: "in_use", remark: "" },
|
{ id: 2, assetCode: "GD2024002", assetName: "打印机", category: "electronic", specification: "惠普M479fdw", purchaseDate: "2023-03-20", originalValue: 3500, usefulLife: 5, residualRate: 5, accumulatedDepreciation: 532, netValue: 2968, location: "文印室", department: "行政部", keeper: "李四", status: "in_use", remark: "" },
|
{ id: 3, assetCode: "GD2024003", assetName: "办公桌椅", category: "furniture", specification: "实木办公桌", purchaseDate: "2023-06-10", originalValue: 2500, usefulLife: 10, residualRate: 5, accumulatedDepreciation: 118.75, netValue: 2381.25, location: "办公室", department: "销售部", keeper: "王五", status: "in_use", remark: "" },
|
{ id: 4, assetCode: "GD2024004", assetName: "商务车", category: "vehicle", specification: "别克GL8", purchaseDate: "2022-08-01", originalValue: 280000, usefulLife: 10, residualRate: 5, accumulatedDepreciation: 53200, netValue: 226800, location: "停车场", department: "行政部", keeper: "赵六", status: "in_use", remark: "" },
|
];
|
|
const totalOriginalValue = computed(() => {
|
return dataList.value.reduce((sum, item) => sum + Number(item.originalValue), 0);
|
});
|
|
const totalDepreciation = computed(() => {
|
return dataList.value.reduce((sum, item) => sum + Number(item.accumulatedDepreciation), 0);
|
});
|
|
const totalNetValue = computed(() => {
|
return dataList.value.reduce((sum, item) => sum + Number(item.netValue), 0);
|
});
|
|
const formatMoney = (value) => {
|
if (value === undefined || value === null) return "0.00";
|
return Number(value).toFixed(2).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
};
|
|
const getCategoryLabel = (category) => {
|
const map = {
|
building: "房屋建筑",
|
machine: "机器设备",
|
vehicle: "运输工具",
|
electronic: "电子设备",
|
furniture: "办公家具",
|
};
|
return map[category] || category;
|
};
|
|
const getStatusLabel = (status) => {
|
const map = { in_use: "在用", idle: "闲置", scrapped: "报废" };
|
return map[status] || status;
|
};
|
|
const getStatusType = (status) => {
|
const map = { in_use: "success", idle: "warning", scrapped: "info" };
|
return map[status] || "";
|
};
|
|
const calculateNetValue = () => {
|
form.netValue = Number((form.originalValue - form.accumulatedDepreciation).toFixed(2));
|
};
|
|
const getTableData = () => {
|
let result = [...mockData];
|
if (filters.assetCode) {
|
result = result.filter(item => item.assetCode.includes(filters.assetCode));
|
}
|
if (filters.assetName) {
|
result = result.filter(item => item.assetName.includes(filters.assetName));
|
}
|
if (filters.category) {
|
result = result.filter(item => item.category === filters.category);
|
}
|
if (filters.status) {
|
result = result.filter(item => item.status === filters.status);
|
}
|
pagination.total = result.length;
|
dataList.value = result.slice((pagination.currentPage - 1) * pagination.pageSize, pagination.currentPage * pagination.pageSize);
|
};
|
|
const resetFilters = () => {
|
filters.assetCode = "";
|
filters.assetName = "";
|
filters.category = "";
|
filters.status = "";
|
pagination.currentPage = 1;
|
getTableData();
|
};
|
|
const changePage = ({ current, size }) => {
|
pagination.currentPage = current;
|
pagination.pageSize = size;
|
getTableData();
|
};
|
|
const add = () => {
|
isEdit.value = false;
|
dialogTitle.value = "新增固定资产";
|
Object.assign(form, {
|
assetCode: "GD" + Date.now().toString().slice(-8),
|
assetName: "",
|
category: "",
|
specification: "",
|
purchaseDate: new Date().toISOString().split('T')[0],
|
originalValue: 0,
|
usefulLife: 5,
|
residualRate: 5,
|
accumulatedDepreciation: 0,
|
netValue: 0,
|
location: "",
|
department: "",
|
keeper: "",
|
status: "in_use",
|
remark: "",
|
});
|
dialogVisible.value = true;
|
};
|
|
const edit = (row) => {
|
isEdit.value = true;
|
currentId.value = row.id;
|
dialogTitle.value = "编辑固定资产";
|
Object.assign(form, row);
|
dialogVisible.value = true;
|
};
|
|
const view = (row) => {
|
ElMessage.info(`查看资产: ${row.assetName}`);
|
};
|
|
const handleDelete = (row) => {
|
ElMessageBox.confirm("确认删除该固定资产吗?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning",
|
}).then(() => {
|
const index = mockData.findIndex(item => item.id === row.id);
|
if (index !== -1) {
|
mockData.splice(index, 1);
|
}
|
ElMessage.success("删除成功");
|
getTableData();
|
});
|
};
|
|
const handleDepreciation = () => {
|
ElMessageBox.confirm("确认进行本月折旧计提吗?", "提示", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "info",
|
}).then(() => {
|
mockData.forEach(item => {
|
if (item.status === "in_use") {
|
const monthlyDepreciation = (item.originalValue * (1 - item.residualRate / 100)) / (item.usefulLife * 12);
|
item.accumulatedDepreciation = Number((item.accumulatedDepreciation + monthlyDepreciation).toFixed(2));
|
item.netValue = Number((item.originalValue - item.accumulatedDepreciation).toFixed(2));
|
}
|
});
|
ElMessage.success("折旧计提完成");
|
getTableData();
|
});
|
};
|
|
const handleOut = () => {
|
ElMessage.success("导出成功");
|
};
|
|
const submitForm = () => {
|
formRef.value.validate((valid) => {
|
if (valid) {
|
calculateNetValue();
|
if (isEdit.value) {
|
const index = mockData.findIndex(item => item.id === currentId.value);
|
if (index !== -1) {
|
mockData[index] = { ...mockData[index], ...form };
|
}
|
ElMessage.success("编辑成功");
|
} else {
|
const newId = mockData.length > 0 ? Math.max(...mockData.map(item => item.id)) + 1 : 1;
|
mockData.push({ id: newId, ...form });
|
ElMessage.success("新增成功");
|
}
|
dialogVisible.value = false;
|
getTableData();
|
}
|
});
|
};
|
|
onMounted(() => {
|
getTableData();
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.actions {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
margin-bottom: 15px;
|
|
> div:first-child {
|
display: flex;
|
align-items: center;
|
}
|
}
|
|
.text-primary {
|
color: #409eff;
|
font-weight: bold;
|
}
|
|
.text-warning {
|
color: #e6a23c;
|
font-weight: bold;
|
}
|
|
.text-success {
|
color: #67c23a;
|
font-weight: bold;
|
}
|
</style>
|