feat: 生产管理

This commit is contained in:
砂糖
2025-08-26 16:51:23 +08:00
parent 666c42a128
commit 503b30ced5
13 changed files with 838 additions and 466 deletions

View File

@@ -31,7 +31,7 @@
<script>
import { listManufacturingSpec } from '@/api/work/manufacturingSpec'
import { debounce } from 'lodash' // 防抖:避免频繁触发接口请求
import { debounce } from '@/utils' // 防抖:避免频繁触发接口请求
export default {
name: 'MSpecSelect',

View File

@@ -0,0 +1,138 @@
<template>
<el-select
v-model="innerValue"
placeholder="请选择或搜索制造规范"
clearable
filterable
remote
:remote-method="handleRemoteSearch"
:loading="loading"
@change="handleSelectChange"
style="width: 100%"
>
<!-- 下拉选项循环制造规范列表 -->
<el-option
v-for="item in mSpecList"
:key="item.specId"
:label="item.specName"
:value="item.specId"
/>
<!-- 无数据提示 -->
<el-option
v-if="mSpecList.length === 0 && !loading"
value=""
disabled
>
暂无匹配制造规范
</el-option>
</el-select>
</template>
<script>
import { listManufacturingSpec } from '@/api/work/manufacturingSpec'
import { debounce } from '@/utils' // 防抖:避免频繁触发接口请求
export default {
name: 'MSpecSelect',
// 1. 接收外部传入的v-model值必加双向绑定的入口
props: {
value: {
type: [String, Number, undefined], // 支持字符串/数字ID兼容不同后端返回类型
default: undefined // 初始值默认undefined未选择状态
},
// 可选:允许外部自定义搜索参数的字段名(增强组件复用性)
searchKey: {
type: String,
default: 'specName' // 默认为“规范名称”搜索对应接口的mSpecName参数
},
// 可选:每页加载数量(外部可配置)
pageSize: {
type: Number,
default: 20
}
},
data() {
return {
mSpecList: [], // 制造规范列表数据
loading: false, // 远程请求加载状态
queryParams: {
// 搜索参数默认用specName可通过searchKey自定义
specName: undefined,
pageNum: 1, // 分页:当前页码
pageSize: this.pageSize // 分页每页条数关联props的pageSize
}
}
},
computed: {
// 2. 核心内部值与外部value的双向同步桥梁
innerValue: {
get() {
// 外部传入的value -> 内部el-select的v-model值初始回显
return this.value
},
set(newVal) {
// 内部el-select值变化时 -> 触发input事件同步给外部v-model
this.$emit('input', newVal)
}
}
},
watch: {
// 3. 监听外部value变化如父组件直接修改v-model值同步更新内部选择状态
value(newVal) {
// 仅当外部值与内部值不一致时更新(避免死循环)
if (newVal !== this.innerValue) {
this.innerValue = newVal
}
},
// 监听searchKey变化外部修改搜索字段时重置搜索参数
searchKey(newKey) {
// 清空原搜索字段的值(避免残留旧字段的搜索条件)
this.queryParams[this.searchKey] = undefined
}
},
created() {
// 初始化:加载默认制造规范列表
this.getList()
// 初始化防抖函数300ms延迟可根据需求调整
this.debouncedSearch = debounce(this.getList, 300)
},
methods: {
// 4. 远程搜索逻辑(输入时触发)
handleRemoteSearch(query) {
// 根据searchKey设置搜索参数specName=query
this.queryParams[this.searchKey] = query.trim() // 去除首尾空格,避免无效搜索
this.queryParams.pageNum = 1 // 重置页码为1新搜索从第一页开始
this.debouncedSearch() // 防抖后执行搜索
},
// 5. 获取制造规范列表(远程接口请求)
getList() {
this.loading = true // 开始加载:显示加载动画
listManufacturingSpec(this.queryParams)
.then(res => {
// 接口成功赋值列表数据兼容res.rows或res.data.rows避免接口返回格式差异
this.mSpecList = res.rows || res.data?.rows || []
})
.catch(() => {
// 接口失败:清空列表,避免旧数据残留
this.mSpecList = []
this.$message.error('获取制造规范列表失败,请重试') // 错误提示(优化用户体验)
})
.finally(() => {
this.loading = false // 结束加载:隐藏加载动画
})
},
// 6. 选择变化时触发(返回完整订单项,方便父组件使用)
handleSelectChange(mSpecId) {
// 根据选中的ID找到对应的完整制造规范对象
const selectedItem = this.mSpecList.find(item => item.specId === mSpecId)
// 触发change事件返回完整项父组件可通过@change接收
this.$emit('change', selectedItem)
// 可选触发input事件后额外触发change事件符合常规组件使用习惯
this.$emit('update:value', selectedItem)
}
}
}
</script>

View File

@@ -54,7 +54,7 @@ export default {
}
// 处理数据,兼容多种字段名,保证任务名唯一
const taskData = this.tasks.map((item, idx) => {
const name = (item.remark || item.taskName || item.productName || item.name || `任务${idx+1}`) + (item.productName ? `-${item.productName}` : '');
const name = (item.taskName || item.planName || item.remark || item.productName || item.name || `任务${idx+1}`) + (item.productName ? `-${item.productName}` : '');
const start = item.startDate || item.start_time || item.start || item.start_date;
const end = item.endDate || item.end_time || item.end || item.end_date;
console.log(item.lineId, item.orderId, idx, '颜色取值依据')

View File

@@ -292,8 +292,8 @@ export default {
processParams: undefined,
scope: undefined,
inspectionStandard: undefined,
status: undefined,
specType: undefined,
status: 1,
specType: 1,
version: undefined,
versionDate: undefined,
standardHours: undefined,

View File

@@ -9,21 +9,21 @@
:value="item.lineId" />
</el-select>
</el-form-item>
<el-form-item label="批次" prop="batchId">
<el-form-item label="生产任务" :prop="binding.key">
<!-- <el-select v-model="detailForm.productId" placeholder="请选择产品" filterable>
<el-option v-for="item in productList" :key="item.productId" :label="item.productName"
:value="item.productId" />
</el-select> -->
<el-select clearable v-model="detailForm.batchId" placeholder="请选择批次" filterable @change="onBatchChange">
<el-option v-for="item in batchList" :key="item.batchId" :label="item.batchNo" :value="item.batchId" />
<el-select clearable v-model="detailForm.taskId" placeholder="请选择生产任务" filterable @change="onTaskChange">
<el-option v-for="item in taskList" :key="item.taskId" :label="item.planName" :value="item.taskId" />
</el-select>
</el-form-item>
<el-form-item label="排产数量" prop="quantity">
<el-input-number :controls=false controls-position="right" v-model="detailForm.quantity" disabled :min="0.01" :step="0.01" style="width:100%" />
<el-input-number :controls=false controls-position="right" v-model="detailForm.quantity" :min="0.01" :step="0.01" style="width:100%" />
</el-form-item>
<el-form-item label="计划日期" prop="dateRange">
<el-date-picker v-model="detailForm.dateRange" type="daterange" range-separator="至" start-placeholder="开始日期"
end-placeholder="结束日期" style="width:100%" />
end-placeholder="结束日期" style="width:100%" @change="onDateRangeChange" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model="detailForm.remark" placeholder="请输入备注" />
@@ -47,22 +47,28 @@
import { listProductionLine } from '@/api/wms/productionLine';
import { ganttProductionLine } from '@/api/wms/productionLine';
import { addSchedulePlanDetail, updateSchedulePlanDetail } from '@/api/wms/schedulePlanDetail';
import { listBatch } from '@/api/wms/batch';
import { listProductionTask } from '@/api/work/productionTask';
import GanttChartEcharts from '../line/GanttChartEcharts.vue';
const binding = {
key: 'taskId',
label: 'planName',
api: listProductionTask,
text: '生产任务'
}
export default {
components: {
GanttChartEcharts
},
data() {
return {
binding,
detailForm: {
detailId: undefined,
planId: undefined,
lineId: undefined,
// productId: undefined,
batchId: undefined,
[binding.key]: undefined,
quantity: 0,
dateRange: [],
startDate: '',
@@ -70,18 +76,19 @@ export default {
remark: ''
},
detailRules: {
batchId: [{ required: true, message: '请选择产品', trigger: 'change' }],
[binding.key]: [{ required: true, message: '请选择' + binding.text, trigger: 'change' }],
lineId: [{ required: true, message: '请选择产线', trigger: 'change' }],
quantity: [{ required: true, message: '请输入排产数量', trigger: 'blur' }],
dateRange: [{ required: true, type: 'array', len: 2, message: '请选择计划日期区间', trigger: 'change' }]
},
lineGanttTasks: [],
productionLineList: [],
previewTask: null,
previewTask: {},
taskList: [],
}
},
created() {
this.fetchBatchList();
this.fetchTaskList();
this.fetchProductionLineList();
},
methods: {
@@ -90,6 +97,25 @@ export default {
this.productionLineList = res.rows || [];
});
},
onTaskChange(taskId) {
const task = this.taskList.find(item => item.taskId === taskId);
if (task) {
this.previewTask = {
...this.previewTask,
taskName: task.taskName,
planName: task.planName,
};
}
},
onDateRangeChange(dateRange) {
if (dateRange && dateRange.length === 2) {
const startDate = this.parseTime(dateRange[0], '{y}-{m}-{d} {h}:{i}:{s}');
const endDate = this.parseTime(dateRange[1], '{y}-{m}-{d} {h}:{i}:{s}');
console.log(startDate, endDate);
this.previewTask.startDate = startDate;
this.previewTask.endDate = endDate;
}
},
onLineChange(lineId) {
if (!lineId) {
this.lineGanttTasks = [];
@@ -100,23 +126,9 @@ export default {
this.updatePreviewTask();
});
},
onBatchChange(batchId) {
if (batchId) {
// 从batchList中查找
const batch = this.batchList.find(item => item.batchId == batchId);
console.log(batch);
if (batch) {
this.detailForm.quantity = batch.totalQuantity;
this.detailForm.dateRange = [
batch.estimatedStartTime,
batch.estimatedEndTime
];
}
}
},
fetchBatchList() {
listBatch({ pageNum: 1, pageSize: 1000 }).then(res => {
this.batchList = res.rows || [];
fetchTaskList() {
listProductionTask({ pageNum: 1, pageSize: 1000 }).then(res => {
this.taskList = res.rows || [];
});
},
submitDetailForm() {
@@ -130,7 +142,7 @@ export default {
this.detailForm.endDate = '';
}
const api = this.detailForm.detailId ? updateSchedulePlanDetail : addSchedulePlanDetail;
const data = Object.assign({}, this.detailForm, { planId: this.planId });
const data = Object.assign({}, this.detailForm, { taskId: this.detailForm.taskId });
api(data).then(() => {
this.$message.success(this.detailForm.detailId ? '修改成功' : '新增成功');
this.detailDialogVisible = false;

View File

@@ -41,6 +41,7 @@ export default {
loading: false,
queryParams: {
orderCode: undefined,
orderStatus: 1,
pageNum: 1,
pageSize: 20
},

View File

@@ -100,14 +100,22 @@
<el-table v-loading="loading" :data="productionTaskList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="主键" align="center" prop="taskId" v-if="true"/>
<el-table-column label="产品规范组ID" align="center" prop="productSpecGroupId" />
<el-table-column label="制造规范ID" align="center" prop="manufacturingSpecId" />
<el-table-column label="订单ID" align="center" prop="orderId" />
<el-table-column label="订单明细ID" align="center" prop="orderItemId" />
<el-table-column label="主键" align="center" prop="taskId" v-if="false" />
<!-- <el-table-column label="产品规范组ID" align="center" prop="productSpecGroupId" /> -->
<el-table-column label="产品规范组" align="center" prop="productSpecGroup.groupName" />
<el-table-column label="产品规范名" align="center" prop="productSpecGroup.groupCode" />
<el-table-column label="工艺步骤" align="center" prop="manufacturingSpec.processRoute" />
<el-table-column label="制造规范名" align="center" prop="manufacturingSpec.specName" />
<el-table-column label="制造规范编号" align="center" prop="manufacturingSpec.specCode" />
<el-table-column label="订单编号" align="center" prop="orderCode" />
<el-table-column label="生产产品" align="center">
<template slot-scope="scope">
<ProductInfo :productId="scope.row.productId" />
</template>
</el-table-column>
<el-table-column label="计划名称" align="center" prop="planName" />
<el-table-column label="计划编号" align="center" prop="planCode" />
<el-table-column label="状态" align="center" prop="status" />
<!-- <el-table-column label="状态" align="center" prop="status" /> -->
<el-table-column label="备注" align="center" prop="remark" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
@@ -139,10 +147,10 @@
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="100px">
<el-form-item label="产品规范组" prop="productSpecGroupId">
<el-input v-model="form.productSpecGroupId" placeholder="请输入产品规范组" />
<PSpecSelect v-model="form.productSpecGroupId" />
</el-form-item>
<el-form-item label="制造规范" prop="manufacturingSpecId">
<el-input v-model="form.manufacturingSpecId" placeholder="请输入制造规范" />
<MSpecSelect v-model="form.manufacturingSpecId" />
</el-form-item>
<!-- <el-form-item label="订单" prop="orderId">
<el-input v-model="form.orderId" placeholder="请输入订单" />
@@ -175,11 +183,17 @@
<script>
import { listProductionTask, getProductionTask, delProductionTask, addProductionTask, updateProductionTask } from "@/api/work/productionTask";
import CreateByOrder from "./panels/createByOrder.vue";
import ProductInfo from "@/components/KLPService/Renderer/ProductInfo";
import MSpecSelect from "../components/MSpecSelect.vue";
import PSpecSelect from "../components/PSpecSelect.vue";
export default {
name: "ProductionTask",
components: {
CreateByOrder
CreateByOrder,
ProductInfo,
MSpecSelect,
PSpecSelect
},
data() {
return {
@@ -353,15 +367,35 @@ export default {
},
handleConfirmCreate(orderItems) {
console.log(orderItems);
Promise.all(orderItems.map(item => {
return addProductionTask({
productSpecGroupId: item.productSpecGroupId,
manufacturingSpecIds: item.manufacturingSpecIds,
orderId: item.orderId,
orderItemId: item.orderItemId,
});
const params = [];
const orderId = orderItems[0].orderId;
for (const item of orderItems) {
if (item.groupId == undefined) {
continue;
}
for (const manufacturingSpecId of item.manufacturingSpecIds) {
params.push({
productSpecGroupId: item.groupId,
manufacturingSpecId: manufacturingSpecId,
orderId: item.orderId,
orderItemId: item.detailId,
planName: '生产任务' + item.detailId,
planCode: 'PT' + item.detailId,
})
}
}
Promise.all(params.map(item => {
return addProductionTask(item);
})).then(res => {
this.$modal.msgSuccess("创建成功");
// 是否将订单状态设置为生产中?
this.$modal.confirm('是否将订单状态设置为生产中?').then(() => {
updateOrder({
orderId,
orderStatus: 2
});
});
this.detailDialogVisible = false;
this.getList();
});

View File

@@ -22,7 +22,9 @@
</el-table-column>
<el-table-column label="制造规格">
<template slot-scope="scope">
<MSpecSelect v-model="scope.row.manufacturingSpecIds" />
<el-select v-model="scope.row.manufacturingSpecIds" placeholder="请选择制造规格" multiple>
<el-option v-for="item in manufacturingSpecList" :key="item.specId" :label="item.specName" :value="item.specId" />
</el-select>
</template>
</el-table-column>
</el-table>
@@ -30,7 +32,12 @@
<el-dialog title="产品规范" :visible.sync="specDialogVisible" width="600px" append-to-body>
<ProductSpec v-if="form.groupId" :groupId="form.groupId" :readonly="false"/>
<div v-else>
暂无产品规格
<el-select placeholder="请选择产品规范" @change="handleChangeSpec" style="width: 100%;">
<el-option v-for="item in productSpecList.filter(item => item.productId != this.form.productId)" :key="item.groupId" :label="item.groupName" :value="item.groupId" />
<template #empty>
<el-button type="primary" @click="handleAddSpec">新增产品规范</el-button>
</template>
</el-select>
</div>
</el-dialog>
</div>
@@ -38,11 +45,14 @@
<script>
import OrderSelect from "../components/OrderSelect";
import { listOrderDetail } from "@/api/wms/orderDetail";
import { listOrderDetail, updateOrderDetail } from "@/api/wms/orderDetail";
import ProductInfo from "@/components/KLPService/Renderer/ProductInfo";
import MSpecSelect from "@/views/work/components/MSpecSelect";
import ProductSpec from "@/views/wms/order/panels/spec.vue";
import { listManufacturingSpec } from "@/api/work/manufacturingSpec";
import { listProductSpecGroup } from "@/api/work/productSpecGroup";
export default {
name: 'CreateByOrder',
components: {
@@ -51,6 +61,14 @@ export default {
MSpecSelect,
ProductSpec
},
created() {
listManufacturingSpec().then(res => {
this.manufacturingSpecList = res.rows;
})
listProductSpecGroup().then(response => {
this.productSpecList = response.rows;
});
},
data() {
return {
order: null,
@@ -58,7 +76,9 @@ export default {
specDialogVisible: false,
form: {
groupId: undefined
}
},
manufacturingSpecList: [],
productSpecList: [],
}
},
methods: {
@@ -72,11 +92,39 @@ export default {
},
handleCreate() {
console.log(this.orderItems);
if (this.orderItems.length === 0) {
this.$message.error('请选择订单');
return;
}
for (const item of this.orderItems) {
if (item.groupId && item.manufacturingSpecIds.length === 0) {
this.$message.error('请选择制造规格');
return;
}
}
this.$emit('create', this.orderItems);
},
handleSpec(row) {
this.specDialogVisible = true;
this.form = row;
},
handleChangeSpec(groupId) {
// 确认更换
this.$modal && this.$modal.confirm('是否确认更换产品规范?').then(() => {
this.form.groupId = groupId;
updateOrderDetail(this.form).then(response => {
this.$modal && this.$modal.msgSuccess("修改成功");
this.open = false;
this.getList();
}).finally(() => {
this.buttonLoading = false;
});
});
},
handleAddSpec() {
this.$router.push({
path: '/production/pspec',
});
}
}
}