batchPrint.vue 5.1 KB

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