@{
    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 class="form-inline" style="line-height:40px;">
                    <div class="form-group">
                        @*<label>下载类型</label>
                            <select id="datatype" name="datatype" class="form-control" style="width:150px">
                                <option value="">请选择下载类型</option>
                                @if (ViewBag.datatypes.Count > 0)
                                {
                                    foreach (var item in ViewBag.datatypes)
                                    {
                                        <option value="@(item.data_type)">@(item.data_type_name)</option>
                                    }
                                }
                            </select>*@
                    </div>
                    <div class="form-group">
                        @*<label></label>
                            <select id="status" name="status" class="form-control" style="width:150px">
                                <option value="">请选择任务状态</option>
                                <option value="0">未认领</option>
                                <option value="1">任务执行失败</option>
                                <option value="2">已认领</option>
                                <option value="3">执行成功</option>
                            </select>*@
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-primary" onclick="list();">查询</button>
                        <button type="button" class="btn btn-success" onclick="Add();">新增</button>
                        <button id="btn_Upload" class="btn btn-warning">导入</button>
                        <a id="btn_UpdateTemplate" class="btn btn-default" href="@Url.Content("~/templatefile/数据仓库字段配置模版.xlsx")" target="_blank">下载导入模版</a>
                    </div>
                </div>
            </form>
        </div>
        <div class="ibox-content m-b-sm border-bottom">
            <table id="roletable" style="table-layout:fixed;"></table>
        </div>
    </div>
</div>

@section css{
    <link href="~/js/webuploader-0.1.5/webuploader.css" rel="stylesheet" />
    <style>
        .webuploader-pick {
            position: relative;
            display: block;
            cursor: pointer;
            background: none;
            padding: 0px;
            color: #fff;
            text-align: center;
            border-radius: 3px;
            overflow: hidden;
        }

        .webuploader-container {
            background-color: cornflowerblue !important;
        }
    </style>
}


@section scripts{
    <script src="~/js/webuploader-0.1.5/webuploader.min.js"></script>
    <script>
        var BASE_URL = '@(Url.Content("~/js/webuploader-0.1.5/"))';
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            list();

            uploadfile('btn_Upload',
                '@Url.Content("~/DataWareHouse/Config/UploadTbConfig")',
                function(result){
                    if(result.success)
                    {
                        alert('上传成功！');
                        list();
                    }
                    else
                    {
                        alert(result.msg);
                    }
            });
        })

        function list() {
            var columns = [
                { field: 'code', title: '编码', width: '130'},
                { field: 'name', title: '中文名称', width: '130' },
                { field: 'fieldtype', title: '字段类型', width: '130'},
                { field: 'length', title: '长度', width: '130' },
                { field: 'decimals', title: '小数位', width: '80' },
                { field: 'type', title: '类型', width: '130' },
                { field: 'note', title: '备注说明', width: '130' }

            ];

            var url = '@Url.Content("~/DataWareHouse/Config/TbConfigListJson")' + '?' + $('#toolbar').serialize();

            if (tb == undefined) {
                tb = OnlyTable("roletable", columns, url, "");
            }
            else {
                tb.bootstrapTable('refresh', { url: url });
            }
        }

        function Add() {
            layer_show('新增库表结构配置', '@Url.Content("~/DataWareHouse/Config/AddTbConfig?id=0")', '90%', '90%');
        }

        function uploadfile(id,url,callback)
        {
            var uploader = new WebUploader.Uploader({
                // swf文件路径
                swf: BASE_URL + 'Uploader.swf',
                // 文件接收服务端。
                server: url!=undefined?url:'@Url.Content("~/File/UploadFile")',
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#'+id,
                // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
                resize: false,
                auto:true
            });

            uploader.on('uploadSuccess', function (file, response) {
                if(callback!=undefined)
                {
                    callback(response);
                }
            });

            uploader.on('uploadError', function (file) {
                layer.msg("上传出错");
            });
        }

    </script>

}


