ZengTao
2025-03-28 f68d3c71819feb59e7a227a5d992b059b900916c
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
<template>
  <div style="margin-left: 10%;margin-top: 10px;">
    <el-input :placeholder="$t('processCard.projectnumber')" v-model="engineerId" autocomplete="off" style="width: 300px;"/>
    <el-button type="primary" style="margin-left: 10px;" @click="selectReportData()">{{ $t('processCard.inquire') }}</el-button>
    <el-button type="info" @click="printTable">{{ $t('processCard.printing') }}</el-button>
    <!-- 表格 -->
    <el-table
      :data="tableData"
      style="width: 100%; height: 700px;margin-top: 10px;"
      ref="tableRef"
      border
    >
      <el-table-column
        prop="flowCardId"
        :label="$t('processCard.flowcard')"
        width="140"
        align="center"
      />
      <el-table-column
        prop="layer"
        :label="$t('processCard.layer')"
        align="center"
        width="80"
      />
      <el-table-column
        prop="engineerId"
        :label="$t('processCard.project')"
        align="center"
        width="110"
      />
      <el-table-column
        prop="temperingLayoutId"
        :label="$t('processCard.temperinglayout')"
        align="center"
        width="80"
      />
      <el-table-column
        prop="temperingFeedSequence"
        :label="$t('processCard.temperingfeed')"
        align="center"
        width="80"
      />
      <el-table-column
        prop="width"
        :label="$t('processCard.width')"
        align="center"
        width="80"
      />
      <el-table-column
        prop="height"
        :label="$t('processCard.height')"
        align="center"
        width="80"
      />
      <el-table-column
        prop="thickness"
        :label="$t('processCard.thickness')"
        align="center"
        width="52"
      />
    </el-table>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import request from "@/utils/request"
import { ElMessage } from 'element-plus';
const {t} = useI18n()
const engineerId = ref('')
// 声明响应式数据
const tableData = ref<any[]>([]);
const tableRef = ref<InstanceType<typeof import('element-plus').ElTable> | null>(null);
  const selectReportData = async () => {
  let postData = {  
    type: 9,  
    workingProcedure: '钢化',  
    ...(engineerId.value !== '' && { engineerId: engineerId.value }),  
  };  
  const response = await request.post("/loadGlass/damage/selectDamagePrint", postData)
  if (response.code === 200) {
    tableData.value = response.data;
    ElMessage.success(response.message);
  } else {
    ElMessage.error(response.message);
  }
};
const fetchData = async () => {
  try {let postData = {  
    type: 9,  
    workingProcedure: '钢化',  
    ...(engineerId.value !== '' && { engineerId: engineerId.value }),  
  };  
    const response = await request.post('/loadGlass/damage/selectDamagePrint',postData)
    tableData.value = response.data;
  } catch (error) {
    ElMessage.error('获取数据失败');
    console.error(error);
  }
};
// 打印表格内容
const printTable = () => {
  if (!tableRef.value) {
    ElMessage.warning('表格未加载完成,请稍后再试');
    return;
  }
  // 创建一个打印窗口
  const printWindow = window.open('', '_blank');
  if (!printWindow) {
    ElMessage.error('无法打开打印窗口');
    return;
  }
  // 写入表格HTML到打印窗口
  printWindow.document.write(`
    <html>
      <head>
        <title>玻璃拿走清单</title>
        <style>
          /* 根据需要添加样式 */
          table {
            width: 100%;
            border-collapse: collapse;
          }
          th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: center;
          }
          th {
            background-color: #f2f2f2;
          }
        </style>
      </head>
      <body>
        <table>
          <thead>
            <tr>
            <th>流程卡</th>
            <th>层号</th>
            <th>工程号</th>
            <th>炉号</th>
            <th>片序</th>
            <th>宽</th>
            <th>高</th>
            <th>厚</th>
            </tr>
          </thead>
          <tbody>
            ${tableData.value.map(item => `
              <tr>
                <td>${item.flowCardId}</td>
                <td>${item.layer}</td>
                <td>${item.engineerId}</td>
                <td>${item.temperingLayoutId}</td>
                <td>${item.temperingFeedSequence}</td>
                <td>${item.width}</td>
                <td>${item.height}</td>
                <td>${item.thickness}</td>
              </tr>
            `).join('')}
          </tbody>
        </table>
      </body>
    </html>
  `);
  // 关闭文档流并打印
  printWindow.document.close();
  printWindow.focus(); // 确保新窗口获得焦点
  printWindow.print();
  printWindow.close(); // 打印完成后关闭窗口(可选)
};
// 在组件挂载后获取数据
onMounted(() => {
  fetchData();
});
</script>
<style scoped>
/* 样式可以根据需求调整 */
</style>