batchPrint.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <view class="batchPrint-manualPrint-wrap" :style="{'padding-top':type=='search'?'100rpx':'0'}">
  3. <view v-if="type=='search'" class="productList-search">
  4. <view class="search flex align_center">
  5. <view class="input">
  6. <u-search
  7. focus
  8. v-model="queryWord"
  9. @input="$u.debounce(searchList, 800)"
  10. @custom="$u.debounce(searchList, 500)"
  11. @search="$u.debounce(searchList, 500)"
  12. @clear="clearSearch"
  13. bg-color="#fff"
  14. :show-action="false"
  15. placeholder="请输入产品编码查询"></u-search>
  16. </view>
  17. </view>
  18. </view>
  19. <view class="batchPrint-manualPrint-body">
  20. <view class="part-list">
  21. <!-- 产品 -->
  22. <productList :list="partList" title="产品列表" ref="productList" noDataText="暂无产品" @allChecked="allCheckedCallback"></productList>
  23. </view>
  24. </view>
  25. <view class="batchPrint-manualPrint-footer">
  26. <view>
  27. <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
  28. </view>
  29. <view>
  30. </view>
  31. <view>
  32. <kk-printer ref="kkprinter" defaultText="开始打印" @startPrint="startPrint"></kk-printer>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. import { clzConfirm, numberToFixed } from '@/libs/tools';
  39. import kkPrinter from '@/components/kk-printer/index.vue';
  40. import productList from './productList.vue'
  41. import {printTempl} from '@/libs/printTools.js'
  42. export default {
  43. components: { productList, kkPrinter },
  44. data() {
  45. return {
  46. show: false,
  47. basicInfoData:null,
  48. partList: [],
  49. allList:[],
  50. allChecked: false,
  51. printIndex: 0,
  52. isParinting: false,
  53. type: '',
  54. queryWord: ''
  55. }
  56. },
  57. onReady() {
  58. if(this.type == 'manual'){
  59. uni.showLoading({
  60. title: '正在加载...'
  61. })
  62. this.$refs.productList.setData(this.partList)
  63. setTimeout(()=>{
  64. uni.hideLoading()
  65. this.allCheckeChange({value:true})
  66. this.allChecked = true
  67. },3000)
  68. }
  69. },
  70. onLoad(option) {
  71. this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
  72. this.type = option.type
  73. // 批量打印
  74. if(this.type == 'manual'){
  75. this.partList = this.$store.state.vuex_tempPrintList
  76. }else{
  77. this.allList = this.$store.state.vuex_tempPrintList
  78. }
  79. // 保持屏幕常亮
  80. uni.setKeepScreenOn({
  81. keepScreenOn: true
  82. });
  83. uni.setNavigationBarColor({
  84. frontColor: '#ffffff',
  85. backgroundColor: this.$config('primaryColor')
  86. })
  87. uni.setNavigationBarTitle({
  88. title: this.type == 'search' ? '按编码搜索打印' : '批量打印——'+this.basicInfoData.layer+'层'
  89. })
  90. },
  91. onUnload() {
  92. this.partList = []
  93. // 保持屏幕常亮
  94. uni.setKeepScreenOn({
  95. keepScreenOn: false
  96. });
  97. this.$store.state.vuex_tempPrintList = []
  98. },
  99. onBackPress(event){
  100. if(event.from == 'backbutton'){
  101. if(this.isParinting){
  102. uni.showToast({
  103. icon:'none',
  104. title: '正在打印中...'
  105. })
  106. }else{
  107. uni.navigateBack({delta: 1})
  108. }
  109. return true // 阻止默认返回行为(会导致无限循环)
  110. }
  111. },
  112. methods: {
  113. searchList(e){
  114. if(this.queryWord == ''){
  115. this.clearSearch()
  116. return
  117. }
  118. uni.showLoading({
  119. mask: true,
  120. title: "正在搜索..."
  121. })
  122. this.partList = []
  123. // 搜索
  124. for(let key in this.allList){
  125. const item = this.allList[key]
  126. const ret = item.filter(a => a.productCode.indexOf(this.queryWord)>=0)
  127. this.partList = this.partList.concat(ret)
  128. }
  129. this.$refs.productList.setData(this.partList)
  130. setTimeout(()=>{
  131. uni.hideLoading()
  132. },1000)
  133. },
  134. clearSearch(){
  135. this.partList = []
  136. this.$refs.productList.setData(this.partList)
  137. },
  138. // 全选
  139. allCheckeChange(e){
  140. this.$refs.productList.allSelect(e.value)
  141. },
  142. allCheckedCallback(val){
  143. this.allChecked = val
  144. },
  145. printOnce(opt,tsc,blesdk,data){
  146. const _this = this
  147. const dealer = this.$store.state.vuex_userData
  148. // 60*40 打印模板
  149. const command = printTempl(tsc,{
  150. dealerName: dealer.orgName,
  151. shelfName: data.shelfName || '',
  152. productCode: data.productCode || '',
  153. productName: data.product.productName|| '',
  154. shelfPlaceCode: data.shelfPlaceCode || '',
  155. currentInven: data.printQty,
  156. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  157. printUser: dealer.userNameCN,
  158. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  159. })
  160. // 开始批量打印
  161. blesdk.senBlData(
  162. opt.deviceId,
  163. opt.serviceId,
  164. opt.writeId,
  165. command.getData(),
  166. function(){
  167. const result =_this.$refs.productList.getAllChecked()
  168. _this.printIndex = _this.printIndex + 1
  169. if(_this.printIndex < result.length){
  170. _this.printOnce(opt,tsc,blesdk,result[_this.printIndex])
  171. }else{
  172. _this.printIndex = 0
  173. _this.$refs.kkprinter.onPrintSuccess()
  174. _this.isParinting = false
  175. uni.hideLoading()
  176. clzConfirm({
  177. title: '提示',
  178. content: '打印已经结束,是否返回上页!',
  179. success (ret) {
  180. if (ret.confirm || ret.index == 0) {
  181. uni.navigateBack()
  182. }
  183. }
  184. })
  185. }
  186. });
  187. },
  188. // 批量打印
  189. startPrint(opt,tsc,blesdk){
  190. const result =this.$refs.productList.getAllChecked()
  191. console.log(result,result.length)
  192. if(result.length){
  193. if(this.isParinting){
  194. return
  195. }
  196. this.isParinting = true
  197. uni.showLoading({
  198. mask: true,
  199. title: '正在打印中,请勿息屏或退出应用!'
  200. })
  201. this.printOnce(opt,tsc,blesdk,result[this.printIndex])
  202. }else{
  203. this.toashMsg("请选择产品!")
  204. this.$refs.kkprinter.onPrintFail()
  205. }
  206. },
  207. }
  208. }
  209. </script>
  210. <style lang="less">
  211. .batchPrint-manualPrint-wrap{
  212. width: 100%;
  213. height: 100%;
  214. overflow: hidden;
  215. padding-bottom: 102upx;
  216. .productList-search{
  217. padding: 20rpx 30rpx;
  218. background-color: #fff;
  219. position: fixed;
  220. left: 0;
  221. top: 0;
  222. width: 100%;
  223. display: flex;
  224. z-index: 100;
  225. .search{
  226. padding: 0.1rem;
  227. border-radius: 50rpx;
  228. border:0.1rpx solid #eee;
  229. width: 100%;
  230. .input{
  231. flex-grow: 1;
  232. padding: 0.1rpx;
  233. }
  234. .icon{
  235. width: 13%;
  236. text-align: center;
  237. font-size: 46rpx;
  238. color: #999;
  239. }
  240. }
  241. }
  242. .batchPrint-manualPrint-body{
  243. .part-list{
  244. padding: 10rpx 25rpx;
  245. background-color: #fff;
  246. margin-bottom: 20rpx;
  247. border-radius: 25rpx;
  248. box-shadow: 2rpx 3rpx 5rpx #eee;
  249. }
  250. }
  251. .batchPrint-manualPrint-footer{
  252. padding: 10upx 32upx 12upx;
  253. background-color: #fff;
  254. position: fixed;
  255. left: 0;
  256. bottom: 0;
  257. width: 100%;
  258. box-shadow: 3px 1px 7px #eee;
  259. display: flex;
  260. align-items: center;
  261. justify-content: space-between;
  262. z-index: 1000;
  263. }
  264. }
  265. </style>