<template>
|
<el-dialog
|
top="10vh"
|
:fullscreen="isFullScreen"
|
:close-on-click-modal="false"
|
:visible.sync="visible">
|
|
<template slot="title">
|
<i :class="isFullScreen?'icon-zuixiaohua':'icon-quanpingzuidahua'"
|
style="position: absolute; right: 52px; float: right" @click="fullscreen">
|
</i>
|
<span>创建制造订单</span>
|
</template>
|
|
<el-form :model="dataForm" :rules="dataRule" ref="dataForm">
|
<div style="background:#f5f7fa;margin-bottom: 10px;">
|
<el-button type="primary" icon="el-icon-s-order" @click="saveMpsStructureComponent">保存结构</el-button>
|
<el-button type="primary" icon="el-icon-more" @click="changeBomNode">修改节点</el-button>
|
<el-button type="primary" icon="el-icon-plus" @click="addBomNode">新增节点</el-button>
|
<el-button type="danger" icon="el-icon-delete" @click="removeBomNode">删除节点</el-button>
|
<el-button type="primary" icon="el-icon-circle-plus-outline" @click="createManufacturingOrder">创建订单</el-button>
|
</div>
|
|
<el-table
|
ref="allTree"
|
:data="allTreeData"
|
style="width: 100%;margin-bottom: 20px;"
|
highlight-current-row
|
@current-change="handleNodeClick"
|
row-key="id"
|
border
|
default-expand-all
|
:tree-props="{children: 'children', hasChildren: 'hasChildren'}">
|
<el-table-column
|
prop="label"
|
label="零件名"
|
sortable
|
width="300">
|
</el-table-column>
|
<el-table-column
|
prop="partNo"
|
label="零件号"
|
sortable
|
width="180">
|
</el-table-column>
|
<el-table-column
|
prop="qpa"
|
label="单位用量"
|
sortable
|
width="100">
|
</el-table-column>
|
<el-table-column
|
prop="unit"
|
label="单位"
|
sortable
|
width="100">
|
</el-table-column>
|
<el-table-column
|
prop="drawingNumber"
|
label="图号"
|
sortable
|
width="180">
|
</el-table-column>
|
</el-table>
|
|
|
</el-form>
|
|
<div slot="footer" class="dialog-footer">
|
<el-button type="info" @click="visible = false">取消</el-button>
|
<!-- <el-button type="primary" @click="dataFormSubmit()">确定</el-button>-->
|
</div>
|
|
<!-- 弹窗, 创建制造订单 -->
|
<table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="refreshNode"/>
|
<!-- 新增节点 -->
|
<node-form v-if="nodeVisible" ref="node" @refreshDataList="addNode"/>
|
</el-dialog>
|
</template>
|
|
<script>
|
import {
|
getMpsStructureComponent,
|
saveMpsStructureComponent,
|
deleteMpsStructureComponentById
|
} from '@/api/plan/masterproductionschedule'
|
import {validateQtyPlaned} from '@/util/validate'
|
import TableForm from '../manufacturingorder/manufacturingorder-form'
|
import NodeForm from './node'
|
|
export default {
|
components: {
|
TableForm, NodeForm
|
},
|
data() {
|
return {
|
dataList: [],
|
isFullScreen: false,
|
visible: true,
|
masterProductionSchedule: null,
|
allTreeData: [],
|
defaultProps: {
|
children: 'children',
|
label: this.showLabel
|
},
|
dataForm: {},
|
dataRule: {},
|
addOrUpdateVisible: false,
|
nodeVisible: false,
|
currentComponent: null,
|
issued: false
|
}
|
},
|
methods: {
|
init(mps) {
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs['dataForm'].resetFields()
|
this.clearTreeSelect()
|
this.allTreeData = []
|
if (mps) {
|
this.masterProductionSchedule = mps
|
this.getTreeData(this.masterProductionSchedule)
|
}
|
})
|
},
|
getTreeData(masterProductionSchedule) {
|
// 1.先去查主计划的备份bom
|
getMpsStructureComponent(masterProductionSchedule.id, masterProductionSchedule.partId).then(response => {
|
if (response.data.data) {
|
if (response.data.data[0].children[0].id == null) {
|
saveMpsStructureComponent(response.data.data, this.masterProductionSchedule.id).then(response => {
|
this.allTreeData = response.data.data
|
this.clearTreeSelect()
|
})
|
} else {
|
this.allTreeData = response.data.data
|
}
|
} else {
|
this.$message.error("该零件没有默认结构")
|
}
|
})
|
},
|
//新增节点
|
addNode(newNode) {
|
if (!this.currentComponent.children) {
|
this.currentComponent.children = []
|
}
|
this.currentComponent.children.push(newNode)
|
},
|
// 刷新节点
|
refreshNode() {
|
this.getTreeData(this.masterProductionSchedule)
|
this.masterProductionSchedule.issued = true
|
},
|
// 创建制造订单
|
createManufacturingOrder() {
|
if (this.nodeSelected()) {
|
this.addOrUpdateVisible = true
|
this.$nextTick(() => {
|
this.$refs.addOrUpdate.init(0, Object.assign({
|
partId: this.currentComponent.partId,
|
partName: this.currentComponent.label,
|
mpsStructureComponentId: this.currentComponent.id,
|
qtyProductionRequired: this.masterProductionSchedule.qtyRequired,
|
requiredProductionDate: this.masterProductionSchedule.requiredDate
|
}))
|
})
|
}
|
},
|
// 树节点操作
|
showLabel(data, node) {
|
return data.label + (data.manufacturingOrderQuantity == undefined ? '' : ('(' + data.manufacturingOrderQuantity + ')'))
|
},
|
handleNodeClick(data) {
|
this.currentComponent = data
|
},
|
// 判断是否选择树节点
|
nodeSelected() {
|
if (this.currentComponent) {
|
if (!this.currentComponent.id) {
|
this.$message.error("请先保存结构节点")
|
return false
|
}
|
} else {
|
this.$message.error("请先选择结构节点")
|
return false
|
}
|
return true
|
},
|
// 判断是否可以编辑bom树
|
checkIssued() {
|
if (this.masterProductionSchedule.issued) {
|
this.$message.error("已下发制造订单,无法修改产品结构")
|
return false
|
}
|
return true
|
},
|
saveMpsStructureComponent() {
|
if (this.allTreeData && this.allTreeData.length > 0) {
|
saveMpsStructureComponent(this.allTreeData, this.masterProductionSchedule.id).then(response => {
|
this.allTreeData = response.data.data
|
this.clearTreeSelect()
|
this.$message.success('保存成功')
|
})
|
}else{
|
this.$message.error("请先创建结构")
|
}
|
},
|
changeBomNode() {
|
if (this.checkIssued() && this.nodeSelected()) {
|
if (this.currentComponent.parentId == 0) {
|
this.$message.error("成品节点无法修改")
|
return
|
}
|
this.nodeVisible = true
|
this.$nextTick(() => {
|
this.$refs.node.init(this.currentComponent, 1)
|
})
|
}
|
},
|
addBomNode() {
|
if (this.checkIssued() && this.nodeSelected()) {
|
this.nodeVisible = true
|
this.$nextTick(() => {
|
this.$refs.node.init(this.currentComponent, 0)
|
})
|
}
|
},
|
removeBomNode() {
|
if (this.checkIssued() && this.nodeSelected()) {
|
if (this.currentComponent.parentId == 0) {
|
this.$message.error("成品节点无法删除")
|
return
|
}
|
deleteMpsStructureComponentById(this.currentComponent.id).then(response => {
|
this.getTreeData(this.masterProductionSchedule);
|
})
|
}
|
},
|
// 清除树的选择
|
clearTreeSelect() {
|
this.$refs.allTree.setCurrentRow()
|
this.currentComponent = null
|
},
|
// 全屏
|
fullscreen() {
|
this.isFullScreen = !this.isFullScreen
|
},
|
},
|
}
|
</script>
|