<?php
use \common\libs\MyLib;
?>
<?php $this->beginBlock('header_css'); ?>
<link rel="stylesheet" type="text/css" href="/assets/css/plugins/webuploader/webuploader.css">
<?php $this->endBlock(); ?>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <form role="form" class="form-horizontal data-from" id="theFrm">
                        <input type="hidden" name="id" value="<?=intval($info->id)?>">
                        <div class="form-group">
                            <label class="col-sm-1 control-label">名称</label>
                            <div class="col-sm-3">
                                <input type="text" name="name" value="<?=$info->name?>" class="form-control">
                            </div>
                            <label class="col-sm-2 control-label">所属分类</label>
                            <div class="col-sm-2">
                                <select name="type_id" class="form-control">
                                    <option value="0">---请选择---</option>
                                    <option value="1" <?=$info->type_id==1?'selected':''?>>实物礼品</option>
                                    <option value="2" <?=$info->type_id==2?'selected':''?>>礼券</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-1">图片</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input type="text" name="img" id="img" class="form-control" value="<?=$info->original_img?>">
                                    <a href="javascript:void(0);" class="input-group-addon" id="upload">
                                        上传文件
                                    </a>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">价格</label>
                            <div class="col-sm-2">
                                <div class="input-group">
                                    <input type="text" name="price" value="<?=$info->price?>" class="form-control">
                                    <div class="input-group-addon">元</div>
                                </div>
                            </div>
                            <label class="col-sm-3 control-label">使用次数</label>
                            <div class="col-sm-2">
                                <input type="text" name="use_num" value="<?=$info->use_num?>" class="form-control">
                            </div>
                            <label class="col-sm-1 control-label">总数量</label>
                            <div class="col-sm-2">
                                <input type="text" name="total" value="<?=$info->total?>" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-1 control-label">描述</label>
                            <div class="col-sm-10">
                                <textarea name="remark" class="form-control"><?=$info->remark?></textarea>
                            </div>
                        </div>
                        <div>
                            <div class="row">
                                <div class="col-sm-5 col-sm-offset-5">
                                    <button class="btn btn-primary btn-save" type="button">
                                        <strong><?=$info ? '保 存':'添 加'?></strong>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<?php $this->beginBlock('footer_js'); ?>
<script src="/assets/js/plugins/webuploader/webuploader.min.js"></script>
<script type="text/javascript" language="javascript">
    layui.use(['upload'], function(){
        var upload = layui.upload;
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            ,url: '/common/upload' //上传接口
            ,accept: 'file'
            ,done: function(res){
                //上传完毕回调
                if(res.status == 'SUCCESS') {
                    $('#img').val(res.fileUrl);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });

    $(function () {
        //提交按钮
        $(".btn-save").click(function(){
            parent.layer.confirm('是否确认提交？', {
                btn: ['确认','取消'], //按钮
                shade: false //不显示遮罩
            }, function(){
                var params = $("#theFrm").serialize();
                $.post('/gift/save',params,function(obj){
                    if(obj.success) {
                        parent.layer.msg('保存成功');
                        parent.refreshList();
                        layer_close();
                    } else {
                        parent.layer.msg(data.msg);
                    }
                },'json');
            }, function(){
                //
            });
        });
    })
</script>
<?php $this->endBlock('footer_js'); ?>
