AdaKing88
2023-08-23 9cad48db6c56c3e2796a9d6da881817ef13b6eca
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
<template>
  <!-- <div class="header_nox">
    <el-button type="warning" circle @click="exportWord">下载</el-button>
    <el-button type="primary" circle v-show="!editable" @click="editable = !editable">编辑</el-button>
    <el-button type="primary" v-show=editable @click="saveData">确定</el-button>
  </div> -->
  <div id="printContent" ref="imageWrapper">
    <h3>502底盖生产情况报告</h3>
    <div class="title_form">
      <div class="title_form_input">
        <span>生产线:</span>
        <span>{{ headData.head.shengcx }}</span>
      </div>
      <div class="title_form_input">
        <span>产品:</span>
        <span>{{ headData.head.chanpin }}</span>
      </div>
      <div class="title_form_input">
        <span>日期:</span>
        <span>{{ headData.head.reportTime }}</span>
      </div>
      <div class="title_form_input">
        <span>班次:</span>
        <span>{{ headData.head.banci }}</span>
      </div>
      <div class="title_form_input">
        <span>记录员:</span>
        <span>{{ headData.head.jiluyuan }}</span>
      </div>
      <div class="title_form_input">
        <span>接班时间:</span>
        <span>{{ headData.head.jieban1 }}</span>
      </div>
      <div class="title_form_input">
        <span>交班时间:</span>
        <span>{{ headData.head.jiaoban1 }}</span>
      </div>
    </div>
    <el-divider />
 
    <HJTABLE
      :SClist="chanliangHeaderData"
      :tableHeader="chanliangHeader"
      :labelName="labelName.b8"
      :editable="editable"
    >
    </HJTABLE>
    <HJTABLE
      :SClist="sh14_yt_fpHeaderData"
      :tableHeader="sh14_yt_fpHeader"
      :labelName="labelName.b1"
      :editable="editable"
    >
    </HJTABLE>
    <HJTABLE
      :SClist="sh14_cc_fpHeaderData"
      :tableHeader="sh14_cc_fpHeader"
      :labelName="labelName.b2"
      :editable="editable"
    >
    </HJTABLE>
    <HJTABLE
      :SClist="sh14_zj_fpHeaderData"
      :tableHeader="sh14_zj_fpHeader"
      :labelName="labelName.b3"
      :editable="editable"
    >
    </HJTABLE>
    <HJTABLE
      :SClist="sh14_gjj_fpHeaderData"
      :tableHeader="sh14_gjj_fpHeader"
      :labelName="labelName.b4"
      :editable="editable"
    ></HJTABLE>
    <HJTABLE
      :SClist="sh14_jg_fpHeaderData"
      :tableHeader="sh14_jg_fpHeader"
      :labelName="labelName.b5"
      :editable="editable"
    >
    </HJTABLE>
    <HJTABLE
      :SClist="sh14_zjHeaderData"
      :tableHeader="sh14_zjHeader"
      :labelName="labelName.b6"
      :editable="editable"
    >
    </HJTABLE>
 
    <HJTABLE
      :SClist="feipinfpHeaderData"
      :tableHeader="feipinfpHeader"
      :labelName="labelName.b9"
      :editable="editable"
    >
    </HJTABLE>
  </div>
</template>
 
<script>
const item = {
  name: "",
  birth: "",
  province: "",
  city: "",
  address: "",
  phone: "",
};
const header = {
  prop: "key",
  label: "自定义",
  editable: false,
  type: "input",
};
import { ref, reactive, onMounted } from "vue";
import { ElMessage } from "element-plus";
import { chong14VoLast, chong14VoSave } from "@/api/gaixian";
import html2canvas from "html2canvas";
import docxtemplater from "docxtemplater";
import PizZip from "pizzip";
import JSZipUtils from "jszip-utils";
import { saveAs } from "file-saver";
import HJTABLE from "@/components/arj/arj-table";
import { useRouter } from "vue-router";
import { headReport } from "@/api/head";
export default {
  name: "",
  components: { HJTABLE },
  props: {},
  setup(props) {
    const router = useRouter();
    const feipinfpHeader = reactive([
      { prop: "total", label: "生产废品(总计)", editable: false, type: "text" },
      { prop: "chongyingNum", label: "重印", editable: false, type: "input" },
      { prop: "louyinNum", label: "漏印", editable: false, type: "input" },
      { prop: "zazhidianNum", label: "杂质点", editable: false, type: "input" },
      {
        prop: "waituzouweiNum",
        label: "外涂走位",
        editable: false,
        type: "input",
      },
      { prop: "louyinNum", label: "漏印", editable: false, type: "input" },
      { prop: "moranNum", label: "墨染", editable: false, type: "input" },
      { prop: "fanbianBl", label: "翻边不良", editable: false, type: "input" },
      { prop: "sechaNum", label: "色差", editable: false, type: "input" },
      { prop: "neiyinseNum", label: "内印色", editable: false, type: "input" },
      {
        prop: "neiwaitucashangNum",
        label: "内外涂擦伤",
        editable: false,
        type: "input",
      },
      {
        prop: "guangyouBzNum",
        label: "光油不准",
        editable: false,
        type: "input",
      },
      {
        prop: "sutiehexianNum",
        label: "素铁黑线",
        editable: false,
        type: "input",
      },
      {
        prop: "taoyinBzNum",
        label: "套印不准",
        editable: false,
        type: "input",
      },
      { prop: "hubanNum", label: "糊板", editable: false, type: "input" },
    ]);
    const chanliangHeader = reactive([
      { prop: "hjzs", label: "冲铁总数", editable: false, type: "text" },
      { prop: "chengpin", label: "成品", editable: false, type: "input" },
      { prop: "zhuancp", label: "转成品", editable: false, type: "input" },
      { prop: "daijp", label: "待检品", editable: false, type: "input" },
      { prop: "jiebqsy", label: "接班前剩余", editable: false, type: "input" },
      { prop: "jiaobhsy", label: "接班后剩余", editable: false, type: "input" },
      { prop: "yinfg", label: "印废盖", editable: false, type: "input" },
      { prop: "feipjbfp", label: "废品", editable: false, type: "input" },
      { prop: "hegcp", label: "合格成品", editable: false, type: "input" },
      { prop: "feipl", label: "废品率", editable: false, type: "input" },
      { prop: "caiytpc", label: "彩印铁批次", editable: false, type: "input" },
    ]);
    const sh14_cc_fpHeader = reactive([
      { prop: "cq", label: "冲缺", editable: "false", type: "text" },
      { prop: "kg", label: "卡盖", editable: "false", type: "text" },
      { prop: "yh", label: "压痕", editable: "false", type: "text" },
      { prop: "cj", label: "抽检", editable: "false", type: "text" },
      { prop: "bx", label: "变形", editable: "false", type: "text" },
      { prop: "gmwr", label: "盖面污染", editable: "false", type: "text" },
      { prop: "sg", label: "双盖", editable: "false", type: "text" },
      { prop: "jyzz", label: "卷缘皱褶", editable: "false", type: "text" },
      { prop: "ldpy", label: "蓝点偏移", editable: "false", type: "text" },
      { prop: "gmyh", label: "盖面压痕", editable: "false", type: "text" },
    ]);
    const sh14_gjj_fpHeader = reactive([
      { prop: "bx", label: "变形", editable: "false", type: "text" },
      { prop: "wj", label: "无胶", editable: "false", type: "text" },
      { prop: "dj", label: "盖面污染", editable: "false", type: "text" },
      { prop: "jj", label: "断胶", editable: "false", type: "text" },
      { prop: "hs", label: "溅胶", editable: "false", type: "text" },
      { prop: "cq", label: "划伤", editable: "false", type: "text" },
      { prop: "gmwr", label: "冲缺", editable: "false", type: "text" },
      { prop: "sg", label: "双盖", editable: "false", type: "text" },
      { prop: "jyzz", label: "卷缘皱褶", editable: "false", type: "text" },
      { prop: "ldpy", label: "蓝点偏移", editable: "false", type: "text" },
      { prop: "gmyh", label: "盖面压痕", editable: "false", type: "text" },
      { prop: "gmbd", label: "盖面白点", editable: "false", type: "text" },
    ]);
    const sh14_jg_fpHeader = reactive([
      { prop: "bx", label: "变形", editable: "false", type: "text" },
      { prop: "wj", label: "无胶", editable: "false", type: "text" },
      { prop: "dj", label: "盖面污染", editable: "false", type: "text" },
      { prop: "jj", label: "断胶", editable: "false", type: "text" },
      { prop: "hs", label: "溅胶", editable: "false", type: "text" },
      { prop: "cq", label: "划伤", editable: "false", type: "text" },
      { prop: "gmwr", label: "冲缺", editable: "false", type: "text" },
      { prop: "sg", label: "双盖", editable: "false", type: "text" },
      { prop: "jyzz", label: "卷缘皱褶", editable: "false", type: "text" },
      { prop: "ldpy", label: "蓝点偏移", editable: "false", type: "text" },
      { prop: "gmyh", label: "盖面压痕", editable: "false", type: "text" },
      { prop: "gmbd", label: "盖面白点", editable: "false", type: "text" },
    ]);
    const sh14_yt_fpHeader = reactive([
      { prop: "cy", label: "重影", editable: "false", type: "text" },
      { prop: "sc", label: "色差", editable: "false", type: "text" },
      { prop: "mr", label: "墨染", editable: "false", type: "text" },
      { prop: "ly", label: "漏印", editable: "false", type: "text" },
      { prop: "zzd", label: "杂质点", editable: "false", type: "text" },
      { prop: "nys", label: "内印色", editable: "false", type: "text" },
      { prop: "ldwy", label: "蓝点外移", editable: "false", type: "text" },
      { prop: "nwtcs", label: "内外涂擦伤", editable: "false", type: "text" },
      { prop: "lt", label: "漏涂", editable: "false", type: "text" },
    ]);
    const sh14_zjHeader = reactive([
      { prop: "jy", label: "检验", editable: "false", type: "text" },
      { prop: "sy", label: "试验", editable: "false", type: "text" },
      { prop: "hj", label: "", editable: "false", type: "text" },
    ]);
    const sh14_zj_fpHeader = reactive([
      { prop: "kg", label: "卡盖", editable: "false", type: "text" },
      { prop: "bx", label: "变形", editable: "false", type: "text" },
      { prop: "wj", label: "无胶", editable: "false", type: "text" },
      { prop: "gmwr", label: "盖面污染", editable: "false", type: "text" },
      { prop: "dj", label: "断胶", editable: "false", type: "text" },
      { prop: "jj", label: "溅胶", editable: "false", type: "text" },
      { prop: "hs", label: "划伤", editable: "false", type: "text" },
    ]);
 
    let tableData = reactive([]);
    const formInline = reactive({
      user: "",
      region: "",
    });
    const imageWrapper = ref(null);
 
    let headData = reactive({
      head: {},
    });
 
    let labelName = {
      b1: "印铁废品",
      b2: "冲床废品",
      b3: "注胶机废品",
      b4: "光验机废品",
      b5: "集盖废品",
      b6: "质检",
      b7: "印废盖",
      b8: "产量统计",
      b9: "印废盖",
    };
    let editable = ref(false);
 
    let SClist = ref([]);
    let hjData = ref({});
 
    let sh14_cc_fpHeaderData = ref([]);
    let sh14_gjj_fpHeaderData = ref([]);
    let sh14_jg_fpHeaderData = ref([]);
    let sh14_yt_fpHeaderData = ref([]);
    let sh14_zjHeaderData = ref([]);
    let sh14_zj_fpHeaderData = ref([]);
    let chanliangHeaderData = ref([]);
    let feipinfpHeaderData = ref([]);
 
    const submitForm = () => {};
 
    const handleEdit = (row) => {
      row.editable = true;
    };
    const handleDelete = (index) => {
      this.tableData.splice(index, 1);
    };
    const prepend = (index) => {
      item.editable = true;
      this.tableData.splice(index, 0, item);
    };
    const append = (index) => {
      item.editable = true;
      this.tableData.splice(index + 1, 0, item);
    };
    const deleteCurrentColumn = (index) => {
      this.tableHeader.splice(index, 1);
    };
    const insertBefore = (index) => {
      header.editable = true;
      this.tableHeader.splice(index, 0, header);
    };
    function checkValue(obj) {
      if (obj == null) return [{ total: 0 }];
      return [obj];
    }
    function checkTotal(obj) {
      if (obj == null) return null;
      return obj.total;
    }
    const getListData = async () => {
      const data = await chong14VoLast();
 
      console.log(".........g14", data);
      parse(data);
    };
 
    function parse(data) {
      headData.head = data.data.head;
      if (headData.head.reportTime != null)
        headData.head.reportTime = headData.head.reportTime.substr(0, 10);
      // headData.head.jieban1 = headData.head.jieban.substr(11, 5);
      // headData.head.jiaoban1 = headData.head.jiaoban.substr(11, 5);
 
      sh14_cc_fpHeaderData.value = [data.data.sh14CcFp];
 
      sh14_gjj_fpHeaderData.value = [data.data.sh14GjjFp];
      sh14_jg_fpHeaderData.value = [data.data.sh14JgFp];
      sh14_yt_fpHeaderData.value = [
        data.data.ytFp == null ? [] : data.data.ytFp,
      ];
 
      sh14_zjHeaderData.value = [data.data.sh14Zj];
      sh14_zj_fpHeaderData.value = [data.data.sh14ZjFp];
 
      chanliangHeaderData.value = [data.data.lineChanliangtongji];
      feipinfpHeaderData.value = [data.data.feipinGuan];
 
      let zhujiao = {
        zjkg: data.data.sh14ZjFp.kg,
        zjbx: data.data.sh14ZjFp.bx,
        zjwj: data.data.sh14ZjFp.wj,
        zjjj: data.data.sh14ZjFp.jj,
        zjdj: data.data.sh14ZjFp.dj,
        zjhs: data.data.sh14ZjFp.hj,
      };
 
      let gjj = {
        gjjsg: data.data.sh14GjjFp.sg,
        gjjdj: data.data.sh14GjjFp.dj,
        gjjcq: data.data.sh14GjjFp.cq,
        gjjjyzz: data.data.sh14GjjFp.gmzz,
        gjjgmwr: data.data.sh14GjjFp.gmwr,
        gjjldpy: data.data.sh14GjjFp.ldpy,
        gjjbx: data.data.sh14GjjFp.bx,
        gjjgmyh: data.data.sh14GjjFp.gmyh,
        gjjgmbd: data.data.sh14GjjFp.gmbd,
        gjjhs: data.data.sh14GjjFp.hs,
        gjjwj: data.data.sh14GjjFp.wj,
        gjjjj: data.data.sh14GjjFp.jj,
      };
 
      let jg = {
        jgsg: data.data.sh14JgFp.sg,
        jgdj: data.data.sh14JgFp.dj,
        jgcq: data.data.sh14JgFp.cq,
        jgjyzz: data.data.sh14JgFp.gmzz,
        jggmwr: data.data.sh14JgFp.gmwr,
        jgldpy: data.data.sh14JgFp.ldpy,
        jgbx: data.data.sh14JgFp.bx,
        jggmyh: data.data.sh14JgFp.gmyh,
        jggmbd: data.data.sh14JgFp.gmbd,
        jghs: data.data.sh14JgFp.hs,
        jgwj: data.data.sh14JgFp.wj,
        jgjj: data.data.sh14JgFp.jj,
      };
      let zj = {
        t1: checkTotal(data.data.feipinYintie),
        t2: checkTotal(data.data.sh14CcFp),
        t3: checkTotal(data.data.sh14ZjFp),
        t4: checkTotal(data.data.sh14GjjFp),
        t5: checkTotal(data.data.sh14JgFp),
 
        t6: checkTotal(data.data.feipinGuan),
      };
      hjData.value = {
        ...headData.head,
        ...data.data.ytFp,
        ...data.data.sh14CcFp,
        ...zhujiao,
        ...gjj,
        ...jg,
        ...data.data.sh14Zj,
        ...data.data.feipinGuan,
        ...zj,
      };
    }
    const saveData = async () => {
      editable = false;
      let data = {
        head: headData.head,
        sh14CcFp: sh14_cc_fpHeaderData.value[0],
        sh14GjjFp: sh14_gjj_fpHeaderData.value[0],
        sh14JgFp: sh14_jg_fpHeaderData.value[0],
        ytFp: sh14_yt_fpHeaderData.value[0],
        sh14Zj: sh14_zjHeaderData.value[0],
        sh14ZjFp: sh14_zj_fpHeaderData.value[0],
        lineChanliangtongji: chanliangHeaderData.value[0],
        feipinGuan: feipinfpHeaderData.value[0],
      };
      console.log("save data...", data);
      const dt = await chong14VoSave(data);
      if (dt.code == 0) {
        ElMessage({
          message: "修改成功",
          type: "success",
        });
      }
      console.log(dt);
    };
    //截图
    const toImage = () => {
      html2canvas(imageWrapper.value, {
        logging: false,
        allowTaint: true,
        scale: window.devicePixelRatio,
        // width: shareContent.clientWidth, //dom 原始宽度
        // height: shareContent.clientHeight,
        scrollY: 0,
        scrollX: 0,
        useCORS: true,
        backgroundColor: "#ffffff",
      }).then(function (canvas) {
        // console.log(canvas);
        let imgUrl = canvas.toDataURL("image/png");
        var tempLink = document.createElement("a"); // 创建一个a标签
        tempLink.style.display = "none";
        tempLink.href = imgUrl;
        tempLink.setAttribute("download", "502底盖生产情况报告"); // 给a标签添加下载属性
 
        if (typeof tempLink.download === "undefined") {
          tempLink.setAttribute("target", "_blank");
        }
        document.body.appendChild(tempLink); // 将a标签添加到body当中
        tempLink.click(); // 启动下载
        document.body.removeChild(tempLink); // 下载完毕删除a标签
        window.URL.revokeObjectURL(imgUrl);
      });
    };
    // 点击导出word
    function exportWord() {
      // 读取并获得模板文件的二进制内容
      JSZipUtils.getBinaryContent("g14.docx", function (error, content) {
        // input.docx是模板。我们在导出的时候,会根据此模板来导出对应的数据
        // 抛出异常
        if (error) {
          throw error;
        }
 
        // 创建一个JSZip实例,内容为模板的内容
        let zip = new PizZip(content);
        // 创建并加载docxtemplater实例对象
 
        let doc = new docxtemplater().loadZip(zip).setOptions({
          nullGetter: function () {
            return "";
          },
        });
        // 设置模板变量的值
        doc.setData({
          ...hjData.value,
        });
 
        try {
          // 用模板变量的值替换所有模板变量
          doc.render();
        } catch (error) {
          // 抛出异常
          let e = {
            message: error.message,
            name: error.name,
            stack: error.stack,
            properties: error.properties,
          };
          console.log(JSON.stringify({ error: e }));
          throw error;
        }
 
        // 生成一个代表docxtemplater对象的zip文件(不是一个真实的文件,而是在内存中的表示)
        let out = doc.getZip().generate({
          type: "blob",
          mimeType:
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
        });
        // 将目标文件对象保存为目标类型的文件,并命名
        saveAs(out, "502底盖生产情况报告.docx");
      });
    }
    const getRouterData = async (req) => {
      console.log("req....", req);
      const data = await headReport(req);
      console.log("jbj router data.....", data);
 
      parse(data);
    };
    onMounted(() => {
      console.log("rrrrrrrrrrr", router.currentRoute.value.query);
      let head_id = router.currentRoute.value.query.id;
      let leixing = router.currentRoute.value.query.leixing;
      console.log("vue recv....", head_id, leixing);
      if (head_id == null) {
        getListData();
      } else {
        getRouterData({ head_id: head_id, leixing: leixing });
      }
    });
    return {
      saveData,
      submitForm,
      formInline,
      tableData,
      insertBefore,
      deleteCurrentColumn,
      append,
      prepend,
      handleDelete,
      handleEdit,
      editable,
      getListData,
      headData,
      toImage,
      imageWrapper,
      labelName,
      exportWord,
      sh14_cc_fpHeaderData,
      sh14_gjj_fpHeaderData,
      sh14_jg_fpHeaderData,
      sh14_yt_fpHeaderData,
      sh14_zjHeaderData,
      sh14_zj_fpHeaderData,
      sh14_cc_fpHeader,
      sh14_gjj_fpHeader,
      sh14_jg_fpHeader,
      sh14_yt_fpHeader,
      sh14_zjHeader,
      sh14_zj_fpHeader,
      chanliangHeaderData,
      chanliangHeader,
      feipinfpHeaderData,
      feipinfpHeader,
      chong14VoLast,
      chong14VoSave,
    };
  },
};
</script>
<style lang="scss" scoped>
.header_nox {
  text-align: right;
}
 
#printContent h3 {
  text-align: center;
  margin-bottom: 40px;
  font-size: 26px;
  font-weight: bold;
}
 
.title_form {
  display: flex;
  justify-content: space-around;
  align-items: center;
  // margin-bottom: 20px;
}
 
.title_form_input {
  font-size: 16px;
}
</style>