@{
    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" />
                    <input id="datatype" name="datatype" type="hidden" value="@ViewBag.m.data_type" />
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">平台名称：</label>
                            <input id="platform" name="platform" class="form-control" value="@ViewBag.m.platform" placeholder="请填写平台名称" style="width:200px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">平台索引值：</label>
                            <input type="number" style="width:100px;display:inline" id="platformindex" name="platformindex" class="form-control" value="@ViewBag.m.platform_index" placeholder="请填写平台索引值（唯一）" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">站点：</label>
                            <input id="website" name="website" class="form-control" value="@ViewBag.m.website" placeholder="平台站点" style="width:200px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">帐号：</label>
                            <input id="account" name="account" class="form-control" value="@ViewBag.m.account" placeholder="帐号" style="width:200px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">密码：</label>
                            <input id="pwd" name="pwd" class="form-control" value="@ViewBag.m.pwd" placeholder="帐号" style="width:200px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">请求地址：</label>
                            <input id="apiurl" name="apiurl" class="form-control" value="@ViewBag.m.apiurl" placeholder="请求地址" style="width:600px;display:inline" />
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-12">
                            <label style="width:110px">token：</label>
                            <input id="token" name="token" class="form-control" value="@ViewBag.m.token" placeholder="token" style="width:600px;display:inline" />
                        </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:110px">备注说明：</label>
                            <input id="note" name="note" class="form-control" value="@ViewBag.m.note" placeholder="备注说明" style="width:600px;display:inline" />
                        </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) {
                $('#status').val('@ViewBag.m.status');

                $('#platformindex').prop('readonly', true);

            }
        })

        function Save() {
            var platform = $('#platform').val();
            var platformindex = $('#platformindex').val();
            var account = $('#account').val();
            var pwd = $('#pwd').val();
            var apiurl = $('#apiurl').val();
            var token = $('#token').val();

            if (platform == '') {
                alert('请填写平台名称');
                return false;
            }
            if (platformindex == '' || platformindex < 0) {
                alert('请填写平台索引值，并且大于0');
                return false;
            }
            if (account == '') {
                alert('请填写帐号');
                return false;
            }
            if (pwd == '' && token == '') {
                alert('密码和token不能同时为空！');
                return false;
            }
            if (apiurl == '') {
                alert('请填写请求地址。');
                return false;
            }

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

        }


    </script>

}