Fixiaobai
2023-10-13 e8308ddac0ba4a1f406e8f63d7e6b6f2541cb770
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
<template>
  <div style="padding:0px 14px;height: 100%;overflow: auto;">
    <div class="steprecord-header">
      <div style="height:28px;line-height:28px;">
        <el-divider class="pane-divider" direction="vertical"></el-divider
        ><span style="font-size:14px;font-weight:bold">工步列表</span>
      </div>
      <div style="height:28px;line-height:28px;">
        <el-tooltip
          class="item"
          effect="dark"
          content="刷新工步"
          placement="top"
        >
          <el-button
            class="step-refresh-btn"
            icon="el-icon-refresh"
            type="info"
            circle
            @click="getDataList"
          ></el-button>
        </el-tooltip>
      </div>
    </div>
    <div style="margin-bottom: 10px;display:inline-block;">
      <el-form
        :rules="stepRecordRule"
        :model="stepRecordForm"
        class="l-mes"
        ref="stepRecordForm"
        :inline="true"
        style="margin-left: 10px"
      >
        <el-form-item prop="stepId" label="工步">
          <el-select
            v-model="stepRecordForm.stepId"
            filterable
            placeholder="请选择工步"
            @change="changeStep"
            @visible-change="visibleChange"
            :disabled="currentDutyRecord.isConfirm"
          >
            <el-option
              v-for="item in steps"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="staffId" label="人员">
          <el-select
            v-model="stepRecordForm.staffId"
            filterable
            placeholder="请选择人员"
            @change="changeStaff"
            @visible-change="visibleChange"
            :disabled="currentDutyRecord.isConfirm"
          >
            <el-option
              v-for="item in staffList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="systemNo" label="SN码">
          <el-input
            ref="snCodeRef"
            v-model="stepRecordForm.systemNo"
            v-focus
            @keyup.enter.native="saveStepRecord"
            :disabled="currentDutyRecord.isConfirm"
          ></el-input>
        </el-form-item>
        <el-form-item prop="number" label="报工的数量">
          <el-input v-model="queryReport.total" disabled></el-input>
        </el-form-item>
      </el-form>
    </div>
    <div style="float:right">
      <el-button
        class="out-btn"
        type="primary"
        icon="tracking-btn-out"
        @click="checkProductOutStep"
        >漏扫检查</el-button
      >
    </div>
    <el-table
      ref="stepRecordTable"
      :data="stepRecordList"
      :height="684"
      :row-height="38"
      :header-cell-style="stepRecordTableHeaderCellStyle"
      :row-class-name="stepRecordTableRowClassName"
      class="step-table"
    >
      <el-table-column label="工步编号" prop="stepNo" align="center">
        <template slot="header" slot-scope="scope">
          <div style="line-height: 14px;">工步编号</div>
          <div class="th" @click.stop>
            <template>
              <el-input
                clearable
                @keyup.enter.native="getDataList"
                v-model="paramObject.stepNo"
                placeholder="工步编号"
                @clear="getDataList"
                style="width: 100%"
              >
              </el-input>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="工步名称" prop="name" align="center">
        <template slot="header" slot-scope="scope">
          <div style="line-height: 14px;">工步名称</div>
          <div class="th" @click.stop>
            <template>
              <el-input
                clearable
                @keyup.enter.native="getDataList"
                v-model="paramObject.name"
                placeholder="工步名称"
                @clear="getDataList"
                style="width: 100%"
              >
              </el-input>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="生产批次" prop="stepBatchNo" align="center">
        <template slot="header" slot-scope="scope">
          <div style="line-height: 14px;">生产批次</div>
          <div class="th" @click.stop>
            <template>
              <el-input
                clearable
                @keyup.enter.native="getDataList"
                v-model="paramObject.stepBatchNo"
                placeholder="生产批次"
                @clear="getDataList"
                style="width: 100%"
              >
              </el-input>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="SN码" prop="systemNo" align="center">
        <template slot="header" slot-scope="scope">
          <div style="line-height: 14px;">SN码</div>
          <div class="th" @click.stop>
            <template>
              <el-input
                clearable
                @keyup.enter.native="getDataList"
                v-model="paramObject.systemNo"
                placeholder="SN码"
                @clear="getDataList"
                style="width: 100%"
              >
              </el-input>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="人员"
        prop="staffName"
        align="center"
        :show-overflow-tooltip="true"
      >
        <template slot="header" slot-scope="scope">
          <div style="line-height: 14px;">人员</div>
          <div class="th" @click.stop>
            <template>
              <el-input
                clearable
                @keyup.enter.native="getDataList"
                v-model="paramObject.staffName"
                placeholder="人员"
                @clear="getDataList"
                style="width: 100%"
              >
              </el-input>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="时间" prop="createTime" align="center">
        <template slot="header" slot-scope="scope">
          <div style="line-height: 18px;">时间</div>
          <div class="th" @click.stop>
            <template>
              <el-date-picker
                clearable
                v-model="paramObject.createTime"
                type="datetimerange"
                start-placeholder="开始"
                end-placeholder="结束"
                value-format="yyyy-MM-dd HH:mm:ss"
                @change="feedDateChange($event)"
                size="mini"
                style="width:150px"
              >
              </el-date-picker>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column align="center" width="85px" fixed="right" label="操作">
        <template slot-scope="scope">
          <el-tooltip effect="dark" content="删除" placement="top-start">
            <el-button
              type="text"
              size="small"
              class="red-but"
              :disabled="currentDutyRecord.isConfirm"
              @click="delStepRecord(scope.$index, scope.row)"
              >删除</el-button
            >
          </el-tooltip>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagin-page">
      <el-pagination
        :current-page="queryReport.current"
        :page-sizes="[10, 15, 20, 50, 100]"
        :page-size="queryReport.size"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChangeReport"
        @current-change="handleCurrentChangeReport"
        :total="queryReport.total"
      >
      </el-pagination>
    </div>
    <!-- 弹窗, 新增 / 修改 -->
    <table-form v-if="addOrUpdateVisible" ref="addOrUpdate"></table-form>
  </div>
</template>
<style lang="scss" scoped>
.step-refresh-btn.el-button--small.is-circle {
  padding: 4px;
}
.steprecord-header {
  margin-top: 20px;
  margin-bottom: 14px;
  display: flex;
  justify-content: flex-start;
  align-items: center;
}
.out-btn {
  background-image: -webkit-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: -moz-linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  background-image: linear-gradient(139deg, #5f6eef 0%, #2783ff 100%);
  color: #fff;
  border-color: #fbecec;
  border-radius: 15px;
  padding: 6px 15px;
}
.pane-divider {
  width: 4px;
  background-color: #4283ee;
}
.step-table >>> .stripe-row {
  background: #f6f9fe;
}
.step-table >>> td {
  padding: 3px 0px;
}
.step-table >>> .el-button {
  padding: 5px 0px;
}
.step-table {
  /deep/ .el-table__fixed-right {
    height: 100% !important; //设置高优先,以覆盖内联样式
  }
}
.blue-but.is-disabled {
  color: #aacfff;
}
 
.blue-but {
  color: #006eff;
}
.red-but.is-disabled {
  color: #fab6b6;
}
 
.red-but {
  color: red;
}
.pagin-page {
  margin-top: 10px;
  margin-bottom: 14px;
  display: flex;
  justify-content: end;
  align-items: center;
}
</style>
<script>
import {
  getSteps,
  getStepRecordsForStep,
  deleteStepRecord,
  saveStepRecord
} from '@/api/product/productstep'
import { judgeAddInput } from '../../../api/product/productstep'
import TableForm from './steprecord-check'
export default {
  props: {
    currOperateTask: {
      type: Object,
      default: () => {
        return {}
      }
    },
    personBoardList: {
      type: Array,
      default: () => {
        return []
      }
    },
    workstationId: {
      type: Number
    },
    currentDutyRecord: {
      type: Object,
      default: () => {
        return {}
      }
    },
    userInfo: {
      type: Object,
      default: () => {
        return {}
      }
    },
    stepShow: {
      type: Boolean,
      default: false
    },
    currItem: {
      type: String,
      default: null
    }
  },
  data() {
    return {
      addOrUpdateVisible: false,
      dateTimeFiltersThree: {},
      paramObject: {},
      productMainId: 0,
      staffList: [], // 操作人
      stepRecordList: [], // 工步记录
      steps: [], // 工序基础工步
      stepRecordForm: {
        stepId: null,
        staffName: null,
        systemNo: null,
        staffId: null
      },
      stepRecordRule: {
        stepId: [
          { required: true, message: '工步不能为空', trigger: 'change' }
        ],
        staffId: [
          { required: true, message: '工人不能为空', trigger: 'change' }
        ]
      },
      queryReport: {
        current: 1,
        size: 20,
        total: 0
      },
      reportAllData: [] // 存放原始数据
    }
  },
  directives: {
    focus: {
      inserted: function(el, option) {
        var defClass = 'el-input'
        var defTag = 'input'
        var value = option.value || true
        if (typeof value === 'boolean') {
          value = { cls: defClass, tag: defTag, foc: value }
        } else {
          value = {
            cls: value.cls || defClass,
            tag: value.tag || defTag,
            foc: value.foc || false
          }
        }
        el.getElementsByTagName(value.tag)[0].focus()
      }
    }
  },
  components: {
    TableForm
  },
  methods: {
    // sn输入框聚焦
    snCodeInputFocus() {
      this.$nextTick(function() {
        this.$refs.snCodeRef.$el.querySelector('input').focus()
      })
    },
    visibleChange(val) {
      if (!val) {
        this.snCodeInputFocus()
      }
    },
    // 工步选择变化时,触发
    changeStep() {
      this.queryReport.current = 1
      this.getStepRecords(
        this.currOperateTask.id,
        this.stepRecordForm.stepId,
        this.productMainId,
        this.stepRecordForm.staffId
      )
    },
    // 漏扫检查
    checkProductOutStep() {
      if (this.currOperateTask.id && this.stepRecordForm.stepId) {
        this.addOrUpdateVisible = true
        var param = null
        var minNo = null
        var maxNo = null
        if (this.reportAllData && this.reportAllData.length > 0) {
          param = this.reportAllData[0].systemNo.substr(0, 9)
          minNo = this.reportAllData[0].systemNo.substr(9, 4)
          maxNo = this.reportAllData[
            this.reportAllData.length - 1
          ].systemNo.substr(9, 4)
        }
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(
            this.stepRecordForm.stepId,
            param,
            minNo,
            maxNo
          )
        })
      } else if (!this.stepRecordForm.stepId) {
        this.$message.error('请选择工步')
      } else {
        this.$message.error('请选择工单')
      }
    },
    // 人员选择变化时,触发
    changeStaff() {
      this.queryReport.current = 1
      const currStaff = this.staffList.find(
        (item) => item.id === this.stepRecordForm.staffId
      )
      this.stepRecordForm.staffName = currStaff.name
      this.getStepRecords(
        this.currOperateTask.id,
        this.stepRecordForm.stepId,
        this.productMainId,
        this.stepRecordForm.staffId
      )
    },
    stepRecordTableHeaderCellStyle({ row, column, rowIndex, columnIndex }) {
      let headerStyle = 'background:#599ef4;color:#fff;'
      if (columnIndex === 0) {
        headerStyle += 'border-radius: 6px 0px 0px 0px;'
      } else if (columnIndex === 6) {
        headerStyle += 'border-radius: 0px 6px 0px 0px;'
      }
      return headerStyle
    },
    stepRecordTableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'stripe-row'
      } else {
        return ''
      }
    },
    // 保存工步记录
    saveStepRecord() {
      this.$refs.stepRecordForm.validate((valid) => {
        if (valid) {
          if (
            this.stepRecordForm.systemNo != null &&
            this.stepRecordForm.systemNo !== ''
          ) {
            var stepRecord = {}
            stepRecord.operationTaskId = this.currOperateTask.id
            stepRecord.stepId = this.stepRecordForm.stepId
            stepRecord.systemNo = this.stepRecordForm.systemNo
            stepRecord.dutyNo = this.currentDutyRecord.dutyNo
            stepRecord.workstationId = this.workstationId
            var stepStaffList = []
            var stepStaff = {}
            stepStaff.staffId = this.stepRecordForm.staffId
            stepStaffList.push(stepStaff)
            stepRecord.stepStaffList = stepStaffList
            judgeAddInput(stepRecord).then((response) => {
              if (response.data.data) {
                this.$confirm('投料不足是否继续操作:', '提示', {
                  confirmButtonText: '确定',
                  cancelButtonText: '取消',
                  closeOnClickModal: false,
                  type: 'warning'
                }).then((data) => {
                  this.saveStepProduction(stepRecord)
                })
              } else {
                this.saveStepProduction(stepRecord)
              }
            })
            this.stepRecordForm.systemNo = null
          } else {
            this.$message.error('SN码不能为空')
          }
        }
      })
    },
    saveStepProduction(stepRecord) {
      saveStepRecord(stepRecord)
        .then((response) => {
          if (response.data.code === 0) {
            this.$message.success('人员工步保存成功!')
            this.getDataList()
            // this.$emit('refreshProductTracking')
          } else {
            this.$message.error('人员工步保存失败!')
          }
          this.stepRecordForm.systemNo = null
        })
        .catch((error) => {
          console.log(error)
          console.log('人员工步保存异常')
        })
    },
    // 删除工步记录
    delStepRecord(index, row) {
      this.$confirm('此操作将永久删除该工步记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteStepRecord(row.id)
            .then((response) => {
              var data = response.data
              if (data.code === 0) {
                this.$message.success('删除工步成功')
                this.refreshStepRecordList(
                  this.currOperateTask.id,
                  this.stepRecordForm.stepId,
                  this.productMainId,
                  this.stepRecordForm.StaffId
                )
                this.$emit('refreshProductTracking')
              } else {
                this.$message.error('删除工步失败')
              }
            })
            .catch((error) => {
              console.log(error)
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    init(id) {
      this.productMainId = id
      if (this.stepRecordForm.stepId != null) {
        this.queryReport.current = 1
        this.getStepRecords(
          this.currOperateTask.id,
          this.stepRecordForm.stepId,
          this.productMainId,
          this.stepRecordForm.staffId
        )
      }
    },
    // 搜索框调用查询
    getDataList() {
      this.queryReport.current = 1
      this.getStepRecords(
        this.currOperateTask.id,
        this.stepRecordForm.stepId,
        this.productMainId,
        this.stepRecordForm.staffId
      )
    },
    // 查询工单下对应工序的工步
    getSteps(taskId) {
      getSteps(taskId)
        .then((response) => {
          var data = response.data
          if (data.code === 0) {
            this.steps = data.data
          } else {
            this.steps = []
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    feedDateChange(val) {
      if (val != null) {
        this.dateTimeFiltersThree.createTime = val
      } else {
        delete this.dateTimeFiltersThree.createTime
      }
      this.getDataList()
    },
    // 查询工单下的工步记录
    getStepRecords(taskId, stepId, productMainId, staffId) {
      if (productMainId == 0) {
        productMainId = null
      }
      if (stepId == null) {
        this.$message('工步不能为空')
        return
      }
      const criteria = {}
      criteria.dateTimeFilters = this.dateTimeFiltersThree
      const query = Object.assign(
        { current: this.queryReport.current, size: this.queryReport.size },
        {
          operationTaskId: taskId,
          stepId: stepId,
          productMainId: productMainId,
          staffId: staffId,
          criteria: JSON.stringify(criteria)
        },
        this.paramObject
      )
      getStepRecordsForStep(query)
        .then((response) => {
          var data = response.data
          if (data.code === 0) {
            this.stepRecordList = data.data.records
            this.queryReport.total = data.data.total
            // this.getReportData()
          } else {
            this.stepRecordList = []
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    // 保存成功后,回调刷新页面
    refreshStepRecordList(taskId, stepId, productMainId, StaffId) {
      this.queryReport.current = 1
      this.getStepRecords(taskId, stepId, productMainId, StaffId)
    },
    handleSizeChangeReport(val) {
      this.queryReport.size = val
      this.queryReport.current = 1
      this.getStepRecords(
        this.currOperateTask.id,
        this.stepRecordForm.stepId,
        this.productMainId,
        this.stepRecordForm.staffId
      )
    },
    handleCurrentChangeReport(val) {
      this.queryReport.current = val
      this.getStepRecords(
        this.currOperateTask.id,
        this.stepRecordForm.stepId,
        this.productMainId,
        this.stepRecordForm.staffId
      )
    },
    getReportData() {
      const list = JSON.parse(JSON.stringify(this.reportAllData))
      this.stepRecordList = list.slice(
        (this.queryReport.current - 1) * this.queryReport.size,
        this.queryReport.current * this.queryReport.size
      )
    },
    // 刷新所有列表的数据
    refreshAllData() {
      this.queryReport.current = 1
      this.getStepRecords(
        this.currOperateTask.id,
        this.stepRecordForm.stepId,
        this.productMainId,
        this.stepRecordForm.staffId
      )
    }
  },
  watch: {
    currOperateTask: {
      handler(newValue, oldValue) {
        if (newValue.id) {
          // 查询工单下对应工序的工步
          this.getSteps(newValue.id)
          this.queryReport.current = 1
          this.queryReport.total = 0
          this.$nextTick(() => {
            if (this.currItem != null && this.currItem === 'step') {
              // 查询工单下的工步记录
              if (this.stepRecordForm.stepId) {
                this.getStepRecords(
                  newValue.id,
                  this.stepRecordForm.stepId,
                  this.productMainId,
                  this.stepRecordForm.staffId
                )
              }
            }
          })
        } else {
          // 清空stepRecordList、steps
          this.stepRecordList = []
          this.steps = []
        }
      },
      deep: true
    },
    stepShow: {
      handler(newValue, oldValue) {
        if (newValue) {
          this.snCodeInputFocus()
        }
      }
    },
    personBoardList: {
      handler(newValue, oldValue) {
        console.log('personBoardList的watch')
        this.staffList = []
        var userInfoFlag = true
        var staff
        for (let i = 0; i < newValue.length; i++) {
          staff = {}
          staff.id = newValue[i].staffId
          staff.name = newValue[i].staffName
          this.staffList.push(staff)
          if (this.userInfo.staffId === staff.id) {
            userInfoFlag = false // 原当班记录中存在登录人员
          }
        }
        if (userInfoFlag) {
          staff = {}
          staff.id = this.userInfo.staffId
          staff.name = this.userInfo.staffName
          this.staffList.push(staff)
        }
        // 默认赋值是当前登录人
        this.stepRecordForm.staffName = this.userInfo.staffName
        this.stepRecordForm.staffId = this.userInfo.staffId
      },
      deep: true
    },
    workstationId() {
      this.stepRecordForm.stepId = null
    }
  }
}
</script>