<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title><!--{$config.system_name}-->-<!--{$top_menu_name}--></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="<!--{$oapath}-->Ins/js/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="<!--{$oapath}-->Ins/js/layui/css/global.css" media="all">
    <link href="<!--{$oapath}-->Ins/font-awesome/css/font-awesome.css" rel="stylesheet">
</head>
<script type="text/javascript">
    var upload_url = "/index.php?m=&c=Sign&a=upload";
    var del_url = "/index.php?m=&c=Sign&a=del_file";
    var app_path = "";
    var ws_push_time = "2";
    var cookie_prefix = "";
    var link_select = "/index.php?m=&c=Popup&a=link_select";
    var push_server = "/index.php?m=&c=push&a=server";
    var is_app = "";
    var enable_chat = true;
    var push_bind_url = '/index.php?m=&c=Push&a=bind';
    var msg_box_url = "/index.php?m=&c=Message&a=box";
    var chat_bind_url = '/index.php?m=&c=Chat&a=bind';
    var chat_init_url = '/index.php?m=&c=Chat&a=init';
    var chat_send_message_url = '/index.php?m=&c=Chat&a=send_message';
    var chat_member_url = '/index.php?m=&c=Chat&a=members';
    var chat_upload_img_url = '/index.php?m=&c=Chat&a=upload_img';
    var chat_upload_file_url = '/index.php?m=&c=Chat&a=upload_file';
    var chat_log_url = '/index.php?m=&c=Chat&a=chat_log';
</script>
<body class="popup">
<style>
    body, html {
        height: 100%;
    }
    .login-box {
        margin-top: 0px;
        width: auto;
        height: 100%;
        margin: 20px;
        padding: 0px;
        border: 0px;
    }
    .allmap {
        border: 1px solid #222;
    }
    .layui-form-label {
        width: 80px;
    }
    .layui-input-block {
        margin-left: 90px;
    }
</style>
<input type="hidden" name="ajax" id="ajax" value="1">
<div class="popup-frame">
    <div class="popup-header">
        <div class="pull-left">
            <h1>签到</h1>
        </div>
        <div class="pull-right">
            <!--{if $sign_out!='1'}-->
            <a class="btn" id="btn_box" onclick="save();">签到</a>
            <!--{/if}-->
            <a class="btn btn-cancel" id="btn_close" onclick="myclose();">关闭</a>
        </div>
    </div>
    <div class="popup-body">
        <div class="popup-body-scroll">
            <div class="popup-content" style="padding-top:0px;margin:0px;">
                <div class="layui-tab layui-tab-brief">
                    <ul class="layui-tab-title text-center">
                        <!--{if $sign_in=='0'}-->
                        <li>
                            <a id="sign_in" class="link layui-this" onclick="sign_in()">上班打卡</a>
                        </li>
                        <!--{/if}-->
                        <!--{if $sign_in=='1' && $sign_out=='0'}-->
                        <li>
                            <a id="sign_out" class="link layui-this" onclick="sign_out()">下班打卡</a>
                        </li>
                        <!--{/if}-->
                        <li>
                            <a id="outside" class="link" onclick="outside()">外勤打卡</a>
                        </li>
                    </ul>
                </div>
                <form id="form_data">
                    <input type='hidden' id="hidden_time" name="time">
                    <!--{if $sign_in=='0'}-->
                    <input type='hidden' id="state" name="state" value="sign_in">
                    <!--{/if}-->
                    <!--{if $sign_in=='1'}-->
                    <input type='hidden' id="state" name="state" value="sign_out">
                    <!--{/if}-->
                    <input type='hidden' id="hidden_location" name="location">
                    <input type='hidden' id="hidden_lat" name="lat">
                    <input type='hidden' id="hidden_lang" name="lang">
                    <div class="layui-form-item">
                        <div id="allmap" style="width:100%;height:200px;border:1px solid #ccc;"></div>
                    </div>
                    <h1 class="text-center" id="msg"><span class="text-danger"><i class="fa fa-location-arrow"></i>GPS定位中...</span>
                    </h1>
                    <div class="layui-form-item" style="margin-bottom: 0px;">
                        <label class="layui-form-label" for="name">时间：</label>
                        <div class="layui-input-block">
                            <div class="layui-input-static">
                                <p id="time" class="text-left"></p>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item" style="margin-bottom: 0px;">
                        <label class="layui-form-label" for="name">地点：</label>
                        <div class="layui-input-block">
                            <div class="layui-input-static">
                                <p id="location" class="text-left autocut"></p>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" for="name"><h3>备注：</h3></label>
                        <div class="layui-input-block">
                            <div class="layui-input-static">
                                <textarea name="remark" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="<!--{$oapath}-->Ins/js/layui/layui.js" charset="utf-8"></script>
<script src="<!--{$oapath}-->Ins/js/common1.js" charset="utf-8"></script>
<script src="<!--{$oapath}-->Ins/js/jquery-2.1.1.js"></script>
<script src="<!--{$oapath}-->Ins/js/plugins/toastr/toastr.min.js"></script>
<script src="<!--{$oapath}-->Ins/js/plugins/gritter/jquery.gritter.min.js"></script>
<script src="<!--{$oapath}-->Ins/js/plugins/bootbox/bootbox.min.js"></script>
<script>
    layui.config({
        base: '<!--{$oapath}-->Ins/js/layui/',
        version: '1479330396824'
    }).extend({
        'moxie': 'plugins/plupload/moxie',
        'plupload': 'plugins/plupload/plupload',
        'moment': 'plugins/fullcalendar/moment',
        'fullcalendar': 'plugins/fullcalendar/fullcalendar',
        'tinymce': 'plugins/tinymce/tinymce',
        'toastr': 'plugins/toastr/toastr',
    });
</script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=HApG6QKUwGzgpS0aEK6P5Xmt4eX1I6cI"></script>
<script type="text/javascript">
    //var index = parent.layer.getFrameIndex(window.name);
    layui.use('global', function () {
        var $ = layui.jquery;
        var fn = {
            go_list: function () {
                location.href = "/index.php?m=&c=sign&a=index";
            },
            sign_in: function () {
                $('.layui-tab-title .layui-this').removeClass('layui-this');
                $('#sign_in').addClass('layui-this');
                $('#sign_in').addClass('layui-this');
                $("#state").val('sign_in');
            },
            sign_out: function () {
                $('.layui-tab-title .layui-this').removeClass('layui-this');
                $('#sign_out').addClass('layui-this');
                $("#state").val('sign_out');
            },
            outside: function () {
                $('.layui-tab-title .layui-this').removeClass('layui-this');
                $('#outside').addClass('layui-this');
                $("#state").val('outside');
            }
        };
        win_exp(fn);
        //关闭iframe
        $('#btn_close').click(function () {
            parent.layer.close(index);
        });
        $(function () {
            getLocation(function ($lat, $lng) {
                $.post("oa.php?c=Sign&a=get_location_baidu", 'state=&emp_no=&lat=' + $lat + '&lng=' + $lng, function (data) {
                    if (data.status) {
                        $msg = '<span class="text-success"><i class="fa fa-check"></i>定位成功</span>';
                        $("#msg").html($msg);
                        $("#time").html(data.time);
                        $('#hidden_time').val(data.time);
                        $("#location").html(data.location);
                        $("#hidden_location").val(data.location);
                        $('#hidden_lat').val(data.lat);
                        $('#hidden_lang').val(data.lang);
                        mark_map(data.lat, data.lang);
                        $('#btn_box').removeClass('hidden');
                    } else {
                        $msg = '<span class="text-danger"><i class="fa fa-times">' + data.info + '</span>';
                        $("#msg").html($msg);
                        $("#time").text(data.time);
                    }
                    ;
                    $(".wx_close").removeClass("hidden");
                }, "json");
            });
        });
    });
    function getLocation(callback) {
        ver = (navigator.appVersion).match(/OS (\d+)_(\d+)_?(\d+)?/);
        if (ver !== null) {
            ver = parseInt(ver[1], 10);
        }
        if (true) {
            var geolocation = new BMap.Geolocation();
            geolocation.getCurrentPosition(function (ret) {
                if (this.getStatus() == BMAP_STATUS_SUCCESS) {
                    //alert('您的位置：' + ret.point.lng + ',' + ret.point.lat);
                    callback(ret.point.lat, ret.point.lng);
                } else {
                    layer.msg('failed' + this.getStatus());
                }
            }, {
                enableHighAccuracy: true
            });
        } else {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function (p) {
                    callback(p.coords.latitude, p.coords.longitude);
                }, function (e) {
                    var msg = e.code + "\n" + e.message;
                });
            }
        }
    }
    function save() {
        var vars = $("#form_data").serialize();
        $.ajax({
            type: "POST",
            url: "oa.php?c=Sign&a=save",
            data: vars,
            dataType: "json",
            success: function (data) {
                if (data.status) {
                    layer.alert(data.info, function () {
                        parent.location.reload(true);
                        myclose();
                    });
                } else {
                    var position;
                    if (is_mobile()) {
                        position = "toast-top-full-width";
                    } else {
                        position = "toast-bottom-right";
                    }
                    toastr.options = {
                        "closeButton": true,
                        "positionClass": position
                    };
                    toastr.error('', data.info);
                }
            }
        });
    }
    /* 关闭弹出窗口*/
    function myclose() {
        parent.winclose();
    }
    function winclose() {
        $("body").removeClass("modal-open");
        $("div.shade").hide();
        $("#dialog").html("");
        $("#dialog").remove();
    }
    function mark_map($lat, $lng) {
        //百度地图api
        var map = new BMap.Map("allmap");
        var point = new BMap.Point($lng, $lat);
        var marker = new BMap.Marker(point);
        // 创建标注
        map.addOverlay(marker);
        // 将标注添加到地图中
        map.centerAndZoom(point, 15);
    }
</script>
</body>
</html>