manualPrint.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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,printCpclTempl} 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. if(item.billState == 'FINISH'){
  91. item.confirmQty = item.putQty ? Number(item.putQty) : 0
  92. item.printQty = item.confirmQty ? Number(item.confirmQty) : 0
  93. }else{
  94. item.confirmQty = item.confirmQty ? Number(item.confirmQty) : 0
  95. item.printQty = item.confirmQty ? Number(item.confirmQty) : 0
  96. }
  97. })
  98. this.partList = res.data || []
  99. this.$nextTick(()=>{
  100. this.allCheckeChange({value:true})
  101. this.allChecked = true
  102. })
  103. }else{
  104. this.partList = []
  105. }
  106. })
  107. },
  108. // 全选
  109. allCheckeChange(e){
  110. this.$refs.partList.allSelect(e.value)
  111. },
  112. allCheckedCallback(val){
  113. this.allChecked = val
  114. },
  115. printOnce(opt,cmd,blesdk,data){
  116. const _this = this
  117. // 60*40 打印模板
  118. const dealer = this.$store.state.vuex_userData
  119. let resultData = ''
  120. const paramsData = {
  121. dealerName: dealer.orgName,
  122. shelfName: this.basicInfoData.shelfInfo.shelfName || '',
  123. productCode: data.productCode || '',
  124. productName: data.product.name || '',
  125. shelfPlaceCode: data.shelfPlaceCode || '',
  126. currentInven: data.printQty,
  127. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  128. printUser: dealer.userNameCN,
  129. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  130. // barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
  131. }
  132. // tsc 指令
  133. console.log(cmd,cmd.type)
  134. if(cmd.type&&cmd.type=='tsc'){
  135. const command = printTempl(cmd,paramsData)
  136. resultData = command.getData()
  137. }else{
  138. resultData = cmd.getData(printCpclTempl(cmd,paramsData))
  139. }
  140. // 开始批量打印
  141. blesdk.senBlData(
  142. opt.deviceId,
  143. opt.serviceId,
  144. opt.writeId,
  145. resultData,
  146. function(){
  147. const result =_this.$refs.partList.getAllChecked()
  148. _this.printIndex = _this.printIndex + 1
  149. if(_this.printIndex < result.length){
  150. _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
  151. }else{
  152. _this.printIndex = 0
  153. _this.$refs.kkprinter.onPrintSuccess()
  154. _this.isParinting = false
  155. uni.hideLoading()
  156. clzConfirm({
  157. title: '提示',
  158. content: '打印已经结束,是否返回上页!',
  159. success (ret) {
  160. if (ret.confirm || ret.index == 0) {
  161. uni.navigateBack()
  162. }
  163. }
  164. })
  165. }
  166. });
  167. },
  168. closeConnect(){
  169. this.isParinting = false
  170. uni.hideLoading()
  171. },
  172. // 批量打印
  173. startPrint(opt,cmd,blesdk){
  174. const result =this.$refs.partList.getAllChecked()
  175. if(result.length){
  176. if(this.isParinting){
  177. return
  178. }
  179. this.isParinting = true
  180. uni.showLoading({
  181. mask: true,
  182. title: '正在打印中,请勿息屏或退出应用!'
  183. })
  184. this.printOnce(opt,cmd,blesdk,result[this.printIndex])
  185. }else{
  186. this.toashMsg("请选择产品!")
  187. this.$refs.kkprinter.onPrintFail()
  188. }
  189. },
  190. }
  191. }
  192. </script>
  193. <style lang="less">
  194. .replenishment-manualPrint-wrap{
  195. position: relative;
  196. width: 100%;
  197. height: 100%;
  198. overflow: hidden;
  199. padding-bottom: 102upx;
  200. .replenishment-manualPrint-body{
  201. .part-list{
  202. padding: 10rpx 25rpx;
  203. background-color: #fff;
  204. margin-bottom: 20rpx;
  205. border-radius: 25rpx;
  206. box-shadow: 2rpx 3rpx 5rpx #eee;
  207. }
  208. }
  209. .replenishment-manualPrint-footer{
  210. padding: 10upx 32upx 12upx;
  211. background-color: #fff;
  212. position: fixed;
  213. left: 0;
  214. bottom: 0;
  215. width: 100%;
  216. box-shadow: 3px 1px 7px #eee;
  217. display: flex;
  218. align-items: center;
  219. justify-content: space-between;
  220. }
  221. }
  222. </style>