From 792cae2ccf15b3c9bd56a319bc0685b3e9b0fd4c Mon Sep 17 00:00:00 2001
From: yyb <995253665@qq.com>
Date: 星期二, 12 五月 2026 15:23:23 +0800
Subject: [PATCH] Merge branch 'dev_NEW_pro' of http://114.132.189.42:9002/r/product-inventory-management into dev_NEW_pro
---
src/views/financialManagement/assets/fixedAssets.vue | 149 ++++++++++++++++++++++++-------------------------
1 files changed, 72 insertions(+), 77 deletions(-)
diff --git a/src/views/financialManagement/assets/fixedAssets.vue b/src/views/financialManagement/assets/fixedAssets.vue
index 61eb245..58b2210 100644
--- a/src/views/financialManagement/assets/fixedAssets.vue
+++ b/src/views/financialManagement/assets/fixedAssets.vue
@@ -189,6 +189,13 @@
import { ref, reactive, onMounted, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import FormDialog from "@/components/Dialog/FormDialog.vue";
+import {
+ listFixedAssetPage,
+ addFixedAsset,
+ updateFixedAsset,
+ deleteFixedAsset,
+ depreciateFixedAsset,
+} from "@/api/financialManagement/fixedAsset";
defineOptions({
name: "鍥哄畾璧勪骇",
@@ -210,13 +217,13 @@
const columns = [
{ label: "璧勪骇缂栧彿", prop: "assetCode", width: "130" },
{ label: "璧勪骇鍚嶇О", prop: "assetName", width: "150" },
- { label: "璧勪骇绫诲埆", prop: "category", slot: "category" },
+ { label: "璧勪骇绫诲埆", prop: "category", dataType: "slot", 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" },
+ { label: "璧勪骇鍘熷��", prop: "originalValue", dataType: "slot", slot: "originalValue" },
+ { label: "绱鎶樻棫", prop: "accumulatedDepreciation", dataType: "slot", slot: "accumulatedDepreciation" },
+ { label: "璧勪骇鍑�鍊�", prop: "netValue", dataType: "slot", slot: "netValue" },
+ { label: "鐘舵��", prop: "status", dataType: "slot", slot: "status" },
+ { label: "鎿嶄綔", prop: "operation", dataType: "slot", slot: "operation", width: "180", fixed: "right" },
];
const dataList = ref([]);
@@ -226,7 +233,7 @@
const isEdit = ref(false);
const currentId = ref(null);
-const form = reactive({
+const createDefaultForm = () => ({
assetCode: "",
assetName: "",
category: "",
@@ -244,6 +251,10 @@
remark: "",
});
+const form = reactive({
+ ...createDefaultForm(),
+});
+
const rules = {
assetName: [{ required: true, message: "璇疯緭鍏ヨ祫浜у悕绉�", trigger: "blur" }],
category: [{ required: true, message: "璇烽�夋嫨璧勪骇绫诲埆", trigger: "change" }],
@@ -251,13 +262,6 @@
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);
@@ -288,35 +292,39 @@
};
const getStatusLabel = (status) => {
- const map = { in_use: "鍦ㄧ敤", idle: "闂茬疆", scrapped: "鎶ュ簾" };
- return map[status] || status;
+ const key = String(status || "").toLowerCase();
+ const map = { in_use: "鍦ㄧ敤", idle: "闂茬疆", repair: "缁翠慨涓�", scrapped: "鎶ュ簾" };
+ return map[key] || status;
};
const getStatusType = (status) => {
- const map = { in_use: "success", idle: "warning", scrapped: "info" };
- return map[status] || "";
+ const key = String(status || "").toLowerCase();
+ const map = { in_use: "success", idle: "warning", repair: "warning", scrapped: "info" };
+ return map[key] || "";
};
const calculateNetValue = () => {
- form.netValue = Number((form.originalValue - form.accumulatedDepreciation).toFixed(2));
+ const originalValue = Number(form.originalValue || 0);
+ const accumulatedDepreciation = Number(form.accumulatedDepreciation || 0);
+ form.netValue = Number((originalValue - accumulatedDepreciation).toFixed(2));
};
-const getTableData = () => {
- let result = [...mockData];
- if (filters.assetCode) {
- result = result.filter(item => item.assetCode.includes(filters.assetCode));
+// 鑱旇皟绾﹀畾锛氬垎椤靛弬鏁板浐瀹氫负 current/size锛岃繑鍥� data.records/data.total
+const getTableData = async () => {
+ try {
+ const { data } = await listFixedAssetPage({
+ current: pagination.currentPage,
+ size: pagination.pageSize,
+ assetCode: filters.assetCode,
+ assetName: filters.assetName,
+ category: filters.category,
+ status: filters.status,
+ });
+ dataList.value = data?.records || [];
+ pagination.total = Number(data?.total || 0);
+ } catch (error) {
+ // 鎻愮ず鐢卞叏灞�璇锋眰鎷︽埅鍣ㄥ鐞嗭紝杩欓噷浠呴槻姝㈡湭鎹曡幏寮傚父
}
- 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 = () => {
@@ -334,25 +342,15 @@
getTableData();
};
+const buildAssetCode = () => `GD${Date.now().toString().slice(-10)}`;
+
const add = () => {
isEdit.value = false;
+ currentId.value = null;
dialogTitle.value = "鏂板鍥哄畾璧勪骇";
- Object.assign(form, {
- assetCode: "GD" + Date.now().toString().slice(-8),
- assetName: "",
- category: "",
- specification: "",
+ Object.assign(form, createDefaultForm(), {
+ assetCode: buildAssetCode(),
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;
};
@@ -361,7 +359,7 @@
isEdit.value = true;
currentId.value = row.id;
dialogTitle.value = "缂栬緫鍥哄畾璧勪骇";
- Object.assign(form, row);
+ Object.assign(form, createDefaultForm(), row);
dialogVisible.value = true;
};
@@ -374,13 +372,14 @@
confirmButtonText: "纭畾",
cancelButtonText: "鍙栨秷",
type: "warning",
- }).then(() => {
- const index = mockData.findIndex(item => item.id === row.id);
- if (index !== -1) {
- mockData.splice(index, 1);
+ }).then(async () => {
+ // 鑱旇皟绾﹀畾锛氬垹闄ゆ帴鍙d娇鐢� ids=1&ids=2
+ await deleteFixedAsset([row.id]);
+ if (dataList.value.length === 1 && pagination.currentPage > 1) {
+ pagination.currentPage -= 1;
}
ElMessage.success("鍒犻櫎鎴愬姛");
- getTableData();
+ await getTableData();
});
};
@@ -389,16 +388,10 @@
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));
- }
- });
+ }).then(async () => {
+ await depreciateFixedAsset({});
ElMessage.success("鎶樻棫璁℃彁瀹屾垚");
- getTableData();
+ await getTableData();
});
};
@@ -407,22 +400,24 @@
};
const submitForm = () => {
- formRef.value.validate((valid) => {
+ formRef.value.validate(async valid => {
if (valid) {
- calculateNetValue();
- if (isEdit.value) {
- const index = mockData.findIndex(item => item.id === currentId.value);
- if (index !== -1) {
- mockData[index] = { ...mockData[index], ...form };
+ try {
+ calculateNetValue();
+ const payload = { ...form };
+ if (isEdit.value) {
+ payload.id = currentId.value;
+ await updateFixedAsset(payload);
+ ElMessage.success("缂栬緫鎴愬姛");
+ } else {
+ await addFixedAsset(payload);
+ ElMessage.success("鏂板鎴愬姛");
}
- 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;
+ await getTableData();
+ } catch (error) {
+ // 鎻愮ず鐢卞叏灞�璇锋眰鎷︽埅鍣ㄥ鐞嗭紝杩欓噷浠呴槻姝㈡湭鎹曡幏寮傚父
}
- dialogVisible.value = false;
- getTableData();
}
});
};
--
Gitblit v1.9.3