123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- <template>
- <view class="batchPrint-manualPrint-wrap" :style="{'padding-top':type=='search'?'100rpx':'0'}">
- <view v-if="type=='search'" class="productList-search">
- <view class="search flex align_center">
- <view class="input">
- <u-search
- v-model="queryWord"
- @input="$u.debounce(searchList, 800)"
- @custom="$u.debounce(searchList, 500)"
- @search="$u.debounce(searchList, 500)"
- @clear="clearSearch"
- bg-color="#fff"
- :show-action="false"
- placeholder="请输入产品编码查询"></u-search>
- </view>
- </view>
- </view>
- <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>
- </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} from '@/libs/printTools.js'
- export default {
- components: { productList, kkPrinter },
- data() {
- return {
- show: false,
- basicInfoData:null,
- partList: [],
- allList:[],
- allChecked: false,
- printIndex: 0,
- isParinting: false,
- type: '',
- queryWord: ''
- }
- },
- onReady() {
- if(this.type == 'manual'){
- uni.showLoading({
- title: '正在加载...'
- })
- this.$refs.productList.setData(this.partList)
- setTimeout(()=>{
- uni.hideLoading()
- this.allCheckeChange({value:true})
- this.allChecked = true
- },3000)
- }
- },
- onLoad(option) {
- this.basicInfoData = JSON.parse(decodeURIComponent(option.data));
- this.type = option.type
- // 批量打印
- if(this.type == 'manual'){
- this.partList = this.$store.state.vuex_tempPrintList
- }else{
- this.allList = this.$store.state.vuex_tempPrintList
- }
- // 保持屏幕常亮
- uni.setKeepScreenOn({
- keepScreenOn: true
- });
- uni.setNavigationBarColor({
- frontColor: '#ffffff',
- backgroundColor: this.$config('primaryColor')
- })
- uni.setNavigationBarTitle({
- title: this.type == 'search' ? '按编码搜索打印' : '批量打印—'+this.basicInfoData.layer+'层'
- })
- },
- onUnload() {
- 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: {
- searchList(e){
- if(this.queryWord == ''){
- this.clearSearch()
- return
- }
-
- uni.showLoading({
- mask: true,
- title: "正在搜索..."
- })
- this.partList = []
- // 搜索
- for(let key in this.allList){
- const item = this.allList[key]
- const ret = item.filter(a => a.productCode.indexOf(this.queryWord)>=0)
- this.partList = this.partList.concat(ret)
- }
- this.$refs.productList.setData(this.partList)
-
- setTimeout(()=>{
- uni.hideLoading()
- },1000)
- },
- clearSearch(){
- this.partList = []
- this.$refs.productList.setData(this.partList)
- },
- // 全选
- allCheckeChange(e){
- this.$refs.productList.allSelect(e.value)
- },
- allCheckedCallback(val){
- this.allChecked = val
- },
- printOnce(opt,tsc,blesdk,data){
- const _this = this
- const dealer = this.$store.state.vuex_userData
- // 60*40 打印模板
- const command = printTempl(tsc,{
- dealerName: dealer.orgName,
- shelfName: data.shelfName || '',
- productCode: data.productCode || '',
- productName: data.product.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}`
- })
- // 开始批量打印
- blesdk.senBlData(
- opt.deviceId,
- opt.serviceId,
- opt.writeId,
- command.getData(),
- function(){
- const result =_this.$refs.productList.getAllChecked()
- _this.printIndex = _this.printIndex + 1
- if(_this.printIndex < result.length){
- _this.printOnce(opt,tsc,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()
- }
- }
- })
- }
- });
- },
- closeConnect(){
- this.isParinting = false
- uni.hideLoading()
- },
- // 批量打印
- startPrint(opt,tsc,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,tsc,blesdk,result[this.printIndex])
- }else{
- this.toashMsg("请选择产品!")
- this.$refs.kkprinter.onPrintFail()
- }
- },
- }
- }
- </script>
- <style lang="less">
- .batchPrint-manualPrint-wrap{
- width: 100%;
- height: 100%;
- overflow: hidden;
- padding-bottom: 102upx;
- .productList-search{
- padding: 20rpx 30rpx;
- background-color: #fff;
- position: fixed;
- left: 0;
- top: 0;
- width: 100%;
- display: flex;
- z-index: 100;
- .search{
- padding: 0.1rem;
- border-radius: 50rpx;
- border:1rpx solid #eee;
- width: 100%;
- .input{
- flex-grow: 1;
- padding: 4rpx;
- }
- .icon{
- width: 13%;
- text-align: center;
- font-size: 46rpx;
- color: #999;
- }
- }
- }
- .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;
- z-index: 1000;
- }
- }
- </style>
|