Houjie
2 天以前 30590221cd34912a61f4734ea474859a0df98be6
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
<template>
  <view class="container">
    <!-- 操作栏:打印/返回 -->
    <view class="header no-print">
      <view @click="handlePrint" class="print-btn">
        <image src="/static/icon_print.png" class="print-icon" alt="打印" />
        <text class="print-text">打印标签</text>
      </view>
      <view @click="navigateBack" class="back-btn">返回</view>
    </view>
 
    <!-- 检验标识卡主体(带绿色边框 + 完整表格) -->
    <view v-if="tagData" class="tag-card">
      <!-- 卡头:标题 + 日期 -->
      <view class="card-header">
        <text class="card-title">检验标识卡</text>
        <text class="card-date">{{ tagData.date }}</text>
      </view>
 
      <!-- 内容表格(带边框) -->
      <view class="card-table">
        <view class="table-row">
          <view class="table-cell label">物料</view>
          <view class="table-cell value">{{ tagData.material }}</view>
          <view class="table-cell label">批次</view>
          <view class="table-cell value">{{ tagData.batch }}</view>
        </view>
        <view class="table-row">
          <view class="table-cell label">型号</view>
          <view class="table-cell value">{{ tagData.model }}</view>
          <view class="table-cell label">数量</view>
          <view class="table-cell value">{{ tagData.quantity }}</view>
        </view>
        <view class="table-row">
          <view class="table-cell label">日期</view>
          <view class="table-cell value">{{ tagData.inspectDate }}</view>
          <view class="table-cell label">检验</view>
          <view class="table-cell value">{{ tagData.inspector }}</view>
        </view>
      </view>
 
      <!-- 底部二维码区域(精准对齐) -->
      <view class="qr-area">
        <uv-qrcode 
          :value="qrContent" 
          :size="80"  
          style="width: 80rpx; height: 80rpx;"
        ></uv-qrcode>
      </view>
    </view>
 
    <!-- 空状态 -->
    <view v-else class="empty-state">
      <text>未获取到检验标识卡数据</text>
    </view>
  </view>
</template>
 
<script>
import uvQrcode from '@/uni_modules/uv-qrcode/components/uv-qrcode/uv-qrcode.vue';
import io from '@hyoga/uni-socket.io';
import { PrinterCommands } from '@/common/util/printer-commands.js';
 
export default {
  components: { uvQrcode },
  data() {
    return {
      tagData: {
        material: '120034535',
        batch: '25098814',
        model: 'G3-2B259',
        quantity: 216,
        inspectDate: '20250408',
        inspector: '王義/合格',
        date: '2025.08.22'
      },
      printerConfig: null,
      qrContent: ''
    };
  },
  onLoad() {
    // 生成二维码内容(拼接关键信息)
    this.qrContent = `M:${this.tagData.material};B:${this.tagData.batch};M:${this.tagData.model}`;
    this.printerConfig = uni.getStorageSync('printerConfig') || null;
  },
  methods: {
    navigateBack() {
      uni.navigateBack();
    },
    async handlePrint() {
      // 打印逻辑与之前一致(省略重复代码,保持原逻辑)
      if (!this.tagData) {
        uni.showToast({ title: '标签数据为空', icon: 'none' });
        return;
      }
      // ... 原打印逻辑代码 ...
    },
    sendPrintCommand(command) {
      // ... 原打印指令代码 ...
    }
  }
};
</script>
 
<style scoped>
/* 容器基础样式 */
.container {
  background-color: #fff;
  padding: 20rpx;
  min-height: 100vh;
}
 
/* 操作栏 */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10rpx 0;
  border-bottom: 1px solid #eee;
}
.print-btn {
  display: flex;
  align-items: center;
}
.print-icon {
  width: 32rpx;
  height: 32rpx;
  margin-right: 8rpx;
}
.print-text {
  font-size: 28rpx;
  color: #007AFF;
}
.back-btn {
  font-size: 28rpx;
  color: #007AFF;
}
 
/* 检验标识卡主体(核心样式) */
.tag-card {
  width: 600rpx; 
  margin: 30rpx auto;
  border: 4rpx solid #28a745; /* 绿色边框 */
  border-radius: 12rpx;
  padding: 20rpx;
  box-shadow: 0 4rpx 12rpx rgba(0,0,0,0.1);
}
 
/* 卡头样式 */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10rpx;
  padding-bottom: 10rpx;
  border-bottom: 2px solid #333; /* 标题分割线 */
}
.card-title {
  font-size: 36rpx;
  font-weight: bold;
  color: #333;
}
.card-date {
  font-size: 28rpx;
  color: #666;
}
 
/* 表格核心样式(带边框) */
.card-table {
  width: 100%;
  border-collapse: collapse; /* 合并边框 */
  margin-bottom: 20rpx;
}
.table-row {
  display: flex;
  border: 1px solid #999; /* 表格行边框 */
}
.table-cell {
  flex: 1;
  padding: 12rpx 8rpx;
  font-size: 26rpx;
  color: #333;
  border-right: 1px solid #999; /* 单元格右侧边框 */
}
.table-cell:last-child {
  border-right: none; /* 最后一列无边框 */
}
.label {
  width: 30%;
  text-align: right;
  color: #666;
  background-color: #f8f8f8; /* 标签列灰色背景 */
}
.value {
  width: 70%;
  text-align: left;
}
 
/* 二维码区域(右下角对齐) */
.qr-area {
  display: flex;
  justify-content: flex-end;
  margin-top: -10rpx; /* 微调与表格间距 */
}
 
/* 空状态 */
.empty-state {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300rpx;
  color: #999;
  font-size: 28rpx;
}
 
/* 打印适配(隐藏操作栏,优化边框) */
@media print {
  .no-print {
    display: none;
  }
  .tag-card {
    border: 4rpx solid #28a745; /* 打印时保留绿色边框 */
    box-shadow: none;
    width: 100%;
  }
}
</style>