<!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/188233/css/main.css" rel="stylesheet" />
    <title>辽宁联达种业有限责任公司</title>
</head>

<body>
    <div class="app">
        <div class="bg"><img src="/static/188233/img/bg.png" style="width: 100%;"></div>
        <div id="cpsy" class="page">
            <div class="title"><img src="/static/188233/img/sy.png"></div>
            <div class="block">
                <div><span>品种名称 :</span><span id="name">联达F085</span></div>
                <div><span>销售区域 :</span><span>黑龙江省</span></div>
                <div><span>收货单位 :</span><span>北京萨福沃农业科技有限公司</span></div>
                <div>
                    国审玉20200393<br>辽审玉2017058<br>冀农告字[2017]4号<br>(蒙)引种[2017]第3号<br>晋引种[2017]第4号<br>(黑)引玉[2017]第30号<br>(吉)引种[2018]第1号<br>津审玉20190009<br>甘农公告[2020]第2号
                </div>
            </div>
            <div class="block" style="margin-bottom: 1rem;">
                <div><span>生产经营许可证 :</span><span id="pl">BC(辽)农种许字(2016)第0006号</span></div>
                <div><span>公司名称 :</span><span>辽宁联达种业有限责任公司</span></div>
                <div><span>地&emsp;&emsp;址 :</span><span>辽宁省北票市蒙古镇</span></div>
            </div>
            <div id="fw" class="btn" style="margin-top: .5rem;">防伪查询</div>
        </div>
        <div id="fwcx" class="page" style="display: none;">
            <div class="title"><img src="/static/188233/img/fw.png"></div>
            <div class="block">
                <div style="text-align: center;">
                    <img src="" id="labelImg" style="width: 30%;" />
                </div>
                <div class="hr"></div>
                <!-- 三维码 -->
                <div class="p p-3" id="warn_swm">
                    <p>请认真核对实物标签上的烫金三维码是否与上图一致，相符则为正品，否则谨防假冒！</p>
                </div>
                <div class="hr"></div>
                <div class="info">
                    <p>标签序号：<span id="cpidSpan"></span></p>
                    <p>首查时间：<span id="firstTime"></span></p>
                    <p>已查次数：<span id="queryNum">0</span> 次</p>
                </div>
                <div class="tips">
                    该产品为辽宁联达种业有限责任公司正品标识 ,<br>请放心使用！
                </div>
            </div>
            <div class="aidiv">
                <!-- <div class="btn">AI查询</div> -->
                <wx-open-launch-weapp id="launch-btn" style="display: block;">
                    <script type="text/wxtag-template">
                            <style>
                                .btn {
                                    width: 55%;
                                    line-height: 2.5;
                                    border-radius: 20px;
                                    margin: auto;
                                    font-size: 14px;
                                    background: #259362;
                                    color: white;
                                    text-align: center;
                                }
                            </style>
                            <div class="btn">AI识别</div>
                        </script>
                </wx-open-launch-weapp>
            </div>
            <div id="sy" class="btn" style="margin-top: .5rem;display: none;">返回溯源</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://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <script src="/static/js/jquery-2.1.0.min.js"></script>
    <script src="/static/js/public/public.js"></script>
    <script>


        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
        })


        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: {
                        cpid: label_code,
                        uid,
                        uuid,
                        os: 'davis'
                    },
                    onLaunch: function () {
                        tj_public.checkMiniprogramAIStatus(
                            {
                                label_code,
                                consumer_id: uid,
                                uuid,
                            }, function (state) {
                                if (state == 1) {
                                    access();
                                }
                            })
                    }
                })
            }
        })
        wx.error(function (res) {
            if (uid) {
                getInfo(0, 0);
            }
        });

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

        // getInfo(0, 0)
        function getInfo(lat, lng) {
            $.ajax({
                url: '/wx/label/scan_record/',
                data: { lat: lat, lng: lng, uid: uid, compid: 188233, 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 inventory = res.inventory.filter(function (f) {
                        //     return f.voucher_type === '销售出库' && f.company_id === 188233
                        // })
                        // if (inventory.length > 0) {
                        //     if (inventory[0].to_company != "") {
                        //         $("#to_company").text(inventory[0].to_company)
                        //     }
                        // }

                        var product_id = res.product_id
                        if (product_id) {
                            $("#proContent").html(decodeURIComponent(res.product_contents))
                            $.ajax({
                                url: '/product/detail/',
                                data: {
                                    id: product_id
                                },
                                success: function (product) {
                                    console.log(product);
                                    var props = product.props;
                                    $("#name").text(product.name);
                                    $("#standard").text(product.standard);
                                    $("#pl").text(product.pl);
                                }
                            })
                        }

                    } else {
                        alert('网络超时！')
                    }
                }, error: function () {
                    alert('网络超时！')
                }
            })
        }


        $('#fw').on('click', function () {
            $('.page').hide();
            $('#fwcx').show();
        });
        $('#sy').on('click', function () {
            $('.page').hide();
            $('#cpsy').show();
        });

    </script>
</body>

</html>