支持打印和搜索
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
<view class="header">
|
||||
<text class="back-btn" @click="goBack">‹ 返回</text>
|
||||
<text class="title">工单详情</text>
|
||||
<text v-if="canModify" class="edit-btn" @click="goEdit">编辑</text>
|
||||
<view v-else class="header-right"></view>
|
||||
<view class="header-right">
|
||||
<text v-if="canModify" class="edit-btn" @click="goEdit">编辑</text>
|
||||
<text class="print-btn" @click="printWorkOrder">打印</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<scroll-view scroll-y class="content" refresher-enabled @refresherrefresh="onRefresh" :refresher-triggered="refreshing">
|
||||
@@ -258,6 +260,16 @@ import { workOrderApi } from '@/api/work_order.js'
|
||||
import api from '@/api/index.js'
|
||||
import { useConfigStore } from '@/stores/config.js'
|
||||
|
||||
// 仅在 App 环境下加载原生插件
|
||||
let printer = null
|
||||
try {
|
||||
if (uni.requireNativePlugin) {
|
||||
printer = uni.requireNativePlugin('LcPrinter')
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('打印机插件加载失败:', e.message)
|
||||
}
|
||||
|
||||
const configStore = useConfigStore()
|
||||
const goBack = () => uni.navigateBack()
|
||||
|
||||
@@ -342,6 +354,59 @@ async function fetchOrderDetail() {
|
||||
}
|
||||
}
|
||||
|
||||
// 打印工单标签
|
||||
function printWorkOrder() {
|
||||
if (!printer) {
|
||||
uni.showToast({ title: '打印机插件未加载(仅在 App 环境可用)', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 标签打印,使用黑标
|
||||
printer.printEnableMark({
|
||||
enable: true
|
||||
})
|
||||
|
||||
// 第一行:标题
|
||||
printer.setFontSize({ fontSize: 0 })
|
||||
printer.setTextBold({ bold: true })
|
||||
printer.printText({
|
||||
content: (order.value.Title || '工单')+'\n'
|
||||
})
|
||||
printer.setTextBold({ bold: false })
|
||||
//printer.printLine({ line_length: 1 })
|
||||
|
||||
// 第二行:描述
|
||||
if (order.value.Description) {
|
||||
//printer.setFontSize({ fontSize: 1 })
|
||||
printer.printText({
|
||||
content: order.value.Description+'\n'
|
||||
})
|
||||
//printer.printLine({ line_length: 1 })
|
||||
}
|
||||
|
||||
// 第三行:创建时间
|
||||
if (order.value.CreatedAt) {
|
||||
printer.setFontSize({ fontSize: 1 })
|
||||
printer.printText({
|
||||
content: formatDate(order.value.CreatedAt)
|
||||
})
|
||||
//printer.printLine({ line_length: 1 })
|
||||
}
|
||||
|
||||
// 条形码(高40)
|
||||
printer.printBarcode({
|
||||
text: 'wo:' + orderId.value,
|
||||
height: 40,
|
||||
barcodeType: 73
|
||||
})
|
||||
//printer.printLine({ line_length: 2 })
|
||||
|
||||
// 提交打印
|
||||
printer.start()
|
||||
|
||||
uni.showToast({ title: '打印成功', icon: 'success' })
|
||||
}
|
||||
|
||||
// 新增进度
|
||||
const selectedStatus = ref({})
|
||||
const commitComment = ref('')
|
||||
@@ -621,7 +686,14 @@ async function onRefresh() {
|
||||
}
|
||||
|
||||
.header-right {
|
||||
width: 60rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 40rpx;
|
||||
}
|
||||
|
||||
.print-btn {
|
||||
font-size: 28rpx;
|
||||
color: #007AFF;
|
||||
}
|
||||
|
||||
.content {
|
||||
|
||||
Reference in New Issue
Block a user