<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>上料报工</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../css/common.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" id="header">
        <a class="aui-pull-left aui-btn  event-back">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title">上料报工</div>
    </header>

    <section class="aui-content" id="subheader">
        <div class="aui-grid aui-bg-info">
            <div class="aui-row sub-title c_stationDesc" id="classify"></div>
        </div>
    </section>

    <section class="aui-content container">
        <div class="aui-timeline" id="shangliaobaogong">
            <script id="shangliaobaogongTemplate" type="text/x-dot-template">
                {{~it:value:index}}
                <div class="aui-timeline-item-header">{{= value.date}}</div>

                {{~value.data:val:ind}}
                <div class="aui-timeline-item">
                    {{ if ('1' == val.status) { }}
                    <div class="aui-timeline-item-label aui-bg-warning text-light text-white">{{= val.descr}}</div>
                    {{ } }} {{ if ('2' == val.status) { }}
                    <div class="aui-timeline-item-label aui-bg-info text-light text-white">{{= val.descr}}</div>
                    {{ } }}
                    <div class="aui-timeline-item-inner">
                        <div class="aui-card-list">
                            <div class="aui-card-list-header">
                                <div>工单:{{= val.workCode}}</div>
                                <div>品名:{{= val.productName}}</div>
                            </div>
                            <div class="aui-card-list-content" style="padding:0rem 0.75rem">
                                <div class="aui-pull-left">筐号:{{= val.number}}</div>
                                <div class="aui-pull-right">数量:{{= val.okCount}}</div>
                            </div>
                            <div class="aui-clearfix"></div>
                            <div class="aui-card-list-footer  aui-font-size-12">
                                <div><i class="aui-iconfont aui-icon-my aui-font-size-14"></i> {{= val.userName}}</div>
                                <div></div>
                                <div><i class="aui-iconfont aui-icon-date aui-font-size-14"></i> {{= val.time.split(' ')[1]}}</div>
                            </div>
                        </div>
                    </div>
                </div>
                {{~}} {{~}}
            </script>
        </div>
    </section>

    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-content-padded">
            <div class="aui-row">
                <div class="aui-col-xs-6" style="padding: 0 5px;">
                    <div class="aui-btn aui-btn-info  aui-btn-block aui-btn-sm b_shangliao" data-params='' data-self="shangliaobaogong" data-page="shangliao" data-qr-title="请扫描工单编号/筐号" onclick="openQRcode(this)" tapmod=""> 上料 </div>
                </div>
                <div class="aui-col-xs-6" style="padding: 0 5px;">
                    <div class="aui-btn aui-btn-info  aui-btn-block aui-btn-sm b_baogong" data-params='' data-self="shangliaobaogong" data-page="baogong" data-qr-title="请扫描筐号" onclick="openQRcode(this)" tapmod=""> 报工 </div>
                </div>
            </div>
        </div>
    </footer>

</body>

<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
<script type="text/javascript" src="../script/md5.js"></script>
<script type="text/javascript" src="../script/swipe.js"></script>
<script type="text/javascript" src="../script/SHA1.js"></script>
<script type="text/javascript" src="../script/doT.min.js"></script>
<script type="text/javascript" src="../script/remotedb.js"></script>
<script type="text/javascript" src="../script/list.js"></script>
<script type="text/javascript" src="../script/aui-tab.js"></script>
<script type="text/javascript" src="../script/aui-toast.js"></script>
<script type="text/javascript" src="../script/zepto.min.js"></script>
<script type="text/javascript" src="../script/jquery.min.js"></script>
<script type="text/javascript" src="../script/lang.js"></script>

<script type="text/javascript">
    var host, user;
    apiready = function() {
        host = $api.getStorage('host');
        fnReady();
        user = $api.getStorage('current_user');
        console.log('用户:' + user);
        ajaxsetup();
        var url = host + '/acc/ProductReport/getlist';
        console.log(JSON.stringify(api.pageParam));
        getList(url, api.pageParam.qrcode, api.pageParam);
    };


    // var url = 'http://61.177.28.246:8100/acc/ProductReport/getlist?machineCode=449';
    // getList(url);

    function getList(url, qrcode, params) {
        console.log('qrcode');
        console.log(qrcode);
        $.ajax({
            url: host + '/acc/ProductReport/getlist',
            data: JSON.stringify({
                "machineCode": qrcode
            }),
            type: 'POST',
            success: function(result) {
                console.log('得到上料报工');
                console.log(JSON.stringify(result));
                if (result.ret == 1) {
                    var newarr = groupJson(result.data.work);

                    var testTemplate = doT.template($("#shangliaobaogongTemplate").text());
                    $("#shangliaobaogong").html(testTemplate(newarr));
                    $(".c_stationDesc").html(result.data.stationDesc);
                    // var c_params = '{"stationDesc":"' + result.data.stationDesc + '","machine":"' + result.data.machine + '","station":"' + result.data.station + '","qrcode":"' + qrcode + '"}';
                    var b_params = '{"stationDesc":"' + result.data.stationDesc + '","machine":"' + result.data.machine + '","station":"' + result.data.station + '","isshowedit":"0","qrcode":"' + qrcode + '"}';
                    $(".b_shangliao").attr("data-params", encodeURIComponent(b_params));
                    $(".b_baogong").attr("data-params", encodeURIComponent(b_params));

                } else {
                    customToast(lang[result.msg], 2000);
                    console.log('xxxxxx33333');
                    setTimeout(function() {

                        api.execScript({
                            name: 'root',
                            script: 'fnCloseWinOpenQR("shangliaobaogong","请扫描设备编号","' + params + '");'
                        });
                        // api.execScript({
                        // name: 'root',
                        // script: 'fnOpenCustomQRCode("shangliaobaogong","请扫描设备编号","");'
                        // });


                    }, 500);

                }

            }
        })

    }


    function groupJson(arr) {
        var map = {},
            dest = [];
        for (var i = 0; i < arr.length; i++) {
            var ai = arr[i];

            var time = ai.time.split(" ");

            if (!map[time[0]]) {
                dest.push({
                    date: time[0],
                    data: [ai]
                });
                map[time[0]] = ai;
            } else {
                for (var j = 0; j < dest.length; j++) {
                    var dj = dest[j];
                    var time = ai.time.split(" ");
                    if (dj.date == time[0]) {
                        dj.data.push(ai);
                        break;
                    }
                }
            }

        }
        return dest;

        // console.log(JSON.stringify(dest));
    }
</script>

</html>
