#
whycq
2023-05-08 3b9a0380f8dfb24964c0afbd635dc7d2f013d475
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<template>
    <view class="content">
        <view>
            <view class="bluetoothConnected">
                <view class="bluetoothList" v-for="(item,index) in GET_CONNECTBLEDATA" :key="index" @tap="confirm_bluetooth(item)">
                    <view class="bluetoothList-name">名称:{{item.name}}</view>
                    <view class="bluetoothList-mac">地址:{{item.mac}}</view>
                </view>
            </view>
            <button type="default" @click="search_bluetooth">搜索蓝牙</button>
            <button @click="senBleLabel">打印</button>
            <view class="bluetoothItem" v-if="GET_INFODATA">
                <view class="bluetoothList" v-for="(item,index) in GET_INFODATA" :key="index" @tap="confirm_bluetooth(item)">
                    <view class="bluetoothList-name">名称:{{item.name}}</view>
                    <view class="bluetoothList-mac">地址:{{item.mac}}</view>
                </view>
            </view>
        </view>
    </view>
</template>
 
<script>
    import printConnect from "@/common/print.js";  //引入打印机模板文件 
    let _this = null;
    import {
        mapGetters,
        mapActions
    } from 'vuex';
    import {
        GET_INFODATA,
        GET_CONNECTBLEDATA
    } from "@/store/gettersType.js";
    import {
        SET_CONNECTBLEDATA
    } from '@/store/actionsType.js';
    // #ifdef APP-PLUS
    const HanyinPlugin = uni.requireNativePlugin('Hanyin-Plugin'); //汉印
    // #endif
    let print;
    export default {
        data() {
            return {
                bArray: [], //用于搜索蓝牙去重用的
                no_match_list: [], //没有配对的蓝牙列表
                match_list: "", //已连接蓝牙打印机
                val: "",
                dateTimer: "",
                valArr: [],
                print_data: '',
                mat: '',
                time: '',
                // 巴枪参数
                // broadcase_actions: "com.android.receive_scan_action",
                // broadcast_flag: "data"
            };
        },
        computed: {
            ...mapGetters([GET_INFODATA, GET_CONNECTBLEDATA])
        },
        onShow() {
            uni.hideLoading();
            //检查是否已连接蓝牙
            // this.$check_bluetooth_connect();
            console.log('onShow');
        },
        onHide() {
            console.log('onHide');
        },
        onUnload() {
            console.log('onUnload');
        },
        onLoad(options) {
            _this = this;
             this.$init_bluetooth();
             let that = this
             const eventChannel = this.getOpenerEventChannel();
             eventChannel.on('data1', function(data1) {
                 that.mat = data1.data
                that.time = data1.time
                console.log(data1);
             })
        },
        methods: {
            ...mapActions([SET_CONNECTBLEDATA]),
            senBleLabel() {
                // console.log(this.$Mock.order_data);
                if(!print) return;
                console.log(this.mat);
                this.print_data =  this.$Mock.order_data
                this.print_data.MATNR = this.mat.matnr
                this.print_data.MAKTX = this.mat.maktx
                this.print_data.MODI_TIME = this.time
                print.startPrint(this.print_data);
            },
            // 连接打印机
            confirm_bluetooth(item) {
                let {
                    name,
                    mac
                } = item;
                //判断蓝牙是否打开
                this.$check_bluetooth_open().then(res => {
                    console.log(res);
                    //进行打印机连接
                    if (res) {
                        print =new printConnect(item);  //打印机连接
                    }
                })
            },
            //搜索没匹配的蓝牙设备
            search_bluetooth(address) {
                let _this = this;
                //检查蓝牙是否开启
                this.$check_bluetooth_open().then(ores => {
                    if (ores) {
                        console.log(ores);
                        //搜索蓝牙
                        _this.$search_bluetooth().then(bres => {
                            console.log(bres);
                            if (bres.code) {
                                _this.$search_pipei().then(pres => {
                                    console.log(pres);
                                })
                            }
                        })
                    }
                })
            }
        }
    }
</script>
 
<style lang="scss">
    .bluetoothItem {
        width: 100%;
        height: 100%;
    
        .bluetoothList {
            display: flex;
            flex-direction: column;
            padding: 20rpx;
            border-bottom: 1rpx solid #BEBEBE;
            font-size: 18rpx;
        }
    }
</style>