Fixiaobai
2023-11-17 1f5009ddcc87f7a7db792d40206bdcf5462089ee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<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>