| | |
| | | </el-form-item> |
| | | </el-form> |
| | | <div> |
| | | <el-button type="primary" @click="openCreateOrder">新增订单</el-button> |
| | | <el-button @click="handleOut">导出</el-button> |
| | | <el-button type="danger" plain :disabled="selectedRows.length === 0" @click="handleBatchDelete">批量删除</el-button> |
| | | </div> |
| | | </div> |
| | | <div class="table_list"> |
| | |
| | | :tableData="tableData" |
| | | :page="page" |
| | | :tableLoading="tableLoading" |
| | | :isSelection="true" |
| | | @selection-change="handleSelectionChange" |
| | | @pagination="pagination"> |
| | | <template #completionStatus="{ row }"> |
| | | <el-progress |
| | |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | <el-dialog v-model="orderFormVisible" |
| | | title="新增生产订单" |
| | | width="520px" |
| | | @close="() => proxy?.resetForm?.('orderFormRef')"> |
| | | <el-form ref="orderFormRef" |
| | | :model="orderForm" |
| | | :rules="orderRules" |
| | | label-width="120px" |
| | | label-position="top"> |
| | | <el-form-item label="产品大类" prop="productId"> |
| | | <el-tree-select v-model="orderForm.productId" |
| | | placeholder="请选择" |
| | | clearable |
| | | check-strictly |
| | | :data="productOptions" |
| | | :render-after-expand="false" |
| | | style="width: 100%" |
| | | @change="getModels" /> |
| | | </el-form-item> |
| | | <el-form-item label="规格型号" prop="productModelId"> |
| | | <el-select v-model="orderForm.productModelId" |
| | | placeholder="请选择" |
| | | clearable |
| | | style="width: 100%" |
| | | @change="getProductModel"> |
| | | <el-option v-for="item in modelOptions" |
| | | :key="item.id" |
| | | :label="item.model" |
| | | :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="单位" prop="unit"> |
| | | <el-input v-model="orderForm.unit" |
| | | placeholder="请输入" |
| | | clearable /> |
| | | </el-form-item> |
| | | <el-row :gutter="12"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="数量" prop="quantity"> |
| | | <el-input-number v-model="orderForm.quantity" |
| | | :step="0.1" |
| | | :min="0" |
| | | :precision="2" |
| | | placeholder="请输入" |
| | | style="width: 100%" |
| | | @change="calculateFromQuantity" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | </el-form> |
| | | <template #footer> |
| | | <span class="dialog-footer"> |
| | | <el-button type="primary" @click="submitCreateOrder">确 认</el-button> |
| | | <el-button @click="orderFormVisible = false">取 消</el-button> |
| | | </span> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { onMounted, ref } from "vue"; |
| | | import { onMounted, ref, reactive, toRefs, getCurrentInstance } from "vue"; |
| | | import { ElMessageBox } from "element-plus"; |
| | | import dayjs from "dayjs"; |
| | | import { useRouter } from "vue-router"; |
| | | import { |
| | | productOrderListPage, |
| | | addProductOrder, |
| | | listProcessRoute, |
| | | bindingRoute, |
| | | listProcessBom, |
| | | deleteProductOrder, |
| | | } from "@/api/productionManagement/productionOrder.js"; |
| | | import { productTreeList, modelList } from "@/api/basicData/product.js"; |
| | | import { listMain as getOrderProcessRouteMain } from "@/api/productionManagement/productProcessRoute.js"; |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | |
| | | width: '120px', |
| | | }, |
| | | { |
| | | label: "销售合同号", |
| | | prop: "salesContractNo", |
| | | width: '150px', |
| | | }, |
| | | { |
| | | label: "客户名称", |
| | | prop: "customerName", |
| | | width: '200px', |
| | | }, |
| | | { |
| | | label: "产品名称", |
| | | label: "产品大类", |
| | | prop: "productCategory", |
| | | width: '120px', |
| | | }, |
| | | { |
| | | label: "规格", |
| | | label: "规格型号", |
| | | prop: "specificationModel", |
| | | width: '120px', |
| | | }, |
| | |
| | | ]); |
| | | const tableData = ref([]); |
| | | const tableLoading = ref(false); |
| | | const selectedRows = ref([]); |
| | | const page = reactive({ |
| | | current: 1, |
| | | size: 100, |
| | |
| | | }, |
| | | }); |
| | | const { searchForm } = toRefs(data); |
| | | |
| | | // 新增订单弹框数据 |
| | | const orderFormVisible = ref(false); |
| | | const orderFormRef = ref(null); |
| | | const orderFormState = reactive({ |
| | | orderForm: { |
| | | productId: null, |
| | | productCategory: "", |
| | | productModelId: "", |
| | | specificationModel: "", |
| | | unit: "", |
| | | quantity: null, |
| | | }, |
| | | orderRules: { |
| | | productId: [{ required: true, message: "请选择产品大类", trigger: "change" }], |
| | | productModelId: [{ required: true, message: "请选择规格型号", trigger: "change" }], |
| | | specificationModel: [{ required: true, message: "请选择规格型号", trigger: "change" }], |
| | | unit: [{ required: true, message: "请输入单位", trigger: "blur" }], |
| | | quantity: [{ required: true, message: "请输入数量", trigger: "blur" }], |
| | | }, |
| | | }); |
| | | const { orderForm, orderRules } = toRefs(orderFormState); |
| | | const productOptions = ref([]); |
| | | const modelOptions = ref([]); |
| | | |
| | | const toProgressPercentage = val => { |
| | | const n = Number(val); |
| | |
| | | }); |
| | | }; |
| | | |
| | | // 表格选择数据 |
| | | const handleSelectionChange = (selection) => { |
| | | selectedRows.value = selection || []; |
| | | }; |
| | | |
| | | // 批量删除 |
| | | const handleBatchDelete = async () => { |
| | | if (selectedRows.value.length === 0) { |
| | | proxy.$modal.msgWarning("请选择要删除的数据"); |
| | | return; |
| | | } |
| | | const ids = selectedRows.value.map(item => item.productModelId).filter(Boolean); |
| | | if (ids.length === 0) { |
| | | proxy.$modal.msgWarning("选中数据缺少ID,无法删除"); |
| | | return; |
| | | } |
| | | try { |
| | | await ElMessageBox.confirm("选中的内容将被删除,是否确认删除?", "提示", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "取消", |
| | | type: "warning", |
| | | }); |
| | | await deleteProductOrder(ids); |
| | | proxy.$modal.msgSuccess("删除成功"); |
| | | selectedRows.value = []; |
| | | getList(); |
| | | } catch (e) { |
| | | // 取消或失败 |
| | | if (e !== 'cancel' && e !== 'close') { |
| | | console.error("批量删除失败:", e); |
| | | proxy.$modal.msgError("删除失败,请重试"); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | const handleConfirmRoute = () => {}; |
| | | |
| | | const openCreateOrder = async () => { |
| | | orderForm.value = { |
| | | productId: null, |
| | | productCategory: "", |
| | | productModelId: "", |
| | | specificationModel: "", |
| | | unit: "", |
| | | quantity: null, |
| | | }; |
| | | await loadProductOptions(); |
| | | orderFormVisible.value = true; |
| | | }; |
| | | |
| | | const loadProductOptions = async () => { |
| | | const tree = await productTreeList(); |
| | | productOptions.value = Array.isArray(tree?.data) ? convertIdToValue(tree.data) : convertIdToValue(tree || []); |
| | | }; |
| | | |
| | | const convertIdToValue = data => { |
| | | return (data || []).map(item => { |
| | | const { id, children, ...rest } = item; |
| | | const newItem = { ...rest, value: id }; |
| | | if (children && children.length > 0) { |
| | | newItem.children = convertIdToValue(children); |
| | | } |
| | | return newItem; |
| | | }); |
| | | }; |
| | | |
| | | const findNodeById = (nodes, productId) => { |
| | | for (let i = 0; i < nodes.length; i++) { |
| | | if (nodes[i].value === productId) { |
| | | return nodes[i].label; |
| | | } |
| | | if (nodes[i].children && nodes[i].children.length > 0) { |
| | | const foundNode = findNodeById(nodes[i].children, productId); |
| | | if (foundNode) { |
| | | return foundNode; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | }; |
| | | |
| | | const getModels = async value => { |
| | | orderForm.value.productId = value; |
| | | orderForm.value.productCategory = findNodeById(productOptions.value, value); |
| | | const res = await modelList({ id: value }); |
| | | modelOptions.value = res || []; |
| | | }; |
| | | |
| | | const getProductModel = value => { |
| | | const index = modelOptions.value.findIndex(item => item.id === value); |
| | | if (index !== -1) { |
| | | orderForm.value.specificationModel = modelOptions.value[index].model; |
| | | orderForm.value.unit = modelOptions.value[index].unit; |
| | | } else { |
| | | orderForm.value.specificationModel = null; |
| | | orderForm.value.unit = null; |
| | | } |
| | | }; |
| | | |
| | | const calculateFromQuantity = () => { |
| | | // 占位:数量变更时可在此扩展逻辑 |
| | | }; |
| | | |
| | | const submitCreateOrder = async () => { |
| | | proxy.$refs["orderFormRef"]?.validate(async valid => { |
| | | if (!valid) return; |
| | | try { |
| | | await addProductOrder(orderForm.value); |
| | | proxy.$modal.msgSuccess("新增成功"); |
| | | orderFormVisible.value = false; |
| | | getList(); |
| | | } catch (e) { |
| | | console.error("新增生产订单失败", e); |
| | | proxy.$modal.msgError("新增失败,请稍后重试"); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | }); |