<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="https://res.wx.qq.com/open/libs/weui/2.4.0/weui.min.css">
    <link href="/static/css/public/reset.css" rel="stylesheet" />
    <link href="/static/css/public/public.css" rel="stylesheet" />
    <script src="/static/js/public/reset.js"></script>
    <link href="/static/css/157716/main.css" rel="stylesheet" />
    <title>英普瑞医疗</title>
</head>

<body>
    <div class="home">
        <div class="banner">
            <img src="/static/images/157716/b.png" style="width: 100%;">
            <img src="/static/images/157716/top.png" class="logo-top">
        </div>
        <div class="machine body">
            <div class="profile">
                <img src="" id="pfp">
                <p id="aname" style="font-size: 1rem;">店铺名称</p>
            </div>
            <div class="form">
                <div class="item">
                    <img src="/static/images/157716/dz.png" class="icon">
                    <p>地址：</p>
                    <p id="addr"></p>
                </div>
                <div class="item">
                    <img src="/static/images/157716/ts.png" class="icon">
                    <p>台数：</p>
                    <p id="num"></p>
                </div>
                <div class="item">
                    <img src="/static/images/157716/bm.png" class="icon">
                    <p>机器编码：</p>
                    <p id="m_code"></p>
                </div>
                <div class="item">
                    <img src="/static/images/157716/jg.png" class="icon">
                    <p>认证机构：</p>
                    <p id="m_ca"></p>
                </div>
            </div>
        </div>
        <div class="error">
            <img src="/static/images/157716/x.png" style="width: 8rem;margin: 4rem;">
            <p>页面扫码错误</p>
            <p>请重新扫描</p>
        </div>
        <div class="footer">
            <div class="line"></div>
            <img src="/static/images/157716/foot.png" style="width: 5rem;margin: 0 1rem;">
            <div class="line"></div>
        </div>
    </div>

    <script src="https://res.wx.qq.com/open/libs/weuijs/1.2.1/weui.min.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script src="/static/js/jquery-2.1.0.min.js"></script>
    <script src="/static/js/public/public.js"></script>
    <script>

        console.log('机器码');

        tj_public.showLoading();
        // tj_public.hideLoading();
        var uid = tj_public.getCookie('TJWX_consumer_id');
        var label_code = tj_public.getCookie('label_code');
        tj_public.wxInit({
            wx_officail_account_id: 6,
            url: window.location.href
        })

        $(function () {

            wx.ready(function () {
                if (uid) {
                    tj_public.getAddress(function (lat, lng) {
                        getInfo(lat, lng)
                    })
                    var uuid = tj_public.getUuid(8, 16);
                    // tj_public.configLaunchWeappBtn({
                    //     el: 'launch-btn',
                    //     username: 'gh_4290b605146b',
                    //     extraData: {
                    //         label_code,
                    //         uid,
                    //         uuid,
                    //         os:'davis'
                    //     },
                    //     onLaunch: function () {
                    //         tj_public.checkMiniprogramAIStatus({
                    //             label_code, uid, uuid
                    //         }, function (state) {
                    //             if (state == 1) {
                    //                 access();
                    //             }
                    //         })
                    //     }
                    // })
                }
            })
            wx.error(function (res) {
                if (uid) {
                    getInfo(0, 0);
                }
            });

            // function access() {
            //     $('.aidiv').hide();
            //     $('.tips').show();
            // }

            // getInfo(0, 0)
            function getInfo(lat, lng) {
                $.ajax({
                    url: '/wx/label/scan_record/',
                    data: { lat: lat, lng: lng, uid: uid, compid: 157716, fwcode: label_code, contents: 1 },
                    success: function (res) {
                        if (res.e === '') {
                            tj_public.hideLoading();
                            // $("#labelImg").attr("src", res.img);
                            // $("#cpidSpan").text(res.code);
                            // if (res.bcode) {
                            //     $("#cpidSpan").text(res.bcode);
                            // }
                            // $("#queryNum").text(res.cnt);
                            // if (res.tm_1st) {
                            //     $("#firstTime").text(res.tm_1st);
                            // }
                            // else {
                            //     var myDate = new Date();
                            //     $("#firstTime").text(myDate.toLocaleString());
                            // }

                            var product_name = res.product_name
                            if (!product_name.startsWith("英普瑞")) {
                                $('.body').hide();
                                $('.error').show();
                            }

                            var agent_id = res.agent_id
                            if (agent_id) {
                                $.ajax({
                                    url: '/company/detail/',
                                    data: {
                                        id: agent_id
                                    },
                                    success: function (company) {
                                        console.log(company);
                                        $("#pfp").attr("src", company.img_logo);
                                        $("#aname").text(company.name);
                                        $("#addr").text(company.address);
                                        $("#num").text(company.remark);
                                    }
                                })
                            }
                            var product_id = res.product_id
                            if (product_id) {
                                $.ajax({
                                    url: '/product/detail/',
                                    data: {
                                        id: product_id
                                    },
                                    success: function (product) {
                                        console.log(product);
                                        $("#m_code").text(product.barcode);
                                        $("#m_ca").text(product.standard);
                                    }
                                })
                            }
                        } else {
                            alert('网络超时！')
                        }
                    }, error: function () {
                        alert('网络超时！')
                    }
                })
            }
        });

    </script>

</body>

</html>