From 09c5667700fb6da21d29c41e51fa5482a4b40bc9 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期五, 24 十月 2025 11:22:22 +0800
Subject: [PATCH] 新公司部署相关配置修改
---
src/views/production/components/ProductionDialog.vue | 818 +++++++++++++++++++++++++++++++++-------------------------
1 files changed, 467 insertions(+), 351 deletions(-)
diff --git a/src/views/production/components/ProductionDialog.vue b/src/views/production/components/ProductionDialog.vue
index 7ce8482..4a21fa4 100644
--- a/src/views/production/components/ProductionDialog.vue
+++ b/src/views/production/components/ProductionDialog.vue
@@ -1,444 +1,556 @@
<template>
<el-dialog
- v-model="dialogVisible"
- :title="dialogType === 'add' ? '鏂板鐢熶骇鍔犲伐' : '缂栬緫鐢熶骇鍔犲伐'"
- width="1200px"
- :close-on-click-modal="false"
- @close="handleClose"
+ v-model="dialogVisible"
+ :title="dialogType === 'add' ? '鏂板鐢熶骇鍔犲伐' : dialogType === 'viewRow' ? '鏌ョ湅鐢熶骇鍔犲伐' : '缂栬緫鐢熶骇鍔犲伐'"
+ width="1200px"
+ :close-on-click-modal="false"
+ @close="handleClose"
>
- <el-button type="primary" @click="handlData">閫夋嫨鏁版嵁</el-button>
- <ETable
- v-if="tableData.length > 0"
- :columns="columns"
- height="200"
- @cell-edit="handleCellEdit"
- :showOperations="false"
- :tableData="tableData"
- @row-click="handleRowClick"
- :editableColumns="['used']"
- />
- <div v-if="tableData.length > 0" class="empty-table">
- <h1>鐢熶骇鏄庣粏</h1>
- <el-row :gutter="10">
- <el-col :span="2">
- <el-button type="primary" @click="addNewRow">
+ <el-row :gutter="10" style="margin-bottom: 10px" v-if="dialogType !== 'viewRow'">
+ <el-col :span="3">
+ <el-button type="primary" @click="handlData"
+ >
<el-icon>
- <Plus />
+ <Plus/>
</el-icon>
- 鏂板
+ 閫夋嫨鏁版嵁
+ </el-button
+ >
+ </el-col>
+ <el-col :span="4">
+ <el-button
+ type="danger"
+ @click="removeSelectedData"
+ :disabled="tableData.length === 0"
+ >
+ <el-icon>
+ <Delete/>
+ </el-icon>
+ 娓呯┖宸查��
</el-button>
</el-col>
- <el-col :span="2">
- <el-button type="danger" @click="clearAllRows">
- <el-icon>
- <Delete />
- </el-icon>
- 娓呯┖
- </el-button>
+ <el-col :span="17" style="text-align: right; line-height: 32px">
+ <el-text type="info" size="small">
+ 宸查�夋嫨 {{ tableData.length }} 椤规暟鎹�
+ <span v-if="tableData.length > 0">
+ 锛屾�讳娇鐢ㄩ噺: {{ totalUsedQuantity.toFixed(2) }}
+ </span>
+ </el-text>
</el-col>
- <!-- <el-col :span="2">
- <el-button type="warning" @click="calculateAllCosts">
- <el-icon>
- <Warning />
- </el-icon> 閲嶆柊璁$畻
- </el-button>
- </el-col> -->
</el-row>
- <ProductionDetailsTable
- v-model="detailsTableData"
- :border="false"
- :show-operations="true"
- :auto-calculate="true"
- @input-change="handleDetailsChange"
- @delete-row="handleDeleteRow"
+ <ETableModify
+ :columns="columns"
+ :showOperations="dialogType !== 'viewRow'"
+ height="200"
+ @cell-edit="handleCellEdit"
+ :tableData="tableData"
+ :showOverflowTooltip="false"
+ @row-click="handleRowClick"
+ :editableColumns="dialogType === 'viewRow' ? [] : ['usedQuantity']"
+ :editableCells="dialogType !== 'viewRow'"
+ @delete="handleRemoveItem"
/>
+ <div class="empty-table">
+ <h1>鐢熶骇鏄庣粏</h1>
+ <el-row :gutter="10">
+ <el-col :span="2">
+ <el-button type="primary" @click="addNewRow" v-if="dialogType !== 'viewRow'">
+ <el-icon>
+ <Plus/>
+ </el-icon>
+ 鏂板
+ </el-button>
+ </el-col>
+ <!-- <el-col :span="2">
+ <el-button type="danger" @click="clearAllRows">
+ <el-icon>
+ <Delete />
+ </el-icon>
+ 娓呯┖
+ </el-button>
+ </el-col> -->
+ </el-row>
+ <ProductionDetailsTable
+ v-model="detailsTableData"
+ :border="false"
+ :show-operations="dialogType !== 'viewRow'"
+ :auto-calculate="true"
+ @input-change="handleDetailsChange"
+ @delete-row="handleDeleteRow"
+ :dialogType="dialogType"
+ />
</div>
- <div style="margin-top: 20px;" v-else>鏆傛棤鏁版嵁锛岃閫夋嫨閰嶇疆鏁版嵁</div>
<template #footer>
<div class="dialog-footer">
- <el-button @click="handleClose">鍙� 娑�</el-button>
- <el-button type="primary" :loading="loading" @click="handleSubmit"
- >纭� 瀹�</el-button
+ <el-button
+ @click="handleClose"
+ >{{ dialogType === 'viewRow' ? '鍏� 闂�' : '鍙� 娑�' }}
+ </el-button
+ >
+ <!-- <el-button @click="handleReset" v-if="dialogType === 'edit'"
+ >閲� 缃�</el-button
+ > -->
+ <el-button
+ v-if="dialogType !== 'viewRow'"
+ type="primary"
+ :loading="loading"
+ @click="handleSubmit"
+ >纭� 瀹�
+ </el-button
>
</div>
</template>
</el-dialog>
<el-dialog
- v-model="innerVisible"
- width="1000"
- title="閫夋嫨閰嶇疆鏁版嵁"
- append-to-body
+ v-model="innerVisible"
+ width="1000"
+ title="閫夋嫨閰嶇疆鏁版嵁"
+ center
+ append-to-body
>
+ <div style="margin-bottom: 10px">
+ <el-alert
+ v-if="tableData.length > 0"
+ :title="`褰撳墠宸查�夋嫨 ${tableData.length} 鏉℃暟鎹甡"
+ type="info"
+ :closable="false"
+ show-icon
+ />
+ </div>
<ETable
- @selection-change="handleSelectionChange"
- :showOperations="false"
- :columns="formalDatabaseDataColumns"
- :tableData="formalDatabaseData"
- height="400"
- @cell-edit="handleCellEdit"
- :show-selection="true"
+ :showIndex="false"
+ :showOverflowTooltip="false"
+ @selection-change="handleSelectionChange"
+ :showOperations="false"
+ ref="etableRef"
+ :columns="formalDatabaseColumns"
+ :tableData="formalDatabaseData"
+ :defaultSelectedIds="selectedIds"
+ :rowKey="'id'"
+ height="400"
+ @cell-edit="handleCellEdit"
+ :show-selection="true"
/>
- <el-row :gutter="24">
- <el-col :span="2" :offset="22">
- <el-button type="primary" @click="handleSelectData">纭畾</el-button>
+ <el-row :gutter="24" style="margin-top: 15px">
+ <el-col :span="12">
+ <el-text type="info">
+ 宸查�夋嫨 {{ formalDatabaseSelectedData.length }} 鏉℃暟鎹�
+ </el-text>
+ </el-col>
+ <el-col :span="12" style="text-align: right">
+ <el-button @click="innerVisible = false">鍙栨秷</el-button>
+ <el-button
+ type="primary"
+ @click="handleSelectData"
+ :disabled="formalDatabaseSelectedData.length === 0"
+ >
+ 纭畾娣诲姞
+ </el-button>
</el-col>
</el-row>
</el-dialog>
</template>
<script setup>
-import { ref, reactive, watch } from "vue";
-import ETable from "@/components/Table/EtableModify.vue";
+import {ref, reactive, watch, onMounted, nextTick, computed} from "vue";
+import ETable from "@/components/Table/ETable.vue";
+import ETableModify from "@/components/Table/EtableModify.vue";
import ProductionDetailsTable from "./ProductionDetailsTable.vue";
-import { ElMessage } from "element-plus";
-import { Delete, Warning, Plus } from "@element-plus/icons-vue";
+import {ElMessage, ElMessageBox, ElAlert, ElText} from "element-plus";
+import {Delete, Warning, Plus} from "@element-plus/icons-vue";
+import {
+ getOfficialAll,
+ addOrEditPM,
+ getCoalInfoList,
+ deleteProductionInventory,
+} from "@/api/production/index.js";
+import { getSupplyList } from "@/api/procureMent/index.js"
+import {validateFormData, validateNumber, deepClone, createDefaultProductionRow} from "@/utils/production";
+import {useCoalData} from "./useCoalData";
+import useUserStore from "@/store/modules/user";
+// Props 鍜� Emits
const props = defineProps({
- visible: {
- type: Boolean,
- default: false,
- },
- type: {
- type: String,
- default: "add", // 'add' 鎴� 'edit'
- },
- rowData: {
- type: Object,
- default: () => ({}),
- },
+ visible: {type: Boolean, default: false},
+ type: {type: String, default: "add"},
+ rowData: {type: Object, default: () => ({})},
});
-const dialogVisible = defineModel("visible", {
- type: Boolean,
- default: false,
-});
-const emit = defineEmits(["update:visible", "success"]);
+const dialogVisible = defineModel("visible", {type: Boolean, default: false});
+const emit = defineEmits(["update:visible", "success", "update:productionAndProcessing"]);
+
+// 鐢ㄦ埛淇℃伅鍜岀叅绉嶆暟鎹�
+const userStore = useUserStore();
+const {getCoalNameById} = useCoalData();
+let userInfo;
+
+// 瀵硅瘽妗嗙姸鎬�
const innerVisible = ref(false);
const dialogType = ref("add");
const loading = ref(false);
-const formRef = ref(null);
+const etableRef = ref(null);
+
+// 鏁版嵁鐘舵��
const tableData = ref([]);
+const detailsTableData = ref([]);
+const formalDatabaseData = ref([]);
+const formalDatabaseSelectedData = ref([]);
+const selectedIds = ref([]);
const currentRow = ref(null);
+const copyForm = ref(null);
+const coalList = ref([])
+const supplierList = ref([]);
+// 琛ㄦ牸鍒楅厤缃�
const columns = [
- { label: "鐓ょ", prop: "category" },
- { label: "鐑��", prop: "Calorific" },
- { label: "搴撳瓨鏁伴噺", prop: "stock" },
- { label: "鏈浣跨敤鏁伴噺", prop: "used" },
-];
-const detailsTableData = ref([
- {
- coalType: "",
- calorificValue: "",
- productionQuantity: "",
- laborCost: "",
- energyCost: "",
- equipmentDepreciation: "",
- purchasePrice: "",
- totalCost: "",
+ {prop: "coalId", label: "鐓ょ", minwidth: 60,
+ formatter: (row) => {
+ return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--";
+ }
},
+ {label: "搴撳瓨鏁伴噺", prop: "inventoryQuantity", minwidth: 100},
+ {
+ label: "浣跨敤鏁伴噺",
+ prop: "usedQuantity",
+ editable: true,
+ minwidth: 120,
+ editType: "number",
+ },
+];
+
+const formalDatabaseColumns = ref([
+ {prop: "coalId", label: "鐓ょ", minwidth: 60,
+ formatter: (row) => {
+ return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--";
+ }
+ },
+ {prop: "inventoryQuantity", label: "搴撳瓨鏁伴噺", minwidth: 80},
+ {prop: "unit", label: "鍗曚綅", minwidth: 20},
+ {prop: "priceExcludingTax", label: "鍗曚环锛堜笉鍚◣锛�", minwidth: 80},
+ {prop: "createTime", label: "鐧昏鏃ユ湡", width: 200},
]);
+// 宸ュ叿鍑芥暟
+const debugIdMatching = () => {
+ if (formalDatabaseData.value.length > 0 && selectedIds.value.length > 0) {
+ const matchedRows = formalDatabaseData.value.filter((row) =>
+ selectedIds.value.includes(row.id)
+ );
+ }
+};
+
const handleRowClick = (row) => {
currentRow.value = row;
};
-const formalDatabaseDataColumns = ref([
- { prop: "name", label: "渚涘簲鍟嗗悕绉�", width: 150 },
- { prop: "type", label: "鐓ょ绫诲瀷", width: 120 },
- { prop: "unit", label: "鍗曚綅", width: 100 },
- { prop: "number", label: "閲囪喘鏁伴噺", width: 100 },
- { prop: "money", label: "鍗曚环锛堝惈绋庯級", width: 120 },
- { prop: "money1", label: "鎬讳环锛堝惈绋庯級", width: 120 },
- { prop: "money2", label: "绋庣巼", width: 80 },
- { prop: "money3", label: "涓嶅惈绋庡崟浠�", width: 120 },
- { prop: "createUser", label: "鐧昏浜�", width: 100 },
- { prop: "createTime", label: "鐧昏鏃ユ湡", width: 150 },
-]);
-// 琛ㄥ崟鏁版嵁
-const formData = reactive({
- category: "",
- unit: "",
- productionVolume: 0,
- laborCost: 0,
- materialCost: 0,
- equipmentCost: 0,
- totalCost: 0,
- totalPrice: 0,
- profit: 0,
- reviewer: "",
- date: "",
-});
-const handlData = () => {
+
+// 鑾峰彇鍩虹鏁版嵁锛堢叅绉嶅拰渚涘簲鍟嗭級
+const loadBasicData = async () => {
+ try {
+ const [coalResponse, supplierResponse] = await Promise.all([
+ getCoalInfoList(),
+ getSupplyList()
+ ]);
+
+ coalList.value = coalResponse.data || [];
+ supplierList.value = supplierResponse.data || [];
+ } catch (error) {
+ ElMessage.error("鑾峰彇鍩虹鏁版嵁澶辫触");
+ }
+};
+
+// 鑾峰彇閰嶇疆鏁版嵁
+const handlData = async () => {
innerVisible.value = true;
+
+ // 纭繚鍩虹鏁版嵁宸插姞杞�
+ if (coalList.value.length === 0 || supplierList.value.length === 0) {
+ await loadBasicData();
+ }
+
+ try {
+ const OfficialAll = await getOfficialAll();
+
+ if (OfficialAll.code === 200) {
+ formalDatabaseData.value = OfficialAll.data;
+ const existingOfficialIds = tableData.value
+ .map((item) => item.officialId)
+ .filter((id) => id);
+ selectedIds.value = existingOfficialIds;
+ debugIdMatching();
+ nextTick(() => {
+ setTimeout(() => {
+ if (etableRef.value && existingOfficialIds.length > 0) {
+ etableRef.value.setDefaultSelection();
+ }
+ }, 100);
+ });
+ } else {
+ ElMessage.error("鑾峰彇閰嶇疆鏁版嵁澶辫触");
+ }
+ } catch (error) {
+ ElMessage.error("鑾峰彇閰嶇疆鏁版嵁澶辫触");
+ }
};
-const formalDatabaseData = ref([]);
-const formalDatabaseSelectedData = ref([]);
-formalDatabaseData.value = [
- {
- id: 1,
- name: "渚涘簲鍟咥",
- type: "鍔ㄥ姏鐓�",
- unit: "鍚�",
- number: 120,
- money: 500,
- money1: 200,
- money2: 200,
- money3: 300,
- money4: "楂樹綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 2,
- name: "渚涘簲鍟咥",
- type: "鍔ㄥ姏鐓�",
- unit: "鍚�",
- number: 100,
- money: 600,
- money1: 300,
- money2: 300,
- money3: 300,
- money4: "浣庝綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 3,
- name: "渚涘簲鍟咮",
- type: "鐒︾叅",
- unit: "鍚�",
- number: 300,
- money: 789,
- money1: 400,
- money2: 400,
- money3: 400,
- money4: "楂樹綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 4,
- name: "渚涘簲鍟咮",
- type: "鐒︾叅",
- unit: "鍚�",
- number: 256,
- money: 800,
- money1: 420,
- money2: 420,
- money3: 420,
- money4: "浣庝綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 5,
- name: "渚涘簲鍟咰",
- type: "鏃犵儫鐓�",
- unit: "鍚�",
- number: 256,
- money: 700,
- money1: 300,
- money2: 300,
- money3: 300,
- money4: "楂樹綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 6,
- name: "渚涘簲鍟咥",
- type: "鍔ㄥ姏鐓�",
- unit: "鍚�",
- number: 120,
- money: 500,
- money1: 200,
- money2: 200,
- money3: 300,
- money4: "楂樹綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 7,
- name: "渚涘簲鍟咥",
- type: "鍔ㄥ姏鐓�",
- unit: "鍚�",
- number: 100,
- money: 600,
- money1: 300,
- money2: 300,
- money3: 300,
- money4: "浣庝綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 8,
- name: "渚涘簲鍟咮",
- type: "鐒︾叅",
- unit: "鍚�",
- number: 300,
- money: 789,
- money1: 400,
- money2: 400,
- money3: 400,
- money4: "楂樹綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 9,
- name: "渚涘簲鍟咮",
- type: "鐒︾叅",
- unit: "鍚�",
- number: 256,
- money: 800,
- money1: 420,
- money2: 420,
- money3: 420,
- money4: "浣庝綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
- {
- id: 10,
- name: "渚涘簲鍟咰",
- type: "鏃犵儫鐓�",
- unit: "鍚�",
- number: 256,
- money: 700,
- money1: 300,
- money2: 300,
- money3: 300,
- money4: "楂樹綅",
- createUser: "admin",
- createTime: "2025-06-01",
- },
-];
+// 鎵嬪姩璁剧疆琛ㄦ牸閫変腑鐘舵��
+const setTableSelection = (ids) => {
+ if (!etableRef.value || !Array.isArray(ids) || ids.length === 0) {
+ return;
+ }
-// 琛ㄥ崟楠岃瘉瑙勫垯
-const rules = {
- category: [{ required: true, message: "璇烽�夋嫨鐓ょ", trigger: "change" }],
+ nextTick(() => {
+ setTimeout(() => {
+ try {
+ etableRef.value.clearSelection();
+ const rowsToSelect = formalDatabaseData.value.filter((row) =>
+ ids.includes(row.id)
+ );
+ if (rowsToSelect.length > 0) {
+ etableRef.value.setRowsSelection(rowsToSelect, true);
+ }
+ } catch (error) {
+ }
+ }, 150);
+ });
};
-// 鍒濆鍖�
-const Initialization = () => {
- console.log("鍒濆鍖栨暟鎹�");
+// 鍒濆鍖栧拰缂栬緫鍒濆鍖�
+const Initialization = async () => {
tableData.value = [];
+ detailsTableData.value = [];
+ copyForm.value = null;
+ dialogType.value = "add";
+
+ // 鍔犺浇鍩虹鏁版嵁
+ await loadBasicData();
};
+
+const editInitialization = async (type, data) => {
+ copyForm.value = deepClone(data);
+ tableData.value = data.productionInventoryList || [];
+ detailsTableData.value = data.productionList || [];
+ dialogType.value = type;
+ const existingOfficialIds = tableData.value
+ .map((item) => item.officialId)
+ .filter((id) => id);
+ selectedIds.value = existingOfficialIds;
+
+ // 鍔犺浇鍩虹鏁版嵁
+ await loadBasicData();
+};
+// 鐩戝惉瀵硅瘽妗嗙姸鎬侊紝鍦ㄦ墦寮�鏃惰缃�変腑鐘舵��
+watch(innerVisible, (newVal) => {
+ if (newVal && selectedIds.value.length > 0) {
+ setTimeout(() => setTableSelection(selectedIds.value), 200);
+ }
+ // 瀵硅瘽妗嗗叧闂椂娓呯┖閫夋嫨鐘舵��
+ if (!newVal) {
+ formalDatabaseSelectedData.value = [];
+ }
+});
+
defineExpose({
- Initialization
+ Initialization,
+ editInitialization,
});
const handleSelectData = (row) => {
+ tableData.value = [];
if (!innerVisible.value) return;
- // 鑾峰彇閫変腑鐨勬暟鎹�
const selectedData = formalDatabaseSelectedData.value;
if (selectedData.length === 0) {
ElMessage.warning("璇疯嚦灏戦�夋嫨涓�鏉℃暟鎹�");
return;
}
- // 灏嗛�変腑鐨勬暟鎹牴鎹渶瑕佺瓫閫夊埌琛ㄦ牸涓�
+ let addedCount = 0;
+ let duplicateCount = 0;
selectedData.forEach((item) => {
- const existingItem = tableData.value.find(
- (row) => row.id === item.id
- );
- if (!existingItem) {
- tableData.value.push({
- id: item.id,
- category: item.type,
- Calorific: item.money4,
- stock: item.number,
- used: 0, // 鍒濆浣跨敤鏁伴噺涓�0
- });
- }
+ const newItem = {
+ ...item, // 澶嶅埗鎵�鏈夊師濮嬫暟鎹�
+ officialId: item.id, // 淇濆瓨鍘熷鐨刬d浣滀负officialId
+ usedQuantity: 0, // 鍒濆浣跨敤鏁伴噺涓�0
+ // 鍙互鏍规嵁闇�瑕佹坊鍔犲叾浠栧瓧娈�
+ };
+ tableData.value.push(newItem);
+ addedCount++;
});
+
+ // 鏇存柊selectedIds锛岀‘淇濆寘鍚墍鏈夊綋鍓峵ableData涓殑officialId
+ const allOfficialIds = tableData.value
+ .map((item) => item.officialId)
+ .filter((id) => id);
+ selectedIds.value = allOfficialIds;
+
+ // 鍏抽棴閫夋嫨瀵硅瘽妗�
innerVisible.value = false;
+
+ // 鏄剧ず缁撴灉娑堟伅
+ let message = "";
+ if (addedCount > 0) {
+ message += `鎴愬姛娣诲姞 ${addedCount} 鏉℃暟鎹甡;
+ }
+ if (duplicateCount > 0) {
+ message += (message ? "锛�" : "") + `璺宠繃 ${duplicateCount} 鏉¢噸澶嶆暟鎹甡;
+ }
+ if (message) {
+ ElMessage.success(message);
+ } else {
+ ElMessage.info("娌℃湁鏂版暟鎹娣诲姞");
+ }
};
const handleSelectionChange = (selection) => {
formalDatabaseSelectedData.value = selection;
};
-const reset = () => {
- // formRef
- formRef.value?.resetFields();
-};
-
-const selectChange = (value) => {};
-
-// 鎻愪氦琛ㄥ崟
+// 鎻愪氦琛ㄥ崟 - 浣跨敤宸ュ叿鍑芥暟楠岃瘉
const handleSubmit = async () => {
- console.log(detailsTableData.value);
- // dialogVisible.value = false;
-};
+ // 楠岃瘉鐢熶骇鏄庣粏鏁版嵁
+ const detailsValidation = validateFormData(detailsTableData.value, [
+ "coalId",
+ "productionQuantity",
+ "laborCost",
+ "energyConsumptionCost",
+ "equipmentDepreciation",
+ "purchasePrice"
+ ]);
+ if (!detailsValidation.isValid) {
+ ElMessage.warning(detailsValidation.message);
+ return;
+ }
+
+ // 楠岃瘉搴撳瓨浣跨敤鏁版嵁
+ if (tableData.value.length === 0) {
+ ElMessage.warning("璇锋坊鍔犵敓浜у姞宸ユ暟鎹�");
+ return;
+ }
+
+ for (let i = 0; i < tableData.value.length; i++) {
+ const element = tableData.value[i];
+ if (element.usedQuantity == 0 || element.usedQuantity === null) {
+ ElMessage.warning(`璇峰~鍐欑敓浜у姞宸ョ叅绉嶇殑浣跨敤鏁伴噺`);
+ return;
+ }
+ }
+
+ try {
+ const data = {
+ ...copyForm.value,
+ productionList: detailsTableData.value,
+ productionInventoryList: tableData.value,
+ };
+ const res = await addOrEditPM(data);
+ if (res.code === 200) {
+ dialogVisible.value = false;
+ emit("success");
+ } else {
+ ElMessage.error("鎻愪氦澶辫触");
+ }
+ } catch (error) {
+ ElMessage.error("鎻愪氦澶辫触锛岃閲嶈瘯");
+ }
+};
// 鍏抽棴寮圭獥
const handleClose = () => {
dialogVisible.value = false;
- formRef.value?.resetFields();
- Object.assign(formData, {
- category: "",
- unit: "",
- productionVolume: 0,
- laborCost: 0,
- materialCost: 0,
- equipmentCost: 0,
- totalCost: 0,
- totalPrice: 0,
- profit: 0,
- reviewer: "",
- date: "",
- });
};
-// 娣诲姞鍗曞厓鏍肩紪杈戝鐞嗗嚱鏁�
+// 浣跨敤鏁伴噺楠岃瘉 - 浣跨敤宸ュ叿鍑芥暟
const handleCellEdit = (row, prop, value) => {
- if (prop === "used" && Number(value) > Number(row.stock)) {
- ElMessage.warning("浣跨敤鏁伴噺涓嶈兘澶т簬搴撳瓨鏁伴噺锛�");
- row.used = row.stock;
+ if (prop === "usedQuantity") {
+ const validation = validateNumber(value, 0, Number(row.inventoryQuantity));
+
+ if (!validation.isValid) {
+ ElMessage.warning(validation.message);
+ row.usedQuantity = validation.value;
+ return;
+ }
+
+ row.usedQuantity = validation.value;
}
};
-// 澶勭悊鐢熶骇鏄庣粏琛ㄦ牸鐨勬搷浣�
+// 澶勭悊鐢熶骇鏄庣粏琛ㄦ牸鐨勬搷浣� - 浣跨敤宸ュ叿鍑芥暟
const addNewRow = () => {
- detailsTableData.value.push({
- coalType: "",
- calorificValue: "",
- productionQuantity: "",
- laborCost: "",
- energyCost: "",
- equipmentDepreciation: "",
- purchasePrice: "",
- totalCost: "",
- });
+ const newRow = createDefaultProductionRow(userInfo);
+ detailsTableData.value.push(newRow);
};
-const clearAllRows = () => {
- detailsTableData.value = [];
- ElMessage.success("宸叉竻绌烘墍鏈夋暟鎹�");
+// 閲嶇疆鏁版嵁 - 浣跨敤娣辨嫹璐�
+const handleReset = () => {
+ if (copyForm.value) {
+ tableData.value = deepClone(copyForm.value.productionInventoryList) || [];
+ detailsTableData.value = deepClone(copyForm.value.productionList) || [];
+ }
};
-const calculateAllCosts = () => {
- detailsTableData.value.forEach((row) => {
- const laborCost = parseFloat(row.laborCost) || 0;
- const energyCost = parseFloat(row.energyCost) || 0;
- const equipmentDepreciation = parseFloat(row.equipmentDepreciation) || 0;
- const purchasePrice = parseFloat(row.purchasePrice) || 0;
+// 鑾峰彇鐢ㄦ埛淇℃伅骞跺姞杞藉熀纭�鏁版嵁
+onMounted(async () => {
+ try {
+ userInfo = await userStore.getInfo();
+ await loadBasicData();
+ } catch (error) {
+ ElMessage.error("鍒濆鍖栧け璐ワ紝璇烽噸璇�");
+ }
+});
- row.totalCost = (
- laborCost +
- energyCost +
- equipmentDepreciation +
- purchasePrice
- ).toFixed(2);
- });
- ElMessage.success("閲嶆柊璁$畻瀹屾垚");
-};
-
+// 绠�鍖栫殑浜嬩欢澶勭悊鍑芥暟
const handleDetailsChange = (data) => {
- console.log("鐢熶骇鏄庣粏鏁版嵁鍙樺寲:", data);
};
const handleDeleteRow = (index) => {
ElMessage.success(`宸插垹闄ょ ${index + 1} 琛屾暟鎹甡);
};
+
+// 鍒犻櫎鍗曚釜宸查�夋暟鎹」
+const handleRemoveItem = (row) => {
+ const index = tableData.value.findIndex(
+ (item) => item.officialId === row.officialId
+ );
+ if (index > -1) {
+ tableData.value.splice(index, 1);
+
+ // 鏇存柊selectedIds
+ const updatedOfficialIds = tableData.value
+ .map((item) => item.officialId)
+ .filter((id) => id);
+ selectedIds.value = updatedOfficialIds;
+ ElMessage.success("宸插垹闄ら�変腑椤�");
+ }
+};
+
+// 娓呯┖鎵�鏈夊凡閫夋暟鎹�
+const removeSelectedData = () => {
+ if (tableData.value.length === 0) {
+ ElMessage.warning("娌℃湁鍙竻绌虹殑鏁版嵁");
+ return;
+ }
+ ElMessageBox.confirm("纭娓呯┖鎵�鏈夊凡閫夋嫨鐨勬暟鎹悧锛�", "璀﹀憡", {
+ confirmButtonText: "纭畾",
+ cancelButtonText: "鍙栨秷",
+ type: "warning",
+ })
+ .then(async () => {
+ if (dialogType.value === "edit") {
+ let res = await deleteProductionInventory({
+ productionInventoryList: tableData.value,
+ });
+ emit("update:productionAndProcessing", tableData.value, copyForm.value);
+ }
+ // [Vue warn]: Component emitted event "update:productionAndProcessing" but it is neither declared in the emits option nor as an "onUpdate:productionAndProcessing" prop.
+
+ formalDatabaseSelectedData.value = [];
+ tableData.value = [];
+ selectedIds.value = [];
+ ElMessage.success("宸叉竻绌烘墍鏈夋暟鎹�");
+ })
+ .catch(() => {
+ });
+};
+
+// 璁$畻鎬讳娇鐢ㄩ噺
+const totalUsedQuantity = computed(() => {
+ return tableData.value.reduce((total, item) => {
+ const usedQty = Number(item.usedQuantity) || 0;
+ return total + usedQty;
+ }, 0);
+});
</script>
<style scoped lang="scss">
@@ -452,4 +564,8 @@
.el-row > .el-col > h1 {
font-weight: bolder;
}
+
+.empty-table > .el-row {
+ margin-bottom: 12px;
+}
</style>
--
Gitblit v1.9.3