@{
    string guid = Html.Guid();
    CurrentUser user = ViewBag.CurrentUser;
    string action = ViewContext.RouteData.Values["action"].ToString();
    IEnumerable<dynamic> fieldData = Html.GetFieldList("pa_column_content_set", action, user);
}
<script src="~/Incs/UEditor/ueditor.forAdmin.config.js" type="text/javascript"></script>
<script src="~/Incs/UEditor/ueditor.all.min.js" type="text/javascript"></script>
<div class="main">
    <form method="post" id="_form" class="form ui-validForm" data-source="@Model" data-validate-params="beforeSubmit:'BeforeSubmit'">
        <div class="tabcontent" data-tab-params="tabName:'基础设置'">
            <div class="form-group">
                <label class="control-label">栏目名称</label>
                <div class="controls">
                    <input name="Name" id="Name" type="text" maxlength="50" class="form-control form-control-sm" data-validate="dataType:'*',nullMsg:'请填写栏目名称！'">
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label">栏目类型</label>
                <div class="controls">
                    <select name="ColumnType" id="ColumnType" class="form-control form-control-sm  ui-show-hide" @*onchange="ChangeType(this.options[this.options.selectedIndex].value)"*@>
                        <option value="0" hideObjs=".box_is_final,.box_tableId,.box_dir,.box_template_detail,.publishSet-box,.box_zdy_url">首页</option>
                        <option value="1" hideObjs=".box_zdy_url" showObjs=".box_is_final,.box_tableId,.box_dir,.box_template_detail,.box_template,.publishSet-box" selected>信息页</option>
                        <option value="2" hideObjs=".box_tableId,.box_template_detail,.publishSet-box,.box_zdy_url" showObjs=".box_is_final,.box_dir,.box_template">单页面</option>
                        <option value="3" hideObjs=".box-httpcache,.box_dir,.box_template,.box_tableId,.publishSet-box" showObjs=".box_zdy_url">自定义链接</option>
                    </select>
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group box_is_final">
                <label class="control-label">是否最终栏目</label>
                <div class="controls">
                    <label class="radio-inline">
                        <input type="radio" name="IsFinal" id="IsFinal" value="1" checked class="ui-edit-readonly">是
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="IsFinal" id="IsFinal" value="0" class="ui-edit-readonly">否
                    </label>
                    <span class="help-block">如果当前栏目有子级栏目，请设置为否</span>
                </div>
            </div>


            <div class="form-group box_tableId">
                <label class="control-label">信息来源表</label>
                <div class="controls form-inline">
                    <select name="TableId" id="TableId" class="form-control form-control-sm ui-convertSelect" data-validate="dataType:'*',nullMsg:'请选择信息表！',ignoreHidden:true" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","InfoTable")',textField:'Remark'">
                        <option value="">请点击右侧按钮选择信息表</option>
                    </select>
                    <button type="button" class="btn btn-sm btn-default ui-dialog" data-custom-params="title:'选择信息表',url:'@Url.ActionUrl("Select","InfoTable")?siteid=@ViewBag.CurrentSiteId&objname=#TableId',width:'80%',height:'90%',target:'_self'">选择信息表</button>
                    <span class="help-block"></span>
                </div>
            </div>


            <div class="form-group">
                <label class="control-label">栏目缓存方案</label>
                <div class="controls form-inline">
                    <select name="HttpcacheSolutionId" id="HttpcacheSolutionId" class="form-control form-control-sm ui-convertSelect" data-custom-params="url:'@Url.ActionUrl("LoadListByIds","HttpCacheSolution")',textField:'Name'">
                        <option value="0">不缓存</option>
                    </select>
                    <button type="button" class="btn btn-sm btn-default ui-dialog" data-custom-params="title:'选择http缓存方案',url:'@Url.ActionUrl("Select","HttpCacheSolution")?objname=#HttpcacheSolutionId',width:'80%',height:'90%',target:'_self'">选择方案</button>
                    <span class="help-block">http缓存方案请到系统>系统配置>http缓存方案中设置</span>
                </div>
            </div>

            <div class="form-group box_dir">
                <label class="control-label">访问路径</label>
                <div class="controls form-inline">
                    <input type="text" maxlength="200" id="Path" name="Path" class="form-control form-control-sm" data-validate="dataType:'path',nullMsg:'请填写访问路径!',errorMsg:'路径格式错误,节点不能包含特殊字段，也不能为纯数字',ignoreHidden:true">
                    <button type="button" class="btn btn-sm btn-default" onclick="SetDir()">生成</button>
                    <span class="help-block">前台的访问路径，如：news，可以填写多级目录，如：news/company</span>
                </div>
            </div>

            <div class="box_template" data-source="@ViewBag.TemplateSet">
                <div class="box_pc">
                    <div class="form-group box_template">
                        <label class="control-label">栏目模板</label>
                        <div class="controls form-inline">
                            <input type="text" placeholder="栏目页的模板文件" maxlength="100" id="template_set_Template" name="template_set_Template" class="form-control form-control-sm" data-validate="dataType:'*',nullMsg:'请选择栏目模板',ignoreHidden:true" />
                            <button type="button" class="btn btn-sm btn-default ui-dialog" data-custom-params="title:'选择栏目模板',url:'@Url.ActionUrl("Select","TemplateManager")?objname=#template_set_Template',width:'80%',height:'90%',target:'self'">选择</button>
                            <span class="help-block"></span>
                        </div>
                    </div>

                    <div class="form-group box_template_detail">
                        <label class="control-label">内容页模版</label>
                        <div class="controls form-inline">
                            <input type="text" placeholder="内容页的模板文件" maxlength="100" id="template_set_TemplateDetail" name="template_set_TemplateDetail" class="form-control form-control-sm" data-validate="dataType:'*',nullMsg:'请选择内容页模板',ignoreHidden:true" />
                            <button type="button" class="btn btn-sm btn-default ui-dialog" data-custom-params="title:'选择内容页模板',url:'@Url.ActionUrl("Select","TemplateManager")?objname=#template_set_TemplateDetail',width:'80%',height:'90%',target:'self'">选择</button>
                            <span class="help-block"></span>
                        </div>
                    </div>

                </div>
            </div>

            <script type="text/javascript">

                //从父级获取的参数
                var tableId = "@ViewBag.TableId";
                var ColumnType = "@ViewBag.ColumnType";
                if (tableId != "") {
                    $("#TableId").ConvertSelect({ ids: tableId, isFormBind: true });
                }
                if (ColumnType != "" && ColumnType != "0") {
                    $("#ColumnType").val(ColumnType);
                }
            </script>


            <div class="form-group">
                <label class="control-label">目标窗口</label>
                <div class="controls radio">
                    <label class="radio-inline">
                        <input type="radio" name="Target" id="Target" checked value="_self">本窗口
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="Target" id="Target" value="_blank">新窗口
                    </label>
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group box_zdy_url">
                <label class="control-label">自定义链接</label>
                <div class="controls">
                    <input type="text" maxlength="100" id="ZdyUrl" name="ZdyUrl" class="form-control form-control-sm" />
                    <span class="help-block">当栏目需要指向其他页面，可通过自定义链接实现</span>
                </div>
            </div>


            <div class="form-group box_show">
                <label class="control-label">是否显示</label>
                <div class="controls">
                    <label class="radio-inline">
                        <input type="radio" name="Show" id="Show" checked value="1">显示
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="Show" id="Show" value="0">隐藏
                    </label>
                    <span class="help-block"></span>
                </div>
            </div>

            <div class="form-group">
                <label class="control-label">序号</label>
                <div class="controls controls-xs">
                    <input name="Xuhao" id="Xuhao" type="text" maxlength="5" class="ui-queryString form-control form-control-xs" value="1" data-validate="dataType:'numeric',nullMsg:'请填写序号！',errorMsg:'序号只能填写数字！'">
                    <span class="help-block"></span>
                </div>
            </div>
        </div>

        <div class="tabcontent" data-tab-params="tabName:'内容设置'">
            <div id="_seoBox" data-source="@ViewBag.SeoSet">
                <div class="form-group">
                    <label class="control-label">seo标题</label>
                    <div class="controls">
                        <input name="seo_set_Title" id="seo_set_Title" type="text" maxlength="50" class="form-control">
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">seo关键词</label>
                    <div class="controls">
                        <input name="seo_set_Keywords" id="seo_set_Keywords" type="text" maxlength="150" class="form-control">
                        <span class="help-block"></span>
                    </div>
                </div>
                <div class="form-group">
                    <label class="control-label">seo描述</label>
                    <div class="controls">
                        <textarea id="seo_set_Description" name="seo_set_Description" class="form-control" style="height:60px;"></textarea>
                        <span class="help-block"></span>
                    </div>
                </div>
                <input type="hidden" id="_seoData" value="" />
            </div>
            <div id="_contentSetBox" data-source="@ViewBag.ContentSet">
                @{
                    string beforeSubmitJs = "";
                    var data = new ViewDataDictionary();
                    data.Add("from", "admin");
                    data.Add("guid", guid);
                    data.Add("currentUser", ViewBag.CurrentUser);
                    data.Add("fieldPrefix", "content_set_");
                    data.Add("i", 0);
                    int i = 0;
                    if (fieldData != null)
                    {
                        foreach (var row in fieldData)
                        {
                            data["i"] = i;
                            beforeSubmitJs += row.BeforeSubmitJs;
                            Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                            i++;
                        }
                    }
                }
            </div>
            <script type="text/javascript">
                function BeforeSubmit() {
                     @Html.Raw(beforeSubmitJs)
                    return true;
                }
            </script>

        </div>


        <div class="postarea">
            <div class="form-group">
                <div class="controls">
                    @Html.AntiForgeryToken()
                    <input type="hidden" name="Guid" id="Guid" value="@guid" />
                    <input type="hidden" name="Id" id="Id" />
                    <input type="hidden" name="SiteId" id="SiteId" value="@ViewBag.CurrentSiteId" />
                    <input type="hidden" name="Level" id="Level" value="1" />
                    <input type="hidden" name="ParentId" id="ParentId" value="@ViewBag.ParentId" />
                    <input type="hidden" name="_AttachmentFields" id="_AttachmentFields" value="Content,@Html.GetAttachmentFields("pa_column_content_set")" />
                    <button type="button" class="btn btn-sm btn-primary ui-pagePost" data-custom-params="url:'@Url.ActionUrl()',callBack:'PostRefreshBack'">提交</button>
                    <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
                </div>
            </div>
        </div>

    </form>
</div>
<script src="/Areas/Admin/Js/pinyin.js" type="text/javascript"></script>
<script type="text/javascript">
    $(".tabcontent").InitTab();

    //访问路径，格式：abc/cbd
    $.ValidateDataType.path = function (gets, obj, curform) {
        if (gets=="") { return false;}
        var arrPath = gets.split("/");
        var length = arrPath.length;
        for (i = 0; i < length; i++) {
            if (arrPath[i].Trim()=="") {
                continue;
            }
            if (!IsStr(arrPath[i])) {
                return "路径节点只能由字母，数据或下划线组成！";
            }
            else if (IsInt(arrPath[i])) {
                return "路径节点不能为纯数字！";
            }
        }
        arrPath = arrPath.filter(function (n) { return n; }); 
        obj.val(arrPath.join("/"));
        return true;
    }

    var $path = $("#Path");
    var $tabhead = $(".tabhead");
    var $table_id = $("#TableId");

    var $publish_set_box = $("#_publishSet");
    var $template_set_template = $("#template_set_Template");
    var $template_set_template_detail = $("#template_set_TemplateDetail");

    var $thetype = $("#ColumnType");
    var $parentId = $("#ParentId");
    var parentId = Request("parentId");
    var $zdyUrl = $("#ZdyUrl");
    var id = Request("id");
    if (id != "") {
        //绑定数据
        $("#_form").FormBind({ dataSourceFrom: "attr" });
        parentId = $parentId.val();
        //ChangeType($thetype.val());

        $("input[name='IsFinal']").attr("disabled", "disabled");

        $("#_seoBox").FormBind({ bindId: false, fieldPrefix: "seo_set_", dataSourceFrom: "attr" });
        $("#_contentSetBox").FormBind({ bindId: false, fieldPrefix: "content_set_", dataSourceFrom: "attr" });
        if (parentId != "0") {
            $thetype.children().eq(0).remove();
            //ChangeType($thetype.val());
        }
    }
    //放外面，因为添加子级时可继承父级的设置
    $(".box_template").FormBind({ bindId: false, fieldPrefix: "template_set_", dataSourceFrom: "attr" });

    function BeforeSubmit() {
        BeforePost();
        return true;
    }

    function BeforePost() {
        var columnType = $thetype.val();
        if (columnType == "0") {
            $table_id.val("0");
            $path.val("");
            $template_set_template_detail.val("");
            $zdyUrl.val("");
        }
        else if (columnType == "1") {
            $zdyUrl.val("");
        }
        else if (columnType == "2") {
            ;
            $table_id.val("0");
            $template_set_template_detail.val("");
            $zdyUrl.val("");
        }
        else if (columnType == "3") {
            $table_id.val("0");
            $template_set_template.val("");
            $template_set_template_detail.val("");
        }
    }

    function SetDir() {
        var columnName = $("#Name").val();
        if (columnName != "") {
            $path.val(ToPY(columnName, 50));
        }
        else {
            Alert("请先填写栏目名称！");
            $("#Name").focus();
        }
    }
</script>
