batchPrint.vue 5.3 KB

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