printTag.vue 6.5 KB

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