zss
2023-11-17 2518e47a3ac999978fbf14612c967c3bbf421d25
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
<template>
  <el-dialog
    width="65%"
    title="自动车间订单"
    top="5vh"
    :visible.sync="innerVisible"
    append-to-body
    @close="$emit('update:currshowlist', false)"
    :show="currshowlist"
    class="part-dialog"
    :close-on-click-modal="false"
  >
    <div>
      <div style="margin-bottom:20px;">
        <div>
          <el-table
            :data="requiredTable"
            border
            style="width: 100%"
            height="400"
          >
            <el-table-column
              type="index"
              label="序号"
              width="50"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="partNo"
              label="零件号"
              width="120"
              align="center"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="partName"
              label="零件描述"
              width="120"
              align="center"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              prop="quantity"
              label="计划需求数量"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="releasedQuantity"
              label="已下达数量"
              align="center"
            >
            </el-table-column>
            <el-table-column
              prop="workshopTypeCode"
              label="车间订单类型"
              width="150"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.workshopTypeCode"
                  placeholder=""
                  style="width:100%"
                  @change="(val) => changeWorkshopTypeCode(val, scope.$index)"
                >
                  <el-option
                    v-for="(item, index) in bomTypeDbOptions"
                    :label="item.label"
                    :value="item.value"
                    :key="index"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="workShop"
              label="车间"
              width="150"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.workShop"
                  placeholder=""
                  style="width:100%"
                  @change="(val) => changeWorkShop(val, scope.$index)"
                >
                  <el-option
                    v-for="item in workShopOptions"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="orderQuantity"
              label="订单需求数量"
              align="center"
            >
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.orderQuantity"
                  placeholder=""
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column
              prop="requiredDate"
              label="订单需求日期"
              width="195"
              align="center"
            >
              <template slot-scope="scope">
                <el-date-picker
                  :clearable="false"
                  v-model="scope.row.requiredDate"
                  style="width: 100%"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  @change="(val) => changeRequiredDate(val, scope.$index)"
                >
                </el-date-picker>
              </template>
            </el-table-column>
            <el-table-column prop="unit" label="计量单位" align="center">
            </el-table-column>
            <el-table-column
              prop="manufactureAttr"
              label="制造属性"
              width="150"
              align="center"
            >
              <template slot-scope="scope">
                <el-select
                  v-model="scope.row.manufactureAttr"
                  placeholder=""
                  style="width:100%"
                  disabled
                >
                  <el-option
                    v-for="item in manufactureAttrs"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </template>
            </el-table-column>
            <el-table-column
              prop="isReportOperation"
              label="IFS车间订单接收时报告工序"
              align="center"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.isReportOperation ? '是' : '否' }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button @click="innerVisible = false">取 消</el-button>
      <el-button type="primary" :disabled="isSubmit" v-thinclick="`createOrder`"
        >创建订单</el-button
      >
    </div>
  </el-dialog>
</template>
<script>
import { remote } from '@/api/admin/dict'
import { getTheoryQuantity } from '@/api/plan/masterproductionschedule'
import { addBatch } from '@/api/plan/manufacturingorder'
export default {
  props: {
    currshowlist: {
      type: Boolean,
      default: false
    },
    masterProduction: {
      type: Object,
      default: () => {
        return {}
      }
    },
    isReportOperation: {
      type: Boolean,
      default: false
    },
    outPutBatchList: {
      type: Array,
      default: () => {
        return []
      }
    },
    qtyPlaned: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      innerVisible: false,
      isSubmit: false,
      requiredTable: [],
      workShopOptions: [],
      bomTypeDbOptions: [],
      manufactureAttrs: []
    }
  },
  created() {
    this.getWorkShopOptions()
    this.getBomTypeDbOptions()
    this.getManufactureAttrs('manufacture_attr_type')
  },
  watch: {
    currshowlist() {
      this.innerVisible = this.currshowlist
      if (this.currshowlist) {
        this.requiredTable = []
        this.$nextTick(() => {
          // 查询需要自动创建车间订单的零件列表
          getTheoryQuantity(
            this.masterProduction.id,
            this.outPutBatchList
          ).then((response) => {
            const resData = response.data
            if (resData.code === 0) {
              const theories = resData.data
              if (theories.length > 0) {
                let requiredItem
                theories.forEach((item) => {
                  requiredItem = {
                    partId: item.partId,
                    partNo: item.partNo,
                    partName: item.partName,
                    routingId: item.routingId,
                    bomId: item.bomId,
                    orderQuantity: item.orderQuantity,
                    quantity: item.quantity,
                    releasedQuantity: item.releasedQuantity,
                    unit: item.unit,
                    workShop: null,
                    workshopTypeCode: 'M',
                    requiredDate: this.masterProduction.requiredDate,
                    id: item.id,
                    manufactureAttr: this.masterProduction.manufactureAttr,
                    isReportOperation: this.isReportOperation
                  }
                  this.requiredTable.push(requiredItem)
                })
              }
            }
          })
        })
      }
    }
  },
  methods: {
    getManufactureAttrs(type) {
      remote(type).then((response) => {
        const code = response.data.code
        if (code === 0) {
          const _data = response.data.data
          this.manufactureAttrs = _data
        }
      })
    },
    createOrder() {
      this.isSubmit = true
      // 校验数据字段
      let checkFlag = true
      let checkMsg = ''
      this.requiredTable.forEach((item, index) => {
        if (item.workShop == null || item.workShop == '') {
          checkFlag = false
          checkMsg = checkMsg + '第' + (index + 1) + '行,车间不能为空;'
        }
        if (item.requiredDate == null || item.requiredDate == '') {
          checkFlag = false
          checkMsg =
            checkMsg + '第' + (index + 1) + '行,订单需求日期不能为空;'
        }
        if (item.orderQuantity == null || item.orderQuantity == '') {
          checkFlag = false
          checkMsg =
            checkMsg + '第' + (index + 1) + '行,订单需求数量不能为空;'
        } else {
          if (!this.checkZero(item.orderQuantity)) {
            checkFlag = false
            checkMsg =
              checkMsg + '第' + (index + 1) + '行,订单需求数量不能为0;'
          } else {
            if (!this.checkPositive(item.orderQuantity)) {
              checkFlag = false
              checkMsg =
                checkMsg + '第' + (index + 1) + '行,订单需求数量需为正数;'
            } else {
              if (!this.checkDecimal(item.orderQuantity)) {
                checkFlag = false
                checkMsg =
                  checkMsg +
                  '第' +
                  (index + 1) +
                  '行,订单需求数量最多六位小数;'
              }
            }
          }
        }
      })
      if (checkFlag) {
        // 提交,创建车间订单
        // addBatch()
        const orderList = []
        this.requiredTable.forEach((item) => {
          orderList.push({
            mpsId: this.masterProduction.id,
            partId: item.partId,
            partNo: item.partNo,
            partName: item.partName,
            technologyRoutingId: item.routingId,
            bomId: item.bomId,
            qtyRequired: item.orderQuantity,
            requiredDate: item.requiredDate,
            workShop: item.workShop,
            workshopTypeCode: item.workshopTypeCode,
            scheduleTheoryQuantityId: item.id,
            manufactureAttr: item.manufactureAttr,
            isReportOperation: item.isReportOperation,
            outPutBatchList: this.outPutBatchList
          })
        })
        addBatch(orderList)
          .then((response) => {
            const resData = response.data
            if (resData.code === 0) {
              this.$message.success('自动创建车间订单成功')
              this.innerVisible = false
              this.$emit('refreshDataList')
            } else {
              this.$message.error('自动创建车间订单失败')
            }
            this.isSubmit = false
          })
          .catch(() => {
            this.isSubmit = false
          })
      } else {
        this.$message.error(checkMsg)
        this.isSubmit = false
      }
    },
    checkZero(value) {
      if (value == 0) {
        return false
      } else {
        return true
      }
    },
    checkPositive(value) {
      if (!/^[0-9]+.?[0-9]*$/.test(value)) {
        return false
      } else {
        return true
      }
    },
    checkDecimal(value) {
      if (
        !/(^[1-9]([0-9]+)?(\.[0-9]{1,6})?$)|(^(0){1}$)|(^[0-9]\.[0-9]{1,6}$)/.test(
          value
        )
      ) {
        return false
      } else {
        return true
      }
    },
    changeWorkshopTypeCode(val, param) {
      if (param === 0) {
        this.requiredTable.forEach((item) => {
          item.workshopTypeCode = val
        })
      }
    },
    changeWorkShop(val, param) {
      if (param === 0) {
        this.requiredTable.forEach((item) => {
          item.workShop = val
        })
      }
    },
    changeRequiredDate(val, param) {
      if (param === 0) {
        this.requiredTable.forEach((item) => {
          item.requiredDate = val
        })
      }
    },
    // 查询结构类型字典
    getBomTypeDbOptions() {
      remote('bom_type_db').then((response) => {
        if (response.data.code === 0) {
          this.bomTypeDbOptions = response.data.data
        } else {
          this.bomTypeDbOptions = []
        }
      })
    },
    getWorkShopOptions() {
      remote('work_shop').then((response) => {
        if (response.data.code === 0) {
          this.workShopOptions = response.data.data
        } else {
          this.workShopOptions = []
        }
      })
    }
  }
}
</script>
<style scoped></style>