<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>主页背景配置</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/bootstrap/bootstrap.min.css" >
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
    <link rel="stylesheet" href="<?php echo base_url();?>public/css/jquery.timepicker.min.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/select2/select2.min.css">

    <style type="text/css">
        .thumbnail {
            margin:10px;
        }

        .lang-name {
            margin-left:42px;
        }

        .upimg {
            cursor: pointer;
        }

    </style>
</head>
<body>
<div id="msg-tip">

</div>
<div class="content_wrapper">
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="form" action="#" style="margin-top: 20px">
                <header><i class="fa fa-fw fa-file"></i>主页背景配置</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-1">
                                <button type="button" style="width: 80%" class="btn btn-success" id="submitBtn">提交</button>
                            </div>
                            <div class="col-sm-1">
                                <button type="button" style="width: 80%" class="btn btn-success" id="importBtn">导入</button>
                                <input type="file" style="display: none;" id="importFile">
                            </div>
                            <div class="col-sm-1">
                                <a type="button" style="width: 80%" class="btn btn-success" href="/export/mainBg" target="_blank" id="exportBtn">导出</a>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <?php foreach ($config as $key => $vl) { ?>
                            <div class="row" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="form-group" >
                                    <label class="col-sm-1 control-label" style="width: 5%">岛屿ID</label>
                                    <div class="col-sm-1" style="width: 5%">
                                        <input type="text" class="form-control" readonly name="config[<?php echo $vl['levelId'];?>][levelId]" value="<?php echo $vl['levelId'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label" style="width: 5%">背景1</label>
                                    <div class="col-sm-1" style="width: 5%">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['levelId'];?>][bg1]" value="<?php echo $vl['bg1'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">背景1云朵色号</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['levelId'];?>][color1]" value="<?php echo $vl['color1'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label" style="width: 5%">背景2</label>
                                    <div class="col-sm-1" style="width: 5%">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['levelId'];?>][bg2]" value="<?php echo $vl['bg2'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">背景2云朵色号</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['levelId'];?>][color2]" value="<?php echo $vl['color2'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">动画</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['levelId'];?>][animation]" value="<?php echo $vl['animation'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">动画2</label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="config[<?php echo $vl['levelId'];?>][animation2]" value="<?php echo $vl['animation2'];?>">
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    $(function () {
        $('#submitBtn').click(function () {
            var data = new FormData(document.getElementById("form"));
            $.ajax({
                url: rootPath + 'Config/actionMainBg',
                type: 'POST',
                data: data,
                dataType: 'json',
                contentType: false, //必须
                processData: false, //必须
                success: function (data) {
                    alert(data.msg);
                    // window.location.reload();
                },
                error: function (msg) {
                    alert(data.msg);
                }
            });
        });
    });


    $('#importBtn').click(function () {
        $('#importFile').click()
    })
    $("#importFile").change(function() {
        var _this = $(this)
        var filePath = _this.val();
        if (filePath) {
            var formData = new FormData();
            formData.append("file",document.getElementById('importFile').files[0]);
            showLoading()
            $.ajax({
                type: "POST", // 数据提交类型
                url: 'import/mainBg',//"activity/importSerialPack", // 发送地址
                data: formData, //发送数据
                processData: false, //processData 默认为false，当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                contentType: false, //
                success: function(data) { // 成功回调
                    hideLoading()
                    _this.val('');
                    data = JSON.parse(data);
                    console.log(data)
                    alert(data.msg)
                    if(data.ret == 0){
                        window.location.reload();
                    }
                },
                error:function(e,x,h){
                    hideLoading()
                    _this.val('');
                    alert(h)
                }
            });
        } else {
            return false
        }
    });
</script>
</html>
