<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="{{asset('icon/faviconc.ico')}}" type="image/x-icon"/>
    <link href="{{ mix('css/app.css') }}" rel="stylesheet">
    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <title>二维码-入库预约</title>
    <style>
        html{
            background: white;
            height: 100%;
            width: 100%;
        }
    </style>
</head>
<body class="h-100">
    <div class="container-fluid w-100 h-100" id="container">
        <div class="h-25"></div>
        <div class="w-50 h-50 m-auto">
            <div id="code" class="ml-5"></div>
        </div>
    </div>
</body>
<script src="{{ mix('js/app.js') }}"></script>
<script src="{{ mix('js/utilities/qrcode.js') }}"></script>
<script type="text/javascript">
    new Vue({
        el:"#container",
        data:{
            list:[],
            key:"",
            baseUrl:"{{url('store/deliveryAppointment/delivery?k=')}}",
            QrCode : null,
        },
        mounted(){
            this._getKey();
        },
        methods:{
            //获取密匙
            _getKey(){
                let url = "{{url('store/deliveryAppointment/getKey')}}";
                window.tempTip.postBasicRequest(url,{},res=>{
                    this.key = res;
                    this._createQrCode(this.baseUrl+this.base64());
                });
            },
            //生成二维码
            _createQrCode(text){
                let dom = document.getElementById("code");
                let hei = dom.parentElement.offsetHeight;
                new QRCode(dom,{
                        text: text,
                        width: hei*1.4,
                        height: hei,
                        colorDark : "#000000",
                        colorLight : "#ffffff",
                    }
                );
            },
            //获取当前时间距离明天0点的时间差  毫秒
            _getDiffDate(){
                let now = new Date();
                let dateTime = now.getTime();
                let yy = now.getFullYear();
                let mm = now.getMonth() + 1;
                let dd = now.getDate();
                let clock = yy + "-";
                if(mm < 10) clock += "0";
                clock += mm + "-";
                if(dd < 10) clock += "0";
                clock += dd+" 00:00:00";
                let timestamp = new Date(clock).getTime()+(24*60*60*1000);
                return timestamp-dateTime;
            },
            //加密
            base64(){
                let _keyStr= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
                let output = "";
                let chr1, chr2, chr3, enc1, enc2, enc3, enc4;
                let i = 0;
                let str = Math.floor(new Date().getTime()/1000).toString();
                str = str.slice(str.length-8);
                let input = this._utf8_encode(this.key+str);
                while (i < input.length) {
                    chr1 = input.charCodeAt(i++);
                    chr2 = input.charCodeAt(i++);
                    chr3 = input.charCodeAt(i++);
                    enc1 = chr1 >> 2;
                    enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
                    enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
                    enc4 = chr3 & 63;
                    if (isNaN(chr2)) {
                        enc3 = enc4 = 64;
                    } else if (isNaN(chr3)) {
                        enc4 = 64;
                    }
                    output = output +
                        _keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
                        _keyStr.charAt(enc3) + _keyStr.charAt(enc4);
                }
                return output;
            },
            _utf8_encode (string) {
                string = string.replace(/\r\n/g,"\n");
                let utftext = "";
                for (let n = 0; n < string.length; n++) {
                    let c = string.charCodeAt(n);
                    if (c < 128) {
                        utftext += String.fromCharCode(c);
                    } else if((c > 127) && (c < 2048)) {
                        utftext += String.fromCharCode((c >> 6) | 192);
                        utftext += String.fromCharCode((c & 63) | 128);
                    } else {
                        utftext += String.fromCharCode((c >> 12) | 224);
                        utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                        utftext += String.fromCharCode((c & 63) | 128);
                    }
                }
                return utftext;
            }
        },
    });
</script>
</html>
