<template>
	暂未完成
    <view>
        <view class="vtopmsg" v-if="btmsg" :style="{background:btmsg == '蓝牙阅读器正常'?'':'#cc0000'}">{{btmsg}}</view>

        <view class="_bg" v-if="bshow">
            <view class="_dialog">
                <view class="_title">选择目标</view>
                <view class="_close" @tap="close()"></view>
                <view class="_content" :style="{maxHeight:maxheight}">
                    <view style="text-align: center;margin:1em 0;">
                        <ciy-qrcode-show :value="epc"></ciy-qrcode-show>
                    </view>
                    <view v-for="(item,index) in sels" :key="index" @tap="sendme(item)" class="selbtn">
                        {{item}}
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>

<style scoped>
    ._bg {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.2);
        z-index: 100;
    }

    ._dialog {
        position: fixed;
        border-radius: 0.5em;
        /*  #ifdef MP-WEIXIN */
        top: 1em;
        /*  #endif  */
        /*  #ifndef MP-WEIXIN */
        top: 4em;
        /*  #endif  */
        left: 1em;
        right: 1em;
        background: #ffffff;
    }

    ._dialog ._title {
        line-height: 1.5em;
        background: #fafafa;
        padding: 0.5em 1em;
        border-radius: 0.5em 0.5em 0 0;
    }

    ._dialog ._content {
        overflow: scroll;
        margin-bottom: 0.5em;
    }

    ._dialog ._close {
        position: absolute;
        right: 0.5em;
        top: 0.5em;
        width: 1.5em;
        height: 1.5em;
        background-image: url("data:image/svg+xml;charset=utf-8;base64,PHN2ZyB2aWV3Qm94PScwIDAgMTAyNCAxMDI0JyB2ZXJzaW9uPScxLjEnIHhtbG5zPSdodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2Zyc+PHBhdGggZD0nTTUxLjI4NTk0ODA3IDUyMC4wMTYwMTM1NGMwIDI1Ni40ODg5MDI4MyAyMDcuNTg2OTEzMzUgNDY0LjA3NTgxNjIgNDY0LjA3NTgxNjE3IDQ2NC4wNzU4MTYxN3M0NjQuMDc1ODE2Mi0yMDcuNTg2OTEzMzUgNDY0LjA3NTgxNjItNDY0LjA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E5NDI1NyAxMS44OTE5NDI1NyAzMi44OTEzNzM1OSAwIDQ0LjgxMjMyMDQ1bC0xNzcuODI4MDUyNjcgMTc3Ljc5OTA0ODM2eicgZmlsbD0nI2ZmZmZmZic+PC9wYXRoPjwvc3ZnPg==");
    }

    .selbtn {
        margin: 1em;
        text-align: center;
        border: 1px solid #0c59a9;
        padding: 0.5em;
        background: #007aff;
        font-size:1.5em;
        color: #ffffff;
        border-radius: 0.3em;
    }
</style>

<script>
    import ciyQrcodeShow from '@/components/ciy-qrcode-show/ciy-qrcode-show'
    var app = getApp();
    export default {
        props: {
            select: {
                type: String
            }
        }
        , data() {
            return {
                bshow: false
                , btmsg: ''
                , sels: []
                , maxheight: '30em'
                , epc: ''
            , };
        }
        , destroyed() {
            console.log('unmounted');
        }
        , mounted() {
            console.log('mounte');

        }
        , methods: {
            open() {
                this.bshow = true;
				var app = getApp();
				var height = app.globalData._sysinfo.screenHeight - 80;
				this.maxheight = height + 'px';
            }
            , sendme(select) {
                console.log('sendme', select);
                this.$emit('scan', {
                    select: select
                    , value: this.epc
                });
                this.close();
            }
            , unmonitor() {
                var devbt = app.globalData.dev_bt.reader;
                if (!devbt)
                    return;
                devbt.onmsg = null;
            }
            , monitor() {
                console.log('monitor');
                this.btmsg = '';
                // setTimeout(() => {
                //     var epc = '372120220009998';
                //     this.sels = this.select.split(',');
                //     if (this.sels.length == 1) {
                //         this.$emit('scan', {
                //             select: this.select
                //             , value: epc
                //         });
                //     } else {
                //         this.epc = epc;
                //         this.open();
                //     }
                // }, 500);
                var devbt = app.globalData.dev_bt.reader;
                if (!devbt)
                    return;
                this.btmsg = '蓝牙阅读器未连接!';
                if (devbt.opened == 10)
                    this.btmsg = '蓝牙阅读器正常';
                devbt.onmsg = res => {
                    if (res.connected !== undefined) {
                        if (res.connected)
                            this.btmsg = '蓝牙阅读器正常';
                        else
                            this.btmsg = '蓝牙阅读器已断开';
                        return;
                    }
                    this.btmsg = '蓝牙阅读器正常';
                    var epc = res.data;
                    if (!epc)
                        return;
                    if (!this.isfront())
                        return;
                    this.sels = this.select.split(',');
                    if (this.sels.length == 1) {
                        this.$emit('scan', {
                            select: this.select
                            , value: epc
                        });
                    } else {
                        this.epc = epc;
                        this.open();
                    }
                };
            }
            , isfront() {
                var ps = getCurrentPages();
                var ftroute = ps[ps.length - 1].route || ps[ps.length - 1].__route__;
                var cproute = this.$parent.__route__ || this.$parent.$parent.route;
                //console.log(this.select, ftroute,cproute);
                return ftroute == cproute;
            }
            , close() {
                this.bshow = false;
            }
        }
    }
</script>
