<!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="goodForm" 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-12">
                                <button type="button" class="btn btn-success" id="goodsubmitBtn">提交</button>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid">
                        <div class="row AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                            <div class="form-group">
                                <label class="col-sm-2 control-label pull-left">召回等级*: </label>
                                <div class="col-sm-2"> <input type="text" class="form-control" name="callback[level]" value="<?=$callback['level']?>"> </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">奖励物品*: </label>
                                <div class="col-sm-8">
                                    <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                        <div class="form-group">
                                            <label class="col-sm-1 control-label">金币*: </label>
                                            <div class="col-sm-3">
                                                <select class="form-control typeControl" name="callback[reward][coins][coins]">
                                                    <option value="coins01" <?php if($callback['reward']['coins'] == "coins01") echo 'selected'; ?>>coins01</option>
                                                    <option value="coins02" <?php if($callback['reward']['coins'] == "coins02") echo 'selected'; ?>>coins02</option>
                                                    <option value="coins03" <?php if($callback['reward']['coins'] == "coins03") echo 'selected'; ?>>coins03</option>
                                                    <option value="coins04" <?php if($callback['reward']['coins'] == "coins04") echo 'selected'; ?>>coins04</option>
                                                    <option value="coins05" <?php if($callback['reward']['coins'] == "coins05") echo 'selected'; ?>>coins05</option>
                                                    <option value="coins06" <?php if($callback['reward']['coins'] == "coins06") echo 'selected'; ?>>coins06</option>
                                                </select>
                                            </div>
                                            <label class="col-sm-1 control-label">倍率*: </label>
                                            <div class="col-sm-3">
                                                <input type="text" class="form-control" name="callback[reward][coins][bet]" value="<?php echo $callback['reward']['coins']['bet'];?>">
                                            </div>
                                        </div>

                                        <?php if(!empty($callback['reward']['props'])){ ?>
                                        <?php foreach ($callback['reward']['props'] as $k => $reward) { ?>
                                            <div class="form-group">
                                                <label class="col-sm-1 control-label">道具*: </label>
                                                <div class="col-sm-3">
                                                    <select class="form-control" name="callback[reward][props][propsId][]">
                                                        <?php foreach ($idData as $propsId=>$props) { ?>
                                                            <option value="<?php echo $propsId;?>" <?php if($reward['propsId'] == $propsId) echo 'selected'; ?>><?php echo $props['msg'];?></option>
                                                        <?php } ?>
                                                    </select>
                                                </div>
                                                <label class="col-sm-2 control-label">数量*: </label>
                                                <div class="col-sm-2">
                                                    <input type="text" class="form-control"  name="callback[reward][props][num][]" value="<?php echo $reward['num'];?>">
                                                </div>
                                                <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                            </div>
                                        <?php } ?>
                                        <?php } ?>
                                        <button type="button" class="btn btn-success addcallBackParent" id="<?php echo $vl['id'];?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                    </div>
                                </div>
                            </div>

                        </div>
                    </div>
                </section>
                <header><i class="fa fa-fw fa-file"></i>好友数量进度奖励配置</header>
                <section>
                    <div class="container-fluid">
                        <?php foreach ($list as $key => $vl) { ?>
                            <div class="row AllTypeControl" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                <div class="form-group" >
                                    <input type="hidden" class="form-control" readonly name="reward[<?php echo $vl['id'];?>][id]" value="<?=$vl['id'];?>">
                                    <label class="col-sm-2 control-label">进度*: </label>
                                    <div class="col-sm-2">
                                        <input type="text" class="form-control" readonly name="step" value="<?=($key+1);?>">
                                    </div>
                                    <label class="col-sm-2 control-label">所需好友数量*: </label>
                                    <div class="col-sm-3">
                                        <input type="text" class="form-control"  name="reward[<?php echo $vl['id'];?>][num]" value="<?php echo $vl['num'];?>">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">奖励物品*: </label>
                                    <div class="col-sm-8">
                                        <div class="container-fluid addOrDelControl" style="border: 1px solid #CCC;margin: 20px 15px;padding-top: 10px;">
                                            <div class="form-group" style="display:none">
                                                <label class="col-sm-1 control-label">金币*: </label>
                                                <div class="col-sm-3">
                                                    <select class="form-control typeControl" name="reward[<?php echo $vl['id'];?>][reward][coins][coins]">
                                                        <option value="coins01" <?php if($vl['reward']['coins']['coins'] == "coins01") echo 'selected'; ?>>coins01</option>
                                                        <option value="coins02" <?php if($vl['reward']['coins']['coins'] == "coins02") echo 'selected'; ?>>coins02</option>
                                                        <option value="coins03" <?php if($vl['reward']['coins']['coins'] == "coins03") echo 'selected'; ?>>coins03</option>
                                                        <option value="coins04" <?php if($vl['reward']['coins']['coins'] == "coins04") echo 'selected'; ?>>coins04</option>
                                                        <option value="coins05" <?php if($vl['reward']['coins']['coins'] == "coins05") echo 'selected'; ?>>coins05</option>
                                                        <option value="coins06" <?php if($vl['reward']['coins']['coins'] == "coins06") echo 'selected'; ?>>coins06</option>
                                                    </select>
                                                </div>
                                                <label class="col-sm-1 control-label">倍率*: </label>
                                                <div class="col-sm-3">
                                                    <input type="text" class="form-control"  name="reward[<?php echo $vl['id'];?>][reward][coins][bet]" value="<?php echo $vl['reward']['coins']['bet'];?>">
                                                </div>
                                            </div>
                                            <?php if(!empty($vl['reward']['props'])){ ?>
                                            <?php foreach ($vl['reward']['props'] as $k => $reward) { ?>
                                                <div class="form-group">
                                                    <label class="col-sm-1 control-label">道具*: </label>
                                                    <div class="col-sm-3">
                                                        <select class="form-control" name="reward[<?php echo $vl['id'];?>][reward][props][propsId][]">
                                                            <?php foreach ($idData as $propsId=>$props) { ?>
                                                                <option value="<?php echo $propsId;?>" <?php if($reward['propsId'] == $propsId) echo 'selected'; ?>><?php echo $props['msg'];?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                    <label class="col-sm-2 control-label">数量*: </label>
                                                    <div class="col-sm-2">
                                                        <input type="text" class="form-control"  name="reward[<?php echo $vl['id'];?>][reward][props][num][]" value="<?php echo $reward['num'];?>">
                                                    </div>
                                                    <button type="button" class="btn btn-danger deleteParent" >删除</button>
                                                </div>
                                            <?php } ?>
                                            <?php } ?>
                                            <button type="button" class="btn btn-success addParent" id="<?php echo $vl['id'];?>" style="margin-left: 12px;margin-bottom: 10px;">增加</button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
</div>
</body>

<script>
    $(function () {
        var idData = JSON.parse('<?php echo json_encode($idData); ?>');

        $('.addOrDelControl').on("click",'.deleteParent',function(){
            $(this).parent().remove();
        });

        $('.addcallBackParent').on("click",function(){
            var id = $(this).attr('id');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-1 control-label">道具*: </label><div class="col-sm-3"><select class="form-control" name="callback[reward][props][propsId][]"">';
            for(var x in idData) {
                str += '<option value="'+x+'">'+idData[x]['msg']+'</option>';
            }
            str += '</select></div><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="callback[reward][props][num][]" value="1">'+
                '</div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });


        $('.addParent').on("click",function(){
            var id = $(this).attr('id');
            var str = "";
            str += '<div class="form-group"><label class="col-sm-1 control-label">道具*: </label><div class="col-sm-3"><select class="form-control" name="reward['+id+'][reward][props][propsId][]"">';
            for(var x in idData) {
                str += '<option value="'+x+'">'+idData[x]['msg']+'</option>';
            }
            str += '</select></div><label class="col-sm-2 control-label">数量*: </label><div class="col-sm-2"><input type="text" class="form-control"  name="reward['+id+'][reward][props][num][]" value="1">'+
                '</div><button type="button" class="btn btn-danger deleteParent" >删除</button></div>';
            $(this).before(str);
        });


        $('#goodsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("goodForm"));
            $.ajax({
                url: rootPath + 'config/saveFriendProgress',
                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);
                }
            });
        });
        
        $(document).on("change",".gsku",function(){
        	var id = $(this).attr("id");
        	var value = $(this).val();
        	var price = $(this).find("option:selected").attr('price');
        	$(".price"+id).val(price);
        	console.log($(this).attr("id"));
        });

    });

</script>
</html>
