printTag.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="printTag">
  3. <u-alert-tips :show="show" @close="show = false" type="warning" description="正在打印中,请勿息屏或退出应用!"></u-alert-tips>
  4. <view class="print-nums flex flex_column align_center justify_center">
  5. <view>打印数量</view>
  6. <view class="u-ninput">
  7. <u-number-box :min="1" v-model="printNum" color="#000" bg-color="#fff" size="30" :input-height="70" :input-width="100"></u-number-box>
  8. </view>
  9. </view>
  10. <view class="shelf-info">
  11. <view class="shelf-info-title">
  12. <view class="shelf-name">{{infoData&&infoData.shelfName || '--'}}</view>
  13. <view class="pno">{{infoData&&infoData.shelfPlaceCode}}</view>
  14. </view>
  15. <view>产品编码:{{fromPage == 'smdy'?infoData.productCode : infoData.productEntity&&infoData.productEntity.code}}</view>
  16. <view>产品名称:{{fromPage == 'smdy'?infoData.productName : infoData.productEntity&&infoData.productEntity.productName}}</view>
  17. <view>{{fromPage == 'smdy'?'实发':'库存'}}数量:{{fromPage == 'smdy'?infoData.confirmQty : infoData.qty}}</view>
  18. </view>
  19. <view class="buttons flex align_center justify_center">
  20. <view v-if="fromPage == 'bdtq'"><u-button @click="cancel" shape="circle" plain>返回列表</u-button></view>
  21. <view v-if="fromPage == 'smdy'"><u-button @click="cancel" shape="circle" plain>重新扫描</u-button></view>
  22. <view>
  23. <kk-printer ref="kkprinter" @startPrint="startPrint"></kk-printer>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { shelfDetail } from '@/api/shelf'
  30. import kkPrinter from '@/components/kk-printer/index.vue';
  31. import {printTempl} from '@/libs/printTools.js'
  32. import moment from 'moment'
  33. export default {
  34. components:{
  35. kkPrinter
  36. },
  37. data() {
  38. return {
  39. show: false,
  40. infoData: null,
  41. fromPage: '',
  42. printInfo: null,
  43. printNum: 0,
  44. isParinting: false
  45. }
  46. },
  47. onLoad(options) {
  48. const _this = this
  49. _this.fromPage = options.page
  50. _this.infoData = options.data ? JSON.parse(options.data) : {},
  51. _this.printNum = _this.fromPage == 'smdy' ? _this.infoData.confirmQty : _this.infoData.qty
  52. _this.printNum = _this.printNum||1
  53. console.log(_this.infoData)
  54. // 保持屏幕常亮
  55. uni.setKeepScreenOn({
  56. keepScreenOn: true
  57. });
  58. },
  59. onUnload() {
  60. // this.$refs.kkprinter.closeConnect()
  61. this.printNum = 1
  62. this.infoData = null
  63. this.printInfo = null
  64. this.fromPage = ''
  65. // 保持屏幕常亮
  66. uni.setKeepScreenOn({
  67. keepScreenOn: false
  68. });
  69. },
  70. // 监听页面返回,返回 event = {from:backbutton、 navigateBack} ,backbutton 表示来源是左上角返回按钮或 android 返回键;navigateBack表示来源是 uni.navigateBack
  71. onBackPress(event){
  72. if(event.from == 'backbutton'){
  73. if(this.isParinting){
  74. uni.showToast({
  75. icon:'none',
  76. title: '正在打印中...'
  77. })
  78. }else{
  79. this.cancel()
  80. }
  81. return true // 阻止默认返回行为(会导致无限循环)
  82. }
  83. },
  84. methods: {
  85. cancel(){
  86. if(this.fromPage == 'bdtq'){ // 补打贴签
  87. uni.navigateBack({delta: 1})
  88. }else if(this.fromPage == 'smdy'){ // 扫码打印
  89. uni.$emit('refreshBL')
  90. uni.navigateBack({delta: 1})
  91. }
  92. },
  93. // 获取打印内容
  94. getPrintContent(){
  95. const _this = this
  96. const nowDate = moment().format('YYYY-MM-DD HH:mm')
  97. if(_this.fromPage == 'bdtq'){
  98. _this.printInfo = {
  99. dealerName: _this.$store.state.vuex_userData.orgName,
  100. shelfName: _this.infoData.shelfName || '',
  101. productCode: _this.infoData.productEntity&&_this.infoData.productEntity.code || '',
  102. productName: _this.infoData.productEntity&&_this.infoData.productEntity.productName || '',
  103. shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
  104. currentInven: _this.printNum,
  105. printDate: nowDate,
  106. printUser: _this.$store.state.vuex_userData.userNameCN,
  107. barCode: `${_this.infoData.shelfSn}&${_this.infoData.productEntity&&_this.infoData.productEntity.code}&${_this.infoData.productEntity&&_this.infoData.productEntity.productSn}&${_this.infoData.shelfPlaceSn}`
  108. // barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productEntity&&_this.infoData.productEntity.productSn}&productCode=${_this.infoData.productEntity&&_this.infoData.productEntity.code}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
  109. }
  110. }else if(_this.fromPage == 'smdy'){
  111. _this.printInfo = {
  112. dealerName: _this.$store.state.vuex_userData.orgName,
  113. shelfName: _this.infoData.shelfName || '',
  114. productCode: _this.infoData.productCode || '',
  115. productName: _this.infoData.productName || '',
  116. shelfPlaceCode: _this.infoData.shelfPlaceCode || '',
  117. currentInven: _this.printNum,
  118. printDate: nowDate,
  119. printUser: _this.$store.state.vuex_userData.userNameCN,
  120. barCode: `${_this.infoData.shelfSn}&${_this.infoData.productCode}&${_this.infoData.productSn}&${_this.infoData.shelfPlaceSn}`
  121. // barCode: `dealerSn=${_this.$store.state.vuex_userData.orgSn}&shelfSn=${_this.infoData.shelfSn}&productSn=${_this.infoData.productSn}&productCode=${_this.infoData.productCode}&shelfPlaceCode=${_this.infoData.shelfPlaceCode}&shelfPlaceSn=${_this.infoData.shelfPlaceSn}`
  122. }
  123. }
  124. console.log('printInfo-----------',_this.printInfo)
  125. },
  126. // 打印
  127. startPrint(opt,tsc,blesdk){
  128. console.log(opt,'opt')
  129. this.getPrintContent()
  130. if(this.printInfo.currentInven<=0){
  131. uni.showToast({
  132. icon:"none",
  133. title: "请选择打印数量"
  134. })
  135. this.$refs.kkprinter.onPrintFail()
  136. return
  137. }
  138. if(this.isParinting){
  139. return
  140. }
  141. this.isParinting = true
  142. this.show = true
  143. const command = printTempl(tsc,this.printInfo)
  144. blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), this.onPrintSuccess);
  145. },
  146. // 打印成功
  147. onPrintSuccess(){
  148. this.$refs.kkprinter.onPrintSuccess()
  149. this.isParinting = false
  150. this.show = false
  151. }
  152. }
  153. }
  154. </script>
  155. <style lang="less">
  156. .printTag{
  157. background-color: #fff;
  158. width: 100vh;
  159. padding: 50rpx 30rpx;
  160. .print-nums{
  161. padding: 50rpx 30rpx;
  162. color: #999;
  163. font-size: 32rpx;
  164. > view{
  165. padding: 20rpx 0;
  166. }
  167. .u-ninput{
  168. border: 2rpx solid #eee;
  169. border-radius: 50rpx;
  170. padding: 0 12rpx;
  171. }
  172. /deep/ .u-icon-disabled{
  173. background: #fff!important;
  174. }
  175. /deep/ .u-number-input{
  176. margin: 0 2rpx;
  177. border: 2rpx solid #eee;
  178. border-top: 0;
  179. border-bottom: 0;
  180. }
  181. /deep/ .u-icon-plus, /deep/ .u-icon-minus{
  182. border-radius: 50rpx;
  183. }
  184. }
  185. .shelf-info{
  186. background-color: #f8f8f8;
  187. padding: 30rpx;
  188. border-radius: 12rpx;
  189. color: #707070;
  190. .shelf-info-title{
  191. font-size: 30rpx;
  192. color: #222222;
  193. display: flex;
  194. justify-content: space-between;
  195. margin-bottom: 10rpx;
  196. .shelf-name{
  197. flex:1;
  198. margin-right: 10rpx;
  199. }
  200. .pno{
  201. background: rgba(3, 54, 146, 0.15);
  202. border-radius: 100rpx;
  203. padding: 0 20rpx;
  204. color: #033692;
  205. font-size: 26rpx;
  206. height: 40rpx;
  207. margin-top:5rpx;
  208. }
  209. }
  210. }
  211. .buttons{
  212. padding: 50rpx 0;
  213. > view{
  214. width: 36%;
  215. margin: 0 2%;
  216. }
  217. }
  218. }
  219. </style>