<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <!--validate css-->
    <link rel="stylesheet" href="plugins/jquery-validation/css/validate.css">
    <link rel="stylesheet" href="common/css/uePicPicker.css">
    <!--fileinput css-->
    <link rel="stylesheet" href="plugins/bootstrap-fileinput/bootstrap-fileinput.css">
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .form-md-line-input{width:48%;float: left;    margin-right: 1%;}
    </style>
</head>
<!-- END HEAD -->
<body class="hold-transition skin-blue sidebar-mini">

<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">

        <section class="content-header">
            <h1>
                促销品管理
                <small>促销品</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">促销品</a></li>
            </ol>
        </section>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <!-- general form elements disabled -->
                    <div class="box box-primary">
                        <form role="form" id="myForm">
                            <input name="id" value="$!{data.id}" hidden="true"/>
                            <input name="typeform" value="$!{typeform}" hidden="true"/>
                            <div class="box-body">
                                <div class="form-group form-md-line-input">
                                    <label>编码</label>
                                    <input type="text"
                                           class="form-control" name="number"
                                           id="number"
                                           maxlength="50" placeholder="编码"
                                           value="$!{data.number}"
                                           readonly
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>申请用途</label>
                                    <div class="input-group">
                                        <input type="text" name="useIds" id="useId"
                                               value="$!{useId}"
                                               class="form-control" style="display: none">
                                        <input type="text" id="useName"
                                               name="useName" value="$!{useName}"
                                               class="form-control" disabled>
                                        <span class="input-group-btn">
                                            <button type="button" id="useSelect"
                                                    class="btn btn-info btn-flat">选择</button>
                                         </span>
                                    </div>

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>促销品名称</label>
                                    <input type="text"
                                           class="form-control" name="name"
                                           id="name"
                                           maxlength="200" placeholder="促销品名称"
                                           value="$!{data.name}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>促销品规格</label>
                                    <input type="text"
                                           class="form-control" name="specifications"
                                           id="specifications"
                                           maxlength="200" placeholder="促销品规格"
                                           value="$!{data.specifications}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>管理员库存</label>
                                    <input type="number"
                                           class="form-control" name="authenticStock"
                                           id="authenticStock"
                                           maxlength="20" placeholder="管理员库存"
                                           value="$!{data.authenticStock}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>虚拟库存</label>
                                    <input type="number"
                                           class="form-control" name="inventedStock"
                                           id="inventedStock"
                                           maxlength="20" placeholder="虚拟库存"
                                           value="$!{data.inventedStock}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>供应商货量</label>
                                    <input type="number"
                                           class="form-control" name="disStock"
                                           id="disStock"
                                           maxlength="20" placeholder="供应商货量"
                                           value="$!{data.disStock}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>促销品单价</label>
                                    <input type="number"
                                           class="form-control" name="price"
                                           id="price"
                                           maxlength="20" placeholder="促销品单价"
                                           value="$!{data.price}"
                                           required="required"
                                    >

                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>排序值</label>
                                    <input type="number"
                                           class="form-control" name="sort"
                                           id="sort"
                                           maxlength="20" placeholder="排序值"
                                           value="$!{data.sort}"
                                    >
                                </div>
                                <div class="form-group form-md-line-input" id="cover">
                                </div>
                                <div class="form-group form-md-line-input">
                                    <label>是否上架</label>
                                    #if($data.isOnline == '0')
                                    <input type="radio" name="isOnline"
                                           maxlength="2"
                                           value="1"
                                           required="required"
                                    >是
                                    <input type="radio" name="isOnline"
                                           maxlength="2"
                                           value="0" checked
                                           required="required"
                                    >否
                                    #else
                                    <input type="radio"  name="isOnline"
                                           maxlength="2"  checked
                                           value="1"
                                           required="required"
                                    >是
                                    <input type="radio"  name="isOnline"
                                           maxlength="2"
                                           value="0"
                                           required="required"
                                    >否
                                    #end

                                </div>
                            </div>

                            <div class="box-footer">
                                #if($shiro.hasPermission("qy:appitems:edit"))
                                <input class="btn btn-primary" id="save" value="保存" type="submit">
                                #end
                                <a href="#springUrl('/a/appitems/list')" class="btn btn-default">取消</a>
                            </div>
                        </form>
                        <!-- /.box-body -->
                    </div><!-- /.box -->


                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->


    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->

<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!--fileinput js-->
<script src="plugins/bootstrap-fileinput/bootstrap-fileinput.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script src="plugins/bootstrap-maxlength/bootstrap-maxlength.min.js" type="text/javascript"></script>
<script src="plugins/security/sha256.js" type="text/javascript"></script>
<script src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<script src="js/jquery.form.min.js"></script>
<script src="js/jquery.serializejson.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/ueditor.all.js"></script>
<script type="text/javascript" charset="utf-8" src="plugins/ueditor-min-1.4.3/lang/zh-cn/zh-cn.js"></script>
<script src="common/js/cfapp.js"></script>
<script src="plugins/Sortable/Sortable.min.js"></script>
<script src="common/component/uePicPicker.js"></script>
<script>
    csrfheader = {name: '_csrf_header', value: '${_csrf.headerName}'};
    csrftoken = {name: '_csrf', value: '${_csrf.token}'};
</script>
<!-- END PAGE LEVEL PLUGINS -->
<script>
    var coverPP = null;
    var initPicsSel = function () {
        var cover = "$!{data.cover}";
        coverPP = new uePicPicker({
            tarId: 'cover',
            title: '促销品图片',
            sizeDes: '60*60',
            max: 1,
            datas: cover == '' ? null : cover.split(","),
            success: null
        });
        coverPP.init();
    };


    $().ready(function () {
        Cfapp.init();
        recdTypeAdd.init();
        initPicsSel();
        var typeformUrl = "#springUrl('/a/use/listData')";
        //选择单据
        $("#useSelect").click(function () {
            Cfapp.f7({
                dataUrl: typeformUrl,
                checkType: 'multi', // 多选为multi
                title: "选择用途",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '用途名称'],
                isSearch: '0',
                searchColumns: ["name"],//搜索的字段名称
                searchColumnsRemarks: ['用途名称'],//搜索的字段备注
                aoColumns: [{
                    "mData": "id"
                }, {
                    "mData": "name"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {
                        return '<input type="checkbox" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.name + '">';
                    }
                }],
                success: function () {

                },
                cancel: function () {

                },
                storeFields: 'useId', // 储存的字段
                displayFields: 'useName'
            })
        });
    });




    var recdTypeAdd = function () {
        var initForm = function () {
            var initFormCtrl = function () {
                bindEvent();
            };
            var bindEvent = function () {

                $("#myForm").validate({
                    rules: {},
                    messages: {},
                    submitHandler: function (form) {


                        if (!$('#useId') || !$('#useId').val() || $('#useId').val() == '' ) {
                            Cfapp.alert({
                                message: "请选择用途",
                                btntext: "确定",
                                success: function () {
                                }
                            });
                            return false;
                        }
                        var dataJson = $("#myForm").serializeJSON();
                        var cover = coverPP.getStringValues();
                        dataJson.cover = cover.substring(0, cover.lastIndexOf(','));
                        dataJson._csrf_header = csrfheader.value;
                        dataJson._csrf = csrftoken.value;
                        $("#save").attr("disabled", true);
                        $.post("#springUrl('/a/appitems/formData')", dataJson, function (returnobj) {
                            $("#save").attr("disabled", false);
                            if (returnobj.errorNo == 2) {  //保存成功
                                Cfapp.confirm({
                                    message: "添加成功",
                                    btnoktext: "继续添加",
                                    btncanceltext: "关闭",
                                    success: function () {
                                        location.href = "#springUrl('/a/appitems/form')";
                                    },
                                    cancel: function () {
                                        location.href = "#springUrl('/a/appitems/list')";
                                    }
                                });
                            } else if (returnobj.errorNo == 0) {  //修改成功
                                Cfapp.alert({
                                    message: "更新成功",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/appitems/list')";
                                    }
                                });
                            } else {
                                Cfapp.alert({
                                    message: "创建失败",
                                    btntext: "确定",
                                    success: function () {
                                        location.href = "#springUrl('/a/appitems/list')";
                                    }
                                });
                            }
                        });
                    }
                })
            }
            initFormCtrl();
        }
        return {

            //main function to initiate the module
            init: function () {
                initForm();
            }

        };
    }();
</script>
</body>
<!-- END BODY -->
</html>
