From 88af20162c250117e4db01e453e24423ceb202a6 Mon Sep 17 00:00:00 2001
From: spring <2396852758@qq.com>
Date: 星期三, 11 六月 2025 13:11:09 +0800
Subject: [PATCH] 核磅打印逻辑编写
---
pages/wareHouse/nuclearScale/nuclearscalerecord.vue | 297 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 264 insertions(+), 33 deletions(-)
diff --git a/pages/wareHouse/nuclearScale/nuclearscalerecord.vue b/pages/wareHouse/nuclearScale/nuclearscalerecord.vue
index ecc7ab9..260c131 100644
--- a/pages/wareHouse/nuclearScale/nuclearscalerecord.vue
+++ b/pages/wareHouse/nuclearScale/nuclearscalerecord.vue
@@ -4,21 +4,15 @@
<u-navbar title="鏍哥璁板綍" :background="background" :border-bottom="false" :title-bold="true" title-color="#000"
back-icon-color="#000">
<view class="navbar-right" slot="right" @click="goPrintAll">
- 鍏ㄩ儴鎵撳嵃
- </view>
- </u-navbar>
+ 鍏ㄩ儴鎵撳嵃
+ </view>
+ </u-navbar>
<view class="wrap">
<scroll-view class="finishProductIn-locno-scroll-list" scroll-y="true" @scrolltolower="loadMore">
<u-cell-group class="finishProductIn-locno-scroll-list-group" :border="false">
- <view
- class="content"
- v-for="(item, index) in list"
- :key="item.locNo"
- :index="index"
- @click="selectNo(item.index)"
- >
+ <view class="content" v-for="(item, index) in list" :key="item.locNo" :index="index" @click="selectNo(item)">
<view class="content-header">
- <view class="content-header-title">{{ index+1 }}</view>
+ <view class="content-header-title">{{ index + 1 }}</view>
</view>
<view class="content-body">
<view class="row-list">
@@ -94,10 +88,21 @@
</view>
</view>
</view>
- </view>
+ </view>
</u-cell-group>
<view class="loadmore" @click="loadMore">
<u-loadmore :status="loadStatus"></u-loadmore>
+ </view>
+ </scroll-view>
+ </view>
+ <u-toast ref="uToast" />
+ <view v-if="maskShow" class="uni-mask" @touchmove.stop.prevent="moveHandle" @click="maskclose">
+ <scroll-view class="uni-scroll_box" scroll-y @touchmove.stop.prevent="moveHandle" @click.stop="moveHandle">
+ <view class="uni-list-box" v-for="(item, index) in listDevice" :key="index" @click="tapQuery(item)">
+ <view>
+ <view class="uni-list_name">鍚嶇О锛歿{ item.name }}</view>
+ <view class="uni-list_item">UUID:{{ item.address }}</view>
+ </view>
</view>
</scroll-view>
</view>
@@ -105,6 +110,27 @@
</template>
<script>
import content_bg from '@/static/custom/finishProductIn/locNoBg.png'
+const jcapi = uni.requireNativePlugin("JCSDK-JCApiModule");
+
+// 浜岀淮鐮佺被鍨�
+const QrCodeType = {
+ QrCode: 31,
+ PDF417: 32,
+ DataMatrix: 33,
+ AZTEC: 34
+}
+// 绾挎潯绫诲瀷
+const LineType = {
+ Solid: 1, // 瀹炵嚎
+ Dotted: 2, // 铏氱嚎锛堥粯璁よ櫄瀹�1:1鐩搁棿锛�
+}
+// 鎹㈣鏂瑰紡
+const LineModeType = {
+ Justified: 1, // 瀹介珮鍥哄畾锛屽唴瀹硅嚜閫傚簲锛堝瓧鍙�/瀛楅棿璺�/琛岄棿璺濇寜姣斾緥缂╂斁锛�
+ AutoHeight: 2, // 瀹藉害鍥哄畾锛岄珮搴﹁嚜閫傚簲
+ Fixed: 4, // 瀹介珮鍥哄畾锛岃秴鍑洪儴鍒嗚鍓�
+ Adapt: 6, // 瀹介珮鍥哄畾锛屽唴瀹硅秴杩囨椂棰勮瀹介珮鑷姩缂╁皬
+}
export default {
data() {
return {
@@ -144,7 +170,10 @@
}
],
count: 0,
- loadStatus: 'loading'
+ loadStatus: 'loading',
+ maskShow: false,
+ listDevice: [], //钃濈墮璁惧鏁版嵁
+ pritList: []
};
},
onLoad() {
@@ -152,6 +181,26 @@
this.alllist = res.data
this.originList = res.data
this.loadList()
+ })
+ // 鍒濆鍖朣DK
+ jcapi.initSDK()
+ // 鐩戝惉椤电爜鍥炶皟
+ jcapi.didReadPrintCountInfo(function (r) {
+ console.log(r)
+ })
+
+ // 鐩戝惉閿欒鍥炶皟
+ jcapi.didReadPrintErrorInfo(function (r) {
+ console.log(r)
+ if (r.code == 23) {
+ // 鎵撳嵃鏈烘柇寮�杩炴帴
+ _this.connectedDevice = null
+ }
+ uni.showToast({
+ icon: 'none',
+ title: JSON.stringify(r),
+ duration: 2 * 1000
+ })
})
},
methods: {
@@ -184,30 +233,211 @@
this.loadList()
},
// 鎵撳嵃鍗曚釜淇℃伅
- selectNo(no) {
+ selectNo(item) {
+ let that = this
uni.showModal({
- title: '鎻愮ず',
- content: '鏄惁鎵撳嵃瑁呯鍗曪紵',
- showCancel: true,
+ title: '鎻愮ず',
+ content: '鏄惁鎵撳嵃瑁呯鍗曪紵',
+ showCancel: true,
success: function (res) {
if (res.confirm) {
-
- }
- }
- });
+ that.searchDevice()
+ that.pritList = [item]
+ }
+ }
+ });
},
// 鎵撳嵃鍏ㄩ儴淇℃伅
goPrintAll() {
+ let that = this
uni.showModal({
- title: '鎻愮ず',
- content: '鏄惁鎵撳嵃瑁呯鍗曪紵',
- showCancel: true,
+ title: '鎻愮ず',
+ content: '鏄惁鎵撳嵃瑁呯鍗曪紵',
+ showCancel: true,
success: function (res) {
if (res.confirm) {
-
- }
- }
- });
+ that.searchDevice()
+ that.pritList = this.list
+ }
+ }
+ });
+ },
+ moveHandle() {
+
+ },
+ maskclose() {
+
+ },
+ //鎵撳嵃浜岀淮鐮�
+ async printQrCode(item) {
+ const params = {
+ rwMatlBindId: item.id
+ }
+ let res = await this.$u.api.dailyPaper.zongjianLabelInfo(params)
+ if (!res.data) {
+ this.$refs.uToast.show({
+ title: '鏈煡璇㈠埌璇ユ爣绛句俊鎭紒',
+ type: 'warning '
+ })
+ return
+ }
+ // 鍒濆鍖栫敾鏉�
+ jcapi.initDrawingBoard({
+ width: 50,
+ height: 100,
+ rotate: 0
+ });
+
+ // // 缁樺埗浜岀淮鐮�
+ jcapi.drawLabelQrCode({
+ x: 14.5,
+ y: 74,
+ width: 20,
+ height: 20,
+ value: jsonString,
+ rotate: 0,
+ codeType: QrCodeType.QrCode,
+ });
+ // 缁樺埗妯嚎 瀹炵嚎8鏉�
+ let sum = 4;
+ for (let i = 1; i < 13; i++) {
+ this.getDrawLabelLine(4, sum, 46, 0.5, 0, LineType.Solid) // 瀹炵嚎
+ sum = (i * 6) + 4
+ }
+ // 浜岀淮鐮佸ぇ妗�
+ this.getDrawLabelLine(4, 97, 46, 0.5, 0, LineType.Solid) // 瀹炵嚎9
+
+ //缁樺埗绔栫嚎
+ this.getDrawLabelLine(4, 4, 0.5, 97, 0, LineType.Solid) // 绔栫嚎1
+ this.getDrawLabelLine(20, 4, 0.5, 66, 0, LineType.Solid) // 绔栫嚎2
+ this.getDrawLabelLine(44.5, 4, 0.5, 97, 0, LineType.Solid) // 绔栫嚎2
+
+ // 濉啿鏂囧瓧鏍囬
+ this.getDrawLabelText(5, 5, 20, 20, '缂� 鍙�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 11, 20, 20, '宸ュ崟鍙�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 17, 20, 20, '鐗� 鍙�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 23, 20, 20, '鐗囧锛坢m锛�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 29, 20, 20, '鍘氬害锛坢m锛�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 35, 20, 20, '閲嶉噺锛圞G锛�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 41, 20, 20, '闀垮害锛坢锛�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 47, 20, 20, '鐢熶骇浜�:', 3.6, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 53, 20, 20, '鐢熶骇鏃堕棿:', 3.4, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 59, 20, 20, '鍘傚:', 3.4, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+ this.getDrawLabelText(5, 65, 20, 20, '閾佹崯:', 3.4, 0, LineModeType.AutoHeight, 0, 0, 0, 1)
+
+ // // 濉啿鍙傛暟鍊�
+ this.getDrawLabelText(22, 5, 35, 12, labelNo, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 11, 35, 12, optaskNo, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 17, 35, 12, grade, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 23, 35, 12, sliceWidth, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 29, 35, 12, thickness, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 35, 35, 12, wweight, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 41, 35, 12, llength, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 47, 35, 12, reportName, 2, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 53, 35, 12, reportTime, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 59, 35, 12, supplierVenderName, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+ this.getDrawLabelText(22, 65, 35, 12, ironLoss, 3, 0, LineModeType.AutoHeight, 0, 0, 0, 0)
+
+ // 鐢熸垚鎵撳嵃鏁版嵁
+ let imageJsonObj = jcapi.generateLabelJson()
+ // 璁剧疆鎵撳嵃浠诲姟
+ jcapi.startJob({
+ totalCount: 1,
+ density: this.printDensity,
+ labelType: this.labelType,
+ printMode: this.printMode,
+ }, function (r) {
+ if (r.code == 0) {
+ // 鎵撳嵃鏁版嵁
+ jcapi.printData(imageJsonObj, {
+ "printQuantity": 1,
+ }, function (r) {
+ if (r.code == 0) {
+ console.log("鎵撳嵃鎴愬姛")
+ } else {
+ console.log("鎵撳嵃澶辫触")
+ }
+ })
+ } else {
+ console.log("璁剧疆鎵撳嵃浠诲姟澶辫触")
+ }
+ })
+ },
+ tapQuery(item) {
+ this.maskShow = false
+ // 杩炴帴鎵撳嵃鏈�
+ let _this = this;
+ console.log(item)
+ jcapi.openPrinterByDevice({
+ address: item.address,
+ name: item.name,
+ deviceType: item.deviceType // 璁惧绫诲瀷锛�0-钃濈墮锛�1-缃戠粶
+ }, function (r) {
+ uni.showToast({
+ title: (r.code == 0) ? "杩炴帴鎴愬姛" : "杩炴帴澶辫触",
+ duration: 2 * 1000
+ })
+ if (r.code == 0) {
+ _this.connectedDevice = item
+ // 缁樻爣绛捐繘琛屾墦鍗�
+ _this.pritList.forEac(async item => {
+ await _this.printQrCode(item)
+ })
+ }
+ })
+ },
+ //鎵撳嵃鐩稿叧
+ searchDevice() {
+ let _this = this
+ uni.openBluetoothAdapter({ // 纭钃濈墮鏄惁鎵撳紑
+ success(r) {
+ uni.showLoading({
+ title: "鎼滅储涓�..."
+ })
+ // 鏈巿浜堣摑鐗欑浉鍏虫潈闄愬拰鏈墦寮�鎵嬫満瀹氫綅浼氭悳绱笉鍒拌澶�
+ jcapi.getBluetoothDevices(function (r) {
+ console.log("device:" + JSON.stringify(r))
+ // 鎼滅储鍒拌澶囧洖璋�
+ uni.hideLoading()
+ _this.listDevice = r;
+ _this.maskShow = true
+ })
+ },
+ fail(e) {
+ uni.showModal({
+ confirmText: "鎵撳紑钃濈墮澶辫触"
+ })
+ console.log("寮�鍚摑鐗欒澶囧け璐�" + e)
+ }
+ })
+ },
+ // 缁樺埗妯嚎 瀹炵嚎
+ getDrawLabelLine(x, y, width, height, rotate, lineType) {
+ jcapi.drawLabelLine({
+ x: x,
+ y: y,
+ width: width,
+ height: height,
+ rotate: rotate,
+ lineType: lineType
+ });
+ },
+ // 濉啿鏂囧瓧鏍囬
+ getDrawLabelText(x, y, width, height, value, fontSize, rotate, lineMode, lineSpace, letterSpace, textAlignHorizontal, textAlignVertical) {
+ jcapi.drawLabelText({
+ x: x,
+ y: y,
+ width: width,
+ height: height,
+ value: value,
+ fontSize: fontSize,
+ rotate: rotate,
+ lineMode: lineMode,
+ lineSpace: lineSpace,
+ letterSpace: letterSpace,
+ textAlignHorizontal: textAlignHorizontal,
+ textAlignVertical: textAlignVertical
+ })
},
//鍒锋柊涓婁竴涓〉闈�
@@ -359,11 +589,12 @@
}
}
}
+
.navbar-right {
- font-weight: 500;
- font-size: 13px;
- color: #0b0b0b;
- line-height: 36rpx;
- margin-right: 32rpx;
+ font-weight: 500;
+ font-size: 13px;
+ color: #0b0b0b;
+ line-height: 36rpx;
+ margin-right: 32rpx;
}
</style>
--
Gitblit v1.9.3