<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link rel="stylesheet" type="text/css" href="/assets/css/plugins/webuploader/webuploader.css">
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>批量处理车辆信息</h5>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <form role="form" class="form-horizontal data-from" id="theFrm">
                        <div class="form-group w-100">
                            <label class="control-label col-sm-1">文件</label>
                            <div class="col-sm-4">
                                <input type="text" name="filename" id="filename" class="form-control" value="">
                                <input type="hidden" name="urlfile" id="urlfile" class="form-control" value="">
                            </div>
                            <div class="col-sm-6">
                                <button type="button" class="btn btn-primary" id="upload">上传文件</button>
                                <button type="button" class="btn btn-primary" id="import-btn" onclick="reloadIframe('/finance/car-info-import')">导入</button>
                                <button type="button" class="btn btn-primary" id="update-btn" onclick="reloadIframe('/finance/car-info-bhx-update')">更新</button>
                                <a href="/print/car_info_import_temp.xlsx" class="btn btn-link" download="车辆信息导入模板.xlsx">[下载车辆信息导入模板]</a>
                                <a href="/print/car_info_update_temp.xlsx" class="btn btn-link" download="车辆信息更新模板.xlsx">[下载车辆信息导入模板]</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="layui-card-body">
                <iframe id="process" src="" frameborder="0"></iframe>
            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footer_js'); ?>
<script src="/assets/js/plugins/webuploader/webuploader.min.js"></script>
<script type="text/javascript" language="javascript">
    layui.use(['upload'], function(){
        var upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            ,url: '/common/upload' //上传接口
            ,accept: 'file'
            ,done: function(res){
                //上传完毕回调
                if(res.status == 'SUCCESS') {
                    $('#filename').val(res.OriginfileName);
                    $('#urlfile').val(res.fileUrl);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
    function reloadIframe(url){
        if (confirm('是否确认提交?')) {
            layer.load(1, {shade: [0.1,'#fff']});
            $('#process').css({
                'width': '100%',
                'height': 'calc(100% - 220px)',
                'background': '#000',
                'overflow': 'hidden',
            }).attr('src', url + '?' + $("#theFrm").serialize());
            $('#process').contents().change(function(){
                $('#process').animate({ scrollTop: $("#frame").height()});
            });
            window.onbeforeunload=function(event){
                return '当前有任务正在进行，确定要退出吗';
            }
        }
    }
</script>
<?php $this->endBlock('footer_js'); ?>
