batchPrint.vue 5.1 KB

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