@{
    ViewData["Title"] = "数据仓库-库表结构配置";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "数据仓库", "库表结构配置列表", "库表结构配置详情" };
}


<div class="row">
    <div class="col-sm-12">
        <div class="ibox-content m-b-sm border-bottom">
            <form id="toolbar">
                <div style="line-height:40px;">
                    <input id="id" name="id" type="hidden" value="@ViewBag.m.id" />

                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">结构配置类型：</label>
                            <select id="type" name="type" class="form-control" style="width:110px;display:inline">
                                <option value="1">表</option>
                                <option value="2">字段</option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">编码(唯一)：</label>
                            <input id="code" name="code" class="form-control" placeholder="请输入表或字段编码" value="@ViewBag.m.code" style="width:160px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">中文名称：</label>
                            <input id="name" name="name" class="form-control" placeholder="请输入表或字段的中文名称" value="@ViewBag.m.name" style="width:160px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">字段类型：</label>
                            <select id="fieldtype" name="fieldtype" class="form-control" style="width:160px;display:inline">
                                <option value="">无</option>
                                <option value="VARCHAR">字符串</option>
                                <option value="decimal">数值</option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">字段长度：</label>
                            <input id="length" name="length" class="form-control" placeholder="请输入字段值的长度" value="@ViewBag.m.length" style="width:160px;display: inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">小数位：</label>
                            <input id="decimals" name="decimals" class="form-control" placeholder="请输入字段有几位小数" value="@ViewBag.m.decimals" style="width:160px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">备注说明：</label>
                            <input id="note" name="note" class="form-control" placeholder="请输入备注说明" value="@ViewBag.m.note" />
                        </div>
                    </div>
                </div>
            </form>
            <div style="margin-top:10px;text-align:center;">
                <button class="btn btn-primary" onclick="Save();">保存</button>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script>
        $(document).ready(function () {
            if ('@ViewBag.m.id' > 0) {
                $('#type').val('@ViewBag.m.type');
                $('#fieldtype').val('@ViewBag.m.fieldtype');
            }
        })

        function Save() {

            var type = $('#type').val();
            var code = $('#code').val();
            var name = $('#name').val();
            var fieldtype = $('#fieldtype').val();
            var length = $('#length').val();
            var decimals = $('#decimals').val();
            var note = $('#note').val();

            if (code == '') {
                alert('请输入编码');
                return false;
            }
            if (type == 2) {
                if (fieldtype == '' || length == '' || decimals == '') {
                    alert('字段类型、字段长度、字段小数位都不能为空');
                    return false;
                }
            }


            $.submit({
                url: '@Url.Content("~/DataWareHouse/Config/SaveTbConfig")',
                paramData: $('#toolbar').serialize(),
                type:'Post',
                func: function (result) {
                    if (result.success) {
                        alert('提交成功！');
                        window.location = window.location;
                    }
                    else {
                        alert(result.msg);
                    }
                }
            })

        }


    </script>

}