Fork me on GitHub

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

<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; }
    }

  

posted @ 2023-08-15 16:35  WantRemake  阅读(14)  评论(0编辑  收藏  举报