@using PageAdmin.Utils;
@using PageAdmin.Common;
@{
    int fieldId = ViewBag.FieldId;
    int parentId = ViewBag.ParentId;
    string parentGuid = ViewBag.parentGuid;
    string subTable = ViewBag.Table;
    CurrentUser currentUser = ViewBag.CurrentUser;
    string actionName = this.ViewContext.RouteData.Values["action"].ToString();
    IEnumerable<dynamic> fieldDataList = Html.GetFieldList(subTable, actionName, currentUser, (FromEnum)ViewBag.From, true);
    string guid = Html.Guid();
}
    <script src="~/Incs/UEditor/ueditor.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-width="150px" label-position="left" size="medium">
            @{
                string beforeSubmitJs = "";
                var data = new ViewDataDictionary();
                data.Add("currentUser", currentUser);
                data.Add("guid", guid);
                data.Add("from", ViewBag.From);
                data.Add("fieldPrefix", "formData");
                data.Add("i", 0);
                int i = 0;
                foreach (var row in fieldDataList)
                {
                    data["i"] = i;
                    beforeSubmitJs += row.BeforeSubmitJs;
                    Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                    i++;
                }
            }
        </el-form>
        <div class="footer-submit-bar" style="padding-left:170px">
            <el-button type="primary" v-on:click="postSubmit">提交保存</el-button>
            <el-button onclick="closeSelf()">关闭</el-button>
            <el-button onclick="closeSelf(parent.loadData)">返回</el-button>
        </div>
</div>

<script type="text/javascript">
    var action="@actionName.ToLower()"
    var formData =@Html.RawModel((string)Model ?? "{}");
    formData.Guid = "@guid";
    formData.FieldId = "@fieldId";
    if (action=="add")
    {
        formData.ParentGuid = "@parentGuid";
        formData.ParentId = "@parentId";
    }

    //提交前执行
    function beforeSubmitExecute() {
        @Html.Raw(beforeSubmitJs)
        return true;
    }
      var vue= new Vue({
          el: "#main",
          data: {
              formData: formData
          },
          methods: {
              postSubmit: function () {
                    var validated = this.validateForm({ beforeSubmit:function (){ return beforeSubmitExecute() }});//jquery表单验证
                    if (validated)
                    {
                        this.submit({ url: "@Url.ActionUrl(actionName)", data: formData,success: function () { callBack() }});
                    }
              },
          },
    });
      function callBack() {
            if (action == "add") {
                location.href = location.href;
            }
        }
</script>

