首页 > 其他分享 >前端html点击新增多项,ajax提交,后台接收

前端html点击新增多项,ajax提交,后台接收

时间:2023-08-15 16:47:27浏览次数:48  
标签:Code res 点击 entity Msg ajax html var data

<body>
    <form id="form1">
        <div class="procureWarp">
            <img class="headBg" src="/images/Cabinet/headUrl_01.png" alt="">
            <div class="head">
                <div class="title">用品采购审批</div>
            </div>
            <div class="procureFrom">
                <div class="fromUl">
                    <div class="itemlist">
                        <div class="fromLi">
                            <div class="label">
                                <img src="/images/Cabinet/procure_01.png" alt="">
                                <span>申请部门</span>
                            </div>
                            <div class="value">
                                <select id="departName" class="fromSelt" name="departName">
                                    <%foreach (var item in areaList)
                                        {%>
                                    <option value="<%=item.AreaName %>" <%=item.AreaName.Equals(CurUserDept)?"selected":"" %>><%=item.AreaName %></option>
                                    <%}%>
                                </select>
                            </div>
                            <img class="rightJt" src="/images/Cabinet/procure_05.png" alt="">
                        </div>
                        <div class="fromLi">
                            <div class="label">
                                <img src="/images/Cabinet/procure_02.png" alt="">
                                <span>物品名称</span>
                            </div>
                            <div class="value">
                                <select class="fromSelt" id="proType" name="proType">
                                    <%foreach (var item in proLIst)
                                        {%>
                                    <option value="<%=item.Name %>"><%=item.Name %></option>
                                    <%}%>
                                </select>
                            </div>
                            <img class="rightJt" src="/images/Cabinet/procure_05.png" alt="">
                        </div>
                        <div class="fromLi">
                            <div class="label">
                                <img src="/images/Cabinet/procure_02.png" alt="">
                                <span>采购数量</span>
                            </div>
                            <div class="value">
                                <input class="inputnum" placeholder="请输入采购数量" id="buyNum" type="number" name="buyNum" />
                            </div>
                        </div>
                    </div>
                    <div class="additem">
                        <div class="uploads">
                            <span class="text">新增 + </span>
                        </div>
                    </div>
                </div>

                <div class="fromUl">
                    <div class="fromLi">
                        <div class="label">
                            <img src="/images/Cabinet/procure_03.png" alt="">
                            <span>附件(word、excel、pdf、rar等格式)</span>
                        </div>
                        <div class="fileUpload">
                            <div class="uploads">
                                <img src="/images/Cabinet/downFile.png" alt="">
                                <span class="text">附件上传</span>
                            </div>
                            <input type="hidden" id="file1" />
                            <input class="upload" name="txtName" type="file" id="uploadify" onchange="uploadfile()" />
                            <div class="filename"></div>
                        </div>
                    </div>
                    <div class="fromLi">
                        <div class="label">
                            <img src="/images/Cabinet/procure_04.png" alt="">
                            <span>详情说明</span>
                        </div>
                        <div class="textear">
                            <textarea id="des" class="input" placeholder="请输入详情说明" maxlength="500"></textarea>
                            <div class="textCount"><span class="num">0</span>/500</div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="butList">
                <div class="but butAct">
                    <a href="javascript:submit()">提交</a>
                </div>
            </div>

            <uc1:foot runat="server" ID="foot2" />
        </div>
    </form>
</body>

<script>
    var beforeHtml = $(".itemlist").html();

    //提交
    function submit() {
        var buyNum = $("#buyNum").val();
        if (buyNum == "") {
            alert("请输入采购数量");
            return;
        }
        var serializeUrl = $("#form1").serialize();

        $.ajax({
            url: "SuppliedPurchasing.aspx", type: "post", dataType: "json",
            data: {
                action: "submit",
                //departmentName: $("#departName").val(),
                //proType: $("#proType").val(),
                //buyNum: buyNum,
                data: JSON.stringify(serializeUrl),

                fileUrl: $("#file1").val(),
                des: $("#des").val()
            },
            success: function (data) {
                alert(data.Msg);
                if (data.Code === 200) {
                    location = "/m/UserCenter/OrderList.aspx";
                }

            }, error: function (data) {
            }
        });
    }

    $(".additem").click(function () {
        $(".itemlist").append("<div class=\"heng\"></div>" + beforeHtml);
    })
</script>

  后台接收

protected string SubmitData()
    {
        ResultInfo res = new ResultInfo()
        {
            Code = 200,
            Msg = "提交申请失败,请稍后重试",
        };

        var formData = JsonConvert.DeserializeObject(Request.Form["data"]).ToString();
        if (formData.IsNullOrEmpty())
        {
            res.Code = 400;
            res.Msg = "数据不能为空!";
        }

        NameValueCollection formValues = HttpUtility.ParseQueryString(formData);
        List<string> departNames = formValues.GetValues("departName").ToList();
        List<string> proTypes = formValues.GetValues("proType").ToList();
        List<string> buyNums = formValues.GetValues("buyNum").ToList();
        if (departNames.Contains(""))
        {
            res.Code = 400;
            res.Msg = "申请部门不能为空!";
        }
        if (proTypes.Contains(""))
        {
            res.Code = 400;
            res.Msg = "物品名称不能为空!";
        }
        if (buyNums.Contains(""))
        {
            res.Code = 400;
            res.Msg = "采购数量不能为空!";
        }

        if (res.Code == 200)
        {
            res.Code = 400;
            for (int i = 0; i < departNames.Count; i++)
            {
                var entity = new DigitalOffice_Ic_CheckRecordByPurchase()
                {
                    OrderNo = IndexCreator.CreateIndex(BasicIndex.SUP),
                    OperatorTypeName = departNames[i],
                    OperatorType = Convert.ToInt32(buyNums[i]),
                    DepartmentName = departNames[i],
                    OperatorId = CurUser.UserId,
                    OperatorName = CurUser.TrueName,
                    OperatorPhone = CurUser.Phone,
                    FileUrl = (Request["fileUrl"] + "").TrimEnd('|'),
                    OperatorRemark = Request["des"],
                    Status = 1,
                    CreateTime = DateTime.Now
                };

                var processRes = SMZX_ApprovalProcess.GenerateCheckProcess(2, entity.Id, entity.DepartmentName, CurUser.TrueName, CurUser.Phone, entity.OrderNo);
                if (processRes.Success)
                {
                    new BaseService().SaveEntity(entity);
                    var nextCheckInfo = SMZX_ApprovalProcess.GetProcessDetailByOrderNumAndStep(entity.Status.Value, entity.OrderNo);
                    if (nextCheckInfo != null && nextCheckInfo.Count > 0)
                    {
                        foreach (var item in nextCheckInfo)
                        {
                            var userInfo = BLL_User.getUserByUserId(item.CheckUserId.Value);
                            if (userInfo != null && userInfo.openid.IsNotNullOrEmpty())
                            {
                                wxHelper.SendWaitCheckWxMsg(userInfo.openid, entity.OrderNo, entity.CreateTime.Value.ToString("yyyy.MM.dd"), "移动端审批", "用品采购");
                            }
                        }
                    }

                    res.Code = 200;
                    res.Msg = "申请提交成功,请等待审批!";
                }
            }
        }

        return JsonConvert.SerializeObject(res);
    }

    public class ResultInfo
    {
        public int Code { get; set; }
        public string Msg { get; set; }
    }

  

标签:Code,res,点击,entity,Msg,ajax,html,var,data
From: https://www.cnblogs.com/SmallChen/p/17631692.html

相关文章

  • html面试4
    html41.标准模式与兼容模式各有什么区别?标准模式的渲染方式和JS引擎的解析方式都是以该浏览器支持的最高标准运行。在兼容模式中,页面以宽松的向后兼容的方式显示,模拟老式浏览器的行为以防止站点无法工作。2.SGML.HTML.XML和XHTML的区别?SGML是标准通用标记语言,是一种定义......
  • html2
    html2HTML部分常见问题1.怎么让—个不定宽高的DIV,垂直水平居中?使用css方法父盒子设置:display:table-cell;text-align:center;vertical-align:middle;Div设置:display:inline-block;vertical-align:middle;使用css3transform父盒子设置:display:......
  • html面试1
    html面试1seo搜索引擎注意事项“SEO是指搜索引擎优化。全称为(SearchEngineOptimization)。根据权重来看,常用的是<title></title>标签,然后是<meta>标签,meta标签一般用两种,<metaname="keywords"content="搜索"></meta>关键字搜索,<metaname="description&q......
  • elementUi table表格 标头自定义,给表头加点击事件
    <el-table-columnlabel="">  <el-table-columnprop="column":render-header="renderHeader"width="160">    <templateslot-scope="scope">      <span>{{scope.row.column[......
  • JQuery&Ajax基础知识
    JQuery&Ajax基础知识1、Jquery简介Query是一个快速、简洁的JavaScript框架,是继Prototype之后又一个优秀的JavaScript代码库(框架)于2006年1月由JohnResig发布。jQuery设计的宗旨是“writeLess,DoMore”,即倡导写更少的代码,做更多的事情。它封装JavaScript常用的功能代码,提供一......
  • uni-app中html5+开发记录
    代码示例:1、创建dom并绑定click事件 btnBack=newplus.nativeObj.View('btnBack',{top:systemInfo.statusBarHeight+'px',//此处top和left是相对于手机屏幕左上角为基准,不支持rightleft:'10px',height:&......
  • HTML&CSS基本知识
    HTML&CSS基本知识一、HTML基本介绍W3C标准(成立于1994年,web技术领域最权威和具影响力的国际中立性技术标准机构)worldWidewebConsortium(万维网联盟)W3c标准包括:结构化标准语言(HTML、XML)表现标准语言(CSS)行为标准(DOM,ECMAScript)HTML:超文本标签语言h5并不是新语言,而是html......
  • C C++ Java python HTML/CSS/JavaScript
    C/C++是一种底层的语言,它可以直接操作内存和硬件,运行速度很快,但是也很难学习和调试,容易出错。Java是一种面向对象的语言,它可以跨平台运行,有很多成熟的框架和库,适合做大型的企业级应用,但是也很繁琐和冗长,需要写很多代码。Python是一种高级的语言,它可以用简洁的语法来实现复杂的功能......
  • C# WINFORM窗体右上角X点击后无法退出调试
    这个是由于你的程序在运行过程中开启了新线程,而在结束时没有把线程退出privatevoidBtnUpdate_Click(objectsender,EventArgse){intiX=this.Left;intiY=this.Top;Threadthr="更新".FindAndMoveMsgBox(iX,iY,true);if(dgv.......
  • HTML 全屏水印 vue 全屏水印
    HTML全屏水印vue全屏水印<!DOCTYPEhtml><html><head><metacharset="utf-8"><title>水印</title><style>#water-div{pointer-events:none;position:fixed;top:0;left:0;right:0;bottom:0;}......