<div class="content_wrapper">

    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>快捷商品配置</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="btn-group" style="margin-bottom:20px;">
                                        <button type="button" class="btn btn-success" data-toggle="modal" data-target="#actionAdd">添加快捷商品配置</button>
                                    </div>
                                    <div class="table-responsive">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>盲住</th>
                                                <th>官方商品</th>
                                                <th>第三方商品</th>
                                                <th>破产商品</th>
                                                <th>更新时间</th>
                                                <th>操作</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <?php 
                                                if(is_array($list)){
                                                    foreach ($list as $key => $val) {
                                            ?>
                                            <tr>
                                                <td><?php echo $val['smallblind'];?></td>
                                                <td><?php echo implode(',',unserialize($val['official_goods']));?></td>
                                                <td><?php echo implode(',',unserialize($val['other_goods']));?></td>
                                                <td><?php echo $val['official_broke_goods'].','.$val['other_broke_goods'];?></td>
                                                <td><?php echo date('Y-m-d H:i:s', $val['updatetime']);?></td>
                                                <td>
                                                    <button type="button" class="btn btn-success editsmallblind" value="<?php echo $val['id'];?>" >编辑</button>
                                                </td>
                                            </tr>
                                            <?php } } else{?>
                                            <tr>
                                                <td colspan="10">暂无数据</td>
                                            </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                    <nav>
                                        <ul class="pagination">
                                            <li class="disabled"><a href="#">共<span class="pagetotal"><?php echo $total;?></span>条</a></li>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<div class="modal fade" id="actionAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">创建快捷商品</h4>
            </div>
            <form class="form-horizontal J_ajaxForm" role="form" method="post" action="Levelinfo/actionAdd">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">盲注:</label>
                        <div class="col-sm-9">
                            <label class="select-inline">
                                <select class="form-control" name="smallblind" id="select_smallblind">
                                <?php 
                                    foreach ($smallblind as $v) {
                                ?>
                                  <option value="<?php echo $v;?>"><?php echo number_format($v);?></option>
                                <?php
                                    }
                                ?>
                                </select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">商品类型:</label>
                        <div class="col-sm-9">
                            <label class="radio-inline">
                              <input type="radio" name="gtype" checked="checked" value="1"> 筹码
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">官方商品:</label>
                        <div class="col-sm-9">
                            <label class="select-inline" style="margin-right: 20px;">
                                <select class="form-control official_gname" name="official_gname[]" id="official_gname1"></select>
                            </label>
                            <label class="select-inline">
                                <select class="form-control official_gname" name="official_gname[]" id="official_gname2"></select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">官方破产商品:</label>
                        <div class="col-sm-9">
                            <label class="select-inline" style="margin-right: 20px;">
                                <select class="form-control official_gname" name="official_broke_goods" id="official_broke_goods"></select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">第三方商品渠道:</label>
                        <div class="col-sm-9">
                            <label class="radio-inline">
                              <input type="radio" name="gchannel" value="2" checked="checked"> SMS
                            </label>
                            <label class="radio-inline">
                              <input type="radio" name="gchannel" value="4"> Bluecoins
                            </label>
                            <label class="radio-inline">
                              <input type="radio" name="gchannel" value="5"> Truemoney
                            </label>
                            <label class="radio-inline">
                              <input type="radio" name="gchannel" value="6"> 12call
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">第三方商品:</label>
                        <div class="col-sm-9">
                            <label class="select-inline" style="margin-right: 20px;">
                                <select class="form-control gname" name="gname[]" id="gname1">
                                </select>
                            </label>
                            <label class="select-inline">
                                <select class="form-control gname" name="gname[]" id="gname2">
                                </select>
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">第三方破产商品:</label>
                        <div class="col-sm-9">
                            <label class="select-inline" style="margin-right: 20px;">
                                <select class="form-control gname" name="broke_gname" id="broke_gname">
                                </select>
                            </label>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary J_ajaxSubmitBtn">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>


<script>
//生成商品
$("input[name='gchannel']").click(function(){
    var gchannelId = $(this).val();
    $('.gname').empty();//把type清空
    $.ajax({
        type: "POST",
        dataType: "JSON",
        url: "<?php echo base_url('levelinfo/getGoodsByChannel');?>",
        data: "gchannelId="+gchannelId,
        success:function(e){
            $.each(e,function (k,p){
                $('.gname').append('<option value="'+p+'">'+p+'</option>');
            });
        }
    });
});

//初始化
$('.official_gname').empty();//把type清空
$('.gname').empty();//把type清空
$.ajax({
        type: "POST",
        dataType: "JSON",
        url: "<?php echo base_url('levelinfo/getGoodsByChannel');?>",
        data: "gchannelId="+1,
        success:function(e){
            $.each(e,function (k,p){
            $('.official_gname').append('<option value="'+p+'">'+p+'</option>');
            });
        }
});
$.ajax({
        type: "POST",
        dataType: "JSON",
        url: "<?php echo base_url('levelinfo/getGoodsByChannel');?>",
        data: "gchannelId="+2,
        success:function(e){
            $.each(e,function (k,p){
            $('.gname').append('<option value="'+p+'">'+p+'</option>');
            });
        }
});


//获取单条数据
$('.editsmallblind').click(function(){
    var id = $(this).val();
    //$('.gname').empty();//把type清空
    $.ajax({
        type: "POST",
        dataType: "JSON",
        url: "<?php echo base_url('levelinfo/actionGetOne');?>",
        data: "id="+id,
        success:function(e){
            var smallblind = e.smallblind;
            var official_goods = e.official_goods;
            var other_goods = e.other_goods;
            var gchannel = e.gchannel;
            var official_broke_goods = e.official_broke_goods;
            var other_broke_goods = e.other_broke_goods;

            $("#select_smallblind option[value='"+smallblind+"']").attr("selected", true);

            $("#official_gname1 option[value='"+official_goods[0]+"']").attr("selected", true);
            $("#official_gname2 option[value='"+official_goods[1]+"']").attr("selected", true);

            $("#gname1 option[value='"+other_goods[0]+"']").attr("selected", true);
            $("#gname2 option[value='"+other_goods[1]+"']").attr("selected", true);

            $("#official_broke_goods option[value='"+official_broke_goods+"']").attr("selected", true);
            $("#broke_gname option[value='"+other_broke_goods+"']").attr("selected", true);

            $(":radio[name='gchannel'][value='" + gchannel + "']").prop("checked", "checked");
        }
    });
    $('#actionAdd').modal();
});
</script>