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
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
<template>
  <div class="assembly viewWrap">
    <a ref="download" style="display: none" />
    <ProductList ref="productList"></ProductList>
    <h2>组装任务计划管理</h2>
    <!-- 搜索功能区 -->
    <div class="wrap">
      <div class="searchWrap">
        <div class="searchItem">
          <span class="searchTitle">产品</span>
          <el-select v-model="proId" ref="productList1" @focus="onShowProductList1" placeholder="请选择" style="width:220px;" clearable>
            <el-option v-for="(item, index) in selectData" :key="index" :label="`${item.name} / ${item.type}`" :value="item.id">
            </el-option>
          </el-select>
        </div>
        <div class="searchItem">
          <span class="searchTitle">开始日期</span>
          <el-date-picker v-model="startDate" value-format="yyyy-MM-dd" type="date" style="width:220px;"
            placeholder="选择日期">
          </el-date-picker>
        </div>
        <div class="searchItem">
          <span class="searchTitle">结束日期</span>
          <el-date-picker v-model="endDate" value-format="yyyy-MM-dd" type="date" style="width:220px;"
            placeholder="选择日期">
          </el-date-picker>
        </div>
        <div class="searchButton">
          <el-button type="primary" @click="onGetSearchData">查询</el-button>
          <el-button @click="onClearSearchData">清空</el-button>
        </div>
      </div>
    </div>
 
    <!-- 数据功能按钮区 -->
    <el-button type="primary" icon="el-icon-plus" style="width: 100px; margin-top: 20px;"
      @click="handleFormDataAdd">添加</el-button>
 
    <!-- 数据表格区 -->
    <el-table stripe :data="tableData" height="0" style="margin-top: 20px;">
      <el-table-column type="index" label="序号" fixed> </el-table-column>
      <el-table-column prop="name" label="名称" fixed> </el-table-column>
      <el-table-column prop="proName" label="产品"> </el-table-column>
      <el-table-column prop="proType" label="型号"> </el-table-column>
      <el-table-column prop="batchNo" label="产品批次" width="100">
      </el-table-column>
      <el-table-column prop="processName" label="生产流程"> </el-table-column>
      <el-table-column prop="number" label="生产数量" width="100">
      </el-table-column>
      <!-- <el-table-column prop="creatorName" label="创建人" width="100"></el-table-column> -->
      <el-table-column prop="status" label="状态" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 1" type="success">
            <i class="iconfont icon-kaishi" style="font-size: 12px;"></i>
            执行中
          </el-tag>
          <el-tag v-if="scope.row.status == 0" type="warning">
            <i class="iconfont icon-zanting" style="font-size: 12px;"></i>
            暂停
          </el-tag>
          <el-tag v-if="scope.row.status == -1" type="danger">
            <i class="iconfont icon-jieshu" style="font-size: 12px;"></i>
            结束
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="dt" label="创建时间" width="170">
      </el-table-column>
      <el-table-column prop="startDate" label="开始日期" width="110">
      </el-table-column>
      <el-table-column prop="endDate" label="结束日期" width="110">
      </el-table-column>
      <el-table-column prop="content" label="作业内容"> </el-table-column>
      <el-table-column label="操作" width="280" fixed="right">
        <template slot-scope="scope">
          <el-button icon="el-icon-edit" @click.native.prevent="handleFormDataEdit(scope.row)" type="text" size="small">
            编辑
          </el-button>
          <el-button v-if="scope.row.status != 0" @click.native.prevent="handleStatus(scope.row, 0, '暂停')" type="text"
            size="small">
            <i class="iconfont icon-zanting" style="font-size: 12px;"></i>
            暂停
          </el-button>
          <el-button v-if="scope.row.status != 1" @click.native.prevent="handleStatus(scope.row, 1, '执行')" type="text"
            size="small">
            <i class="iconfont icon-kaishi" style="font-size: 12px;"></i>
            执行
          </el-button>
          <el-button v-if="scope.row.status != -1" @click.native.prevent="handleStatus(scope.row, -1, '结束')" type="text"
            size="small">
            <i class="iconfont icon-jieshu" style="font-size: 12px;"></i>
            结束
          </el-button>
          <el-button type="text" size="small" @click.native.prevent="onShowCodeList(scope.row)">
            <i class="iconfont icon-erweima" style="font-size: 12px;"></i>
            设备码清单
          </el-button>
        </template>
      </el-table-column>
    </el-table>
 
    <!-- 分页组件 -->
    <el-pagination style="margin-top: 20px;" @size-change="onGetTableData" @current-change="onGetTableData"
      :current-page.sync="pageCurr" :page-size.sync="pageSize" :page-sizes="[10, 20, 50, 100]"
      layout="total, sizes, prev, pager, next, jumper" :total="total">
    </el-pagination>
 
    <!-- 表单 -->
    <el-dialog :title="dialogTitle" :visible.sync="showFromData" width="600px" :before-close="handleFormDataClose">
      <el-form :model="formData" :rules="formRules" ref="formData" label-width="140px">
        <el-form-item label="ID" prop="id" style="display: none;">
          <el-input style="width:320px" v-model="formData.id" disabled></el-input>
        </el-form-item>
        <el-form-item label="名称" prop="name">
          <el-input style="width:320px" v-model="formData.name" clearable></el-input>
        </el-form-item>
        <el-form-item label="订单" prop="orderId">
          <el-select v-model="formData.orderId" placeholder="请选择" style="width:320px;" clearable
            @change="handleOrderIdChange">
            <el-option v-for="(item, index) in orderData" :key="index" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="产品" prop="proId">
          <el-select v-model="formData.proId" placeholder="请选择" style="width:320px;" clearable
            @change="handleProIdChange">
            <el-option v-for="(item, index) in selectData" :key="index" :label="`${item.name} / ${item.type}`" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生产流程" prop="processId">
          <el-select v-model="formData.processId" placeholder="请选择" style="width:320px;" clearable>
            <el-option v-for="(item, index) in processData" :key="index" :label="item.name" :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生产数量" prop="number">
          <el-input-number style="width:320px" v-model="formData.number" clearable></el-input-number>
        </el-form-item>
        <el-form-item label="作业内容" prop="content">
          <el-input style="width:320px" v-model="formData.content" clearable></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select v-model="formData.status" placeholder="请选择" style="width:320px;" clearable>
            <el-option label="执行中" :value="1"></el-option>
            <el-option label="暂停" :value="0"></el-option>
            <el-option label="停止" :value="-1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="开始日期" prop="status">
          <el-date-picker v-model="formData.startDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width:320px;">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" prop="endDate">
          <el-date-picker v-model="formData.endDate" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width:320px;">
          </el-date-picker>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleFormDataClose">取 消</el-button>
        <el-button type="primary" @click="handleFormDataSubmit">确 定</el-button>
      </span>
    </el-dialog>
 
    <!-- 设备码清单 -->
    <el-dialog title="设备码清单" :visible.sync="showCodeList" width="1000px">
      <!-- 数据功能按钮区 -->
      <el-button type="primary" icon="el-icon-plus"  @click="handleCodeAdd">补增</el-button>
      <el-button type="primary" icon="el-icon-download"  @click="handleExport">导出二维码</el-button>
      <el-button type="primary" icon="el-icon-download"  @click="handleExportNo">导出设备号</el-button>
 
      <el-table stripe :data="codeList" style="margin-top: 20px; overflow: auto;">
        <el-table-column type="index" label="序号"> </el-table-column>
        <el-table-column prop="deviceNo" label="设备号"> </el-table-column>
        <el-table-column label="二维码" width="120">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.native.prevent="handleShowCode(scope.row)">
              <i class="iconfont icon-erweima" style="font-size: 12px;"></i>
              查看二维码
            </el-button>
          </template>
        </el-table-column>
      </el-table>
 
      <!-- 分页组件 -->
      <el-pagination style="margin-top: 20px;" @size-change="onGetCodeListData" @current-change="onGetCodeListData"
        :current-page.sync="codeListPageCurr" :page-size.sync="codeListPageSize" :page-sizes="[10, 20, 50, 100]"
        layout="total, sizes, prev, pager, next, jumper" :total="codeListTotal">
      </el-pagination>
      <!-- 二维码 -->
      <div class="codeWrap" v-show="showCode" @click="handleCloseCode">
        <transition name="el-zoom-in-center">
          <img v-show="showCode" :src="imgBase64" />
        </transition>
        <div class="codeMessage">点击屏幕关闭二维码</div>
      </div>
    </el-dialog>
  </div>
</template>
 
<style lang="less" scoped>
.assembly {
  padding: 20px;
}
</style>
 
<script>
import ProductList from '@/components/ProductList'
 
export default {
  name: "assembly",
  components: { ProductList },
  data() {
    return {
      proId: null,
      startDate: null,
      endDate: null,
      pageSize: 10,
      pageCurr: 1,
      total: 0,
      tableData: [],
      showFromData: false,
      formData: {
        id: null,
        name: null,
        orderId: null,
        proId: null,
        processId: null,
        number: null,
        content: null,
        startDate: null,
        endDate: null,
        status: null,
      },
      formRules: {
        name: [{ required: true, message: "必填项", trigger: "blur" }],
        proId: [{ required: true, message: "必填项", trigger: "blur" }],
        processId: [{ required: true, message: "必填项", trigger: "blur" }],
        number: [{ required: true, message: "必填项", trigger: "blur" }],
        content: [{ required: true, message: "必填项", trigger: "blur" }],
        startDate: [{ required: true, message: "必填项", trigger: "blur" }],
        endDate: [{ required: true, message: "必填项", trigger: "blur" }],
        status: [{ required: true, message: "必填项", trigger: "blur" }],
      },
      orderData: [],
      selectData: [],
      processData: [],
      dialogTitle: null,
 
      showCodeList: false,
      batchId: null,
      planId: null,
      codeList: [],
      codeListPageSize: 10,
      codeListPageCurr: 1,
      codeListTotal: 0,
      addNum: null,
      showCode: false,
      imgBase64: null,
    };
  },
  computed: {},
  watch: {
    // "formData.orderId": function(newVal, oldVal) {
    //   // if (newVal) {
    //   //   this.onGetSelectData();
    //   // } else {
    //   // }
    //   this.formData.proId = null;
    //   this.selectData = [];
    //   this.onGetSelectData();
    // },
    // "formData.proId": function(newVal, oldVal) {
    //   if (newVal) {
    //     this.onGetProcessData();
    //   } else {
    //     this.formData.processId = null;
    //     this.processData = [];
    //   }
    // },
  },
  mounted() {
    this.onGetTableData();
    this.onGetOrderData();
    this.onGetSelectData();
    this.onGetProcessData();
  },
  methods: {
    // 执行条件查询
    onGetSearchData: function () {
      this.pageCurr = 1;
      this.onGetTableData();
    },
    // 清空查询条件
    onClearSearchData: function () {
      this.proId = null;
      this.startDate = null;
      this.endDate = null;
      this.pageCurr = 1;
      this.onGetTableData();
    },
    // 获取表格数据
    onGetTableData: function () {
      var that = this;
      var data = {
        proId: this.proId,
        startDate: this.startDate,
        endDate: this.endDate,
        pageSize: this.pageSize,
        pageCurr: this.pageCurr,
      };
      that
        .$axiosAdmin({
          method: "post",
          url: "production/assembly/some",
          data: JSON.stringify(data),
        })
        .then((res) => {
          if (res.success == true) {
            that.tableData = res.content.obj;
            that.total = res.content.itemTotal;
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 添加
    handleFormDataAdd: function () {
      this.formData.id = null;
      this.formData.name = null;
      this.formData.orderId = null;
      this.formData.proId = null;
      this.formData.processId = null;
      this.formData.number = null;
      this.formData.content = null;
      this.formData.startDate = null;
      this.formData.endDate = null;
      this.formData.status = null;
      this.showFromData = true;
      this.dialogTitle = "添加组装任务计划";
    },
    // 关闭
    handleFormDataClose: function () {
      this.formData.id = null;
      this.formData.name = null;
      this.formData.orderId = null;
      this.formData.proId = null;
      this.formData.processId = null;
      this.formData.number = null;
      this.formData.content = null;
      this.formData.startDate = null;
      this.formData.endDate = null;
      this.formData.status = null;
      this.showFromData = false;
      this.dialogTitle = null;
      this.selectData = [];
      this.processData = [];
      this.$refs["formData"].resetFields();
    },
    // 编辑
    handleFormDataEdit: function (row) {
      this.formData.id = row.id;
      this.formData.name = row.name;
      this.formData.orderId = row.orderId;
      this.formData.proId = row.proId;
      this.formData.processId = row.processId;
      this.formData.number = row.number;
      this.formData.content = row.content;
      this.formData.startDate = row.startDate;
      this.formData.endDate = row.endDate;
      this.formData.status = row.status;
      this.showFromData = true;
      this.dialogTitle = "编辑组装任务计划";
      this.onGetProcessData();
    },
    handleOrderIdChange: function () {
      this.formData.proId = null;
      this.formData.processId = null;
      this.onGetSelectData();
    },
    handleProIdChange: function () {
      this.formData.processId = null;
      this.onGetProcessData();
    },
    // 提交数据确认
    handleFormDataSubmit: function () {
      this.$confirm(`此操作将保存并更新数据, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.onFormDataSubmit();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 提交数据
    onFormDataSubmit: function () {
      var that = this;
      var url, data;
      if (this.formData.id) {
        url = "production/assembly/update";
        data = {
          id: this.formData.id,
          name: this.formData.name,
          orderId: this.formData.orderId,
          proId: this.formData.proId,
          processId: this.formData.processId,
          number: this.formData.number,
          content: this.formData.content,
          startDate: this.formData.startDate,
          endDate: this.formData.endDate,
          status: this.formData.status,
        };
      } else {
        url = "production/assembly/save";
        data = {
          name: this.formData.name,
          orderId: this.formData.orderId,
          proId: this.formData.proId,
          processId: this.formData.processId,
          number: this.formData.number,
          content: this.formData.content,
          startDate: this.formData.startDate,
          endDate: this.formData.endDate,
          status: this.formData.status,
        };
      }
      that
        .$axiosAdmin({
          method: "post",
          url: url,
          data: JSON.stringify(data),
        })
        .then((res) => {
          if (res.success == true) {
            that.$message({
              type: "success",
              message: "已成功",
            });
            that.handleFormDataClose();
            that.onGetTableData();
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 状态变更确认
    handleStatus(row, status, msg) {
      this.$confirm(`此操作将 ${msg} 该任务, 是否继续?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.onStatus(row, status);
        })
        .catch(() => {
          this.onGetTableData();
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 执行状态变更
    onStatus: function (row, status) {
      var that = this;
      var data = {
        id: row.id,
        status: status,
      };
      that
        .$axiosAdmin({
          method: "post",
          url: "production/assembly/updateStatus",
          data: JSON.stringify(data),
        })
        .then((res) => {
          if (res.success == true) {
            that.$message({
              type: "success",
              message: "已成功",
            });
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
          that.onGetTableData();
        })
        .catch((err) => {
          console.log(err);
          that.onGetTableData();
        });
    },
    // 获取产品数据
    onGetOrderData: function () {
      var that = this;
      that
        .$axiosAdmin({
          method: "get",
          url: "production/order/all",
        })
        .then((res) => {
          if (res.success == true) {
            this.orderData = res.content;
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取产品数据
    onGetSelectData: function () {
      if (!this.formData.orderId) {
        this.formData.orderId = ""
      }
      var that = this;
      that
        .$axiosAdmin({
          method: "get",
          url: "platform/product/getProduct?orderId=" + this.formData.orderId,
        })
        .then((res) => {
          if (res.success == true) {
            this.selectData = res.content;
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 获取流程数据
    onGetProcessData: function () {
      var that = this;
      var data = {
        proId: this.formData.proId,
      };
      that
        .$axiosAdmin({
          method: "get",
          url: "production/process/queryAll",
          params: data,
        })
        .then((res) => {
          if (res.success == true) {
            that.processData = res.content;
            var unmatched = true;
            that.processData.forEach((item) => {
              if (that.formData.processId == item.id) {
                unmatched = false;
              }
            });
            if (unmatched) {
              that.formData.processId = null;
            }
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 查看设备码清单
    onShowCodeList: function (row) {
      this.batchId = row.batchId;
      this.planId = row.id;
      this.codeList = [];
      this.codeListPageSize = 10;
      this.codeListPageCurr = 1;
      this.codeListTotal = 0;
      this.addNum = null;
      this.showCodeList = true;
      this.onGetCodeListData();
    },
    // 关闭设备码清单
    onCloseCodeList: function () {
      this.batchId = null;
      this.planId = null;
      this.codeList = [];
      this.codeListPageSize = 10;
      this.codeListPageCurr = 1;
      this.codeListTotal = 0;
      this.addNum = null;
      this.showCodeList = false;
    },
    // 获取设备码清单数据
    onGetCodeListData: function () {
      if (!this.batchId) return;
      var that = this;
      var data = {
        batchId: this.batchId,
        pageSize: this.codeListPageSize,
        pageCurr: this.codeListPageCurr,
      };
      that
        .$axiosAdmin({
          method: "post",
          url: "production/assembly/someDevice",
          data: JSON.stringify(data),
        })
        .then((res) => {
          if (res.success == true) {
            that.codeList = res.content.obj;
            that.codeListTotal = res.content.itemTotal;
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 查看二维码
    handleShowCode: function (row) {
      this.imgBase64 = row.qrCode;
      this.showCode = true;
    },
    // 关闭二维码
    handleCloseCode: function () {
      this.imgBase64 = null;
      this.showCode = false;
    },
    // 导出二维码
    handleExport: function () {
      var that = this;
      var data = {
        batchId: this.batchId,
      };
      that
        .$axiosAdmin({
          method: "get",
          responseType: "blob",
          url: "production/assembly/exportDevice",
          params: data,
        })
        .then((res) => {
          const blob = res;
          that.$refs.download.href = window.URL.createObjectURL(
            new Blob([blob], {
              type:
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            })
          );
          that.$refs.download.download = `二维码清单.xlsx`;
          that.$refs.download.click();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 导出设备号
    handleExportNo: function () {
      var that = this;
      var data = {
        batchId: this.batchId,
      };
      that
        .$axiosAdmin({
          method: "get",
          responseType: "blob",
          url: "production/assembly/exportDeviceNo",
          params: data,
        })
        .then((res) => {
          const blob = res;
          that.$refs.download.href = window.URL.createObjectURL(
            new Blob([blob], {
              type:
                "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            })
          );
          that.$refs.download.download = `设备号清单.xlsx`;
          that.$refs.download.click();
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 补增设备码
    handleCodeAdd: function () {
      this.$prompt("请输入数量", "补增设备码", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /^[0-9]*$/,
        inputErrorMessage: "数量格式不正确",
      })
        .then(({ value }) => {
          this.$confirm(
            `此操作将在该任务中补增 ${value} 个设备码, 是否继续?`,
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }
          )
            .then(() => {
              this.onCodeAdd(value);
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消",
              });
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消",
          });
        });
    },
    // 执行补增设备码
    onCodeAdd: function (value) {
      if (!this.planId) return;
      if (!value) return;
      var that = this;
      var data = {
        planId: this.planId,
        addNum: value,
      };
      that
        .$axiosAdmin({
          method: "post",
          url: "production/assembly/addDevice",
          data: JSON.stringify(data),
        })
        .then((res) => {
          if (res.success == true) {
            that.$message({
              type: "success",
              message: "已成功",
            });
            that.onGetCodeListData();
            that.onGetTableData();
          } else {
            that.$alert(res.content, "提示", {
              confirmButtonText: "确定",
            });
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    onShowProductList1: function () {
      this.$refs.productList1.blur()
      this.$refs.productList.show((res) => {
        if (!res) return;
        this.proId = res.id
      })
    },
    onShowProductList2: function () {
      this.$refs.productList2.blur()
      this.$refs.productList.show((res) => {
        if (!res) return;
        this.formData.proId = res.id
      })
    },
  },
};
</script>