batchPrint.vue 7.5 KB

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