printTag.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <view class="printTag">
  3. <view class="print-nums flex flex_column align_center justify_center">
  4. <view>打印数量</view>
  5. <view class="u-ninput">
  6. <u-number-box :min="1" v-model="printNum" color="#000" bg-color="#fff" size="30" :input-height="70" :input-width="100"></u-number-box>
  7. </view>
  8. </view>
  9. <view class="shelf-info">
  10. <view class="shelf-info-title">
  11. <view>{{infoData&&infoData.shelfName || '--'}}</view>
  12. <view class="pno">{{infoData&&infoData.shelfPlaceCode}}</view>
  13. </view>
  14. <view>产品编码:{{fromPage == 'smdy'?infoData.productCode : infoData.productEntity&&infoData.productEntity.code}}</view>
  15. <view>产品名称:{{fromPage == 'smdy'?infoData.productName : infoData.productEntity&&infoData.productEntity.productName}}</view>
  16. <view>{{fromPage == 'smdy'?'实发':'库存'}}数量:{{fromPage == 'smdy'?infoData.confirmQty : infoData.qty}}</view>
  17. </view>
  18. <view class="buttons flex align_center justify_center">
  19. <view v-if="fromPage == 'bdtq'"><u-button @click="cansel" shape="circle" plain>返回列表</u-button></view>
  20. <view v-if="fromPage == 'smdy'"><u-button @click="cansel" shape="circle" plain>重新扫描</u-button></view>
  21. <view>
  22. <kk-printer ref="kkprinter" @startPrint="startPrint"></kk-printer>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import { shelfDetail } from '@/api/shelf'
  29. import kkPrinter from '@/components/kk-printer/index.vue';
  30. export default {
  31. components:{
  32. kkPrinter
  33. },
  34. data() {
  35. return {
  36. infoData: null,
  37. fromPage: '',
  38. printInfo: null,
  39. printNum: 0
  40. }
  41. },
  42. onLoad(options) {
  43. const _this = this
  44. _this.fromPage = options.page
  45. _this.infoData = options.data ? JSON.parse(options.data) : {},
  46. _this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
  47. console.log(_this.infoData)
  48. var myDate = new Date()
  49. if(_this.fromPage == 'bdtq'){
  50. _this.printInfo = {
  51. dealerName: _this.$store.state.vuex_userData.orgName,
  52. shelfName: _this.infoData.shelfName || '',
  53. productCode: _this.infoData.productEntity&&_this.infoData.productEntity.code || '',
  54. productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
  55. shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
  56. currentInven: _this.printNum,
  57. printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
  58. printUser: _this.$store.state.vuex_userData.username,
  59. 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}`
  60. }
  61. }else if(_this.fromPage == 'smdy'){
  62. _this.printInfo = {
  63. dealerName: _this.$store.state.vuex_userData.orgName,
  64. shelfName: _this.infoData.shelfName || '',
  65. productCode: _this.infoData.productCode || '',
  66. productName: _this.infoData.productName || '',
  67. shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
  68. currentInven: _this.printNum,
  69. printDate: myDate.toLocaleDateString() +' '+myDate.getHours() +':'+myDate.getMinutes() +':'+myDate.getSeconds(),
  70. printUser: _this.$store.state.vuex_userData.username,
  71. 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}`
  72. }
  73. }
  74. console.log('printInfo-----------',_this.printInfo)
  75. },
  76. onUnload() {
  77. this.$refs.kkprinter.closeConnect()
  78. },
  79. methods: {
  80. cansel(){
  81. uni.$emit('refreshBL')
  82. uni.navigateBack()
  83. },
  84. textFormat(command,text,maxFontNums,left,top,lightHeight){
  85. const textLen = text.length
  86. console.log(textLen,maxFontNums)
  87. if(textLen > maxFontNums){
  88. const rows = Math.ceil(textLen/maxFontNums)
  89. for(let i=0;i<rows;i++){
  90. top = top+i*lightHeight
  91. console.log(top)
  92. // 最后一行
  93. if(i==rows-1){
  94. const ltxt = text.substring(i*maxFontNums)
  95. const ltlen = ltxt.length
  96. command.setText(left+((maxFontNums-ltlen)/2)*lightHeight, top, "TSS24.BF2", 1, 1, ltxt)
  97. }else{
  98. command.setText(left, top, "TSS24.BF2", 1, 1, text.substring(i*maxFontNums,maxFontNums))
  99. }
  100. }
  101. }else{
  102. command.setText(left+((maxFontNums-textLen)/2)*lightHeight, top, "TSS24.BF2", 1, 1, text)
  103. }
  104. return top
  105. },
  106. // 打印
  107. startPrint(opt,tsc,blesdk){
  108. console.log(opt,'opt')
  109. let top = 10 // 距离顶部10点像素
  110. const left = 10 // 距离左边10点
  111. const lightHeight = 24 // 行高3mm,1mm = 8点
  112. const pageW = 40 // 页签宽度mm
  113. const pageH = 30 // 页签高度mm
  114. const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
  115. // 初始化打印机
  116. const command = tsc.jpPrinter.createNew()
  117. command.init()
  118. command.setSize(pageW, pageH) // 标签纸张宽高,单位mm
  119. command.setGap(2) // 标签上下间距,单位mm
  120. command.setCls() // 清除缓冲区数据
  121. // 经销商文字高度,是否换行
  122. top = this.textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight)
  123. // 数字货架名称文字
  124. top = top+lightHeight
  125. top = this.textFormat(command,this.printInfo.shelfName,Math.floor(maxFontNums*0.6),left,top,lightHeight)
  126. // 产品编码
  127. top = top+lightHeight+15
  128. command.setText(left, top, "TSS24.BF2", 1, 1, this.printInfo.productCode)
  129. // 产品名称
  130. top = top+lightHeight
  131. this.textFormat(command,this.printInfo.productName,Math.floor(maxFontNums*0.6),left,top,lightHeight)
  132. // command.setQR(50, 50, "L", 5, "A", "https://www.baidu.com")
  133. // command.setBox(5, 5, 795, 595, 1)
  134. command.setPagePrint(1,1) // 打印分数1,每个标签重发打印2次
  135. console.log("开始打印了",command.getData())
  136. blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
  137. },
  138. // 打印成功
  139. onPrintSuccess(){
  140. // uni.navigateBack()
  141. this.$refs.kkprinter.onPrintSuccess()
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="less">
  147. .printTag{
  148. background-color: #fff;
  149. width: 100vh;
  150. padding: 50rpx 30rpx;
  151. .print-nums{
  152. padding: 50rpx 30rpx;
  153. color: #999;
  154. font-size: 32rpx;
  155. > view{
  156. padding: 20rpx 0;
  157. }
  158. .u-ninput{
  159. border: 2rpx solid #eee;
  160. border-radius: 50rpx;
  161. padding: 0 12rpx;
  162. }
  163. /deep/ .u-icon-disabled{
  164. background: #fff!important;
  165. }
  166. /deep/ .u-number-input{
  167. margin: 0 2rpx;
  168. border: 2rpx solid #eee;
  169. border-top: 0;
  170. border-bottom: 0;
  171. }
  172. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  173. border-radius: 50rpx;
  174. }
  175. }
  176. .shelf-info{
  177. background-color: #f8f8f8;
  178. padding: 30rpx;
  179. border-radius: 12rpx;
  180. color: #707070;
  181. .shelf-info-title{
  182. font-size: 32rpx;
  183. color: #222222;
  184. display: flex;
  185. justify-content: space-between;
  186. margin-bottom: 10rpx;
  187. .pno{
  188. background: rgba(3, 54, 146, 0.15);
  189. border-radius: 100rpx;
  190. padding: 6rpx 20rpx;
  191. color: #033692;
  192. font-size: 24rpx;
  193. }
  194. }
  195. }
  196. .buttons{
  197. padding: 50rpx 0;
  198. > view{
  199. width: 36%;
  200. margin: 0 2%;
  201. }
  202. }
  203. }
  204. </style>