123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- <template>
- <view class="printTag">
- <view class="print-nums flex flex_column align_center justify_center">
- <view>打印数量</view>
- <view class="u-ninput">
- <u-number-box :min="1" v-model="printNum" color="#000" bg-color="#fff" size="30" :input-height="70" :input-width="100"></u-number-box>
- </view>
- </view>
- <view class="shelf-info">
- <view class="shelf-info-title">
- <view>{{infoData&&infoData.shelfName || '--'}}</view>
- <view class="pno">{{infoData&&infoData.shelfPlaceCode}}</view>
- </view>
- <view>产品编码:{{fromPage == 'smdy'?infoData.productCode : infoData.productEntity&&infoData.productEntity.code}}</view>
- <view>产品名称:{{fromPage == 'smdy'?infoData.productName : infoData.productEntity&&infoData.productEntity.productName}}</view>
- <view>{{fromPage == 'smdy'?'实发':'库存'}}数量:{{fromPage == 'smdy'?infoData.confirmQty : infoData.qty}}</view>
- </view>
- <view class="buttons flex align_center justify_center">
- <view v-if="fromPage == 'bdtq'"><u-button @click="cansel" shape="circle" plain>返回列表</u-button></view>
- <view v-if="fromPage == 'smdy'"><u-button @click="cansel" shape="circle" plain>重新扫描</u-button></view>
- <view>
- <kk-printer ref="kkprinter" @startPrint="startPrint"></kk-printer>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { shelfDetail } from '@/api/shelf'
- import kkPrinter from '@/components/kk-printer/index.vue';
- export default {
- components:{
- kkPrinter
- },
- data() {
- return {
- infoData: null,
- fromPage: '',
- printInfo: null,
- printNum: 0
- }
- },
- onLoad(options) {
- const _this = this
- _this.fromPage = options.page
- _this.infoData = options.data ? JSON.parse(options.data) : {},
- _this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
- _this.printNum = _this.printNum||1
- console.log(_this.infoData)
- },
- onUnload() {
- // this.$refs.kkprinter.closeConnect()
- this.printNum = 1
- this.infoData = null
- this.printInfo = null
- this.fromPage = ''
- },
- methods: {
- cansel(){
- uni.$emit('refreshBL')
- uni.navigateBack()
- },
- // 获取打印内容
- getPrintContent(){
- const _this = this
- const myDate = new Date()
- if(_this.fromPage == 'bdtq'){
- _this.printInfo = {
- dealerName: _this.$store.state.vuex_userData.orgName,
- shelfName: _this.infoData.shelfName || '',
- productCode: _this.infoData.productEntity&&_this.infoData.productEntity.code || '',
- productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
- shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
- currentInven: _this.printNum,
- printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
- printUser: _this.$store.state.vuex_userData.username,
- barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productEntity&&_this.infoData.productEntity.productSn}&productCode=${_this.infoData.productEntity&&_this.infoData.productEntity.code}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
- }
- }else if(_this.fromPage == 'smdy'){
- _this.printInfo = {
- dealerName: _this.$store.state.vuex_userData.orgName,
- shelfName: _this.infoData.shelfName || '',
- productCode: _this.infoData.productCode || '',
- productName: _this.infoData.productName || '',
- shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
- currentInven: _this.printNum,
- printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
- printUser: _this.$store.state.vuex_userData.username,
- barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productSn}&productCode=${_this.infoData.productCode}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
- }
- }
- console.log('printInfo-----------',_this.printInfo)
- },
- getBytesCount(str){
- var bytesCount = 0;
- if (str != null) {
- for (var i = 0; i < str.length; i++) {
- var c = str.charAt(i);
- if (c.match(/[^\x00-\xff]/ig) != null) //全角
- {
- bytesCount += 2;
- } else {
- bytesCount += 1;
- }
- }
- }
- return bytesCount;
- },
- // JS 包含中文的字符串按固定长度拆分换行算法
- getTextRows(str,iPageSize){
- var strArray = [];
- var tempStr = "";
- var iTotalLength = this.getBytesCount(str);
- for (var i = 0; i < str.length; i++) {
- var iCount = this.getBytesCount(str[i]);
- var iCountTemp = this.getBytesCount(tempStr);
- //iCountTemp + iCount >= iPageSize 这里可能出现两种情况:
- //长度等于 iPageSize 或 等于 iPageSize + 1(最后一个为中文字符就等于 9 + 2 情况)
- if (iCountTemp + iCount >= iPageSize) {
- tempStr += str[i];
- strArray.push(tempStr);
- // console.log("iCountTemp + iCount >= iPageSize " + tempStr)
- tempStr = "";
- } else {
- tempStr += str[i];
- }
- }
-
- // //最后一次尾巴
- if (tempStr.length > 0){
- strArray.push(tempStr)
- }
- return strArray
- },
- textFormat(command,text,maxFontNums,left,top,lightHeight,align,fontSize){
- let rowTop = top
- const textArr = this.getTextRows(text.replace(/\s+/g, ' '),maxFontNums*2)
- const rows = textArr.length
- for(let i=0;i<rows;i++){
- if(align=="center"){
- const ltxt = textArr[i]
- const ltlen = ltxt.replace(/[^x00-xFF]/g,'**').length/2
- command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, rowTop, "TSS24.BF2", fontSize, fontSize, ltxt)
- }
- else{
- command.setText(left, rowTop, "TSS24.BF2", fontSize, fontSize, textArr[i])
- }
- rowTop = rowTop+lightHeight
- }
- return rowTop
- },
- // 打印
- startPrint(opt,tsc,blesdk){
- console.log(opt,'opt')
- this.getPrintContent()
- if(this.printInfo.currentInven<=0){
- uni.showToast({
- icon:"none",
- title: "请选择打印数量"
- })
- this.$refs.kkprinter.onPrintFail()
- return
- }
- let top = 10 // 距离顶部10点像素
- const left = 24 // 距离左边
- const lightHeight = 24 // 行高3mm,1mm = 8点
- const pageW = 40 // 页签宽度mm
- const pageH = 30 // 页签高度mm
- const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
- let rightTop = 0
- let rightLeft = Math.floor(maxFontNums*0.7)*lightHeight
- // 初始化打印机
- const command = tsc.jpPrinter.createNew()
- command.init()
- command.setSize(pageW, pageH) // 标签纸张宽高,单位mm
- command.setGap(2) // 标签上下间距,单位mm
- command.setCls() // 清除缓冲区数据
- // 经销商文字高度,是否换行
- top = this.textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight,"center",1)
- // 数字货架名称文字
- top = top+10
- rightTop = top
- const lwidth = Math.floor(maxFontNums*0.6)
- rightLeft = (lwidth + 1.5) * lightHeight
- top = this.textFormat(command,this.printInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
- // 产品编码
- top = top+10
- top = this.textFormat(command,this.printInfo.productCode,lwidth,left,top,lightHeight,"left",1)
- // 产品名称
- top = top+5
- top = this.textFormat(command,this.printInfo.productName,lwidth,left,top,lightHeight,"left",1)
- // 货位号
- this.textFormat(command,this.printInfo.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
- // 二维码
- const qrtop = rightTop +lightHeight+10
- command.setQR(rightLeft, qrtop, "L", 3, "A", this.printInfo.barCode)
- command.setPagePrint(1,this.printInfo.currentInven) // 打印分数1,每个标签重发打印2次
- console.log("开始打印了",command.getData())
- blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
- },
- // 打印成功
- onPrintSuccess(){
- // uni.navigateBack()
- this.$refs.kkprinter.onPrintSuccess()
- }
- }
- }
- </script>
- <style lang="less">
- .printTag{
- background-color: #fff;
- width: 100vh;
- padding: 50rpx 30rpx;
- .print-nums{
- padding: 50rpx 30rpx;
- color: #999;
- font-size: 32rpx;
- > view{
- padding: 20rpx 0;
- }
- .u-ninput{
- border: 2rpx solid #eee;
- border-radius: 50rpx;
- padding: 0 12rpx;
- }
- /deep/ .u-icon-disabled{
- background: #fff!important;
- }
- /deep/ .u-number-input{
- margin: 0 2rpx;
- border: 2rpx solid #eee;
- border-top: 0;
- border-bottom: 0;
- }
- /deep/ .u-icon-plus, /deep/ .u-icon-minus{
- border-radius: 50rpx;
- }
- }
- .shelf-info{
- background-color: #f8f8f8;
- padding: 30rpx;
- border-radius: 12rpx;
- color: #707070;
- .shelf-info-title{
- font-size: 32rpx;
- color: #222222;
- display: flex;
- justify-content: space-between;
- margin-bottom: 10rpx;
- .pno{
- background: rgba(3, 54, 146, 0.15);
- border-radius: 100rpx;
- padding: 4rpx 20rpx;
- color: #033692;
- font-size: 26rpx;
- }
- }
- }
- .buttons{
- padding: 50rpx 0;
- > view{
- width: 36%;
- margin: 0 2%;
- }
- }
- }
- </style>
|