manualPrint.vue 5.2 KB

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