<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="btn-group" style="margin-bottom:20px;">
                                <a href="<?php echo base_url('/#mall/add/')?>" class="btn btn-success" role="button"><i class="fa fa-plus-square"></i>添加兑换商品</a>
                                <a style="margin-left: 5px;" href="<?php echo base_url('/#mall/couponlist/')?>" class="btn btn-info" role="button"><i class="fa fa-plus-square"></i>礼品券/礼券列表</a>
                                <a style="margin-left: 5px;" href="<?php echo base_url('/#mall/exchangerecord/')?>" class="btn btn-info" role="button"><i class="fa fa-plus-square"></i>玩家兑换记录</a>
                            </div>
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive">
                                        <table id="example" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>商品ID</th>
                                                <th>图片</th>
                                                <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) {
                                                    $nameList = json_decode($val['name'], 1);
                                                    $nameStr = '';
                                                    if(!empty($nameList)) {
                                                        foreach ($nameList as $k => $v) {
                                                           isset($langList[$k]) &&  $nameStr .= $langList[$k] . ':'. $v."<br/>";
                                                        }
                                                    }
                                                    ?>
                                                    <tr>
                                                        <td><?php echo $val['id'];?></td>
                                                        <td><img src="<?php echo  empty($val['img']) ? '' :  $baseUrl.'/mall/'.$val['img'];?>" width="60px" height="60px"  /></td>
                                                        <td><?php echo $nameStr;?></td>
                                                        <td><?php echo $couponName[$val['coupon']];?></td>
                                                        <td><?php echo $val['num'];?></td>
                                                        <td><?php echo $val['status'] == 1 ? '<span class="label label-success">上架</span>' : '<span class="label label-default">下架</span>';?></td>
                                                        <td><?php echo $val['sort'];?></td>
                                                        <td>
                                                            <a href="<?php echo base_url('/#mall/edit/'.$val['id']);?>" class="btn btn-primary active" role="button">编辑</a>
                                                            <button type="button" class="del btn btn-danger" data-mid="<?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>
                                            <?php echo $pageurl;?>
                                        </ul>
                                    </nav>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>

</div>

<!-- 兑换商城 START-->
<div class="modal fade" id="myModal" 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" role="form" method="post" action="gift/edit" enctype="multipart/form-data">
                <div class="modal-body">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">当前图片:</label>
                        <div class="col-sm-9">
                            <img class="giftimg" src="" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">中文名称:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="中文名称" name="cname">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">泰文:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="泰文" name="ename">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">礼物类型:</label>
                        <div class="col-sm-9">
                            <?php foreach ($giftType as $v => $n) {?>
                                <label class="radio-inline">
                                    <input type="radio" name="type" cname="<?php echo $n;?>" value="<?php echo $v;?>"> <?php echo $n;?>
                                </label>
                            <?php } ?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">价格:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="价格" name="price">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">礼物图片</label>
                        <div class="col-sm-9">
                            <input type="file" name="giftfile">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">属性:</label>
                        <div class="col-sm-9">
                            <?php foreach ($giftProperty as $v => $n) {?>
                                <label class="radio-inline">
                                    <input type="radio" name="prop" cname="<?php echo $n;?>" value="<?php echo $v;?>"> <?php echo $n;?>
                                </label>
                            <?php } ?>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">有效天数:</label>
                        <div class="col-sm-9">
                            <input type="text" class="form-control" placeholder="有效天数" name="expire">
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="submit" class="btn btn-primary">提交</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 兑换商城 END-->
<script>

    //删除商品
    $('.del').click(function(){
        if( confirm('确认删除吗?') ){
            var mid = $(this).attr('data-mid');
            $.ajax({
                type: "POST",
                url : 'mall/actionDelete',
                dataType: "json",
                data: "mid="+mid,
                success:function(e){
                    if(e.num >= 1){
                        alert('删除成功');
                        location.reload();
                    }else{
                        alert('删除失败');
                    }
                }
            });
        }
    });
</script>