chenlu
2024-05-30 b663f3c695edaf65b854054ef644903a08f7a494
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
<script setup>
import request from "@/utils/request"
import {ElDatePicker, ElMessage} from "element-plus"
import {nextTick, onMounted, onUnmounted, reactive, ref, watch} from "vue"
import {Search} from "@element-plus/icons-vue"
import {useRouter} from 'vue-router'
import {changeFilterEvent, filterChanged} from "@/hook"
import {useI18n} from 'vue-i18n'
import deepClone from "@/utils/deepClone";
//语言获取
const {t} = useI18n()
let router = useRouter()
let produceList = ref([])
let labelList = ref([])
let list = ref()
 
 
const data = ref({
  printList: []
})
 
const {currentRoute} = useRouter()
const route = currentRoute.value
data.value.printList = JSON.parse(route.query.printList)
onMounted(() => {
 
      request.post(`/processCard/getSelectPrintLabel`, data.value).then((res) => {
        if (res.code == 200) {
 
          produceList.value = deepClone(res.data.data)
          for (let i = 0; i < produceList.value.length; i++) {
           let count= produceList.value[i].quantity
            for (let j = 0; j < count; j++) {
              labelList.value.push(produceList.value[i])
 
            }
          }
          console.log(labelList.value)
        } else {
          ElMessage.warning(res.msg)
          router.push("/login")
        }
      })
 
    }
 
)
 
 
 
// 打印方法
  const printFlowCard = () => {
    // 需要打印的局部区域赋予"print-wrap"的id
    let el = document.getElementById("printFlowCard");
    let doc = document;
    let body = doc.body || doc.getElementsByTagName("body")[0];
    let printId = "print-" + Date.now();
 
    // 创建无副作用的打印容器(因不确定页面的打印元素有无其它样式)
    let content = doc.createElement("div");
    content.id = printId;
 
    // 样式控制与打印无关的元素隐藏
    let style = doc.createElement("style");
    style.innerHTML =
        "body>#" +
        printId +
        "{display:none}@media print{body>:not(#" +
        printId +
        "){display:none !important}body>#" +
        printId +
        "{display:block;padding-top:1px}}";
    //
    content.innerHTML = el.outerHTML;
    // // console.log("el.outerHTML", el.outerHTML);
    body.appendChild(style);
 
    // 与style元素设置的样式相配合
    // 把打印内容的元素添加到body(作为body的子元素,可用body的子选择器 '>' 控制打印样式)
    body.appendChild(content);
    setTimeout(() => {
      window.print();
      body.removeChild(content);
      body.removeChild(style);
    }, 20);
  }
</script>
 
<template>
  <el-button id="printButton" @click="printFlowCard();">打印</el-button>
  <div id="printFlowCard" >
    <div id="entirety" v-for="(item,id) in labelList" style="border: 1px solid black">
      <div class="row1">{{ item.customer_name }}</div>
      <div class="row2">{{ item.order_id }} {{ item.type_name }} {{ item.remarks }}</div>
      <div class="row5">{{item.project}} {{item.child_width}}*{{item.child_height}}={{item.quantity}}</div>
      <div class="row6">{{item.glass_child}}</div>
    </div>
  </div>
 
</template>
 
<style scoped>
* {
  margin: 0;
  padding: 0;
}
 
#printButton {
  margin-top: -20px;
  width: 100px;
}
 
#printFlowCard {
  margin-left: 20px;
  display: flex;
  justify-content: left;
  flex-wrap: wrap;
 
//font-weight: bolder; height: 600px;
}
 
#entirety{
  text-align: center;
  width: 190px;
  height: 90px;
  margin-bottom: 10px;
}
 
.row1 {
  font-size: 9pt;
  font-weight: bold;
}
 
.row2 {
  font-size: 9pt;
  font-weight: bold;
}
 
.row3 {
 
  font-size: 9pt;
  font-weight: bolder;
  display: flex;
  justify-content: space-between;
}
 
.remarks{
  margin-right: 40px;
}
.type{
  margin-left: 40px;
}
 
.row4 {
  font-weight: bold;
  font-size: 9pt;
}
.row5 {
  margin-left: 5px;
  font-weight: bold;
  font-size: 9pt;
}
 
.row6 {
  font-weight: bold;
  font-size: 9pt;
}
 
 
 
@page {
  size: auto;  /* auto is the initial value */
  margin: 5mm 2mm 0mm 0mm  /* this affects the margin in the printer settings */
 
}
 
@media print {
  div {
    display: table-footer-group;
    page-break-inside: avoid;
    text-align: center;
  }
 
 
}
 
</style>