batchPrint.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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,printCpclTempl} 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,cmd,blesdk,data){
  145. const _this = this
  146. const dealer = this.$store.state.vuex_userData
  147. const paramsData = {
  148. dealerName: dealer.orgName,
  149. shelfName: this.basicInfoData.shelfName || '',
  150. productCode: data.productCode || '',
  151. productName: data.product.productName|| '',
  152. shelfPlaceCode: data.shelfPlaceCode || '',
  153. currentInven: data.printQty,
  154. printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
  155. printUser: dealer.userNameCN,
  156. barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
  157. }
  158. // 打印成功后函数
  159. const onPrintSuccess = function(){
  160. const result =_this.$refs.productList.getAllChecked()
  161. _this.printIndex = _this.printIndex + 1
  162. if(_this.printIndex < result.length){
  163. _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
  164. }else{
  165. _this.printIndex = 0
  166. _this.$refs.kkprinter.onPrintSuccess()
  167. _this.isParinting = false
  168. uni.hideLoading()
  169. clzConfirm({
  170. title: '提示',
  171. content: '打印已经结束,是否返回上页!',
  172. success (ret) {
  173. if (ret.confirm || ret.index == 0) {
  174. uni.navigateBack()
  175. }
  176. }
  177. })
  178. }
  179. }
  180. // 开始批量打印
  181. // tsc 指令 // 60*40 打印模板
  182. console.log(cmd,cmd.type)
  183. if(cmd.type&&cmd.type=='tsc'){
  184. const command = printTempl(cmd,paramsData)
  185. blesdk.senBlData(opt.deviceId, opt.serviceId, opt.writeId, command.getData(), onPrintSuccess, this.onPrintError);
  186. }else{
  187. const resultData = printCpclTempl(cmd,paramsData)
  188. blesdk.sendDataToDevice({
  189. deviceId: opt.deviceId,
  190. serviceId: opt.serviceId,
  191. characteristicId: opt.writeId,
  192. value: resultData,
  193. lasterSuccess: onPrintSuccess,
  194. lasterError: this.onPrintError
  195. });
  196. }
  197. },
  198. closeConnect(){
  199. this.isParinting = false
  200. uni.hideLoading()
  201. },
  202. onPrintError(){
  203. this.$refs.kkprinter.onPrintFail()
  204. this.isParinting = false
  205. this.show = false
  206. uni.showToast({
  207. title: '打印失败,请重试!'
  208. })
  209. },
  210. // 批量打印
  211. startPrint(opt,cmd,blesdk){
  212. const result =this.$refs.productList.getAllChecked()
  213. console.log(result,result.length)
  214. if(result.length){
  215. if(this.isParinting){
  216. return
  217. }
  218. this.isParinting = true
  219. uni.showLoading({
  220. mask: true,
  221. title: '正在打印中,请勿息屏或退出应用!'
  222. })
  223. this.printOnce(opt,cmd,blesdk,result[this.printIndex])
  224. }else{
  225. this.toashMsg("请选择产品!")
  226. this.$refs.kkprinter.onPrintFail()
  227. }
  228. },
  229. }
  230. }
  231. </script>
  232. <style lang="less">
  233. .batchPrint-manualPrint-wrap{
  234. width: 100%;
  235. height: 100%;
  236. overflow: hidden;
  237. padding-bottom: 102upx;
  238. .productList-search{
  239. padding: 20rpx 30rpx;
  240. background-color: #fff;
  241. position: fixed;
  242. left: 0;
  243. top: 0;
  244. width: 100%;
  245. display: flex;
  246. z-index: 100;
  247. .search{
  248. padding: 0.1rem;
  249. border-radius: 50rpx;
  250. border:1rpx solid #eee;
  251. width: 100%;
  252. .input{
  253. flex-grow: 1;
  254. padding: 4rpx;
  255. }
  256. .icon{
  257. width: 13%;
  258. text-align: center;
  259. font-size: 46rpx;
  260. color: #999;
  261. }
  262. }
  263. }
  264. .batchPrint-manualPrint-body{
  265. .part-list{
  266. padding: 10rpx 25rpx;
  267. background-color: #fff;
  268. margin-bottom: 20rpx;
  269. border-radius: 25rpx;
  270. box-shadow: 2rpx 3rpx 5rpx #eee;
  271. }
  272. }
  273. .batchPrint-manualPrint-footer{
  274. padding: 10upx 32upx 12upx;
  275. background-color: #fff;
  276. position: fixed;
  277. left: 0;
  278. bottom: 0;
  279. width: 100%;
  280. box-shadow: 3px 1px 7px #eee;
  281. display: flex;
  282. align-items: center;
  283. justify-content: space-between;
  284. z-index: 1000;
  285. }
  286. }
  287. </style>