batchPrint.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view class="batchPrint-manualPrint-wrap">
  3. <view class="batchPrint-manualPrint-body">
  4. <u-alert-tips :show="show" @close="show = false" type="warning" description="正在打印中,请勿息屏或退出应用!"></u-alert-tips>
  5. <view class="part-list">
  6. <!-- 产品 -->
  7. <productList :list="partList" title="产品列表" ref="productList" noDataText="暂无产品" @allChecked="allCheckedCallback"></productList>
  8. </view>
  9. </view>
  10. <view class="batchPrint-manualPrint-footer">
  11. <view>
  12. <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
  13. </view>
  14. <view>
  15. <kk-printer ref="kkprinter" defaultText="开始打印" @startPrint="startPrint"></kk-printer>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import kkPrinter from '@/components/kk-printer/index.vue';
  22. import productList from './productList.vue'
  23. import {printTempl} from '@/libs/printTools.js'
  24. export default {
  25. components: { productList, kkPrinter },
  26. data() {
  27. return {
  28. show: false,
  29. basicInfoData:null,
  30. partList: [],
  31. allChecked: false,
  32. printIndex: 0,
  33. isParinting: false
  34. }
  35. },
  36. onReady() {
  37. uni.setNavigationBarColor({
  38. frontColor: '#ffffff',
  39. backgroundColor: this.$config('primaryColor')
  40. })
  41. this.$refs.productList.setData(this.partList)
  42. },
  43. onLoad(option) {
  44. this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
  45. this.partList = this.basicInfoData.list
  46. // 保持屏幕常亮
  47. uni.setKeepScreenOn({
  48. keepScreenOn: true
  49. });
  50. },
  51. onUnload() {
  52. // this.$refs.kkprinter.closeConnect()
  53. this.partList = []
  54. // 保持屏幕常亮
  55. uni.setKeepScreenOn({
  56. keepScreenOn: false
  57. });
  58. },
  59. onBackPress(event){
  60. if(event.from == 'backbutton'){
  61. if(this.isParinting){
  62. uni.showToast({
  63. icon:'none',
  64. title: '正在打印中...'
  65. })
  66. }else{
  67. uni.navigateBack({delta: 1})
  68. }
  69. return true // 阻止默认返回行为(会导致无限循环)
  70. }
  71. },
  72. methods: {
  73. // 全选
  74. allCheckeChange(e){
  75. this.$refs.productList.allSelect(e.value)
  76. },
  77. allCheckedCallback(val){
  78. this.allChecked = val
  79. },
  80. printOnce(opt,tsc,blesdk,data){
  81. const _this = this
  82. const dealer = this.$store.state.vuex_userData
  83. // 60*40 打印模板
  84. const command = printTempl(tsc,{
  85. dealerName: dealer.orgName,
  86. shelfName: data.shelfName || '',
  87. productCode: data.productCode || '',
  88. productName: data.productName || '',
  89. shelfPlaceCode: data.shelfPlaceCode || '',
  90. currentInven: data.printQty,
  91. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  92. printUser: dealer.userNameCN,
  93. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  94. })
  95. // 开始批量打印
  96. blesdk.senBlData(
  97. opt.deviceId,
  98. opt.serviceId,
  99. opt.writeId,
  100. command.getData(),
  101. function(){
  102. const result =_this.$refs.productList.getAllChecked()
  103. _this.printIndex = _this.printIndex + 1
  104. if(_this.printIndex < result.length){
  105. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  106. }else{
  107. _this.printIndex = 0
  108. _this.$refs.kkprinter.onPrintSuccess()
  109. _this.isParinting = false
  110. _this.show = false
  111. }
  112. });
  113. },
  114. // 批量打印
  115. startPrint(opt,tsc,blesdk){
  116. const result =this.$refs.productList.getAllChecked()
  117. console.log(result,result.length)
  118. if(result.length){
  119. if(this.isParinting){
  120. return
  121. }
  122. this.isParinting = true
  123. this.show = true
  124. this.printOnce(opt,tsc,blesdk,result[this.printIndex])
  125. }else{
  126. this.toashMsg("请选择产品!")
  127. this.$refs.kkprinter.onPrintFail()
  128. }
  129. },
  130. }
  131. }
  132. </script>
  133. <style lang="less">
  134. .batchPrint-manualPrint-wrap{
  135. position: relative;
  136. width: 100%;
  137. height: 100%;
  138. overflow: hidden;
  139. padding-bottom: 102upx;
  140. .p-title{
  141. padding: 20rpx;
  142. display: flex;
  143. align-items: center;
  144. color: #222;
  145. font-size: 32rpx;
  146. .shelfName{
  147. width: 80%;
  148. flex-grow: 1;
  149. font-weight: bold;
  150. text{
  151. display: block;
  152. height: 30rpx;
  153. width: 6rpx;
  154. background: #0485F6;
  155. margin-right: 10rpx;
  156. border-radius: 10rpx;
  157. }
  158. }
  159. .btns{
  160. width:100rpx;
  161. text-align: right;
  162. font-size: 28rpx;
  163. }
  164. }
  165. .batchPrint-manualPrint-body{
  166. .part-list{
  167. padding: 10rpx 25rpx;
  168. background-color: #fff;
  169. margin-bottom: 20rpx;
  170. border-radius: 25rpx;
  171. box-shadow: 2rpx 3rpx 5rpx #eee;
  172. }
  173. }
  174. .batchPrint-manualPrint-footer{
  175. padding: 10upx 32upx 12upx;
  176. background-color: #fff;
  177. position: fixed;
  178. left: 0;
  179. bottom: 0;
  180. width: 100%;
  181. box-shadow: 3px 1px 7px #eee;
  182. display: flex;
  183. align-items: center;
  184. justify-content: space-between;
  185. }
  186. }
  187. </style>