manualPrint.vue 6.4 KB

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