<!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/243885/css/main.css" rel="stylesheet" />
    <title>防伪查询</title>
    <style>
        .display {
            display: none;
        }
    </style>
</head>

<body>
    <div class="app">
        <div class="title">
            <img src="/static/243885/img/logo.png" style="width: 80%;">
        </div>
        <div id="container"></div>
        <div class="form">
            <div class="h1">溯源信息</div>
            <div class="block">
                <div class="row display">品种名称：<span id="prod"></span></div>
                <div class="row">生产经营者：<span>辽宁铁研种业科技有限公司</span></div>
                <div class="row display">品种批次：<span id="pici"></span></div>
                <div class="row display">生产日期：<span id="bindtm"></span></div>
                <div class="row">查询次数：<span id="queryNum"></span></div>
                <div class="row">首次时间：<span id="firstTime"></span></div>
                <div class="row display">上级码：<span id="box"></span></div>
                <div class="row display">发货商：<span id="agent"></span></div>
                <div class="row display">发货时间：<span id="fhdate"></span></div>
                <div>销售区域：<span>全国</span></div>
            </div>
            <div class="block">
                <div>单元识别码：<span class="cpidSpan"></span></div>
                <div>追溯网址：http://pinet.cn/f9/getmsg_f9.asp?c=
                    <span class="cpidSpan"></span>
                </div>
            </div>
        </div>
        <div class="aidiv">
            <!-- <div class="aibtn">防伪查询</div> -->
            <wx-open-launch-weapp id="launch-btn" style="display: block;">
                <script type="text/wxtag-template">
                        <style>
                            .btn {
                                width: 50%;
                                line-height: 2.5;
                                border-radius: 50px;
                                margin: auto;
                                font-size: 14px;
                                background: #259362;
                                color: white;
                                text-align: center;
                            }
                        </style>
                        <div class="btn">防伪查询</div>
                    </script>
            </wx-open-launch-weapp>
        </div>
        <div class="qyjs">
            辽宁铁研种业科技有限公司，公司注册资本金4047万元。由安缴荃银高科种业股份有限公司(控股)与铁岭市农业科学院共同出资组建而成。安徽荃银高科种业股份有限公司是集农作物种子科研、生产、加工、国内外营销等业务于一体的种业企业，是我国首家登陆创业板的种业公司。铁研公司以两大股东为强大后盾，发展成为科研实力雄厚、产品质量过硬、服务水平一流、企业理念先进的“育、繁、推”一体的具有核心竞争力的种业公司。
        </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');
        var jmcpid = tj_public.getCookie('jmcpid');
        var label = jmcpid ? jmcpid : 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,
                        uid,
                        uuid,
                        os: 'davis'
                    },
                    // onLaunch: function () {
                    //     tj_public.checkMiniprogramAIStatus(
                    //         {
                    //             label_code: label,
                    //             consumer_id: uid,
                    //             uuid,
                    //         }, function (state) {
                    //             if (state == 1) {
                    //                 access();
                    //             }
                    //         })
                    // }
                })
            }
        })
        wx.error(function (res) {
            if (uid) {
                getInfo(0, 0);
            }
        });

        $.ajax({
            type: 'get',
            url: 'https://tjfnew.china315net.com/ajax/video_url.ashx?videoid=a057ee0239ab71ef81224531948c0102&json=1',
            success: function (result) {
                var res = JSON.parse(result);
                $("#container").html('<video id="video" controls="controls" poster="' + res.CoverURL + '" width="100%"><source type="video/mp4" src="' + res.playUrl + '"></video>');
            }, error: function () {
            }
        })


        function getInfo(lat, lng) {
            $.ajax({
                url: '/wx/label/scan_record/',
                data: { lat: lat, lng: lng, uid: uid, compid: 243885, 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 rk = res.inventory.filter(function (f) {
                            return f.voucher === '成品入库'
                        })
                        var ck = res.inventory.filter(function (f) {
                            return f.voucher === '销售出库'
                        })

                        if (res.product_name) {
                            $("#prod").text(res.product_name).parent().show();
                        }
                        if (rk.length > 0) {
                            $("#pici").text(rk[0].bill_no).parent().show();
                            $("#bindtm").text(rk[0].tm).parent().show();
                        }
                        if (res.bind_tm) {
                            $("#bindtm").text(res.bind_tm).parent().show();
                        }

                        if (res.boxes) {
                            $("#box").text(res.boxes).parent().show();
                        }
                        if (ck.length > 0) {
                            $("#agent").text(ck[0].agent.name).parent().show();
                            $("#fhdate").text(ck[0].tm).parent().show();
                        }

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

    </script>
</body>

</html>