manualPrint.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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" :disabled="basicInfoData&&basicInfoData.billState == 'FINISH' && !basicInfoData.totalPutQty" @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. // 保持屏幕常亮
  48. uni.setKeepScreenOn({
  49. keepScreenOn: true
  50. });
  51. },
  52. onUnload() {
  53. // this.$refs.kkprinter.closeConnect()
  54. // 保持屏幕常亮
  55. uni.setKeepScreenOn({
  56. keepScreenOn: false
  57. });
  58. },
  59. onBackPress(event){
  60. if(event.from == 'backbutton'){
  61. if(this.isParinting){
  62. uni.showToast({
  63. icon:'none',
  64. title: '正在打印中...'
  65. })
  66. }else{
  67. uni.navigateBack({delta: 1})
  68. }
  69. return true // 阻止默认返回行为(会导致无限循环)
  70. }
  71. },
  72. methods: {
  73. // 查询详情
  74. getDetail(){
  75. shelfReplenishDetail({ sn: this.replenishBillSn }).then(res => {
  76. if(res.status == 200){
  77. this.basicInfoData = res.data || null
  78. }else{
  79. this.basicInfoData = null
  80. }
  81. this.getPartList()
  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.printQty = item.putQty ? Number(item.putQty) : 0
  92. }else{
  93. item.printQty = item.qty ? Number(item.qty) : 0
  94. }
  95. })
  96. this.partList = res.data || []
  97. this.$nextTick(()=>{
  98. this.allCheckeChange({value:true})
  99. this.allChecked = !(this.basicInfoData&&this.basicInfoData.billState == 'FINISH' && !this.basicInfoData.totalPutQty)
  100. })
  101. }else{
  102. this.partList = []
  103. }
  104. })
  105. },
  106. // 全选
  107. allCheckeChange(e){
  108. this.$refs.partList.allSelect(e.value)
  109. },
  110. allCheckedCallback(val){
  111. this.allChecked = val
  112. },
  113. printOnce(opt,cmd,blesdk,data){
  114. const _this = this
  115. // 60*40 打印模板
  116. const dealer = this.$store.state.vuex_userData
  117. const paramsData = {
  118. dealerName: dealer.orgName,
  119. shelfName: this.basicInfoData.shelfInfo.shelfName || '',
  120. productCode: data.productCode || '',
  121. productName: data.product.name || '',
  122. shelfPlaceCode: data.shelfPlaceCode || '',
  123. currentInven: data.printQty,
  124. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  125. printUser: dealer.userNameCN,
  126. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  127. // barCode: `dealerSn=${dealer.orgSn}&shelfSn=${data.shelfSn}&productSn=${data.productSn}&productCode=${data.productCode}&shelfPlaceCode=${data.shelfPlaceCode}&shelfPlaceSn=${data.shelfPlaceSn}`
  128. }
  129. // 打印成功后函数
  130. const onPrintSuccess = function(){
  131. const result =_this.$refs.partList.getAllChecked()
  132. _this.printIndex = _this.printIndex + 1
  133. if(_this.printIndex < result.length){
  134. _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
  135. }else{
  136. _this.printIndex = 0
  137. _this.$refs.kkprinter.onPrintSuccess()
  138. _this.isParinting = false
  139. uni.hideLoading()
  140. clzConfirm({
  141. title: '提示',
  142. content: '打印已经结束,是否返回上页!',
  143. success (ret) {
  144. if (ret.confirm || ret.index == 0) {
  145. uni.navigateBack()
  146. }
  147. }
  148. })
  149. }
  150. }
  151. // tsc 指令
  152. console.log(cmd,cmd.type)
  153. if(cmd.type&&cmd.type=='tsc'){
  154. const command = printTempl(cmd,paramsData)
  155. // 开始批量打印
  156. blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
  157. }else{
  158. const resultData = printCpclTempl(cmd,paramsData)
  159. blesdk.sendDataToDevice({
  160. deviceId: opt.deviceId,
  161. serviceId: opt.serviceId,
  162. characteristicId: opt.writeId,
  163. value: resultData,
  164. lasterSuccess: onPrintSuccess,
  165. lasterError: this.onPrintError
  166. });
  167. }
  168. },
  169. closeConnect(){
  170. this.isParinting = false
  171. uni.hideLoading()
  172. },
  173. onPrintError(){
  174. this.$refs.kkprinter.onPrintFail()
  175. this.isParinting = false
  176. this.show = false
  177. uni.showToast({
  178. title: '打印失败,请重试!'
  179. })
  180. },
  181. // 批量打印
  182. startPrint(opt,cmd,blesdk){
  183. const result =this.$refs.partList.getAllChecked()
  184. if(result.length){
  185. if(this.isParinting){
  186. return
  187. }
  188. this.isParinting = true
  189. uni.showLoading({
  190. mask: true,
  191. title: '正在打印中,请勿息屏或退出应用!'
  192. })
  193. this.printOnce(opt,cmd,blesdk,result[this.printIndex])
  194. }else{
  195. this.toashMsg("请选择产品!")
  196. this.$refs.kkprinter.onPrintFail()
  197. }
  198. },
  199. }
  200. }
  201. </script>
  202. <style lang="less">
  203. .replenishment-manualPrint-wrap{
  204. position: relative;
  205. width: 100%;
  206. height: 100%;
  207. overflow: hidden;
  208. padding-bottom: 102upx;
  209. .replenishment-manualPrint-body{
  210. .part-list{
  211. padding: 10rpx 25rpx;
  212. background-color: #fff;
  213. margin-bottom: 20rpx;
  214. border-radius: 25rpx;
  215. box-shadow: 2rpx 3rpx 5rpx #eee;
  216. }
  217. }
  218. .replenishment-manualPrint-footer{
  219. padding: 10upx 32upx 12upx;
  220. background-color: #fff;
  221. position: fixed;
  222. left: 0;
  223. bottom: 0;
  224. width: 100%;
  225. box-shadow: 3px 1px 7px #eee;
  226. display: flex;
  227. align-items: center;
  228. justify-content: space-between;
  229. }
  230. }
  231. </style>