@{
    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>&nbsp;</label>
                        <button type="button" class="btn btn-warning" onclick="Add();">新增模版</button>
                    </div>
                    <div class="form-group" style="margin-left:5px;">
                        <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="1">启用</option>
                            <option value="0">停用</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <button type="button" class="btn btn-primary" onclick="list();">查询</button>
                    </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 scripts{
    <script>
        var tb;
        $(document).ready(function () {
            var height = document.body.clientHeight;
            $("#roletable").attr("data-height", (height - 170));

            list();
        })

        function list() {
            var columns = [
                { field: 'download_type', title: '数据类型', width: '130'},
                { field: 'start_frequency_month', title: '启动频率-月', width: '130' },
                { field: 'start_frequency_day', title: '启动频率-天', width: '130'},
                { field: 'start_frequency_hour', title: '启动频率-小时', width: '130' },
                { field: 'status', title: '状态', width: '80' },
                { field: 'lastupdatetime', title: '最后更新时间', width: '130' },
                { field: 'note', title: '备注', width: '200' },
                {
                    field: '', title: '操作', width: '100', formatter: function (idx, data) {
                        return '<a href="javascript:;" onclick="Detail(' + data.id + ')" class="btn btn-success btn-xs">查看详情</a>' +
                            '<a href="javascript:;" onclick="ShowAccount(' + data.id + ')" class="btn btn-warning btn-xs" style="margin-left:3px;">帐号管理</a>';
                    }
                }
            ];

            var url = '@Url.Content("~/TaskCenter/Home/TemplatesJson")' + '?' + $('#toolbar').serialize();

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

        function Add() {
            layer_show('新增模版', '@Url.Content("~/TaskCenter/Home/AddTaskTemplate?id=0")', '90%', '90%');
        }

        function Detail(id) {
            layer_show('模板详情', '@Url.Content("~/TaskCenter/Home/AddTaskTemplate?id=")'+id, '90%', '90%');
        }

        function ShowAccount(id) {
            layer_show('帐号列表', '@Url.Content("~/TaskCenter/Home/ListAccount?datatype=")'+id, '90%', '90%');
        }

    </script>

}
