@{
    string guid = Html.Guid();
    int xuhao = StringHelper.Format<int>(Request.QueryString["xuhao"]);
    if (xuhao <= 0)
    {
        xuhao = 1;
    }
    else
    {
        xuhao++;
    }
    CurrentUser user = ViewBag.CurrentUser;
    string action = ViewContext.RouteData.Values["action"].ToString();
}
<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" id="main" v-cloak>
    <el-form label-position="left" label-width="150px" size="medium" >
        <el-tabs v-model="activeName" type="card">
            <el-tab-pane label="基础设置" name="first">
                <el-form-item label="栏目名称" style="width:600px">
                    <el-input v-model.trim="column.Name" maxlength="50" v-validate="{data:column.Name,dataType:'*',nullMsg:'请填写栏目名称！'}"></el-input>
                    <span class="help-block validate-tips-box"></span>
                </el-form-item>
                <el-form-item label="栏目类型" style="width:600px">
                    <el-select v-model="column.ColumnType" placeholder="请选择" v-validate="{data:column.ColumnType,dataType:'*',nullMsg:'请选择栏目类型！'}">
                        <el-option :key="0" :value="0" label="首页"></el-option>
                        <el-option :key="1" :value="1" selected label="信息页"></el-option>
                        <el-option :key="2" :value="2" label="单页面"></el-option>
                        <el-option :key="3" :value="3" label="自定义链接"></el-option>
                    </el-select>
                    <span class="help-block validate-tips-box"></span>
                </el-form-item>
                <div v-show="column.ColumnType!=3">
                    <el-form-item label="节点类型" v-show="column.ColumnType>0">
                        <el-radio v-model="column.IsFinal" :label="0" :disabled="column.Id>0">分类节点</el-radio>
                        <el-radio v-model="column.IsFinal" :label="1" :disabled="column.Id>0">最终栏目</el-radio>
                        <span class="help-block">如果当前栏目需要添加子级栏目，请设置为分类节点</span>
                    </el-form-item>
                    <el-form-item label="栏目信息表" v-show="column.ColumnType==1" style="width:600px">
                        <el-input-convert placeholder="请选择信息表" :convert-url="'@Url.ActionUrl("getName","infoTable")?id='+column.TableId" v-validate="{data:column.TableId,dataType:'numeric',min:1,errorMsg:'请选择信息表',nullMsg:'请选择信息表！',ignore:column.ColumnType!=1}">
                            <el-button type="button" v-on:click="dialog({title:'选择信息表',url:'@Url.ActionUrl("Select","InfoTable")?siteid=@ViewBag.CurrentSiteId&changesite=0&setData=parent.vue.column.TableId',width:'660px',height:'95%',target:'_self'})">选择</el-button>
                        </el-input-convert>
                        <span class="help-block" id="_ValidateTips_TableId"></span>
                    </el-form-item>
                    <el-form-item label="栏目缓存方案" style="width:600px">
                        <el-input-convert placeholder="选择栏目缓存方案" :clearable="true" v-model="column.HttpcacheSolutionId" :convert-url="'@Url.ActionUrl("getName","HttpCacheSolution")?id='+column.HttpcacheSolutionId">
                            <el-button type="button" v-on:click="dialog({title:'选择http缓存方案',url:'@Url.ActionUrl("Select","HttpCacheSolution")?setData=parent.vue.column.HttpcacheSolutionId',width:'660px',height:'95%',target:'_self'})">选择</el-button>
                        </el-input-convert>
                        <span class="help-block" id="_ValidateTips_HttpcacheSolutionId">开启缓存可提升网站访问速度和并发负载，建议在网站上线后启用。</span>
                    </el-form-item>
                    <el-form-item label="访问路径" style="width:600px" v-show="column.ColumnType==1 || column.ColumnType==2">
                        <el-input placeholder="设置访问路径" v-model.trim="column.Path" v-validate="{data:column.Path,dataType:'path',nullMsg:'请填写访问路径!',errorMsg:'路径格式错误,节点不能包含特殊字段，也不能为纯数字',ignore:(column.ColumnType==0 || column.ColumnType==3)}">
                            <template slot="append">
                                <el-button type="button" onclick="SetDir()">生成</el-button>
                            </template>
                        </el-input>
                        <span class="help-block" id="_ValidateTips_Path">前台的访问路径，如：news，可以填写多级目录，如：news/company</span>
                    </el-form-item>
                    <el-form-item label="栏目模板" style="width:600px">
                        <el-input type="text" placeholder="栏目页的模板文件" maxlength="100" v-model.trim="templateSet.Template" class="form-control form-control-sm" v-validate="{data:templateSet.Template,dataType:'*',nullMsg:'请选择栏目模板',ignore:column.ColumnType==3}">
                            <template slot="append">
                                <el-button type="button" v-on:click="dialog({title:'选择栏目模板',url:'@Url.ActionUrl("Select","TemplateManager")?setData=parent.vue.templateSet.Template',width:'600px',height:'90%',target:'self'})">选择</el-button>
                                <el-button type="button" v-show="templateSet.Template!=''" style="border-left:1px solid #DCDFE6;" v-on:click="dialog({title:'编辑',url:'@Url.ActionUrl("Edit","TemplateManager")'+TemplateParameter(templateSet.Template),width:'95%',height:'95%',target:'self'})">编辑</el-button>
                            </template>
                        </el-input>
                        <span class="help-block" id="_ValidateTips_template_set_Template">模板只能选择.cshtml后缀的文件</span>
                    </el-form-item>
                    <el-form-item label="内容页模版" style="width:600px" v-show="column.ColumnType==1">
                        <el-input type="text" placeholder="内容页的模板文件" maxlength="100" v-model.trim="templateSet.TemplateDetail" class="form-control form-control-sm" v-validate="{data:templateSet.TemplateDetail,dataType:'*',nullMsg:'请选择内容页模板',ignore:column.ColumnType!=1}">
                            <template slot="append">
                                <el-button type="button" v-on:click="dialog({title:'选择内容页模板',url:'@Url.ActionUrl("Select","TemplateManager")?setData=parent.vue.templateSet.TemplateDetail',width:'600px',height:'90%',target:'self'})">选择</el-button>
                                <el-button type="button" v-show="templateSet.TemplateDetail!=''" style="border-left:1px solid #DCDFE6;" v-on:click="dialog({title:'编辑',url:'@Url.ActionUrl("Edit","TemplateManager")'+TemplateParameter(templateSet.TemplateDetail),width:'95%',height:'95%',target:'parent'})">编辑</el-button>
                            </template>
                        </el-input>
                        <span class="help-block" id="_ValidateTips_template_set_TemplateDetail">模板只能选择.cshtml后缀的文件</span>
                    </el-form-item>
                </div>
                <el-form-item label="目标窗口">
                    <el-radio label="_self" v-model="column.Target">本窗口</el-radio>
                    <el-radio label="_blank" v-model="column.Target">新窗口</el-radio>
                    <span class="help-block"></span>
                </el-form-item>
                <el-form-item label="自定义链接" style="width:600px">
                    <el-input type="text" maxlength="100" v-model="column.ZdyUrl"></el-input>
                    <span class="help-block">当栏目需要指向其他页面，可通过自定义链接实现</span>
                </el-form-item>
                <el-form-item label="是否显示">
                    <el-switch inactive-text="否" active-text="是" v-model="column.Show" :active-value="1" :inactive-value="0"></el-switch>
                    <span class="help-block"></span>
                </el-form-item>
                @{
                    IEnumerable<dynamic> fieldData = Html.GetFieldList("pa_column", action, user);
                    string beforeSubmitJs = "";
                    var data = new ViewDataDictionary();
                    data.Add("from", PageAdmin.Common.FromEnum.Admin);
                    data.Add("guid", guid);
                    data.Add("currentUser", ViewBag.CurrentUser);
                    data.Add("fieldPrefix", "column");
                    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++;
                        }
                    }
                }
                <el-form-item label="序号" style="width:600px">
                    <el-input-number controls-position="right" :min="0" :max="9999999" type="text" v-model="column.Xuhao" v-validate="{data:column.Xuhao,dataType:'numeric',nullMsg:'请填写序号！',errorMsg:'序号只能填写数字！'}"></el-input-number>
                    <span class="help-block"></span>
                </el-form-item>
            </el-tab-pane>
            <el-tab-pane label="内容设置" name="second">
                <el-form-item label="seo标题">
                    <el-input type="text" maxlength="150" v-model.trim="seoSet.Title"></el-input>
                    <span class="help-block"></span>
                </el-form-item>
                <el-form-item label="seo关键词">
                    <el-input maxlength="200" v-model.trim="seoSet.Keywords" class="form-control"></el-input>
                    <span class="help-block"></span>
                </el-form-item>
                <el-form-item label="seo描述">
                    <div class="controls">
                        <el-input type="textarea" class="form-control" v-model.trim="seoSet.Description" :autosize="{ minRows:3, maxRows:6}"></el-input>
                        <span class="help-block"></span>
                    </div>
                </el-form-item>
                @{
                    fieldData = Html.GetFieldList("pa_column_content_set", action, user);
                    data = new ViewDataDictionary();
                    data.Add("from", PageAdmin.Common.FromEnum.Admin);
                    data.Add("guid", guid);
                    data.Add("currentUser", ViewBag.CurrentUser);
                    data.Add("fieldPrefix", "columnContent");
                    data.Add("detailId", ViewBag.ContentSetId ?? 0);
                    data.Add("i", 0);
                    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++;
                        }
                    }
                }
            </el-tab-pane>
        </el-tabs>
    </el-form>
    <div class="footer-submit-bar" style="padding-left:170px">
        <el-button type="primary" v-on:click="postSubmit">提交保存</el-button>
        <el-button v-on:click="closeDrawer()">关闭</el-button>
    </div>
</div>


<script src="/Areas/Admin/Js/pinyin.js" type="text/javascript"></script>
<script>
    //访问路径，格式：abc/cbd
    validateDataTypes.path = function (gets, obj) {
        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.el.value = arrPath.join("/")
        var sysPath = new Array("e", "views", "upload", "templates", "js", "incs", "entities", "css", "config", "bin", "areas", "appplugins", "appdata", "member", "admin", "views");
        if (sysPath.indexOf(gets.trim().toLowerCase())>=0) {
            return gets + "为系统路径，请更换一个路径！";
        }
        return true;
    }
</script>
<script type="text/javascript">
    var activeName = request("activeName");
    if (isNullOrEmpty(activeName)) {
        activeName="first"
    }
    var action= "@action";
    var postUrl= "";
    var vueData = {
        activeName:"first",
        column:@Html.RawModel((string)Model),
        columnContent:@Html.RawModel((string)ViewBag.ContentSet),
        templateSet: { Template: "", TemplateDetail: "" },
        seoSet: { Title: "", Keywords: "", Description: "" }
    }
    vueData.column.Guid = "@guid";
    vueData.columnContent.Guid = "@guid";

    @if (action == "Add")
    {
        <text>
        var initColumn = { ColumnType:@(ViewBag.ColumnType??1), HttpcacheSolutionId:@(ViewBag.HttpcacheSolutionId ??0),IsFinal:1, TableId: @(ViewBag.TableId??0), Target: "_self", Show: 1, Xuhao: @xuhao, SiteId: @ViewBag.CurrentSiteId, ParentId: @(ViewBag.ParentId??0) };
        vueData.column = extend(vueData.column, initColumn);
        postUrl = "@Url.ActionUrl("ColumnAdd")";
      </text>
    }
    else
    {
      <text>
       postUrl = "@Url.ActionUrl("ColumnEdit")";
       var seoSet = @Html.Raw(ViewBag.SeoSet??"{}");
       vueData.seoSet = extend(vueData.seoSet, seoSet);
     </text>
    }
   var templateSet=@Html.Raw(ViewBag.TemplateSet ?? "{}");
   vueData.templateSet = extend(vueData.templateSet, templateSet);
    //提交前执行
    function beforeSubmitExecute() {
        var columnType = vueData.column.ColumnType.toString();
        switch (columnType) {
            case "0":
                vueData.column.TableId = 0;
                vueData.column.Path = "";
                vueData.templateSet.TemplateDetail = "";
                vueData.column.ZdyUrl = "";
                break;
            case "2":
                vueData.column.TableId = 0;
                vueData.templateSet.TemplateDetail = "";
                break;
            case "3":
                vueData.column.TableId = 0;
                vueData.templateSet.Template = "";
                vueData.templateSet.TemplateDetail = "";
                break;
        }
        @Html.Raw(beforeSubmitJs)
        return true;
    }

      var vue= new Vue({
          el: "#main",
          data: vueData,
          methods: {
              TemplateParameter: function (templatePath) {
                  var _this = this;
                  var name = "";
                  var path = "";
                  var template = templatePath;
                  if (template!="")
                  {
                      var templateSetS = template.split("/");
                      name = templateSetS[templateSetS.length - 1];
                      path = template.substring(0, template.length - name.length);
                  }
                  var url = "?name=" + encodeURIComponent(name) + "&path=" + encodeURIComponent("Views/"+path)+"&blockset=1";
                  return url;
              },
              postSubmit: function () {
                  var validated = this.validateForm({ beforeSubmit: function () { return beforeSubmitExecute() }, tipsStyle: 1 });//jquery表单验证
                  if (validated) {
                      this.submit({ url: postUrl, data: vueData, contentType: "application/json", success: function () { callBack() }, });
                  }
              },
          },
    });

      function SetDir() {
          var columnName = vueData.column.Name;
          if (columnName) {
              vueData.column.Path = ToPY(columnName, 50);}
          else {
              vue.$message.warning("请先填写栏目名称！");
          }
      }

      function callBack()
      {
          if (action == "Add")
          {
              location.href = "@Url.ActionUrl("Add")?xuhao=@(xuhao)&parentId=@(ViewBag.ParentId??0)";
          }
          parent.loadData();
      }

</script>
