From 0f4dc4ea8a7de1ffdf34a640c79c29d55b79321c Mon Sep 17 00:00:00 2001 From: 张诺 <zhang_12370@163.com> Date: 星期五, 13 六月 2025 17:53:27 +0800 Subject: [PATCH] 添加生产管理接口及优化表格字段 --- src/views/production/components/ProductionDialog.vue | 497 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 259 insertions(+), 238 deletions(-) diff --git a/src/views/production/components/ProductionDialog.vue b/src/views/production/components/ProductionDialog.vue index 2787bb2..b75a3e2 100644 --- a/src/views/production/components/ProductionDialog.vue +++ b/src/views/production/components/ProductionDialog.vue @@ -1,188 +1,159 @@ -<template> +div<template> <el-dialog v-model="dialogVisible" :title="dialogType === 'add' ? '鏂板鐢熶骇鍔犲伐' : '缂栬緫鐢熶骇鍔犲伐'" - width="800px" + width="1200px" :close-on-click-modal="false" @close="handleClose" > - <el-form - ref="formRef" - :model="formData" - :rules="rules" - label-width="120px" - class="production-form" - > - <el-row :gutter="20"> - <el-col :span="12"> - <el-form-item label="鐓ょ" prop="category"> - <el-select v-model="formData.category" placeholder="璇烽�夋嫨鐓ょ" clearable style="width: 100%"> - <el-option label="鐐肩劍" value="鐐肩劍" /> - <el-option label="姘旂叅" value="姘旂叅" /> - <el-option label="鏃犵儫鐓�" value="鏃犵儫鐓�" /> - <el-option label="闀跨劙鐓�" value="闀跨劙鐓�" /> - <el-option label="璐叅" value="璐叅" /> - </el-select> - </el-form-item> - </el-col> - <el-col :span="12"> - <el-form-item label="鍗曚綅" prop="unit"> - <el-select v-model="formData.unit" placeholder="璇烽�夋嫨鍗曚綅" clearable style="width: 100%"> - <el-option label="鍚ㄤ綅" value="鍚ㄤ綅" /> - <el-option label="鍗冨厠" value="鍗冨厠" /> - </el-select> - </el-form-item> - </el-col> - </el-row> + <el-button type="primary" @click="handlData">閫夋嫨鏁版嵁</el-button> + <ETableModify + :columns="columns" + height="200" + @cell-edit="handleCellEdit" + :showOperations="false" + :tableData="tableData" + @row-click="handleRowClick" + :editableColumns="['used']" + /> + <div class="empty-table"> + <h1>鐢熶骇鏄庣粏</h1> + <el-row :gutter="10"> + <el-col :span="2"> + <el-button type="primary" @click="addNewRow"> + <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-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" + /> - <el-row :gutter="20"> - <el-col :span="12"> - <el-form-item label="鐢熶骇鏁伴噺" prop="productionVolume"> - <el-input-number - v-model="formData.productionVolume" - :min="0" - :precision="2" - style="width: 100%" - @change="calculateTotal" - /> - </el-form-item> - </el-col> - <el-col :span="12"> - <el-form-item label="浜哄伐鎴愭湰" prop="laborCost"> - <el-input-number - v-model="formData.laborCost" - :min="0" - :precision="2" - style="width: 100%" - @change="calculateTotal" - /> - </el-form-item> - </el-col> - </el-row> - - <el-row :gutter="20"> - <el-col :span="12"> - <el-form-item label="鍘熸枡鎴愭湰" prop="materialCost"> - <el-input-number - v-model="formData.materialCost" - :min="0" - :precision="2" - style="width: 100%" - @change="calculateTotal" - /> - </el-form-item> - </el-col> - <el-col :span="12"> - <el-form-item label="璁惧璐圭敤" prop="equipmentCost"> - <el-input-number - v-model="formData.equipmentCost" - :min="0" - :precision="2" - style="width: 100%" - @change="calculateTotal" - /> - </el-form-item> - </el-col> - </el-row> - - <el-row :gutter="20"> - <el-col :span="12"> - <el-form-item label="鎬绘垚鏈�" prop="totalCost"> - <el-input-number - v-model="formData.totalCost" - :min="0" - :precision="2" - style="width: 100%" - disabled - /> - </el-form-item> - </el-col> - <el-col :span="12"> - <el-form-item label="鎬讳环鏍�" prop="totalPrice"> - <el-input-number - v-model="formData.totalPrice" - :min="0" - :precision="2" - style="width: 100%" - @change="calculateProfit" - /> - </el-form-item> - </el-col> - </el-row> - - <el-row :gutter="20"> - <el-col :span="12"> - <el-form-item label="鍒╂鼎" prop="profit"> - <el-input-number - v-model="formData.profit" - :min="0" - :precision="2" - style="width: 100%" - disabled - /> - </el-form-item> - </el-col> - <el-col :span="12"> - <el-form-item label="澶嶈浜�" prop="reviewer"> - <el-input v-model="formData.reviewer" placeholder="璇疯緭鍏ュ璁颁汉" /> - </el-form-item> - </el-col> - </el-row> - - <el-row :gutter="20"> - <el-col :span="12"> - <el-form-item label="鏃ユ湡" prop="date"> - <el-date-picker - v-model="formData.date" - type="date" - placeholder="璇烽�夋嫨鏃ユ湡" - style="width: 100%" - value-format="YYYY-MM-DD" - /> - </el-form-item> - </el-col> - </el-row> - </el-form> + </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 type="primary" :loading="loading" @click="handleSubmit" + >纭� 瀹�</el-button + > </div> </template> + </el-dialog> + <el-dialog + v-model="innerVisible" + width="1000" + title="閫夋嫨閰嶇疆鏁版嵁" + center + append-to-body + > + <ETable + @selection-change="handleSelectionChange" + :showOperations="false" + :columns="formalDatabaseColumns" + :tableData="formalDatabaseData" + 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-col> + </el-row> </el-dialog> </template> <script setup> -import { ref, reactive, watch } from 'vue' -import { ElMessage } from 'element-plus' +import { ref, reactive, watch } 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 { getOfficialAll } from "@/api/production/index.js"; const props = defineProps({ visible: { type: Boolean, - default: false + default: false, }, type: { type: String, - default: 'add' // 'add' 鎴� 'edit' + default: "add", // 'add' 鎴� 'edit' }, rowData: { type: Object, - default: () => ({}) - } -}) + default: () => ({}), + }, +}); +const dialogVisible = defineModel("visible", { + type: Boolean, + default: false, +}); +const emit = defineEmits(["update:visible", "success"]); -const emit = defineEmits(['update:visible', 'success']) +const innerVisible = ref(false); +const dialogType = ref("add"); +const loading = ref(false); +const formRef = ref(null); +const tableData = ref([]); +const currentRow = ref(null); +const columns = [ + { label: "渚涘簲鍟嗗悕绉�", prop: "supplierName" }, + { label: "鐓ょ", prop: "coal" }, + { label: "鍗曚环(涓嶅惈绋�)", prop: "priceExcludingTax" }, + { label: "搴撳瓨鏁伴噺", prop: "inventoryQuantity" }, + { + label: "浣跨敤鏁伴噺", + prop: "used", + editable: true, + width: 120, + editType: "number", + }, -const dialogVisible = ref(false) -const dialogType = ref('add') -const loading = ref(false) -const formRef = ref(null) - +]; +const detailsTableData = ref([ + +]); +const handleRowClick = (row) => { + currentRow.value = row; +}; +const formalDatabaseColumns = ref([ + { prop: "supplierName", label: "渚涘簲鍟嗗悕绉�", minwidth: 150 }, + { prop: "coal", label: "鐓ょ绫诲瀷", minwidth: 60 }, + { prop: "inventoryQuantity", label: "搴撳瓨鏁伴噺", minwidth: 80 }, + { prop: "unit", label: "鍗曚綅", minwidth: 100 }, + { prop: "priceExcludingTax", label: "鍗曚环锛堜笉鍚◣锛�", minwidth: 80 }, + { prop: "createTime", label: "鐧昏鏃ユ湡", minwidth: 400 }, +]); // 琛ㄥ崟鏁版嵁 const formData = reactive({ - category: '', - unit: '', + category: "", + unit: "", productionVolume: 0, laborCost: 0, materialCost: 0, @@ -190,76 +161,82 @@ totalCost: 0, totalPrice: 0, profit: 0, - reviewer: '', - date: '' -}) - -// 琛ㄥ崟楠岃瘉瑙勫垯 -const rules = { - category: [{ required: true, message: '璇烽�夋嫨鐓ょ', trigger: 'change' }], - unit: [{ required: true, message: '璇烽�夋嫨鍗曚綅', trigger: 'change' }], - productionVolume: [{ required: true, message: '璇疯緭鍏ョ敓浜ф暟閲�', trigger: 'blur' }], - laborCost: [{ required: true, message: '璇疯緭鍏ヤ汉宸ユ垚鏈�', trigger: 'blur' }], - materialCost: [{ required: true, message: '璇疯緭鍏ュ師鏂欐垚鏈�', trigger: 'blur' }], - equipmentCost: [{ required: true, message: '璇疯緭鍏ヨ澶囪垂鐢�', trigger: 'blur' }], - totalPrice: [{ required: true, message: '璇疯緭鍏ユ�讳环鏍�', trigger: 'blur' }], - reviewer: [{ required: true, message: '璇疯緭鍏ュ璁颁汉', trigger: 'blur' }], - date: [{ required: true, message: '璇烽�夋嫨鏃ユ湡', trigger: 'change' }] -} - -// 鐩戝惉visible鍙樺寲 -watch(() => props.visible, (val) => { - dialogVisible.value = val - if (val) { - dialogType.value = props.type - if (props.type === 'edit') { - Object.assign(formData, props.rowData) - } + reviewer: "", + date: "", +}); +const handlData =async () => { + innerVisible.value = true; + let res = await getOfficialAll(); + console.log("鑾峰彇閰嶇疆鏁版嵁", res); + if (res.code === 200) { + formalDatabaseData.value = res.data; + } else { + ElMessage.error("鑾峰彇閰嶇疆鏁版嵁澶辫触"); } -}) +}; +const formalDatabaseData = ref([]); +const formalDatabaseSelectedData = ref([]); +formalDatabaseData.value = [ +]; +// 鍒濆鍖� +const Initialization = () => { + tableData.value = []; +}; +defineExpose({ + Initialization +}); +const handleSelectData = (row) => { + if (!innerVisible.value) return; + // 鑾峰彇閫変腑鐨勬暟鎹� + const selectedData = formalDatabaseSelectedData.value; + if (selectedData.length === 0) { + ElMessage.warning("璇疯嚦灏戦�夋嫨涓�鏉℃暟鎹�"); + return; + } + // 灏嗛�変腑鐨勬暟鎹牴鎹渶瑕佺瓫閫夊埌琛ㄦ牸涓� + selectedData.forEach((item) => { + const existingItem = tableData.value.find( + (row) => row.id === item.id + ); + if (!existingItem) { + tableData.value.push( + Object.assign({}, item, { + used: 0, // 鍒濆浣跨敤鏁伴噺涓�0 + }) + ); + } + }); + innerVisible.value = false; +}; +const handleSelectionChange = (selection) => { + formalDatabaseSelectedData.value = selection; +}; +const reset = () => { + // formRef + formRef.value?.resetFields(); +}; -// 鐩戝惉dialogVisible鍙樺寲 -watch(() => dialogVisible.value, (val) => { - emit('update:visible', val) -}) - -// 璁$畻鎬绘垚鏈� -const calculateTotal = () => { - formData.totalCost = ( - formData.laborCost + - formData.materialCost + - formData.equipmentCost - ) - calculateProfit() -} - -// 璁$畻鍒╂鼎 -const calculateProfit = () => { - formData.profit = formData.totalPrice - formData.totalCost -} +const selectChange = (value) => {}; // 鎻愪氦琛ㄥ崟 const handleSubmit = async () => { - if (!formRef.value) return - - await formRef.value.validate((valid) => { - if (valid) { - loading.value = true - // 瑙﹀彂鎴愬姛浜嬩欢锛屼紶閫掕〃鍗曟暟鎹� - emit('success', { ...formData }) - loading.value = false - handleClose() - } - }) -} + console.log("鎻愪氦琛ㄥ崟鏁版嵁:", tableData.value); + console.log(detailsTableData.value); + let data = { + productionList: detailsTableData.value, + productionInventoryList: tableData.value, + }; + console.log("鎻愪氦鏁版嵁", data); + // dialogVisible.value = false; +}; // 鍏抽棴寮圭獥 const handleClose = () => { - dialogVisible.value = false - formRef.value?.resetFields() + dialogVisible.value = false; + formRef.value?.resetFields(); Object.assign(formData, { - category: '', - unit: '', + category: "", + unit: "", productionVolume: 0, laborCost: 0, materialCost: 0, @@ -267,32 +244,76 @@ totalCost: 0, totalPrice: 0, profit: 0, - reviewer: '', - date: '' - }) -} + reviewer: "", + date: "", + }); +}; + +// 娣诲姞鍗曞厓鏍肩紪杈戝鐞嗗嚱鏁� +const handleCellEdit = (row, prop, value) => { + if (prop === "used" && Number(value) > Number(row.stock)) { + ElMessage.warning("浣跨敤鏁伴噺涓嶈兘澶т簬搴撳瓨鏁伴噺锛�"); + row.used = row.stock; + } +}; + +// 澶勭悊鐢熶骇鏄庣粏琛ㄦ牸鐨勬搷浣� +const addNewRow = () => { + detailsTableData.value.push({ + coalType: "", + productionQuantity: "", + laborCost: "", + energyConsumptionCost: "", + equipmentDepreciation: "", + purchasePrice: "", + autoCalculate: "0.00", + producer:"", + }); +}; + +const clearAllRows = () => { + detailsTableData.value = []; + ElMessage.success("宸叉竻绌烘墍鏈夋暟鎹�"); +}; + +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; + + row.totalCost = ( + laborCost + + energyCost + + equipmentDepreciation + + purchasePrice + ).toFixed(2); + }); + ElMessage.success("閲嶆柊璁$畻瀹屾垚"); +}; + +const handleDetailsChange = (data) => { + console.log("鐢熶骇鏄庣粏鏁版嵁鍙樺寲:", data); +}; + +const handleDeleteRow = (index) => { + ElMessage.success(`宸插垹闄ょ ${index + 1} 琛屾暟鎹甡); +}; </script> -<style scoped> -.production-form { - padding: 20px; +<style scoped lang="scss"> +.el-form { + .el-row { + padding-top: 20px; + background: rgba($color: #f8fafb, $alpha: 0.5); + } } -.dialog-footer { - display: flex; - justify-content: flex-end; - gap: 10px; +.el-row > .el-col > h1 { + font-weight: bolder; } - -:deep(.el-form-item__label) { - font-weight: bold; +.empty-table > .el-row{ + margin-bottom: 12px; } - -:deep(.el-input-number) { - width: 100%; -} - -:deep(.el-select) { - width: 100%; -} -</style> \ No newline at end of file +</style> -- Gitblit v1.9.3