jiangping
2023-08-17 8d7cb8876ac222eca1c82d5bab250f5551531edb
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
<template>
  <GlobalWindow
    :title="title"
    width="1182px"
    :visible.sync="visible"
    :confirm-working="isWorking"
    @confirm="confirm"
  >
    <div style="min-width:1150px">
      <el-form :model="form" ref="form" label-width="100px" label-suffix=":" inline>
        <div style="margin-bottom:15px">
          <span class="text-code">{{ form.procedureName + ' | ' + form.mmodel.name + ' ' + form.mmodel.code }}</span>
          <!-- 0已创建、1已备料、2已完工检、3已检验、4已报工、、6已取消 -->
          <span v-if="form.status==0" style="background-color: #305ED5;" class="status-log">已创建</span>
          <span v-else-if="form.status==6" style="background-color: #BBBBBB;" class="status-log">已取消</span>
          <span v-else style="background-color: #03AF76;" class="status-log">{{ form.status==1 ? '已备料' : form.status==2 ? '已完工检' : form.status==3 ? '已检验' : '已报工' }}</span>
          <!-- <span v-if="form.status==3" style="background-color: #BBBBBB;" class="status-log">已取消</span> -->
        </div>
        <el-form-item label="工单编号" prop="workorderCode" class="count-style" >
          {{ form.code }}
        </el-form-item>
        <el-form-item label="生产日期" prop="proTime" class="count-style" >
          {{ form.planDate }}
        </el-form-item>
        <el-form-item label="生产批次号" prop="batch" class="count-style" >
          {{ form.batch }}
        </el-form-item>
        <!-- <el-form-item label="计划人员" prop="planUser" class="count-style" >
          {{ form.planUser }}
        </el-form-item>
        <el-form-item label="计划日期" prop="planDate" class="count-style" >
          {{ form.pmodel.createTime }}
        </el-form-item> -->
        <el-form-item label="生产数量" prop="machine" class="count-style" >
          {{ form.planNum ? (form.planNum + (form.umodel.name ? form.umodel.name : '')) : '0'  }}
        </el-form-item>
        <!-- <el-form-item label="计划数量" prop="planNum" class="count-style" >
          {{ form.pmodel.num }}
        </el-form-item> -->
        <el-form-item label="工单来源" prop="origin" class="count-style">
          {{ originToStr(form.originId) }}
        </el-form-item>
        <!-- <el-form-item label="发布日期" prop="startDate" class="count-style" >
          {{ form.pmodel.publishDate }}
        </el-form-item> -->
        <el-form-item label="原工单号" prop="originWorkorderId" class="count-style" >
          {{ form.originWorkorderId }}
        </el-form-item>
        <el-form-item label="分配人员" prop="distributeUser" class="count-style" >
          {{ form.userName }}
        </el-form-item>
        <el-form-item label="分配时间" prop="distributeTime" class="count-style" >
          {{ form.createTime }}
        </el-form-item>
        <el-form-item label="生产人员" prop="proUser" class="count-style" >
  
          <div v-for="(item, index) in form.proUserList" :key="index">{{ item.proUserDepartName }}</div>
          <!-- {{ form.proUserName + (form.proUserDepartName ? ('/' + form.proUserDepartName) : '') }} -->
        </el-form-item>
        <el-form-item label="生产设备" prop="machine" class="count-style" >
          {{ form.pgmodel && `【${form.pgmodel.code}】${form.pgmodel.name}`}}
        </el-form-item>
        
        <el-form-item label="合格数量" prop="qualifiedNum" class="count-style" >
          {{ form.qualifiedNum ? (form.qualifiedNum + (form.umodel.name ? form.umodel.name : '')) : '0' }}
        </el-form-item>
        <el-form-item label="不良数量" prop="unqualifiedNum" class="count-style" >
          {{ form.unqualifiedNum ? (form.unqualifiedNum + (form.umodel.name ? form.umodel.name : '')) : '0' }}
        </el-form-item>
      </el-form>
      <!-- 表格和分页 -->
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="生产报工" name="first">
          <el-table
            v-loading="isSearch"
            :data="report"
            border
            show-summary
            :summary-method="getReportSummaries"
          >
          <!-- stripe -->
            <el-table-column prop="createTime" label="报工时间" min-width="140px"></el-table-column>
            <el-table-column label="生产人员" show-overflow-tooltip min-width="100px">
              <template slot-scope="{row}">
                <span class="long-title-style">{{ row.procedureName }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="machine" label="生产设备" min-width="100px">
              {{ form.pgmodel && `【${form.pgmodel.code}】${form.pgmodel.name}`}}
            </el-table-column>
            <!-- <el-table-column prop="amodel.code" label="工装容器编号" show-overflow-tooltip="" min-width="100px"></el-table-column> -->
            <el-table-column prop="mmodel.name" label="物料名称" show-overflow-tooltip min-width="100px"></el-table-column>
            <el-table-column prop="doneType" label="报工类型" min-width="60px">
              <template slot-scope="{row}">
                <span v-if="row.doneType==0" class="valid-style">合格</span>
                <span v-else-if="row.doneType==1" class="unvalid-style">不良</span>
                <span v-else-if="row.doneType==2" class="scrap-style">报废</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column prop="num" label="生产数量" show-overflow-tooltip min-width="100px">
              <template slot-scope="{row}">
                <span :class="row.doneType==0 ? 'valid-style' : (row.doneType==1 ? 'unvalid-style' :(row.doneType==2 ? 'scrap-style' : ''))">{{ row.num ? (row.num + (row.umodel.name ? row.umodel.name : '')) : '0' }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="生产检验" name="second">
          <el-table
            v-loading="isSearch"
            :data="verify"
            stripe
            border>
            <el-table-column prop="code" label="检验记录编号" min-width="140px"></el-table-column>
            <el-table-column prop="createTime" label="检验时间" min-width="140px"></el-table-column>
            <el-table-column prop="smodelRealName" label="检验人员" min-width="100px"></el-table-column>
            <el-table-column prop="num" label="生产数量" min-width="100px">
              <template slot-scope="{row}">
                <!-- {{ row.num + row.umodel.name }} -->
                {{ row.num ? (row.num + (row.umodel.name ? row.umodel.name : '')) : '0' }}
              </template>
            </el-table-column>
            <el-table-column prop="qualifiedNum" label="合格数量" min-width="100px">
              <template slot-scope="{row}">
                {{ row.qualifiedNum ? (row.qualifiedNum + (row.umodel.name ? row.umodel.name : '')) : '0' }}
              </template>
            </el-table-column>
            <el-table-column prop="unqualifiedNum" label="不良数量" min-width="100px">
              <template slot-scope="{row}">
                {{ row.unqualifiedNum ? (row.unqualifiedNum + (row.umodel.name ? row.umodel.name : '')) : '0' }}
              </template>
            </el-table-column>
            <el-table-column prop="verifyType" label="检验类型" min-width="100px">
              <template slot-scope="{row}">
                <!-- 0巡线、1巡检、2终检 -->
                {{ row.checkType == 0 ? '巡线' : row.checkType == 1 ? '巡检' : '完工检' }}
              </template>
            </el-table-column>
            <el-table-column prop="devmodel.code" label="生产设备" min-width="100px">
              <template slot-scope="{row}">
                {{ row.devmodel && `【${row.devmodel.code}】${row.devmodel.name}`}}
              </template>
            </el-table-column>
            <!-- <el-table-column prop="proUserids" label="生产人员" show-overflow-tooltip min-width="100px"></el-table-column> -->
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="生产投料" name="third">
          <el-table
            v-loading="isSearch"
            :data="feeds"
            stripe
            border
            show-summary
            :summary-method="getPutSummaries"
          >
            <el-table-column prop="createTime" label="投料时间" min-width="140px"></el-table-column>
            <!-- <el-table-column prop="amodel.code" label="工装容器编号" min-width="100px"></el-table-column> -->
            <el-table-column prop="mmodel.name" label="物料名称" min-width="100px"></el-table-column>
            <el-table-column prop="promodel.name" label="工序名称" min-width="100px"></el-table-column>
            <el-table-column label="质量属性" min-width="100px">
              <template slot-scope="{row}">
                <span v-if="row.materialDonetype==0" class="valid-style">合格</span>
                <span v-else-if="row.materialDonetype==1" class="unvalid-style">不良</span>
                <span v-else-if="row.materialDonetype==2" class="scrap-style">报废</span>
                <span v-else>-</span>
              </template>
            </el-table-column>
            <el-table-column prop="num" label="投入数量" min-width="100px">
              <template slot-scope="{row}">
                {{ row.num ? (row.num + (row.umodel.name ? row.umodel.name : '')) : '0' }}
              </template>
            </el-table-column>
            <el-table-column prop="proUserids" label="投料人员" min-width="100px">
              <template slot-scope="{row}">
                <span class="long-title-style">{{ row.procedureName }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
        <el-tab-pane label="生产点检" name="fourth">
          <el-table
            v-loading="isSearch"
            :data="check"
            stripe
            border
          >
            <el-table-column prop="createTime" label="记录时间" min-width="140px"></el-table-column>
            <el-table-column prop="userName" label="操作人员" min-width="100px"></el-table-column>
            <el-table-column prop="attrName" label="检点属性" min-width="100px"></el-table-column>
            <el-table-column prop="val" label="检点属性值" min-width="100px"></el-table-column>
          </el-table>
          <!-- <el-table
            :show-header="false"
            :data="check"
            :cell-style="columnStyle"
            style="width: 100%; margin-top: 20px"
          >
            <el-table-column prop="name" width="140px" align="right">
              <template slot-scope="{row}">
                {{ row.name + ':' }}
              </template>
            </el-table-column>
            <el-table-column prop="value" align="left"></el-table-column>
          </el-table> -->
        </el-tab-pane>
        <Pagination
          style="margin-top:10px"
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :pagination="pagination"
        ></Pagination>
      </el-tabs>
    </div>
    <div slot="footer" class="window__header">
      <el-button type="primary" @click="cancel">返回</el-button>
    </div>
  </GlobalWindow>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import GlobalWindow from '@/components/common/GlobalWindow'
import Pagination from '@/components/common/Pagination'
import { fetchList as workorderCheck } from '@/api/ext/workorderCheckExt'
import { workorderRecordExtPage, workorderCheckAttrExttPage } from '@/api/ext/workorderExt'
import { addPrecision } from '@/utils/util'
 
export default {
  name: 'OperaWorkorderDetailWindow',
  extends: BaseOpera,
  components: { GlobalWindow, Pagination },
  data () {
    return {
      // 表单数据
      form: {
        id: null,
        code: null,
        planNum: null,
        batch: null,
        createTime: null, // 分配日期
        planDate: null, // 生产日期
        procedureName: null, // 工序名称
        proUserName: null,
        originId: null,
        status: null,
        startDate: null,
        originWorkorderId: null,
        userName: null,
        distributeTime: null,
        pgmodel: {},
        mmodel: {},
        pmodel: {},
        umodel: {},
        proTime: null,
        num: null,
        qualifiedNum: null,
        unqualifiedNum: null,
        proUserList: []
      },
      // 验证规则
      rules: {
      },
      activeName: 'first',
      isSearch: false,
      pagination: {
        pageIndex: 1,
        pageSize: 10,
        total: 1
      },
      // origins: [],
      status: [
        // 0已分配、1已领料、2已完工检、3已检验、4已返工、5已入库、6已暂停、7已取消、8已关闭
        { name: '已分配', id: 0 },
        { name: '已领料', id: 1 },
        { name: '已完工检', id: 2 },
        { name: '已检验', id: 3 },
        { name: '已返工', id: 4 },
        { name: '已入库', id: 5 },
        { name: '已暂停', id: 6 },
        { name: '已取消', id: 7 },
        { name: '已关闭', id: 8 }
      ],
      report: [],
      verify: [],
      feeds: [],
      check: []
    }
  },
  inject: ['origins'],
  created () {
    this.config({
      api: '/ext/materialExt',
      'field.id': 'id'
    })
    // queryListByCode('?dicCode=WORKORDER_SOURCE')
    //   .then(res => {
    //     // console.log(res)
    //     this.origins = res
    //   })
    //   .catch(err => {
    //     console.log(err)
    //   })
  },
  methods: {
    open (title, target) {
      this.title = title
      this.visible = true
      this.activeName = 'first',
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        // console.log('this.form', this.form)
        workorderRecordExtPage(
          {
            capacity: this.pagination.pageSize,
            model: {
              type: 1,
              workorderId: this.form.id
            },
            page: this.pagination.pageIndex,
            sorts: null
          })
          .then(res => {
            // console.log(res)
            this.report = res.records
            this.pagination.pageIndex = res.page
            this.pagination.total = res.total
            this.pagination.pageSize = res.capacity
          })
          .catch(err => {
            console.log(err)
          })
      })
    },
    cancel () {
      this.$refs.form.resetFields()
      this.activeName = 'first'
      this.pagination.pageIndex = 1
      this.pagination.pageSize = 10
      this.pagination.total = 0
      this.visible = false
    },
    statusToStr (status) {
      for (const item of this.status) {
        if (item.id === status) {
          return item.name
        }
      }
    },
    originToStr (id) {
      for (const item of this.origins()) {
        if (item.id === id) {
          return item.code
        }
      }
    },
    columnStyle ({ row, column, rowIndex, columnIndex }) {
      if (rowIndex % 2 === 0) {
        // 修改每行第一个单元格的背景色
        return 'background:#f3f6fc;'
      } else {
        return 'background:#ffffff;'
      }
    },
    handleClick (tab, event) {
      this.pagination.pageIndex = 1
      this.pagination.pageSize = 10
      this.pagination.total = 0
      this.search()
    },
    handleSizeChange (pageSize) {
      this.pagination.pageSize = pageSize
      this.search()
    },
    handlePageChange (pageIndex) {
      this.pagination.pageIndex = pageIndex
      // console.log('获取数据')
      this.search()
    },
    search () {
      if (this.activeName === 'first') {
        workorderRecordExtPage(
          {
            capacity: this.pagination.pageSize,
            model: {
              type: 1,
              workorderId: this.form.id
            },
            page: this.pagination.pageIndex,
            sorts: [{direction: "DESC", property: "CREATE_TIME"}]
          })
          .then(res => {
            // console.log(res)
            this.report = res.records
            this.pagination.pageIndex = res.page
            this.pagination.total = res.total
            this.pagination.pageSize = res.capacity
          })
          .catch(err => {
            this.$tip.error(err)
          })
      } else if (this.activeName === 'second') {
        workorderCheck({
          capacity: this.pagination.pageSize,
          model: {
            workorderId: this.form.id
          },
          page: this.pagination.pageIndex,
          sorts: [{direction: "DESC", property: "CREATE_TIME"}]
        })
          .then(res => {
            // console.log(res.records)
            this.verify = res.records
            this.pagination.pageIndex = res.page
            this.pagination.total = res.total
            this.pagination.pageSize = res.capacity
          })
          .catch(err => {
            this.$tip.error(err)
          })
      } else if (this.activeName === 'third') {
        workorderRecordExtPage(
          {
            capacity: this.pagination.pageSize,
            model: {
              type: 0,
              workorderId: this.form.id
            },
            page: this.pagination.pageIndex,
            sorts: [{direction: "DESC", property: "CREATE_TIME"}]
          })
          .then(res => {
            // console.log(res)
            this.feeds = res.records
            this.pagination.pageIndex = res.page
            this.pagination.total = res.total
            this.pagination.pageSize = res.capacity
          })
          .catch(err => {
            this.$tip.error(err)
          })
      } else {
        workorderCheckAttrExttPage(
          {
            capacity: this.pagination.pageSize,
            model: {
              workorderId: this.form.id
            },
            page: this.pagination.pageIndex,
            sorts: [{direction: "DESC", property: "CREATE_TIME"}]
          })
          .then(res => {
            // console.log(res)
            this.check = res.records
            this.pagination.pageIndex = res.page
            this.pagination.total = res.total
            this.pagination.pageSize = res.capacity
          })
          .catch(err => {
            this.$tip.error(err)
          })
      }
    },
    getPutSummaries (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        } else if (index === 3) {
          sums[index] = '-';
          return;
        } else if (index === 5) {
          sums[index] = '-';
          return;
        } 
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = 0
          values.forEach(item => {
            sums[index] = addPrecision(item, sums[index])
          })
        } else {
          sums[index] = '-';
        }
      });
      return sums
    },
    getReportSummaries (param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        } else if (index === 4) {
          sums[index] = '-';
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = 0
          values.forEach(item => {
            sums[index] = addPrecision(item, sums[index])
          })
        } else {
          sums[index] = '-';
        }
      });
      return sums
    }
  }
}
</script>
 
<style lang="scss" scoped>
.count-style {
  display: inline-block;
  width: 23%;
  // height: 32px;
}
::v-deep .el-form-item {
  margin-bottom: 8px !important;
}
.text-code {
  color: #333;
  font-weight: 500;
  padding-right: 15px;
  font-size: 15px;
  vertical-align:middle;
}
.status-log {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  color:#fff;
  vertical-align:middle;
}
</style>