@{
    CurrentUser user = ViewBag.CurrentUser;
    string action = ViewContext.RouteData.Values["action"].ToString();
    IEnumerable<dynamic> fieldData = Html.GetFieldList((string)ViewBag.Table, action, user);
    string guid = Html.Guid();
    int parentId = StringHelper.Format<int>(Request.QueryString["parentId"]);
    int xuhao = StringHelper.Format<int>(Request.QueryString["xuhao"]);
    if (xuhao <= 0)
    {
        xuhao = 1;
    }
}
<div class="main" id="main" v-cloak>
    <el-form ref="form" label-width="200px" label-position="left">
        <el-form-item label="名称">
            <el-input v-model.trim="formData.Name" style="width:700px;" maxlength="50" v-validate="{data:formData.Name,dataType:'*',checkError:'部门重复，请重写输入！'}"></el-input>
            <span class="help-block validate-tips-box"></span>
        </el-form-item>
        <el-form-item label="是否最终节点">
            <el-radio-group v-model="formData.IsFinal">
                <el-radio :label=1 :disabled="formData.Id>0">是</el-radio>
                <el-radio :label=0 :disabled="formData.Id>0">否</el-radio>
            </el-radio-group>
            <span class="help-block validate-tips-box">最终节点不能再继续增加子部门</span>
        </el-form-item>
        @{
            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", "formData");
            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="序号">
            <el-input-number controls-position="right" v-model.trim="formData.Xuhao" :min="0" :max="999999" v-validate="{data:formData.Xuhao,dataType:'numeric',errorMsg:'请填写数字！'}" ></el-input-number>
            <span class="help-block validate-tips-box"></span>
        </el-form-item>
    </el-form>
    <div class="footer-submit-bar" style="padding-left:150px">
        <el-button type="primary" v-on:click="postSubmit">提交保存</el-button>
        <el-button v-on:click="closeDrawer()">关闭</el-button>
    </div>
</div>


<script type="text/javascript">

    function BeforeSubmit()
    {
        @Html.Raw(beforeSubmitJs)
        return true;
    }

    //绑定数据
    var id = "@Request.QueryString["id"]";
    var formData = @Html.RawModel((string)Model ?? "{}");
    formData.Guid = "@guid";
    if (isNullOrEmpty(id))
    {
        formData.Id = 0;
        formData.ParentId =@parentId;
        formData.Xuhao = @xuhao;
        formData.IsFinal = 1;
        formData.Level = 0;
    }
    var vue = new Vue({
        el: "#main",
        data: {
            formData: formData
        },
        methods: {
            postSubmit: function () {
                var validated = this.validateForm({ beforeSubmit: function () { return BeforeSubmit();}, });//jquery表单验证
                if (validated) {
                    this.submit({ url: "@Url.ActionUrl()", data: formData, success: "PostBack()" });
                }
            }
        },
    });
    function PostBack() {
        if (isNullOrEmpty(id)) {
            location.href = "@(HttpContext.Current.Request.Path)?parentId=@parentId&Xuhao=@(xuhao+1)&id=" + id;
        }
        parent.loadData();
    }
</script>

