batchPrint.vue 6.7 KB

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