<!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>
            <header><i class="fa fa-fw fa-file"></i>活动模式</header>
            <section>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-2">
                            <select class="form-control" id="RankModel" style="display: inline-block;">
                                <option value="1" <?php if($model == 1){ echo 'selected';}?> >钻石模式</option>
                                <option value="2" <?php if($model == 2){ echo 'selected';}?> >收集模式</option>
                                <option value="3" <?php if($model == 3){ echo 'selected';}?> >兼容模式</option>
                            </select>
                        </div>
                        <div class="col-sm-1">
                            <button type="button" class="btn btn-success" onclick="setModel()">提交</button>
                        </div>
                    </div>
                </div>
            </section>
        </aside>
    </div>
    <div class="container-fluid">
        <aside>
            <form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"  id="goodForm" action="#" style="margin-top: 20px">
                <input type="hidden" value="<?php echo $id;?>" name="id"/>
                <input type="hidden" value="rank" name="type"/>
                <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">
                        <?php foreach ($rankConfig 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">排行*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control" readonly name="rank[<?php echo $vl['id'];?>][id]" value="<?php echo $vl['id'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">金币奖励*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="rank[<?php echo $vl['id'];?>][coins]" value="<?php echo $vl['coins'];?>">
                                    </div>
                                    <label class="col-sm-1 control-label">体力奖励*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="rank[<?php echo $vl['id'];?>][spins]" value="<?php echo $vl['spins'];?>">
                                    </div>
                                    <div class="col-sm-3">
                                        <label class="col-sm-4 control-label">活动类型:</label>
                                        <select class="form-control" name="rank[<?php echo $vl['id'];?>][props][propsId]" style="display: inline-block;width: 50%">
                                            <option value="0" <?php if($vl['props']['propsId'] == 0){ echo 'selected';}?> >无</option>
                                            <option value="1" <?php if($vl['props']['propsId'] == 1){ echo 'selected';}?> >木质宝箱</option>
                                            <option value="2" <?php if($vl['props']['propsId'] == 2){ echo 'selected';}?> >白银宝箱</option>
                                            <option value="3" <?php if($vl['props']['propsId'] == 3){ echo 'selected';}?> >黄金宝箱</option>
                                            <option value="4" <?php if($vl['props']['propsId'] == 4){ echo 'selected';}?> >魔幻宝箱</option>
                                        </select>
                                    </div>
                                    <label class="col-sm-1 control-label">奖励数量*: </label>
                                    <div class="col-sm-1">
                                        <input type="text" class="form-control"  name="rank[<?php echo $vl['id'];?>][props][num]" value="<?php echo $vl['props']['num'];?>">
                                    </div>
                                </div>
                            </div>
                        <?php } ?>
                    </div>
                </section>
            </form>
        </aside>
    </div>
    <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 $id;?>" name="id"/>
                <input type="hidden" value="progress" name="type"/>
                <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>
                            </div>
                        </div>
                    </div>
                    <div class="container-fluid" style="border: 1px solid #CCC;margin: 20px 15px;">
                        <div class="row">
                        	<?php foreach ($rankProgressConfig as $key => $vl) { ?>
                            <div class="form-group" style="border: 1px solid #CCC;margin:10px 5px;padding: 5px 0;">
                                
                                    <div class="col-sm-12">
                                        <div class="col-sm-1">
                                            <span style="display: inline-block">进度:</span>
                                            <input type="text" class="form-control" readonly name="progress[<?php echo $vl['id'];?>][id]" value="<?php echo $vl['id'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <div class="col-sm-1">
                                            <span style="display: inline-block">进度条:</span>
                                            <input type="text" class="form-control" name="progress[<?php echo $vl['id'];?>][progressBarId]" value="<?php echo $vl['progressBarId'];?>" style="display: inline-block;width: 50%">
                                        </div>
                                        <div class="col-sm-2">
                                            <span style="display: inline-block">进度数量:</span>
                                            <input type="text" class="form-control" name="progress[<?php echo $vl['id'];?>][max]" value="<?php echo $vl['max'];?>" 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="progress[<?php echo $vl['id'];?>][coins]" value="<?php echo $vl['coins'];?>" 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="progress[<?php echo $vl['id'];?>][spins]" value="<?php echo $vl['spins'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        <div class="col-sm-4 addOrDelControl">
                                            <label class="col-sm-4 control-label">道具奖励:</label>

                                            <div class="col-sm-8">
												<?php 
													if(!empty($vl['props'])){
														foreach ($vl['props'] as $key => $val){
												?>
					                            <div class="col-sm-12" style="margin-top: 1rem;padding-left:0">
					                            	<div class="col-sm-5">
					                            		<select class="form-control typeControl" name="progress[<?php echo $vl['id'];?>][props][propsId][<?php echo $key;?>]">
					                            			<option value="0" <?php if($vl['props'][$key]['propsId'] == -1){ echo 'selected';}?>>卡片</option>
					                            			<option value="1" <?php if($vl['props'][$key]['propsId'] == 1){ echo 'selected';}?>>木质宝箱</option>
					                            			<option value="2" <?php if($vl['props'][$key]['propsId'] == 2){ echo 'selected';}?>>白银宝箱</option>
					                            			<option value="3" <?php if($vl['props'][$key]['propsId'] == 3){ echo 'selected';}?>>黄金宝箱</option>
					                            			<option value="4" <?php if($vl['props'][$key]['propsId'] == 4){ echo 'selected';}?>>魔幻宝箱</option>
					                            			<option value="5" <?php if($vl['props'][$key]['propsId'] == 5){ echo 'selected';}?>>卡组祈福</option>
					                            			<option value="6" <?php if($vl['props'][$key]['propsId'] == 6){ echo 'selected';}?>>卡片祈福</option>
					                            			<option value="7" <?php if($vl['props'][$key]['propsId'] == 7){ echo 'selected';}?>>夺宝卷</option>
					                            			<option value="8" <?php if($vl['props'][$key]['propsId'] == 8){ echo 'selected';}?>>宠物经验</option>
					                            			<option value="9" <?php if($vl['props'][$key]['propsId'] == 9){ echo 'selected';}?>>宠物食物</option>
					                            			<option value="10" <?php if($vl['props'][$key]['propsId'] == 10){ echo 'selected';}?>>绿宝箱</option>
					                            			<option value="11" <?php if($vl['props'][$key]['propsId'] == 11){ echo 'selected';}?>>蓝宝箱</option>
					                            			<option value="12" <?php if($vl['props'][$key]['propsId'] == 12){ echo 'selected';}?>>红宝箱</option>
					                            		</select>
					                            	</div>
					                            	<div class="col-sm-5">
					                            		<input type="number" class="form-control" placeholder="道具数量" name="progress[<?php echo $vl['id'];?>][props][num][<?php echo $key;?>]" min="1" value="<?php echo $vl['props'][$key]['num'];?>">
					                            	</div>
					                            	<div class="col-sm-1">
					                            		<button type="button" class="btn btn-danger deleteParent">删除</button>
					                            	</div>
					                            </div>
												<?php
														}
													} 
												?>
					                            <div class="col-sm-12" style="margin-top: 1rem;">
					                                <button type="button" class="btn btn-success addParent" bid="<?php echo $vl['id'];?>">新增道具</button>
					                            </div>
					                        </div>
					                        <!--
                                            <select class="form-control" name="progress[<?php echo $vl['id'];?>][props][propsId]" id="img" style="display: inline-block;width: 50%">
                                                <option value="0" <?php if($vl['props']['propsId'] == 0){ echo 'selected';}?>>无</option>
                                                <option value="1" <?php if($vl['props']['propsId'] == 1){ echo 'selected';}?>>木质宝箱</option>
                                                <option value="2" <?php if($vl['props']['propsId'] == 2){ echo 'selected';}?>>黄金宝箱</option>
                                                <option value="3" <?php if($vl['props']['propsId'] == 3){ echo 'selected';}?>>魔幻宝箱</option>
                                            </select>
                                            -->
                                        </div>
                                        <!--
                                        <div class="col-sm-2">
                                            <span style="display: inline-block">奖励数量:</span>
                                            <input type="text" class="form-control" name="progress[<?php echo $vl['id'];?>][props][num]]" value="<?php echo $vl['props']['num'];?>" style="display: inline-block;width: 55%">
                                        </div>
                                        -->
                                    </div>
                                    
                                
                            </div>
                            <?php } ?>
                        </div>
            </form>
    </div>
    </section>

    </aside>
</div>
</div>
</div>
</body>

<script type="text/javascript">
    function setModel() {
        $.ajax({
            url: rootPath + 'activity/setRankModel',
            type: 'POST',
            data: {
                'model':$('#RankModel').val(),
            },
            dataType: 'json',
            success: function (data) {
                alert(data.msg);
            },
            error: function (data) {
                alert(data.msg);
            }
        }) ;
    }
    $(function () {
        $('#goodsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("goodForm"));
            $.ajax({
                url: rootPath + 'activity/actionConfig',
                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);
                }
            });
        });
        $('#configsubmitBtn').click(function () {
            var data = new FormData(document.getElementById("configForm"));
            $.ajax({
                url: rootPath + 'activity/actionConfig',
                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);
                }
            });
        });
        
        
        var idData = JSON.parse('<?php echo json_encode($propsConfig['props']); ?>');
    
	    $('.addParent').on("click",function(){
	    	var id = $(this).attr("bid");
	        var str = '<div class="col-sm-12" style="margin-top: 1rem;padding-left:0"><div class="col-sm-5"><select class="form-control typeControl" name="progress['+id+'][props][propsId][]">';
	        
	        for(var x in idData) {
	        	console.log(x);
	            str += '<option value="'+x+'">'+idData[x]['msg']+'</option>';
	        }
	        str +='</select></div><div class="col-sm-5"><input type="number" class="form-control" placeholder="道具数量" name="progress['+id+'][props][num][]" min="1" value="1"></div><div class="col-sm-1"><button type="button" class="btn btn-danger deleteParent" >删除</button></div></div>';
	        $(this).parent().before(str);
	    });
	    $('.addOrDelControl').on("click",'.deleteParent',function(){
	        $(this).parent().parent().remove();
	    });
    });
    
    
</script>
</html>
