123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- <template>
- <view class="batchPrint-manualPrint-wrap">
- <view class="batchPrint-manualPrint-body">
- <view class="part-list">
- <!-- 产品 -->
- <productList :list="partList" title="产品列表" ref="productList" noDataText="暂无产品" @allChecked="allCheckedCallback"></productList>
- </view>
- </view>
- <view class="batchPrint-manualPrint-footer">
- <view>
- <u-checkbox size="40" @change="allCheckeChange" v-model="allChecked" shape="circle">{{allChecked?'取消全选':'全选'}}</u-checkbox>
- </view>
- <view>
- 共 {{partList.length}}产品
- </view>
- <view>
- <kk-printer ref="kkprinter" defaultText="开始打印" @closeConnect="closeConnect" @startPrint="startPrint"></kk-printer>
- </view>
- </view>
- </view>
- </template>
- <script>
- import { clzConfirm, numberToFixed } from '@/libs/tools';
- import kkPrinter from '@/components/kk-printer/index.vue';
- import productList from './productList.vue'
- import {printTempl,printCpclTempl} from '@/libs/printTools.js'
- export default {
- components: { productList, kkPrinter },
- data() {
- return {
- basicInfoData:null,
- partList: [],
- allChecked: false,
- printIndex: 0,
- isParinting: false
- }
- },
- onReady() {
- this.$refs.productList.setData(this.partList)
- setTimeout(()=>{
- uni.hideLoading()
- // 默认全选
- if(this.partList.length){
- this.allCheckeChange({value: true})
- this.allChecked = true
- }
- },Math.floor(this.partList.length * 15))
- },
- onLoad(option) {
- this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
- this.partList = this.$store.state.vuex_tempPrintList
- uni.showLoading({
- title: '正在加载...'
- })
- // 保持屏幕常亮
- uni.setKeepScreenOn({
- keepScreenOn: true
- });
- uni.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: this.$config('primaryColor')
- })
- },
- onUnload() {
- // this.$refs.kkprinter.closeConnect()
- this.partList = []
- // 保持屏幕常亮
- uni.setKeepScreenOn({
- keepScreenOn: false
- });
- this.$store.state.vuex_tempPrintList = []
- },
- onBackPress(event){
- if(event.from == 'backbutton'){
- if(this.isParinting){
- uni.showToast({
- icon:'none',
- title: '正在打印中...'
- })
- }else{
- uni.navigateBack({delta: 1})
- }
- return true // 阻止默认返回行为(会导致无限循环)
- }
- },
- methods: {
- // 全选
- allCheckeChange(e){
- this.$refs.productList.allSelect(e.value)
- },
- allCheckedCallback(val){
- this.allChecked = val
- },
- printOnce(opt,cmd,blesdk,data){
- const _this = this
- const dealer = this.$store.state.vuex_userData
- const paramsData = {
- dealerName: dealer.orgName,
- shelfName: data.shelfName || '',
- productCode: data.productCode || '',
- productName: data.productName || '',
- shelfPlaceCode: data.shelfPlaceCode || '',
- currentInven: data.printQty,
- printDate: this.$u.timeFormat(this.timestamp, 'yyyy-mm-dd hh:MM'),
- printUser: dealer.userNameCN,
- barCode: `${data.shelfSn}&${data.productCode}&${data.productSn}&${data.shelfPlaceSn}`
- }
- const onPrintSuccess = function(){
- const result =_this.$refs.productList.getAllChecked()
- _this.printIndex = _this.printIndex + 1
- if(_this.printIndex < result.length){
- _this.printOnce(opt,cmd,blesdk,result[_this.printIndex])
- }else{
- _this.printIndex = 0
- _this.$refs.kkprinter.onPrintSuccess()
- _this.isParinting = false
- uni.hideLoading()
- clzConfirm({
- title: '提示',
- content: '打印已经结束,是否返回上页!',
- success (ret) {
- if (ret.confirm || ret.index == 0) {
- uni.navigateBack()
- }
- }
- })
- }
- }
- // 开始批量打印
- // tsc 指令 // 60*40 打印模板
- console.log(cmd,cmd.type)
- if(cmd.type&&cmd.type=='tsc'){
- const command = printTempl(cmd,paramsData)
- // 开始批量打印
- blesdk.senBlData(
- opt.deviceId,
- opt.serviceId,
- opt.writeId,
- command.getData(),
- onPrintSuccess
- );
- }else{
- const resultData = printCpclTempl(cmd,paramsData)
- blesdk.sendDataToDevice({
- deviceId: opt.deviceId,
- serviceId: opt.serviceId,
- characteristicId: opt.writeId,
- value: resultData,
- lasterSuccess: onPrintSuccess,
- lasterError: this.onPrintError
- });
- }
-
- },
- closeConnect(){
- this.isParinting = false
- uni.hideLoading()
- },
- onPrintError(){
- this.$refs.kkprinter.onPrintFail()
- this.isParinting = false
- this.show = false
- uni.showToast({
- title: '打印失败,请重试!'
- })
- },
- // 批量打印
- startPrint(opt,cmd,blesdk){
- const result =this.$refs.productList.getAllChecked()
- console.log(result,result.length)
- if(result.length){
- if(this.isParinting){
- return
- }
- this.isParinting = true
- uni.showLoading({
- mask: true,
- title: '正在打印中,请勿息屏或退出应用!'
- })
- this.printOnce(opt,cmd,blesdk,result[this.printIndex])
- }else{
- this.toashMsg("请选择产品!")
- this.$refs.kkprinter.onPrintFail()
- }
- },
- }
- }
- </script>
- <style lang="less">
- .batchPrint-manualPrint-wrap{
- position: relative;
- width: 100%;
- height: 100%;
- overflow: hidden;
- padding-bottom: 102upx;
- .p-title{
- padding: 20rpx;
- display: flex;
- align-items: center;
- color: #222;
- font-size: 32rpx;
- .shelfName{
- width: 80%;
- flex-grow: 1;
- font-weight: bold;
- text{
- display: block;
- height: 30rpx;
- width: 6rpx;
- background: #0485F6;
- margin-right: 10rpx;
- border-radius: 10rpx;
- }
- }
- .btns{
- width:100rpx;
- text-align: right;
- font-size: 28rpx;
- }
- }
- .batchPrint-manualPrint-body{
- .part-list{
- padding: 10rpx 25rpx;
- background-color: #fff;
- margin-bottom: 20rpx;
- border-radius: 25rpx;
- box-shadow: 2rpx 3rpx 5rpx #eee;
- }
- }
- .batchPrint-manualPrint-footer{
- padding: 10upx 32upx 12upx;
- background-color: #fff;
- position: fixed;
- left: 0;
- bottom: 0;
- width: 100%;
- box-shadow: 3px 1px 7px #eee;
- display: flex;
- align-items: center;
- justify-content: space-between;
- }
- }
- </style>
|