@{
    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">
            <div class="" style="margin-bottom:10px;"><span style="color:red;">*</span>启动频率必须至少要设置一个</div>
            <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="download_type" name="download_type" class="form-control" style="width:110px;display:inline">
                                <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>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">启动频率-月：</label>
                            <input id="start_frequency_month" name="start_frequency_month" type="number" class="form-control" placeholder="" value="@ViewBag.m.start_frequency_month" style="width:110px;display:inline;" />
                            <span style="color:#ccc;font-size:13px;margin-left:10px;">说明：月，如果指定月份启动，则填写对应的月份，0则不指定</span>
                        </div>

                        <div class="col-sm-12">
                            <label style="width:110px">启动频率-日：</label>
                            <input id="start_frequency_day" name="start_frequency_day" type="number" class="form-control" placeholder="" value="@ViewBag.m.start_frequency_day" style="width:110px;display:inline;" />
                            <span style="color:#ccc;font-size:13px;margin-left:10px;">说明：日，如果指定每个月的哪天启动，则填写对应的每月的几号，0则不指定</span>
                        </div>

                        <div class="col-sm-12">
                            <label style="width:110px">启动频率-小时：</label>
                            <input id="start_frequency_hour" name="start_frequency_hour" type="number" class="form-control" placeholder="" value="@ViewBag.m.start_frequency_hour" style="width:110px;display:inline;" />
                            <span style="color:#ccc;font-size:13px;margin-left:10px;">说明：时，如果指定每个天的某个小时启动，则填写对应的每天的几点，0则不指定</span>
                        </div>

                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">状态：</label>
                            <select id="status" name="status" class="form-control" style="width:110px;display:inline">
                                <option value="1">启用</option>
                                <option value="0">禁用</option>
                            </select>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:130px">备注：</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) {
                $('#download_type').val('@ViewBag.m.download_type');
            }
        })

        function Save() {
            var download_type = $('#download_type').val();
            var start_frequency_month = $('#start_frequency_month').val();
            var start_frequency_day = $('#start_frequency_day').val();
            var start_frequency_hour = $('#start_frequency_hour').val();

            if (download_type == '') {
                alert('请选择下载类型');
                return false;
            }

            if ((start_frequency_month == '' || start_frequency_month == '0') && (start_frequency_day == '' || start_frequency_day == '0') && (start_frequency_hour == '' || start_frequency_hour == '0')) {
                alert('请设置启动频率');
                return false;
            }

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

        }


    </script>

}