manualPrint.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <view class="replenishment-manualPrint-wrap">
  3. <view class="replenishment-manualPrint-body">
  4. <view class="part-list">
  5. <!-- 补货产品 -->
  6. <partList :list="partList" title="补货产品" model="checkbox" fromPage="manualPrint" ref="partList" noDataText="暂无产品" @allChecked="allCheckedCallback"></partList>
  7. </view>
  8. </view>
  9. <view class="replenishment-manualPrint-footer">
  10. <view>
  11. <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
  12. </view>
  13. <view>
  14. <kk-printer @closeConnect="closeConnect" ref="kkprinter" defaultText="开始打印" @startPrint="startPrint"></kk-printer>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. import { clzConfirm, numberToFixed } from '@/libs/tools';
  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. this.$nextTick(()=>{
  95. this.allCheckeChange({value:true})
  96. this.allChecked = true
  97. })
  98. }else{
  99. this.partList = []
  100. }
  101. })
  102. },
  103. // 全选
  104. allCheckeChange(e){
  105. this.$refs.partList.allSelect(e.value)
  106. },
  107. allCheckedCallback(val){
  108. this.allChecked = val
  109. },
  110. printOnce(opt,tsc,blesdk,data){
  111. const _this = this
  112. const dealer = this.$store.state.vuex_userData
  113. // 60*40 打印模板
  114. const command = printTempl(tsc,{
  115. dealerName: dealer.orgName,
  116. shelfName: this.basicInfoData.shelfInfo.shelfName || '',
  117. productCode: data.productCode || '',
  118. productName: data.product.name || '',
  119. shelfPlaceCode: data.shelfPlaceCode || '',
  120. currentInven: data.printQty,
  121. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  122. printUser: dealer.userNameCN,
  123. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  124. // barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
  125. })
  126. // 开始批量打印
  127. blesdk.senBlData(
  128. opt.deviceId,
  129. opt.serviceId,
  130. opt.writeId,
  131. command.getData(),
  132. function(){
  133. const result =_this.$refs.partList.getAllChecked()
  134. _this.printIndex = _this.printIndex + 1
  135. if(_this.printIndex < result.length){
  136. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  137. }else{
  138. _this.printIndex = 0
  139. _this.$refs.kkprinter.onPrintSuccess()
  140. _this.isParinting = false
  141. uni.hideLoading()
  142. clzConfirm({
  143. title: '提示',
  144. content: '打印已经结束,是否返回上页!',
  145. success (ret) {
  146. if (ret.confirm || ret.index == 0) {
  147. uni.navigateBack()
  148. }
  149. }
  150. })
  151. }
  152. });
  153. },
  154. closeConnect(){
  155. this.isParinting = false
  156. uni.hideLoading()
  157. },
  158. // 批量打印
  159. startPrint(opt,tsc,blesdk){
  160. const result =this.$refs.partList.getAllChecked()
  161. if(result.length){
  162. if(this.isParinting){
  163. return
  164. }
  165. this.isParinting = true
  166. uni.showLoading({
  167. mask: true,
  168. title: '正在打印中,请勿息屏或退出应用!'
  169. })
  170. this.printOnce(opt,tsc,blesdk,result[this.printIndex])
  171. }else{
  172. this.toashMsg("请选择产品!")
  173. this.$refs.kkprinter.onPrintFail()
  174. }
  175. },
  176. }
  177. }
  178. </script>
  179. <style lang="less">
  180. .replenishment-manualPrint-wrap{
  181. position: relative;
  182. width: 100%;
  183. height: 100%;
  184. overflow: hidden;
  185. padding-bottom: 102upx;
  186. .replenishment-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. .replenishment-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>