| | |
| | | <template> |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | :title="dialogType === 'add' ? '新增生产加工' : '编辑生产加工'" |
| | | width="1200px" |
| | | :close-on-click-modal="false" |
| | | @close="handleClose" |
| | | v-model="dialogVisible" |
| | | :title="dialogType === 'add' ? '新增生产加工' : '编辑生产加工'" |
| | | width="1200px" |
| | | :close-on-click-modal="false" |
| | | @close="handleClose" |
| | | > |
| | | <el-row :gutter="10" style="margin-bottom: 10px"> |
| | | <el-col :span="3"> |
| | | <el-button type="primary" @click="handlData" |
| | | ><el-icon> <Plus /> </el-icon>选择数据</el-button |
| | | > |
| | | <el-icon> |
| | | <Plus/> |
| | | </el-icon> |
| | | 选择数据 |
| | | </el-button |
| | | > |
| | | </el-col> |
| | | <el-col :span="4"> |
| | | <el-button |
| | | type="danger" |
| | | @click="removeSelectedData" |
| | | :disabled="tableData.length === 0" |
| | | type="danger" |
| | | @click="removeSelectedData" |
| | | :disabled="tableData.length === 0" |
| | | > |
| | | <el-icon> |
| | | <Delete /> |
| | | <Delete/> |
| | | </el-icon> |
| | | 清空已选 |
| | | </el-button> |
| | |
| | | </el-col> |
| | | </el-row> |
| | | <ETableModify |
| | | :columns="columns" |
| | | :showOperations="false" |
| | | height="200" |
| | | @cell-edit="handleCellEdit" |
| | | :tableData="tableData" |
| | | :showOverflowTooltip="false" |
| | | @row-click="handleRowClick" |
| | | :editableColumns="['usedQuantity']" |
| | | @delete="handleRemoveItem" |
| | | :columns="columns" |
| | | :showOperations="false" |
| | | height="200" |
| | | @cell-edit="handleCellEdit" |
| | | :tableData="tableData" |
| | | :showOverflowTooltip="false" |
| | | @row-click="handleRowClick" |
| | | :editableColumns="['usedQuantity']" |
| | | @delete="handleRemoveItem" |
| | | /> |
| | | <div class="empty-table"> |
| | | <h1>生产明细</h1> |
| | |
| | | <el-col :span="2"> |
| | | <el-button type="primary" @click="addNewRow"> |
| | | <el-icon> |
| | | <Plus /> |
| | | <Plus/> |
| | | </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" |
| | | v-model="detailsTableData" |
| | | :border="false" |
| | | :show-operations="true" |
| | | :auto-calculate="true" |
| | | @input-change="handleDetailsChange" |
| | | @delete-row="handleDeleteRow" |
| | | /> |
| | | </div> |
| | | |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button |
| | | @click="handleClose" |
| | | v-if="dialogType === 'add' || dialogType === 'edit'" |
| | | >取 消</el-button |
| | | @click="handleClose" |
| | | v-if="dialogType === 'add' || dialogType === 'edit'" |
| | | >取 消 |
| | | </el-button |
| | | > |
| | | <!-- <el-button @click="handleReset" v-if="dialogType === 'edit'" |
| | | >重 置</el-button |
| | | > --> |
| | | <el-button type="primary" :loading="loading" @click="handleSubmit" |
| | | >确 定</el-button |
| | | >确 定 |
| | | </el-button |
| | | > |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | <el-dialog |
| | | v-model="innerVisible" |
| | | width="1000" |
| | | title="选择配置数据" |
| | | center |
| | | 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 |
| | | v-if="tableData.length > 0" |
| | | :title="`当前已选择 ${tableData.length} 条数据`" |
| | | type="info" |
| | | :closable="false" |
| | | show-icon |
| | | /> |
| | | </div> |
| | | <ETable |
| | | :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" |
| | | :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" style="margin-top: 15px"> |
| | | <el-col :span="12"> |
| | |
| | | <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" |
| | | type="primary" |
| | | @click="handleSelectData" |
| | | :disabled="formalDatabaseSelectedData.length === 0" |
| | | > |
| | | 确定添加 |
| | | </el-button> |
| | |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, reactive, watch, onMounted, nextTick, computed } from "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, ElMessageBox, ElAlert, ElText } 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 { validateFormData, validateNumber, deepClone, createDefaultProductionRow } from "@/utils/production"; |
| | | import { useCoalData } from "./useCoalData"; |
| | | 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" }, |
| | | 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 dialogVisible = defineModel("visible", {type: Boolean, default: false}); |
| | | const emit = defineEmits(["update:visible", "success", "update:productionAndProcessing"]); |
| | | |
| | | // 用户信息和煤种数据 |
| | | const userStore = useUserStore(); |
| | | const { getCoalNameById } = useCoalData(); |
| | | const {getCoalNameById} = useCoalData(); |
| | | let userInfo; |
| | | |
| | | // 对话框状态 |
| | |
| | | const selectedIds = ref([]); |
| | | const currentRow = ref(null); |
| | | const copyForm = ref(null); |
| | | const coalList = ref([]) |
| | | const supplierList = ref({}); |
| | | // 表格列配置 |
| | | const columns = [ |
| | | { label: "煤种", prop: "coal", minwidth: 120 }, |
| | | { label: "库存数量", prop: "inventoryQuantity", minwidth: 100 }, |
| | | {prop: "coalId", label: "煤种", minwidth: 60,slot:false, |
| | | formatter: (row) => { |
| | | return coalList.value.find(coal => coal.id === row.coalId)?.coal || "--"; |
| | | } |
| | | }, |
| | | {label: "库存数量", prop: "inventoryQuantity", minwidth: 100}, |
| | | { |
| | | label: "使用数量", |
| | | prop: "usedQuantity", |
| | |
| | | ]; |
| | | |
| | | const formalDatabaseColumns = ref([ |
| | | { prop: "supplierName", label: "供应商名称", minwidth: 150 }, |
| | | { prop: "coal", label: "煤种类型", minwidth: 60 }, |
| | | { prop: "inventoryQuantity", label: "库存数量", minwidth: 80 }, |
| | | { prop: "unit", label: "单位", minwidth: 20 }, |
| | | { prop: "priceExcludingTax", label: "单价(不含税)", minwidth: 80 }, |
| | | { prop: "createTime", label: "登记日期", width: 200 }, |
| | | {prop: "supplierName", label: "供应商名称", minwidth: 150 |
| | | // ,formatter: (row) => { |
| | | // console.log(row); |
| | | // return supplierList.value[row.supplierId] || "--"; |
| | | // } |
| | | }, |
| | | {prop: "coalId", label: "煤种", minwidth: 60, |
| | | formatter: (row) => { |
| | | // return coalList.value[row.coalId].coal || "--"; |
| | | 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) |
| | | selectedIds.value.includes(row.id) |
| | | ); |
| | | } |
| | | }; |
| | |
| | | // 获取配置数据 |
| | | const handlData = async () => { |
| | | innerVisible.value = true; |
| | | let res = await getOfficialAll(); |
| | | if (res.code === 200) { |
| | | formalDatabaseData.value = res.data; |
| | | let getSupplier = await getOfficialAll(); |
| | | let getCoalName = await getCoalInfoList(); |
| | | coalList.value = getCoalName.data || []; |
| | | supplierList.value = getSupplier.data || []; |
| | | if (getSupplier.code === 200) { |
| | | formalDatabaseData.value = getSupplier.data; |
| | | const existingOfficialIds = tableData.value |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = existingOfficialIds; |
| | | debugIdMatching(); |
| | | nextTick(() => { |
| | |
| | | try { |
| | | etableRef.value.clearSelection(); |
| | | const rowsToSelect = formalDatabaseData.value.filter((row) => |
| | | ids.includes(row.id) |
| | | ids.includes(row.id) |
| | | ); |
| | | if (rowsToSelect.length > 0) { |
| | | etableRef.value.setRowsSelection(rowsToSelect, true); |
| | |
| | | detailsTableData.value = data.productionList || []; |
| | | dialogType.value = "edit"; |
| | | const existingOfficialIds = tableData.value |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = existingOfficialIds; |
| | | }; |
| | | // 监听对话框状态,在打开时设置选中状态 |
| | |
| | | |
| | | // 更新selectedIds,确保包含所有当前tableData中的officialId |
| | | const allOfficialIds = tableData.value |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = allOfficialIds; |
| | | |
| | | // 关闭选择对话框 |
| | |
| | | // 验证生产明细数据 |
| | | const detailsValidation = validateFormData(detailsTableData.value, [ |
| | | "coalId", |
| | | "productionQuantity", |
| | | "productionQuantity", |
| | | "laborCost", |
| | | "energyConsumptionCost", |
| | | "equipmentDepreciation", |
| | | "purchasePrice" |
| | | ]); |
| | | |
| | | |
| | | if (!detailsValidation.isValid) { |
| | | ElMessage.warning(detailsValidation.message); |
| | | return; |
| | |
| | | const handleCellEdit = (row, prop, value) => { |
| | | 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 handleRemoveItem = (row) => { |
| | | const index = tableData.value.findIndex( |
| | | (item) => item.officialId === row.officialId |
| | | (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); |
| | | .map((item) => item.officialId) |
| | | .filter((id) => id); |
| | | selectedIds.value = updatedOfficialIds; |
| | | ElMessage.success("已删除选中项"); |
| | | } |
| | |
| | | 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. |
| | | .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(() => {}); |
| | | formalDatabaseSelectedData.value = []; |
| | | tableData.value = []; |
| | | selectedIds.value = []; |
| | | ElMessage.success("已清空所有数据"); |
| | | }) |
| | | .catch(() => { |
| | | }); |
| | | }; |
| | | |
| | | // 计算总使用量 |
| | |
| | | .el-row > .el-col > h1 { |
| | | font-weight: bolder; |
| | | } |
| | | |
| | | .empty-table > .el-row { |
| | | margin-bottom: 12px; |
| | | } |