batchPrint.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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,printCpclTempl} 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. this.$refs.productList.setData(this.partList)
  40. setTimeout(()=>{
  41. uni.hideLoading()
  42. // 默认全选
  43. if(this.partList.length){
  44. this.allCheckeChange({value: true})
  45. this.allChecked = true
  46. }
  47. },Math.floor(this.partList.length * 15))
  48. },
  49. onLoad(option) {
  50. this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
  51. this.partList = this.$store.state.vuex_tempPrintList
  52. uni.showLoading({
  53. title: '正在加载...'
  54. })
  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,cmd,blesdk,data){
  95. const _this = this
  96. const dealer = this.$store.state.vuex_userData
  97. const paramsData = {
  98. dealerName: dealer.orgName,
  99. shelfName: data.shelfName || '',
  100. productCode: data.productCode || '',
  101. productName: data.productName || '',
  102. shelfPlaceCode: data.shelfPlaceCode || '',
  103. currentInven: data.printQty,
  104. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  105. printUser: dealer.userNameCN,
  106. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  107. }
  108. const onPrintSuccess = function(){
  109. const result =_this.$refs.productList.getAllChecked()
  110. _this.printIndex = _this.printIndex + 1
  111. if(_this.printIndex < result.length){
  112. _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
  113. }else{
  114. _this.printIndex = 0
  115. _this.$refs.kkprinter.onPrintSuccess()
  116. _this.isParinting = false
  117. uni.hideLoading()
  118. clzConfirm({
  119. title: '提示',
  120. content: '打印已经结束,是否返回上页!',
  121. success (ret) {
  122. if (ret.confirm || ret.index == 0) {
  123. uni.navigateBack()
  124. }
  125. }
  126. })
  127. }
  128. }
  129. // 开始批量打印
  130. // tsc 指令 // 60*40 打印模板
  131. console.log(cmd,cmd.type)
  132. if(cmd.type&&cmd.type=='tsc'){
  133. const command = printTempl(cmd,paramsData)
  134. // 开始批量打印
  135. blesdk.senBlData(
  136. opt.deviceId,
  137. opt.serviceId,
  138. opt.writeId,
  139. command.getData(),
  140. onPrintSuccess
  141. );
  142. }else{
  143. const resultData = printCpclTempl(cmd,paramsData)
  144. blesdk.sendDataToDevice({
  145. deviceId: opt.deviceId,
  146. serviceId: opt.serviceId,
  147. characteristicId: opt.writeId,
  148. value: resultData,
  149. lasterSuccess: onPrintSuccess,
  150. lasterError: this.onPrintError
  151. });
  152. }
  153. },
  154. closeConnect(){
  155. this.isParinting = false
  156. uni.hideLoading()
  157. },
  158. onPrintError(){
  159. this.$refs.kkprinter.onPrintFail()
  160. this.isParinting = false
  161. this.show = false
  162. uni.showToast({
  163. title: '打印失败,请重试!'
  164. })
  165. },
  166. // 批量打印
  167. startPrint(opt,cmd,blesdk){
  168. const result =this.$refs.productList.getAllChecked()
  169. console.log(result,result.length)
  170. if(result.length){
  171. if(this.isParinting){
  172. return
  173. }
  174. this.isParinting = true
  175. uni.showLoading({
  176. mask: true,
  177. title: '正在打印中,请勿息屏或退出应用!'
  178. })
  179. this.printOnce(opt,cmd,blesdk,result[this.printIndex])
  180. }else{
  181. this.toashMsg("请选择产品!")
  182. this.$refs.kkprinter.onPrintFail()
  183. }
  184. },
  185. }
  186. }
  187. </script>
  188. <style lang="less">
  189. .batchPrint-manualPrint-wrap{
  190. position: relative;
  191. width: 100%;
  192. height: 100%;
  193. overflow: hidden;
  194. padding-bottom: 102upx;
  195. .p-title{
  196. padding: 20rpx;
  197. display: flex;
  198. align-items: center;
  199. color: #222;
  200. font-size: 32rpx;
  201. .shelfName{
  202. width: 80%;
  203. flex-grow: 1;
  204. font-weight: bold;
  205. text{
  206. display: block;
  207. height: 30rpx;
  208. width: 6rpx;
  209. background: #0485F6;
  210. margin-right: 10rpx;
  211. border-radius: 10rpx;
  212. }
  213. }
  214. .btns{
  215. width:100rpx;
  216. text-align: right;
  217. font-size: 28rpx;
  218. }
  219. }
  220. .batchPrint-manualPrint-body{
  221. .part-list{
  222. padding: 10rpx 25rpx;
  223. background-color: #fff;
  224. margin-bottom: 20rpx;
  225. border-radius: 25rpx;
  226. box-shadow: 2rpx 3rpx 5rpx #eee;
  227. }
  228. }
  229. .batchPrint-manualPrint-footer{
  230. padding: 10upx 32upx 12upx;
  231. background-color: #fff;
  232. position: fixed;
  233. left: 0;
  234. bottom: 0;
  235. width: 100%;
  236. box-shadow: 3px 1px 7px #eee;
  237. display: flex;
  238. align-items: center;
  239. justify-content: space-between;
  240. }
  241. }
  242. </style>