manualPrint.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. const paramsData = {
  120. dealerName: dealer.orgName,
  121. shelfName: this.basicInfoData.shelfInfo.shelfName || '',
  122. productCode: data.productCode || '',
  123. productName: data.product.name || '',
  124. shelfPlaceCode: data.shelfPlaceCode || '',
  125. currentInven: data.printQty,
  126. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  127. printUser: dealer.userNameCN,
  128. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  129. // barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
  130. }
  131. // 打印成功后函数
  132. const onPrintSuccess = function(){
  133. const result =_this.$refs.partList.getAllChecked()
  134. _this.printIndex = _this.printIndex + 1
  135. if(_this.printIndex < result.length){
  136. _this.printOnce(opt,cmd,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. // tsc 指令
  154. console.log(cmd,cmd.type)
  155. if(cmd.type&&cmd.type=='tsc'){
  156. const command = printTempl(cmd,paramsData)
  157. // 开始批量打印
  158. blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
  159. }else{
  160. const resultData = printCpclTempl(cmd,paramsData)
  161. blesdk.sendDataToDevice({
  162. deviceId: opt.deviceId,
  163. serviceId: opt.serviceId,
  164. characteristicId: opt.writeId,
  165. value: resultData,
  166. lasterSuccess: onPrintSuccess,
  167. lasterError: this.onPrintError
  168. });
  169. }
  170. },
  171. closeConnect(){
  172. this.isParinting = false
  173. uni.hideLoading()
  174. },
  175. onPrintError(){
  176. this.$refs.kkprinter.onPrintFail()
  177. this.isParinting = false
  178. this.show = false
  179. uni.showToast({
  180. title: '打印失败,请重试!'
  181. })
  182. },
  183. // 批量打印
  184. startPrint(opt,cmd,blesdk){
  185. const result =this.$refs.partList.getAllChecked()
  186. if(result.length){
  187. if(this.isParinting){
  188. return
  189. }
  190. this.isParinting = true
  191. uni.showLoading({
  192. mask: true,
  193. title: '正在打印中,请勿息屏或退出应用!'
  194. })
  195. this.printOnce(opt,cmd,blesdk,result[this.printIndex])
  196. }else{
  197. this.toashMsg("请选择产品!")
  198. this.$refs.kkprinter.onPrintFail()
  199. }
  200. },
  201. }
  202. }
  203. </script>
  204. <style lang="less">
  205. .replenishment-manualPrint-wrap{
  206. position: relative;
  207. width: 100%;
  208. height: 100%;
  209. overflow: hidden;
  210. padding-bottom: 102upx;
  211. .replenishment-manualPrint-body{
  212. .part-list{
  213. padding: 10rpx 25rpx;
  214. background-color: #fff;
  215. margin-bottom: 20rpx;
  216. border-radius: 25rpx;
  217. box-shadow: 2rpx 3rpx 5rpx #eee;
  218. }
  219. }
  220. .replenishment-manualPrint-footer{
  221. padding: 10upx 32upx 12upx;
  222. background-color: #fff;
  223. position: fixed;
  224. left: 0;
  225. bottom: 0;
  226. width: 100%;
  227. box-shadow: 3px 1px 7px #eee;
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-between;
  231. }
  232. }
  233. </style>