printTag.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. import {textFormat} from '@/libs/printTools.js'
  31. import moment from 'moment'
  32. export default {
  33. components:{
  34. kkPrinter
  35. },
  36. data() {
  37. return {
  38. infoData: null,
  39. fromPage: '',
  40. printInfo: null,
  41. printNum: 0,
  42. isParinting: false
  43. }
  44. },
  45. onLoad(options) {
  46. const _this = this
  47. _this.fromPage = options.page
  48. _this.infoData = options.data ? JSON.parse(options.data) : {},
  49. _this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
  50. _this.printNum = _this.printNum||1
  51. console.log(_this.infoData)
  52. },
  53. onUnload() {
  54. // this.$refs.kkprinter.closeConnect()
  55. this.printNum = 1
  56. this.infoData = null
  57. this.printInfo = null
  58. this.fromPage = ''
  59. },
  60. methods: {
  61. cansel(){
  62. uni.$emit('refreshBL')
  63. uni.navigateBack()
  64. },
  65. // 获取打印内容
  66. getPrintContent(){
  67. const _this = this
  68. const nowDate = moment().format('YYYY-MM-DD HH:mm')
  69. if(_this.fromPage == 'bdtq'){
  70. _this.printInfo = {
  71. dealerName: _this.$store.state.vuex_userData.orgName,
  72. shelfName: _this.infoData.shelfName || '',
  73. productCode: _this.infoData.productEntity&&_this.infoData.productEntity.code || '',
  74. productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
  75. shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
  76. currentInven: _this.printNum,
  77. printDate: nowDate,
  78. printUser: _this.$store.state.vuex_userData.userNameCN,
  79. 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}`
  80. }
  81. }else if(_this.fromPage == 'smdy'){
  82. _this.printInfo = {
  83. dealerName: _this.$store.state.vuex_userData.orgName,
  84. shelfName: _this.infoData.shelfName || '',
  85. productCode: _this.infoData.productCode || '',
  86. productName: _this.infoData.productName || '',
  87. shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
  88. currentInven: _this.printNum,
  89. printDate: nowDate,
  90. printUser: _this.$store.state.vuex_userData.userNameCN,
  91. 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}`
  92. }
  93. }
  94. console.log('printInfo-----------',_this.printInfo)
  95. },
  96. // 打印
  97. startPrint(opt,tsc,blesdk){
  98. console.log(opt,'opt')
  99. this.getPrintContent()
  100. if(this.printInfo.currentInven<=0){
  101. uni.showToast({
  102. icon:"none",
  103. title: "请选择打印数量"
  104. })
  105. this.$refs.kkprinter.onPrintFail()
  106. return
  107. }
  108. if(this.isParinting){
  109. return
  110. }
  111. this.isParinting = true
  112. let top = 10 // 距离顶部10点像素
  113. const left = 8 // 距离左边
  114. const lightHeight = 24 // 行高3mm,1mm = 8点
  115. const pageW = 40 // 页签宽度mm
  116. const pageH = 30 // 页签高度mm
  117. const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
  118. let rightTop = 0
  119. let rightLeft = (Math.floor(maxFontNums*0.6)+1)*lightHeight
  120. // 初始化打印机
  121. const command = tsc.jpPrinter.createNew()
  122. command.init()
  123. command.setSize(pageW, pageH) // 标签纸张宽高,单位mm
  124. command.setGap(2) // 标签上下间距,单位mm
  125. command.setCls() // 清除缓冲区数据
  126. // 经销商文字高度,是否换行
  127. top = textFormat(command,this.printInfo.dealerName,maxFontNums,left,top,lightHeight,"center",1)
  128. // 数字货架名称文字
  129. top = top+10
  130. rightTop = top
  131. const lwidth = Math.floor(maxFontNums*0.6)
  132. top = textFormat(command,this.printInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
  133. // 产品编码
  134. top = top+10
  135. top = textFormat(command,this.printInfo.productCode,lwidth,left,top,lightHeight,"left",1)
  136. // 产品名称
  137. top = top+10
  138. top = textFormat(command,this.printInfo.productName,lwidth,left,top,lightHeight,"left",1)
  139. // 打印人打印时间
  140. top = top+10
  141. top = textFormat(command,this.printInfo.printDate+' '+this.printInfo.printUser,lwidth,left,top,lightHeight,"left",1)
  142. // 货位号
  143. textFormat(command,this.printInfo.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
  144. // 二维码
  145. const qrtop = rightTop +lightHeight+10
  146. command.setQR(rightLeft, qrtop, "L", 3, "A", this.printInfo.barCode)
  147. command.setPagePrint(1,this.printInfo.currentInven) // 打印分数1,每个标签重发打印2次
  148. console.log("开始打印了",command.getData())
  149. blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
  150. },
  151. // 打印成功
  152. onPrintSuccess(){
  153. // uni.navigateBack()
  154. this.$refs.kkprinter.onPrintSuccess()
  155. this.isParinting = false
  156. }
  157. }
  158. }
  159. </script>
  160. <style lang="less">
  161. .printTag{
  162. background-color: #fff;
  163. width: 100vh;
  164. padding: 50rpx 30rpx;
  165. .print-nums{
  166. padding: 50rpx 30rpx;
  167. color: #999;
  168. font-size: 32rpx;
  169. > view{
  170. padding: 20rpx 0;
  171. }
  172. .u-ninput{
  173. border: 2rpx solid #eee;
  174. border-radius: 50rpx;
  175. padding: 0 12rpx;
  176. }
  177. /deep/ .u-icon-disabled{
  178. background: #fff!important;
  179. }
  180. /deep/ .u-number-input{
  181. margin: 0 2rpx;
  182. border: 2rpx solid #eee;
  183. border-top: 0;
  184. border-bottom: 0;
  185. }
  186. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  187. border-radius: 50rpx;
  188. }
  189. }
  190. .shelf-info{
  191. background-color: #f8f8f8;
  192. padding: 30rpx;
  193. border-radius: 12rpx;
  194. color: #707070;
  195. .shelf-info-title{
  196. font-size: 32rpx;
  197. color: #222222;
  198. display: flex;
  199. justify-content: space-between;
  200. margin-bottom: 10rpx;
  201. .pno{
  202. background: rgba(3, 54, 146, 0.15);
  203. border-radius: 100rpx;
  204. padding: 4rpx 20rpx;
  205. color: #033692;
  206. font-size: 26rpx;
  207. }
  208. }
  209. }
  210. .buttons{
  211. padding: 50rpx 0;
  212. > view{
  213. width: 36%;
  214. margin: 0 2%;
  215. }
  216. }
  217. }
  218. </style>