printTag.vue 7.8 KB

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