<!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="addExpForm" action="#" style="margin-top: 20px">
                <input type="hidden" value="<?php echo $petId;?>" name="petId" id="petId"/>
                <header><i class="fa fa-fw fa-file"></i>宠物追加经验配置</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-success" id="addExpSubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid" style="border: 1px solid #CCC;margin: 20px 15px;">
                        <div class="row">
                            <div class="form-group addOrDelControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <?php foreach ($petInfo['addExp'] as $key => $vl) { ?>
                                    <div class="col-sm-12">
                                        <div class="col-sm-2">
                                            <span style="display: inline-block">等级:</span>
                                            <input type="text" class="form-control" name="add[minLv][]" value="<?php echo $vl['minLv'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <div class="col-sm-2">
                                            <span style="display: inline-block">喂食:</span>
                                            <input type="text" class="form-control" name="add[feedAddExp][]" value="<?php echo $vl['feedAddExp'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <?php if($petId ==1 ){?>
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">偷成功:</span>
                                                <input type="text" class="form-control" name="add[stealAddExp][]" value="<?php echo $vl['stealAddExp'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                        <?php } ?>
                                        <?php if($petId ==2 ){?>
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">防御成功:</span>
                                                <input type="text" class="form-control" name="add[defenseAddExp][]" value="<?php echo $vl['defenseAddExp'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                        <?php } ?>
                                        <?php if($petId ==3 ){?>
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">攻击成功:</span>
                                                <input type="text" class="form-control" name="add[attackAddExp][]" value="<?php echo $vl['attackAddExp'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">攻击失败:</span>
                                                <input type="text" class="form-control" name="add[defenseAddExp][]" value="<?php echo $vl['defenseAddExp'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                        <?php } ?>
                                        <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                    </div>
                                <?php } ?>
                                <button type="button" class="btn btn-success addParent" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                            </div>
                        </div>
                    </div>
                </section>
            </form>
        </aside>
    </div>


    <?php if($petId ==3 ){?>
        <div class="container-fluid">
            <aside>
                <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="skillBaseForm" action="#" style="margin-top: 20px">
                    <input type="hidden" value="<?php echo $petId;?>" name="petId" id="petId"/>
                    <header><i class="fa fa-fw fa-file"></i>宠物金币基础值配置</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <button type="button" class="btn btn-success" id="skillBaseSubmitBtn">提交</button>
                                </div>
                            </div>
                        </div>
                        <div class="container-fluid" style="border: 1px solid #CCC;margin: 20px 15px;">
                            <div class="row">
                                <div class="form-group addOrDelControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                    <?php foreach ($petInfo['skillBase'] as $key => $vl) { ?>
                                        <div class="col-sm-12">
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">等级:</span>
                                                <input type="text" class="form-control" name="add[minLv][]" value="<?php echo $vl['minLv'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">攻击成功:</span>
                                                <input type="text" class="form-control" name="add[sucAttack][]" value="<?php echo $vl['sucAttack'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                            <div class="col-sm-2">
                                                <span style="display: inline-block">攻击失败:</span>
                                                <input type="text" class="form-control" name="add[failAttack][]" value="<?php echo $vl['failAttack'];?>" style="display: inline-block;width: 55%">
                                            </div>
                                            <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                        </div>
                                    <?php } ?>
                                    <button type="button" class="btn btn-success addSkillBaseParent" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                </div>
                            </div>
                        </div>
                    </section>
                </form>
            </aside>
        </div>
    <?php } ?>



    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="configForm" action="#" style="margin-top: 20px">
                <input type="hidden" value="<?php echo $petId;?>" name="petId"/>
                <header><i class="fa fa-fw fa-file"></i>宠物经验配置</header>
                <section>
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-sm-12">
                                <button type="button" class="btn btn-success" id="configsubmitBtn">提交</button>
                                <button type="button" class="btn btn-success" id="importBtn">导入</button><input  type="file" style="display: none" id="importFile">
                                <button type="button" class="btn btn-success" id="exportBtn">导出</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid" style="border: 1px solid #CCC;margin: 20px 15px;">
                        <div class="row">
                            <div class="form-group" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <label class="col-sm-1 control-label">经验*: </label>
                                <?php foreach ($list as $key => $vl) { ?>
                                    <?php if($key !=0 ){ echo "<label class=\"col-sm-1 control-label\"></label>";}?>
                                    <div class="col-sm-11">
                                        <div class="col-sm-3">
                                            <span style="display: inline-block">等级:</span>
                                            <input type="text" class="form-control" readonly name="config[<?php echo $vl['lv'];?>][lv]" value="<?php echo $vl['lv'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <div class="col-sm-3">
                                            <span style="display: inline-block">星星:</span>
                                            <input type="text" class="form-control" readonly name="config[<?php echo $vl['lv'];?>][star]" value="<?php echo $vl['star'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <div class="col-sm-3">
                                            <span style="display: inline-block">经验值:</span>
                                            <input type="text" class="form-control" name="config[<?php echo $vl['lv'];?>][exp]" value="<?php echo $vl['exp'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <div class="col-sm-3">
                                            <span style="display: inline-block">技能增益:</span>
                                            <input type="text" class="form-control" name="config[<?php echo $vl['lv'];?>][skill]" value="<?php echo $vl['skill'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                    </div>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    $('.addParent').on("click",function(){
        var petId = $('#petId').val();
        if(petId == 1){
            var str = "";
            str += '<div class="col-sm-12"><div class="col-sm-2"><span style="display: inline-block">等级:</span><input type="text" class="form-control" name="add[minLv][]" value="1" style="display: inline-block;width: 55%">';
            str += '</div><div class="col-sm-2"><span style="display: inline-block">喂食:</span><input type="text" class="form-control" name="add[feedAddExp][]" value="1" style="display: inline-block;width: 55%"></div>';
            str += '<div class="col-sm-2"><span style="display: inline-block">偷成功:</span><input type="text" class="form-control" name="add[stealAddExp][]" value="1" style="display: inline-block;width: 55%"></div>';
            str += '<button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        }else if(petId == 2){
            var str = "";
            str += '<div class="col-sm-12"><div class="col-sm-2"><span style="display: inline-block">等级:</span><input type="text" class="form-control" name="add[minLv][]" value="1" style="display: inline-block;width: 55%">';
            str += '</div><div class="col-sm-2"><span style="display: inline-block">喂食:</span><input type="text" class="form-control" name="add[feedAddExp][]" value="1" style="display: inline-block;width: 55%"></div>';
            str += '<div class="col-sm-2"><span style="display: inline-block">防御成功:</span><input type="text" class="form-control" name="add[defenseAddExp][]" value="1" style="display: inline-block;width: 55%"></div>';
            str += '<button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        }else if(petId == 3){
            var str = "";
            str += '<div class="col-sm-12"><div class="col-sm-2"><span style="display: inline-block">等级:</span><input type="text" class="form-control" name="add[minLv][]" value="1" style="display: inline-block;width: 55%">';
            str += '</div><div class="col-sm-2"><span style="display: inline-block">喂食:</span><input type="text" class="form-control" name="add[feedAddExp][]" value="1" style="display: inline-block;width: 55%"></div>';
            str += '<div class="col-sm-2"><span style="display: inline-block">攻击成功:</span><input type="text" class="form-control" name="add[attackAddExp][]" value="1" style="display: inline-block;width: 55%">';
            str += '</div><div class="col-sm-2"><span style="display: inline-block">攻击失败:</span><input type="text" class="form-control" name="add[defenseAddExp][]" value="1" style="display: inline-block;width: 55%"></div>';
            str += '<button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        }
    });

    $('.addSkillBaseParent').on("click",function(){
        var str = "";
        str += '<div class="col-sm-12"><div class="col-sm-2"><span style="display: inline-block">等级:</span><input type="text" class="form-control" name="add[minLv][]" value="1" style="display: inline-block;width: 55%">\n' +
            '</div><div class="col-sm-2"><span style="display: inline-block">攻击成功:</span><input type="text" class="form-control" name="add[sucAttack][]" value="1" style="display: inline-block;width: 55%">\n' +
            '</div><div class="col-sm-2"><span style="display: inline-block">攻击失败:</span><input type="text" class="form-control" name="add[failAttack][]" value="1" style="display: inline-block;width: 55%"></div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
        $(this).before(str);
    });



    $('.addOrDelControl').on("click",'.deleteParent',function(){
        $(this).parent().remove();
    });
    $(function () {
        $('#configsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("configForm"));
            $.ajax({
                url: rootPath + 'pet/actionConfig2',
                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);
                }
            });
        });
        $('#addExpSubmitBtn').click(function () {
            var data = new FormData(document.getElementById("addExpForm"));
            $.ajax({
                url: rootPath + 'pet/actionConfig3',
                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);
                }
            });
        });
        $('#skillBaseSubmitBtn').click(function () {
            var data = new FormData(document.getElementById("skillBaseForm"));
            $.ajax({
                url: rootPath + 'pet/actionConfig4',
                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);
                }
            });
        });

        $('#exportBtn').click(function () {
            window.open("/export/petConfig/<?=$petId?>")
        })
        $('#importBtn').click(function () {
            $('#importFile').click()
        })
        $('#importFile').change(function(){
            var _this = $(this)
            var filePath = _this.val();
            var fileId = _this.attr('id')
            if (filePath) {
                showLoading()
                var formData = new FormData();
                formData.append("file",document.getElementById(fileId).files[0]);
                $.ajax({
                    type: "POST", // 数据提交类型
                    url: "/import/petConfig/<?=$petId?>",
                    data: formData, //发送数据
                    async: false, // 是否异步
                    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>
