manualPrint.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <view class="replenishment-manualPrint-wrap">
  3. <view class="replenishment-manualPrint-body">
  4. <view class="part-list">
  5. <!-- 补货产品 -->
  6. <partList :list="partList" title="补货产品" model="checkbox" fromPage="manualPrint" ref="partList" noDataText="暂无产品" @allChecked="allCheckedCallback"></partList>
  7. </view>
  8. </view>
  9. <view class="replenishment-manualPrint-footer">
  10. <view>
  11. <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
  12. </view>
  13. <view>
  14. <kk-printer ref="kkprinter" defaultText="开始打印" @startPrint="startPrint"></kk-printer>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import kkPrinter from '@/components/kk-printer/index.vue';
  21. import { shelfReplenishDetail, shelfReplenishDetailList, shelfReplenishPrintSign } from '@/api/shelfReplenish'
  22. import partList from '@/pages/common/partList.vue'
  23. import {textFormat} from '@/libs/printTools.js'
  24. export default {
  25. components: { partList, kkPrinter },
  26. data() {
  27. return {
  28. replenishBillSn: '',
  29. basicInfoData:null,
  30. partList: [],
  31. allChecked: false,
  32. printIndex: 0,
  33. }
  34. },
  35. onReady() {
  36. uni.setNavigationBarColor({
  37. frontColor: '#ffffff',
  38. backgroundColor: this.$config('primaryColor')
  39. })
  40. },
  41. onLoad(option) {
  42. this.replenishBillSn = option.sn
  43. this.getDetail()
  44. this.getPartList()
  45. },
  46. onUnload() {
  47. this.$refs.kkprinter.closeConnect()
  48. },
  49. methods: {
  50. // 查询详情
  51. getDetail(){
  52. shelfReplenishDetail({ sn: this.replenishBillSn }).then(res => {
  53. if(res.status == 200){
  54. this.basicInfoData = res.data || null
  55. }else{
  56. this.basicInfoData = null
  57. }
  58. })
  59. },
  60. // 查询列表
  61. getPartList(){
  62. const _this = this
  63. shelfReplenishDetailList({ replenishBillSn: this.replenishBillSn }).then(res => {
  64. if(res.status == 200 && res.data){
  65. res.data.map(item =>{
  66. item.confirmQty = item.confirmQty ? Number(item.confirmQty) : 0
  67. item.printQty = item.confirmQty ? Number(item.confirmQty) : 0
  68. })
  69. this.partList = res.data || []
  70. }else{
  71. this.partList = []
  72. }
  73. })
  74. },
  75. // 全选
  76. allCheckeChange(e){
  77. this.$refs.partList.allSelect(e.value)
  78. },
  79. allCheckedCallback(val){
  80. this.allChecked = val
  81. },
  82. printOnce(opt,tsc,blesdk,data){
  83. const _this = this
  84. const dealer = this.$store.state.vuex_userData
  85. console.log(opt,data,'opt')
  86. let top = 10 // 距离顶部10点像素
  87. const left = 8 // 距离左边
  88. const lightHeight = 24 // 行高3mm,1mm = 8点
  89. const pageW = 40 // 页签宽度mm
  90. const pageH = 30 // 页签高度mm
  91. const maxFontNums = Math.floor((pageW*8-left*2)/lightHeight) // 每行最多字体数
  92. let rightTop = 0
  93. let rightLeft = Math.floor(maxFontNums*0.6)*lightHeight
  94. // 初始化打印机
  95. const command = tsc.jpPrinter.createNew()
  96. command.init()
  97. command.setSize(pageW, pageH) // 标签纸张宽高,单位mm
  98. command.setGap(2) // 标签上下间距,单位mm
  99. command.setCls() // 清除缓冲区数据
  100. // 经销商文字高度,是否换行
  101. top = textFormat(command,dealer.orgName,maxFontNums,left,top,lightHeight,"center",1)
  102. // 数字货架名称文字
  103. top = top+10
  104. rightTop = top
  105. const lwidth = Math.floor(maxFontNums*0.6)
  106. top = textFormat(command,this.basicInfoData.shelfInfo.shelfName,lwidth,left,top,lightHeight,"left",1)
  107. // 产品编码
  108. top = top+10
  109. top = textFormat(command,data.productCode,lwidth,left,top,lightHeight,"left",1)
  110. // 产品名称
  111. top = top+5
  112. top = textFormat(command,data.product.name,lwidth,left,top,lightHeight,"left",1)
  113. // 时间
  114. top = top+10
  115. top = textFormat(command,this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),lwidth,left,top,lightHeight,"left",1)
  116. // 货位号
  117. textFormat(command,data.shelfPlaceCode,maxFontNums-lwidth,rightLeft,rightTop,lightHeight,"center",1)
  118. // 二维码
  119. const qrtop = rightTop +lightHeight+10
  120. const qrcont = `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
  121. command.setQR(rightLeft, qrtop, "L", 3, "A", qrcont)
  122. command.setPagePrint(1,data.printQty) // 打印分数1,每个标签重发打印2次
  123. console.log("开始打印了",command.getData())
  124. blesdk.senBlData(
  125. opt.deviceId,
  126. opt.serviceId,
  127. opt.writeId,
  128. command.getData(),
  129. function(){
  130. const result =_this.$refs.partList.getAllChecked()
  131. _this.printIndex = _this.printIndex + 1
  132. if(_this.printIndex < result.length){
  133. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  134. }else{
  135. _this.printIndex = 0
  136. _this.$refs.kkprinter.onPrintSuccess()
  137. }
  138. });
  139. },
  140. // 打印
  141. startPrint(opt,tsc,blesdk){
  142. const result =this.$refs.partList.getAllChecked()
  143. if(result.length){
  144. this.printOnce(opt,tsc,blesdk,result[this.printIndex])
  145. }else{
  146. this.toashMsg("请选择产品!")
  147. this.$refs.kkprinter.onPrintFail()
  148. }
  149. },
  150. }
  151. }
  152. </script>
  153. <style lang="less">
  154. .replenishment-manualPrint-wrap{
  155. position: relative;
  156. width: 100%;
  157. height: 100%;
  158. overflow: hidden;
  159. padding-bottom: 102upx;
  160. .replenishment-manualPrint-body{
  161. > view{
  162. padding: 10rpx 25rpx;
  163. background-color: #fff;
  164. margin-bottom: 20rpx;
  165. border-radius: 25rpx;
  166. box-shadow: 2rpx 3rpx 5rpx #eee;
  167. }
  168. }
  169. .replenishment-manualPrint-footer{
  170. padding: 10upx 32upx 12upx;
  171. background-color: #fff;
  172. position: fixed;
  173. left: 0;
  174. bottom: 0;
  175. width: 100%;
  176. box-shadow: 3px 1px 7px #eee;
  177. display: flex;
  178. align-items: center;
  179. justify-content: space-between;
  180. }
  181. }
  182. </style>