| | |
| | | <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> |
| | | <ETable |
| | | v-if="tableData.length > 0" |
| | | :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" v-if="tableData.length > 0"> |
| | | <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-if="tableData.length > 0" |
| | | v-model="detailsTableData" |
| | | :border="false" |
| | | :show-operations="true" |
| | | :auto-calculate="true" |
| | | @input-change="handleDetailsChange" |
| | | @delete-row="handleDeleteRow" |
| | | /> |
| | | <div style="margin-top: 20px;" v-else>暂无数据,请选择配置数据</div> |
| | | |
| | | <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="选择配置数据" |
| | | append-to-body |
| | | > |
| | | <ETable |
| | | @selection-change="handleSelectionChange" |
| | | :showOperations="false" |
| | | :columns="formalDatabaseDataColumns" |
| | | :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/EtableModify.vue"; |
| | | import ProductionDetailsTable from "./ProductionDetailsTable.vue"; |
| | | import { ElMessage } from "element-plus"; |
| | | import { Delete, Warning, Plus } from "@element-plus/icons-vue"; |
| | | |
| | | 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 dialogVisible = ref(false) |
| | | const dialogType = ref('add') |
| | | const loading = ref(false) |
| | | const formRef = ref(null) |
| | | |
| | | 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: "category" }, |
| | | { label: "热值", prop: "Calorific" }, |
| | | { label: "库存数量", prop: "stock" }, |
| | | { label: "本次使用数量", prop: "used" }, |
| | | ]; |
| | | const detailsTableData = ref([ |
| | | { |
| | | coalType: "", |
| | | calorificValue: "", |
| | | productionQuantity: "", |
| | | laborCost: "", |
| | | energyCost: "", |
| | | equipmentDepreciation: "", |
| | | purchasePrice: "", |
| | | totalCost: "", |
| | | }, |
| | | ]); |
| | | 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: '', |
| | | category: "", |
| | | unit: "", |
| | | productionVolume: 0, |
| | | laborCost: 0, |
| | | materialCost: 0, |
| | |
| | | totalCost: 0, |
| | | totalPrice: 0, |
| | | profit: 0, |
| | | reviewer: '', |
| | | date: '' |
| | | }) |
| | | reviewer: "", |
| | | date: "", |
| | | }); |
| | | const handlData = () => { |
| | | innerVisible.value = true; |
| | | }; |
| | | const formalDatabaseData = ref([]); |
| | | const formalDatabaseSelectedData = ref([]); |
| | | formalDatabaseData.value = [ |
| | | { |
| | | id: 1, |
| | | name: "供应商A", |
| | | type: "动力煤", |
| | | unit: "吨", |
| | | number: 120, |
| | | money: 500, |
| | | money1: 200, |
| | | money2: 200, |
| | | money3: 300, |
| | | money4: "高位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 2, |
| | | name: "供应商A", |
| | | type: "动力煤", |
| | | unit: "吨", |
| | | number: 100, |
| | | money: 600, |
| | | money1: 300, |
| | | money2: 300, |
| | | money3: 300, |
| | | money4: "低位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 3, |
| | | name: "供应商B", |
| | | type: "焦煤", |
| | | unit: "吨", |
| | | number: 300, |
| | | money: 789, |
| | | money1: 400, |
| | | money2: 400, |
| | | money3: 400, |
| | | money4: "高位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 4, |
| | | name: "供应商B", |
| | | type: "焦煤", |
| | | unit: "吨", |
| | | number: 256, |
| | | money: 800, |
| | | money1: 420, |
| | | money2: 420, |
| | | money3: 420, |
| | | money4: "低位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 5, |
| | | name: "供应商C", |
| | | type: "无烟煤", |
| | | unit: "吨", |
| | | number: 256, |
| | | money: 700, |
| | | money1: 300, |
| | | money2: 300, |
| | | money3: 300, |
| | | money4: "高位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 6, |
| | | name: "供应商A", |
| | | type: "动力煤", |
| | | unit: "吨", |
| | | number: 120, |
| | | money: 500, |
| | | money1: 200, |
| | | money2: 200, |
| | | money3: 300, |
| | | money4: "高位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 7, |
| | | name: "供应商A", |
| | | type: "动力煤", |
| | | unit: "吨", |
| | | number: 100, |
| | | money: 600, |
| | | money1: 300, |
| | | money2: 300, |
| | | money3: 300, |
| | | money4: "低位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 8, |
| | | name: "供应商B", |
| | | type: "焦煤", |
| | | unit: "吨", |
| | | number: 300, |
| | | money: 789, |
| | | money1: 400, |
| | | money2: 400, |
| | | money3: 400, |
| | | money4: "高位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 9, |
| | | name: "供应商B", |
| | | type: "焦煤", |
| | | unit: "吨", |
| | | number: 256, |
| | | money: 800, |
| | | money1: 420, |
| | | money2: 420, |
| | | money3: 420, |
| | | money4: "低位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | { |
| | | id: 10, |
| | | name: "供应商C", |
| | | type: "无烟煤", |
| | | unit: "吨", |
| | | number: 256, |
| | | money: 700, |
| | | money1: 300, |
| | | money2: 300, |
| | | money3: 300, |
| | | money4: "高位", |
| | | createUser: "admin", |
| | | createTime: "2025-06-01", |
| | | }, |
| | | ]; |
| | | |
| | | // 表单验证规则 |
| | | 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' }] |
| | | } |
| | | category: [{ 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) |
| | | } |
| | | // 初始化 |
| | | const Initialization = () => { |
| | | console.log("初始化数据"); |
| | | 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({ |
| | | id: item.id, |
| | | category: item.type, |
| | | Calorific: item.money4, |
| | | stock: item.number, |
| | | 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(detailsTableData.value); |
| | | // 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, |
| | |
| | | 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: "", |
| | | calorificValue: "", |
| | | productionQuantity: "", |
| | | laborCost: "", |
| | | energyCost: "", |
| | | equipmentDepreciation: "", |
| | | purchasePrice: "", |
| | | totalCost: "", |
| | | }); |
| | | }; |
| | | |
| | | 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> |
| | | </style> |