schangxiang@126.com
2024-08-16 65bd2dc1d4c1fb136af853c7ede93a338431be29
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
<template>
  <div>
    <x-card :bordered="false" v-if="hasPerm('WorkPieceProcess:page')">
      <div slot="content" class="table-page-search-wrapper">
        <a-form :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-row :gutter="gutter">
            <a-col :md="colMd" :sm="colSm">
              <a-form-item label="查询维度">
                <a-select
                  @change="changeModel"
                  style="width: 100%"
                  v-model="queryParam.selectModel"
                  placeholder="请选择查询维度"
                >
                  <a-select-option v-for="(item, index) in modelEnums" :key="index" :value="item.code">
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="colMd" :sm="colSm">
              <a-form-item label="工件号">
                <a-input v-model="queryParam.workPieceID" allow-clear placeholder="请输入工件号" />
              </a-form-item>
            </a-col>
             <a-col :md="colMd" :sm="colSm">
              <a-form-item label="成品码">
                <a-input v-model="queryParam.oP80NewCode" allow-clear placeholder="请输入成品码" />
              </a-form-item>
            </a-col>
            <a-col :md="colMd" :sm="colSm">
              <a-form-item label="工序">
                <a-select
                  allow-clear
                  style="width: 100%"
                  v-model="queryParam.WorkingProcedureCurrent"
                  placeholder="请选择工序"
                >
                  <a-select-option v-for="(item, index) in ProcessSelectData" :key="index" :value="item.code">
                    {{ item.name }}
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="colMd2" :sm="colSm2">
                <a-form-item :label="queryParam.selectModel == 1?'初始上线时间':'上线时间'">
                  <a-range-picker  style="width:100%" :show-time="{format:'HH:mm'}" v-model="queryParam.dates" format="YYYY-MM-DD HH:mm" />
                </a-form-item>
              </a-col>
            <template v-if="advanced">
              <a-col :md="colMd" :sm="colSm">
                <a-form-item label="工件状态" v-if="queryParam.selectModel == 1">
                  <a-select
                    allow-clear
                    style="width: 100%"
                    v-model="queryParam.WorkPieceState"
                    placeholder="请选择工件状态"
                  >
                    <a-select-option v-for="(item, index) in WorkPieceSelectData" :key="index" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
 
              <a-col :md="colMd" :sm="colSm">
                <a-form-item label="质量状态">
                  <a-select
                    allow-clear
                    style="width: 100%"
                    v-model="queryParam.qualityState"
                    placeholder="请选择质量状态"
                  >
                    <a-select-option v-for="(item, index) in QualityState" :key="index" :value="item.code">
                      {{ item.name }}
                    </a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
 
              <a-col :md="colMd" :sm="colSm">
                <a-form-item label="操作类型" v-if="queryParam.selectModel == 2">
                  <a-input v-model="queryParam.operationType" allow-clear placeholder="请输入操作类型" />
                </a-form-item>
 
                <a-form-item label="设备名称" v-if="queryParam.selectModel == 1">
                  <a-select
                    show-search
                    option-filter-prop="children"
                    :filter-option="filterOption"
                    :allowClear="true"
                    style="width: 100%"
                    v-model="queryParam.equipmentName"
                    placeholder="请选择设备名称"
                  >
                    <a-select-option v-for="item in equitypeData" :key="item.id" :value="item.equipmentName">{{
                      item.equipmentName
                    }}</a-select-option>
                  </a-select>
                </a-form-item>
              </a-col>
 
             
            </template>
            <a-col :md="colMd" :sm="colSm">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="getData(1)">查询</a-button>
                <a-button style="margin-left: 8px" @click="resetQueryData">重置</a-button>
                <a @click="advanced = !advanced" style="margin-left: 8px">
                  {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'" />
                </a>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </x-card>
 
    <a-card :bordered="false">
      <div style="margin-bottom:10px">
        <a-button type="info" icon="download" @click="exportExcel">导出Excel</a-button>
      </div>
 
      <a-spin :spinning="confirmLoading">
        <a-table
          :rowClassName="getRowBackGround"
          :columns="columns"
          :data-source="data"
          :pagination="pages"
          :rowKey="(record) => record.id"
        >
          <span slot="workPieceinitOnlineTime" slot-scope="text">
            <span v-if="text">{{ moment(moment(text)).format('YYYY-MM-DD HH:mm:ss') }}</span>
            <span v-else>{{ text }}</span>
          </span>
          <span slot="workPieceLastOfflineTime" slot-scope="text">
            <span v-if="text">{{ moment(moment(text)).format('YYYY-MM-DD HH:mm:ss') }}</span>
            <span v-else>{{ text }}</span>
          </span>
          <span slot="qualityDeatil" slot-scope="item, record">
            <a :disabled="record.disabled" @click="$refs.qualityDetail.show(record)">质量详情</a>
          </span>
        </a-table>
      </a-spin>
    </a-card>
 
    <qualityDetail ref="qualityDetail" />
  </div>
</template>
<script>
// 工件加工追溯
import { STable, XCard } from '@/components'
import { downloadFile,getThisWeekRange } from '@/utils/util'
import moment from 'moment'
import {
  workPieceInfoMachiningPage,
  workPieceProcessMachiningPage,
  WorkPieceInfoToExcel,
  workPieceProcessToExcel
} from '@/api/modular/main/WorkPieceInfoManage'
// 获取设备下拉框数据
import { getEquipmentName } from '@/api/modular/main/EquipmentBaseInfoManage'
import qualityDetail from './modules/qualityDetail.vue'
export default {
  components: {
    STable,
    XCard,
    qualityDetail
  },
  data() {
    return {
      gutter: 36,
      colMd: 6,
      colSm: 18,
      colMd2: 10,
      colSm2: 24,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 17 }
      },
      advanced: false, // 高级搜索 展开/关闭
      confirmLoading: false,
      currentSelModel:1,//当前选择的维护
      queryParam: { 
        selectModel: 1,
        dates:[]
      },
      pages: {
        current: 1,
        pageSize: 10,
        total: 0,
        showSizeChanger: true,
        showTotal: (total, range) => `${range[0]}-${range[1]}共${total}条`,
        pageSizeOptions: ['10', '20', '30', '40'],
        onChange: this.getData,
        onShowSizeChange: this.pageSizeChange
      },
      columns: [
        {
          title: '序号',
          dataIndex: 'index',
          key: 'index',
          align: 'center',
          customRender: (text, record, index) => `${index + 1}`
        },
        {
          title: '工件号',
          align: 'center',
          sorter: true,
          dataIndex: 'workPieceID'
        },
        {
          title: '当前工序',
          align: 'center',
          sorter: true,
          dataIndex: 'workingProcedureCurrent'
        },
        {
          title: '质量状态',
          align: 'center',
          sorter: true,
          dataIndex: 'qualityStateName'
        },
        {
          title: '成品码',
          align: 'center',
          sorter: true,
          dataIndex: 'oP80NewCode'
        },
        {
          title: '质量详情',
          align: 'center',
          sorter: true,
          scopedSlots: { customRender: 'qualityDeatil' }
        }
      ],
      columns1: [
        {
          title: '工件状态',
          align: 'center',
          sorter: true,
          dataIndex: 'workPieceStateName'
        },
        {
          title: '设备名称',
          align: 'center',
          sorter: true,
          dataIndex: 'equipmentName'
          // scopedSlots: {customRender: 'equipmentName'}
        },
        {
          title: '初始上线时间',
          align: 'center',
          sorter: true,
          dataIndex: 'workPieceinitOnlineTime',
          scopedSlots: {
            customRender: 'workPieceinitOnlineTime'
          }
        },
        {
          title: '最终下线时间',
          align: 'center',
          sorter: true,
          dataIndex: 'workPieceLastOfflineTime',
          scopedSlots: {
            customRender: 'workPieceLastOfflineTime'
          }
        },
        {
          title: '加工时长',
          align: 'center',
          sorter: true,
          dataIndex: 'workPieceCurr'
        }
      ],
      columns2: [
        {
          title: '操作类型',
          align: 'center',
          sorter: true,
          dataIndex: 'operationTypeHand'
        },
        {
          title: '设备名称',
          align: 'center',
          sorter: true,
          dataIndex: 'equipmentName'
        },
        {
          title: '上线时间',
          align: 'center',
          sorter: true,
          dataIndex: 'startTime'
        },
        {
          title: '下线时间',
          align: 'center',
          sorter: true,
          dataIndex: 'endTime'
        },
        {
          title: '加工时长',
          align: 'center',
          sorter: true,
          dataIndex: 'timeSceonds'
        },
        {
          title: '数据来源',
          align: 'center',
          sorter: true,
          dataIndex: 'createUserName'
        }
      ],
      data: [],
      tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
      // 加载数据方法 必须为 Promise 对象
      // 设备下拉框数据
      equitypeData: [],
      // 工序下拉框数据
      WorkPieceSelectData: [],
      selectedRowKeys: [],
      selectedRows: [],
      QualityState: []
    }
  },
  watch: {
    'queryParam.selectModel': {
      handler(val, oldVal) {
        var old_dates=this.queryParam.dates;
        this.queryParam = { selectModel: val,dates:[] }
        this.queryParam.dates = old_dates;
        this.currentSelModel=val;
        if (val == 1) {
          if (oldVal) {
            this.columns.splice(3, this.columns2.length)
          }
          this.columns.splice(3, 0, ...this.columns1)
        } else if (val == 2) {
          this.columns.splice(3, this.columns1.length)
          this.columns.splice(3, 0, ...this.columns2)
        }
      },
      immediate: true
    }
  },
  created() {
    this.getEquipmentName()
    this.ProcessSelectData = this.$options.filters['dictData']('process_type')
    this.WorkPieceSelectData = this.$options.filters['dictData']('workpiece_state')
 
    this.modelEnums = [
      { name: '工件', code: 1 },
      { name: '工件+工序', code: 2 }
    ]
    this.QualityState = this.$options.filters['dictData']('quality_state')
    this.initData();
    this.getData()
  },
  methods: {
    initData(){
      this.queryParam.dates = [];
      this.queryParam.dates = getThisWeekRange();
    },
    //重置
    resetQueryData(){
      this.queryParam = { selectModel: this.currentSelModel,dates:[] }
      this.initData();
    },
    setDisabled() {
      this.data.forEach((item) => {
        if (item.operationTypeHand == 'SPC') {
          item.disabled =
            item.workingProcedureCurrent == 'OP05' ||
            item.workingProcedureCurrent == 'OP70' ||
            item.workingProcedureCurrent == 'OP80'
        } else {
          item.disabled = item.workingProcedureCurrent == 'OP05' || item.workingProcedureCurrent == 'OP50'
          || item.workingProcedureCurrent == 'OP70'
        }
      })
    },
    moment,
    // 查询列表数据
    async getData(pageNo) {
      if (pageNo) this.pages.current = pageNo
      const { current, pageSize } = this.pages
      this.queryParam.pageNo = current
      this.queryParam.pageSize = pageSize
      this.confirmLoading = true
      try {
        if (this.queryParam.selectModel == 1) {
          const { data } = await workPieceInfoMachiningPage(this.switchingDate())
          this.data = data.rows
          this.pages.total = data.totalRows
        } else {
          const { data } = await workPieceProcessMachiningPage(this.switchingDate())
          this.data = data.rows
          this.pages.total = data.totalRows
        }
      } catch (error) {
        console.log(error)
      }
      this.confirmLoading = false
 
      this.setDisabled()
    },
    getRowBackGround(record) {
      if (this.queryParam.selectModel == 1) {
        switch (
          record.cololType // 这里根据条件改变表格背景色
        ) {
          case 1:
            return 'table-color-yellow'
          case 2:
            return 'table-color-green'
          case 3:
            return 'table-color-red'
          case 4:
            return 'table-color-blue'
          case 5:
            return 'table-color-gray'
        }
      }
    },
    // 导出
    exportExcel() {
      if (this.queryParam.selectModel == 1) {
        WorkPieceInfoToExcel(this.queryParam)
        .then((res) => {
          downloadFile(res)
        })
        .catch((err) => {
          console.info(err)
          this.$message.error('下载错误:获取文件流错误' + err)
        })
      } else {
        workPieceProcessToExcel(this.queryParam)
        .then((res) => {
          downloadFile(res)
        })
        .catch((err) => {
          console.info(err)
          this.$message.error('下载错误:获取文件流错误' + err)
        })
      }
    },
    /**
     * 查询参数组装
     */
    switchingDate() {
      const dates = this.queryParam.dates
      if (dates != null) {
        this.queryParam.startTimeBeginTime = moment(dates[0]).format('YYYY-MM-DD HH:mm')
        this.queryParam.startTimeEndTime = moment(dates[1]).format('YYYY-MM-DD HH:mm')
        if (dates.length < 1) {
          delete this.queryParam.startTimeBeginTime
          delete this.queryParam.startTimeEndTime
        }
      }
      const obj = JSON.parse(JSON.stringify(this.queryParam))
      return obj
    },
    getEquipmentName() {
      getEquipmentName().then((res) => {
        this.equitypeData = res.data
      })
    },
    onSelectChange(rows) {
      console.log(rows)
    },
    // 设备查询框筛选
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    // pageSize 变化的回调
    pageSizeChange(current, size) {
      this.pages.pageSize = size
      this.getData(1)
    },
    changeModel() {
      this.data = []
    }
  }
}
</script>
<style lang="less">
.table-operator {
  margin-bottom: 18px;
}
button {
  margin-right: 8px;
}
 
.table-color-yellow{
  background-color: rgb(202, 202, 86);
}
 
.table-color-green{
  background-color: rgb(147, 228, 147);
}
 
.table-color-red{
  background-color: rgb(236, 157, 157);
}
 
.table-color-blue{
  background-color: rgb(156, 156, 231);
}
 
.table-color-gray{
  background-color: rgb(181, 172, 172);
}
</style>