zouyu
2023-11-17 d8ac6057eaad648687699e25a575f3b7b8c1b102
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
<template>
  <div class="main">
    <div class="out row1 flex">
      <div class="l">
        <div class="scan flex">
          <div class="l">
            <div class="flex" style="padding-bottom: 15px;">
              <div class="label">
                <!-- 二维码扫码区 -->
                扫码区:
              </div>
              <div style="flex:1">
                <el-input
                  placeholder="MES二维码\条形码"
                  @input="codeChange"
                  type="textarea"
                  v-model.trim="setting.code"
                  rows="3"
                />
              </div>
            </div>
            <!-- <div class="flex">
              <div class="label">
                条码扫码区
              </div>
              <div style="flex:1">
                <el-input @input="codeChange" v-model="setting.code2" />
              </div>
            </div> -->
          </div>
          <div class="r">
            <div class="t">标签打印模块当前参数状态</div>
            <div class="content">
              当前打印模式:新增后{{ setting.auto ? '' : '不' }}自动打印
              <br />
              当前数据新增模式:
              {{ setting.cache ? '本地缓存后批量提交' : '不缓存' }}
              <br />
              当前打印标签:{{ currentLabel.labelDesc || '待选择' }}
            </div>
          </div>
        </div>
        <div class="fun flex">
          <el-button @click="goRePrint" type="primary" size="mini">
            打印
          </el-button>
          <el-checkbox v-model="setting.auto">新增后自动打印</el-checkbox>
          <el-checkbox v-model="setting.cache">开启本地缓存模式</el-checkbox>
          <div class="flex">
            <span style="padding:0 10px 0 30px;">标签</span>
            <el-select
              v-model="setting.labelUniqueCode"
              @change="labelChange"
              filterable
              :disabled="cacheList.length > 0"
            >
              <el-option
                v-for="item in labelList"
                :key="item.labelUniqueCode"
                :label="item.labelDesc"
                :value="item.labelUniqueCode"
              />
            </el-select>
          </div>
        </div>
      </div>
      <div class="r">
        <div class="t">
          本地缓存列表
        </div>
        <div class="cacheListWrap">
          <div class="scrollWrap">
            <div v-if="cacheList.length === 0" class="empty">无缓存</div>
            <div v-for="(x, i) in cacheList" :key="i" class="list flex">
              <div>{{ i + 1 }}</div>
              <div>{{ x.sn }}</div>
              <div class="del" @click="cacheDel(i)">删除</div>
            </div>
          </div>
          <div class="btnsWrap flex">
            <el-button
              :disabled="cacheList.length === 0"
              @click="goSubmit"
              type="primary"
              size="mini"
            >
              提交
            </el-button>
            <el-button @click="clearCache" size="mini">清空</el-button>
          </div>
        </div>
      </div>
    </div>
    <div class="out row2 flex">
      <div class="l">
        <ttable
          :table="table"
          @handleSelectionChange="handleSelectionChange"
          @ttRowClick="ttRowClick"
          :options="options"
          :ajaxFun="ajaxFun"
          ref="labelprintprinttable"
        >
          <template #toolbar></template>
        </ttable>
      </div>
      <div class="r">
        <div class="t">标签信息预览</div>
        <PreviewBox :rowInfo="rowInfo" />
      </div>
    </div>
    <secretFormDialog
      ref="SecretForm"
      :currshowlist.sync="showSecretForm"
      @goOnListPrint="goOnListPrint"
    />
  </div>
</template>
 
<script>
import ttable from '@/views/common/ztt-table.vue'
import { fetchList, printLabel, putObj, reprint } from '@/api/print/print'
import { fetchList as getLabelList } from '@/api/print/config'
import { remote } from '@/api/admin/dict'
import secretFormDialog from './secret-form.vue'
import PreviewBox from '../PreviewBox'
import { judgeLabelMark } from '@/api/warehouse/check'
import { goPrintUtil } from './print'
export default {
  components: {
    ttable,
    secretFormDialog,
    PreviewBox
  },
  data() {
    const tt = (prop, label, config) => {
      const w = (label.length - 1) * 20 + 15
      return Object.assign(
        {
          minWidth: w,
          // width: w < 140 ? 140 : w,
          prop,
          label,
          sort: true,
          isTrue: true,
          isSearch: true,
          searchInfoType: 'text'
        },
        config
      )
    }
    return {
      setting: {
        // 230411000018N
        code: null,
        code2: null,
        auto: true,
        cache: true,
        labelUniqueCode: null
      },
      currentLabel: {},
      labelList: [],
      cacheList: [],
      ajaxFun: fetchList,
      options: {
        height: 300, // 默认高度-为了表头固定
        stripe: true, // 是否为斑马纹 table
        highlightCurrentRow: false, // 是否要高亮当前行
        border: true, // 是否有纵向边框
        lazy: false, // 是否需要懒加载
        fit: true, // 列的宽度是否自撑开
        multiSelect: true, //
        seqNo: true,
        isRefresh: true,
        isShowHide: true, // 是否显示显影按钮
        isSearch: false, // 高级查询按钮
        defaultOrderBy: { column: 'id', direction: 'desc' }
      },
      table: {
        total: 0,
        currentPage: 1,
        pageSize: 20,
        data: [],
        // 标题
        column: [
          tt('labelTypeDesc', '标签类别描述', {
            searchInfoType: 'select',
            formatter: (row, column, cellValue) => {
              const theOne = this.labelTypeOptions.find(
                (e) => e.value === cellValue
              )
              return theOne ? theOne.label : ''
            },
            optList: () => {
              return this.labelTypeOptions
            }
          }),
          tt('labelDesc', '标签描述'),
          tt('partBatchNo', 'SN号'),
          tt('ifsBatchNo', 'IFS批次号'),
          tt('wdr', 'wdr'),
          tt('labelSize', '标签尺寸'),
          tt('printCount', '打印次数'),
          tt('createUser', '创建人'),
          tt('createTime', '创建时间'),
          tt('updateUser', '更新人'),
          tt('updateTime', '更新时间')
        ],
        operator: [
          {
            text: '删除',
            type: 'text',
            size: 'small',
            fun: this.deleteHandle
          }
        ],
        operatorConfig: {
          fixed: 'right',
          label: '操作',
          width: 80,
          minWidth: 80
        }
      },
      multipleSelection: [],
      rowInfo: {},
      timer: null,
      showSecretForm: false,
      labelTypeOptions: []
    }
  },
  created() {
    getLabelList({
      current: 1,
      size: 999
    }).then((res) => {
      this.labelList = res.data.data.records
    })
    remote('label_type').then((response) => {
      if (response.data.code === 0) {
        this.labelTypeOptions = response.data.data
      }
    })
  },
  methods: {
    labelChange() {
      this.currentLabel = this.labelList.find(
        (e) => e.labelUniqueCode === this.setting.labelUniqueCode
      )
    },
    codeChange() {
      if (this.timer) {
        clearTimeout(this.timer)
      }
      if (!this.setting.code) {
        return
      }
      this.timer = setTimeout(() => {
        if (!this.setting.labelUniqueCode) {
          this.$message.warning('请先选择标签')
          this.setting.code = ''
          return
        }
        this.setting.code = this.setting.code.replace(
          /(^[\r\n\s]*)|([\r\n\s]*$)/g,
          ''
        )
        let c
        if (this.setting.code.indexOf('{') < 0) {
          c = {
            sn_no: this.setting.code
          }
        } else {
          c = JSON.parse(this.setting.code)
        }
        // {
        //   "part_no": "88.118.1/A0467594",
        //   "lot_batch_no": "230313000229S",
        //   "qty_arrived": 0.16,
        //   "wdr": "检8",
        //   "material_code": "",
        //   "sn_no": "230313000229S"
        // }
        const data = {
          partNo: c.part_no,
          ifsBatchNo: c.lot_batch_no,
          qty: c.qty_arrived,
          wdr: c.wdr,
          sn: c.sn_no
        }
        if (this.setting.cache) {
          // 开启本地缓存
          this.cacheList.push(data)
        } else {
          this.goPrint([data])
        }
        this.setting.code = ''
      }, 500)
    },
    goSubmit() {
      this.goPrint(this.cacheList)
    },
    // 扫码打印
    goPrint(data) {
      printLabel({
        isPrint: this.setting.auto,
        labelUniqueCode: this.setting.labelUniqueCode,
        snList: data.map((e) => e.sn)
      }).then((res) => {
        this.clearCache()
        if (this.setting.auto) {
          this.goOnListPrint(res.data.data)
        } else {
          this.getData()
        }
      })
    },
    // 补打印
    goRePrint() {
      if (this.multipleSelection.length) {
        const theFirstOne = this.multipleSelection[0]
        if (
          this.multipleSelection.every((e) => {
            return e.labelUniqueCode === theFirstOne.labelUniqueCode
          })
        ) {
          const idList = this.multipleSelection.map((e) => e.id)
          reprint({ idList }).then((res) => {
            if (res.data.data) {
              this.goOnListPrint()
            } else {
              // 需要输入密码
              this.showSecretForm = true
              this.$refs.SecretForm.init(idList)
            }
          })
        } else {
          this.$message.warning('请选择同一种标签描述')
        }
      } else {
        this.$message.warning('请选择打印标签')
      }
    },
    // 去打印
    goOnListPrint(
      data = this.multipleSelection.map((e) => {
        return {
          labelDesc: e.labelDesc,
          sn: e.partBatchNo,
          // ifsBatchNo: e.ifsBatchNo,
          qualityLabelPrintConfigDetail: JSON.parse(e.labelInfo)
            .qualityLabelPrintConfigDetail
        }
      })
    ) {
      this.getData()
      judgeLabelMark(data.map((e) => e.sn)).then((resp) => {
        data.forEach((e) => {
          e.markFlag = resp.data.data.includes(e.sn)
          // e.qualityLabelPrintConfigDetail.push({
          //   caption: 'IFS批次号',
          //   defaultValue: e.ifsBatchNo
          // })
          goPrintUtil(e)
        })
      })
    },
    cacheDel(i) {
      this.cacheList.splice(i, 1)
    },
    clearCache() {
      this.cacheList = []
    },
    // 下半部分
    getData() {
      this.$refs.labelprintprinttable.getDataList()
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    ttRowClick(val) {
      this.rowInfo = val
    },
    // 删除
    deleteHandle(row) {
      this.$confirm('是否确认删除SN号为:' + row.partBatchNo, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      })
        .then(function() {
          return putObj(
            Object.assign(row, {
              active: false
            })
          )
        })
        .then((data) => {
          this.$message.success('删除成功')
          this.getData()
        })
    }
  }
}
</script>
 
<style lang="scss" scoped>
.main {
  padding: 20px;
  font-size: 14px;
  background: white;
}
.flex {
  display: flex;
}
.out {
  > .l {
    width: calc(100% - 335px);
  }
  > .r {
    width: 320px;
    margin-left: 15px;
  }
}
.row1 {
  padding-left: 50px;
  > .l {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding-bottom: 20px;
  }
  .scan {
    align-items: flex-end;
    padding: 20px 0 20px 0px;
    > .l {
      width: 320px;
      padding-right: 40px;
      > .flex {
        align-items: center;
      }
      .label {
        white-space: nowrap;
        padding-right: 10px;
      }
    }
    > .r {
      flex: 1;
      .content {
        color: red;
        line-height: 25px;
        font-size: 16px;
        padding-top: 10px;
        min-width: 100px;
      }
    }
  }
  .fun {
    align-items: center;
    padding-left: 6.5em;
    .el-button {
      margin-right: 30px;
    }
    .el-checkbox {
      margin-right: 20px;
      color: black;
    }
    > .flex {
      align-items: center;
    }
  }
  > .r {
    position: relative;
    .t {
      position: absolute;
      left: -100px;
    }
    .cacheListWrap {
      border: 1px solid #ccc;
      border-radius: 6px;
      padding: 0 10px;
      height: 265px;
      .scrollWrap {
        height: calc(100% - 55px);
        overflow: auto;
        margin: 10px 0;
        .empty {
          line-height: 30px;
          text-align: center;
          color: #999;
        }
        .list {
          justify-content: space-between;
          padding: 4px 10px 4px 4px;
          &:hover {
            background: #eee;
          }
          .del {
            color: rgb(255, 100, 100);
            &:hover {
              cursor: pointer;
              color: rgb(255, 0, 0);
            }
          }
        }
      }
      .btnsWrap {
        justify-content: space-around;
        padding: 0 30px;
      }
    }
  }
}
.row2 {
  > .r {
    .t {
      padding: 40px 0 20px;
      text-align: center;
    }
  }
}
</style>