ASP.NET MVC 实现页落网资源分享网站+充值管理+后台管理(11)之支付管理及广告管理
源码下载地址:http://www.yealuo.com/Sccnn/Detail?KeyValue=c891ffae-7441-4afb-9a75-c5fe000e3d1c
本项目属于个人项目,不支持在线支付功能,所有的支付都是扫码支付到个人,再上传到后台进行半自动的充值,所有后台需要一个支付管理功能。
对于需要在线支付的,我们可以使用ASP.NET SignalR的客户端和服务器之间双向通信实现在线支付全自动功能,在这里不多赘述,感兴趣的朋友可以搜搜相关文章。
然后就是我们的广告管理功能,在我们的项目中可能会挂一些广告或者友情链接分类及横幅幻灯等分类的功能,我们都可以在这里用分类来做一个简单的管理,其功能和知识点都跟前面的功能类似,这里就直接上这两块功能的代码:
一、支付管理:
按流程创建一个PayForMangeController控制器和Index.cshtml视图:
(1)PayForMangeController
using Bobo.Utilities; using IA.Business; using IA.Entity; using IA.WebApp.SystemExtension; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Web; using System.Web.Mvc; namespace IA.WebApp.Areas.BackstageModule.Controllers { [LoginAuthorize("~/BackstageModule/Login/Index")] public class PayForMangeController : PublicController<Com_PayFor> { // // GET: /BackstageModule/PayForMange/ /// <summary> /// 获取分页数据 /// </summary> /// <param name="UserAccount"></param> /// <param name="jgp"></param> /// <returns></returns> public ActionResult GetTable(string UserAccount, int? PayForState, JqGridParam jgp) { UserAccount = UserAccount.Replace(" ", ""); Com_PayForBll bll = new Com_PayForBll(); DataTable model = bll.GetTablePage(UserAccount, PayForState, ref jgp); //构建分页数据 var JsonData = new { success = true, pageData = jgp, message = "", data = model }; return Content(JsonData.ToJson()); } /// <summary> /// 假删方法 /// </summary> /// <param name="KeyValue"></param> /// <returns></returns> public ActionResult DeleteOther(string KeyValue) { Com_PayForBll bll = new Com_PayForBll(); try { int IsOk = 1; string Message = "删除成功"; if (!string.IsNullOrEmpty(KeyValue)) { string[] array = KeyValue.Split(','); foreach (var item in array) { Com_PayFor Oldentity = bll.Factory.FindEntity(item);//获取没更新之前实体对象 Oldentity.DeleteMark = 1; Oldentity.Modify(item); IsOk = bll.Factory.Update(Oldentity); this.WriteLog(IsOk, Oldentity, Oldentity, item, Message); } } else { Message = "删除失败"; IsOk = 1; } return Content(new JsonMessage { Success = true, Code = IsOk.ToString(), Message = Message }.ToString()); } catch (Exception ex) { this.WriteLog(-1, null, null, KeyValue, "操作失败:" + ex.Message); return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString()); } } /// <summary> /// 状态更改 /// </summary> /// <param name="KeyValue"></param> /// <param name="PayForState"></param> /// <param name="Idea"></param> /// <returns></returns> public ActionResult SetPayForState(string KeyValue, int? PayForState, string Idea) { Com_PayForBll bll = new Com_PayForBll(); Com_ApproveBll all = new Com_ApproveBll(); Com_MemberBll mll = new Com_MemberBll(); DbTransaction transaction = bll.Factory.BeginTrans(); try { string czMsg = ""; switch (PayForState) { case 0: czMsg = "待审核"; break; case 1: czMsg = "审核通过"; break; case -1: czMsg = "审核不通过"; break; } int IsOk = 1; string Message = "操作成功"; if (!string.IsNullOrEmpty(KeyValue)) { string[] array = KeyValue.Split(','); foreach (var item in array) { Com_PayFor Oldentity = bll.Factory.FindEntity(item);//获取没更新之前实体对象 Com_Member menity = mll.Factory.FindEntity(Oldentity.CreateUserId); if (Oldentity.PayForState != 0 || PayForState != -1) { //更新会员金币 if (PayForState > 0) { menity.Integral = menity.Integral + Oldentity.Integral; } else { menity.Integral = menity.Integral - Oldentity.Integral; } menity.Modify(Oldentity.CreateUserId); mll.Factory.Update(menity, transaction); } Oldentity.PayForState = PayForState; Oldentity.Modify(item); IsOk = bll.Factory.Update(Oldentity, transaction); IsOk = all.SubmitApproveData(KeyValue, PayForState.ToString(), czMsg, Idea, transaction);//插入审批记录 string emailTit = "页落素材网支付凭证处理结果"; string emailBody= "<h2>尊敬的" + menity.RealName + ",您好:</h2>您上传的页落素材网支付凭证已进行处理,处理结果为:[" + czMsg + "],详情请前往会员中心 http://www.yealuo.com/MemberCenterModule/MemberSystem/Index【我的充值】查看"; NetHelper.SendMailByWeb(menity.Email, ConfigHelper.ReadAppConfig("FromEmail"), emailTit, emailBody, ConfigHelper.ReadAppConfig("EmailPwd"), ConfigHelper.ReadAppConfig("SmtpServer"));//支付成功发送邮件 bll.Factory.Commit(); this.WriteLog(IsOk, Oldentity, Oldentity, item, Message); } } else { Message = "上报失败"; IsOk = 1; } return Content(new JsonMessage { Success = true, Code = IsOk.ToString(), Message = Message }.ToString()); } catch (Exception ex) { this.WriteLog(-1, null, null, KeyValue, "操作失败:" + ex.Message); return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString()); } } /// <summary> /// 获取审批记录 /// </summary> /// <param name="DataId"></param> /// <returns></returns> public ActionResult GetApprove(string DataId) { Com_ApproveBll bll = new Com_ApproveBll(); if (!StringHelper.IsNullOrEmpty(DataId)) { List<Com_Approve> List = bll.GetApproveList(DataId, null, null); return Content(List.ToJson()); } else { return null; } } } }
(2)Index.cshtml
@{ ViewBag.Title = "支付凭证管理"; Layout = "~/Views/Shared/_LayoutMange.cshtml"; } <style> html { background-color: #f3f4f4; } .w_header .header-nav .nav-item li a.wzgl { border-bottom: 2px solid #2D81E0; background-color: #E8F4FF; color: #2D81E0; font-weight: bold; } .w_center .center-nav-item a.zfgl { color: #156cd1; } </style> <div class="w_center clear mAuto"> @Html.Partial("_PartialNav") <div class="center-main R"> <h2 class="center-main-title font-yahei"> <span>支付凭证管理 /</span><i>PayFor Mange</i> </h2> <div class="center-main-box"> <div class="toolbarBox clear"> <div id="searchForm"> <div class="L attSeach"> <span>数据状态:</span> <select class="att-txt" id="PayForState" name="PayForState" onchange="getPageData();"> <option value="">==所有==</option> <option value="0">待审核</option> <option value="1">已通过</option> <option value="-1">退回</option> </select> </div> <div class="L searchForm" style="width:220px;"> <span class="seachTit">会员账号:</span> <input type="text" id="UserAccount" class="seachText" value="" style="width:130px;" /> <a id="searchBtn" class="searchBtn" href="javascript:;" title="搜索"></a> </div> </div> <div class="toolbar R"> @*<input type="button" value="通过" class="addBtn greenBtn" onclick="SetPayForState(1)" /> <input type="button" value="退回" class="addBtn yellowBtn" onclick="Return()" />*@ <input type="button" value="删除" class="delBtn redBtn" onclick="delBtn()" /> </div> </div> <table class="dataTable" style="width:100%;"> <thead> <tr> <td style="width:6%;" class="remElem"><input type="checkbox" class="ckbAll " />选中</td> <td style="width:20%;" class="tbTit">会员信息</td> <td style="width:12%;" class="tbTit">支付内容</td> <td style="width:10%;" class="remElem">支付类型</td> <td style="width:20%;">支付凭证</td> <td style="width:12%;">提交时间</td> <td style="width:10%;">状态</td> </tr> </thead> <tbody id="dataBody"></tbody> </table> <div id="listPage" class="m_pageBar com_pageBar" style="padding:0 30px;"></div> </div> </div> </div> @*分页数据模版*@ <script id="tempBody" type="text/template"> {#each data as item} <tr> <td style="text-align: center;"><input type="checkbox" class="ckb" data-id="!{item.PayForID}" onclick="change(this)" /></td> <td> <div>账号:<span>!{item.RealName}</span></div> <div>金币:<span>!{item.HasIntegral}</span></div> <div> 会员类型: {#if item.MemberType>0} <span>VIP会员</span> {#else} <span>普通会员</span> {#/if} </div> </td> {#if item.PayForContent==5} <td style="text-align:center;">5个金币/5元</td> {#else if item.PayForContent==10} <td style="text-align:center;">10个金币/10元</td> {#else if item.PayForContent==22} <td style="text-align:center;">22个金币/20元</td> {#else if item.PayForContent==33} <td style="text-align:center;">33个金币/30元</td> {#else if item.PayForContent==44} <td style="text-align:center;">44个金币/40元</td> {#else if item.PayForContent==55} <td style="text-align:center;">55个金币/50元</td> {#else if item.PayForContent==110} <td style="text-align:center;">110个金币/100元</td> {#else if item.PayForContent==220} <td style="text-align:center;">220个金币/200元</td> {#else if item.PayForContent==330} <td style="text-align:center;">330个金币/300元</td> {#else if item.PayForContent==440} <td style="text-align:center;">440个金币/400元</td> {#else if item.PayForContent==550} <td style="text-align:center;">550个金币/500元</td> {#/if} {#if item.PayForType==1} <td style="text-align:center;">微信</td> {#else} <td style="text-align:center;">支付宝</td> {#/if} <td style="text-align:center;"> <a href="javascript:;" onclick="layer.full(layer.open({ content: $(this).html()}));"> <img src="!{item.PayForUrl}" style="width:99%;" /> </a> </td> <td style="text-align:center;">!{formatDate(item.CreateDate, "yyyy-MM-dd hh:mm:ss")}</td> <td style="text-align:center;"> {#if item.PayForState>0} <span style="color:#00ff21;">通过</span> <a href="javascript:;" data-id="!{item.PayForID}" onclick="Return($(this))" class="tbBtn tbDel">退回</a> {#else if item.PayForState==-1} <span style="color:#999;">退回</span> <a href="javascript:;" data-id="!{item.PayForID}" onclick="SetPayForState($(this))" class="tbBtn tbPass">通过</a> {#else} <span style="color:#ff0000;">待审核 </span> <a href="javascript:;" data-id="!{item.PayForID}" onclick="Return($(this))" class="tbBtn tbDel">退回</a> <a href="javascript:;" data-id="!{item.PayForID}" onclick="SetPayForState($(this))" class="tbBtn tbPass">通过</a> {#/if} <a href="javascript:;" data-id="!{item.PayForID}" onclick="ApproveDetail($(this))" class="tbBtn tbDetail">记录</a> </td> </tr> {#/each} </script> @*隐藏弹窗模版*@ <script id="Return" type="text/template"> <div style="margin:20px 20px;"> <form id="form1" action="/BackstageModule/PayForMange/SetPayForState" method="post" enctype="multipart/form-data" style="margin: 1px"> <input type="hidden" id="PayForState" name="PayForState" value="-1" /> <table class="layer-table-form"> <tr> <td style="height:100px;"><textarea name="Idea" class="layer-form-content-tarea" id="Idea" datacol="yes" err="意见" checkexpession="NotNull"></textarea> </td> </tr> </table> </form> </div> </script> @*隐藏审批记录模版*@ <script id="DialogApprove" type="text/template"> <div class="Dialog-Box font-yahei"> <div class="Dialog-Com" style="display:block;"> <table class="Dialog-table"> <thead> <tr> <td class="Dialog-table-tit" style="text-align:center;">状态</td> <td class="Dialog-table-tit" style="text-align:center;">操作人</td> <td class="Dialog-table-tit" style="text-align:center;">操作时间</td> <td class="Dialog-table-tit" style="text-align:center;">原因</td> </tr> </thead> <tbody id="Approve"></tbody> </table> </div> </div> </script> @section scripts{ <script type="text/javascript"> var KeyValue = ""; $(function () { juicer.register('formatDate', formatDate); getPageData(); searchEvent(); }); //初始化分页函数 function getPageData() { var param = { rows: 10, url: "/BackstageModule/PayForMange/GetTable", sidx: "CreateDate", sord: "DESC", searchForm: "#searchForm", infoPanel: '#dataBody', barPanel: '#listPage', template: '#tempBody', callback: handleSuccess } Pager.init(param); } ///审核记录详情 function ApproveDetail(elem) { var dataId = elem.attr("data-id"); layer.open({ title: "审核记录", type: 1, skin: 'layui-layer-rim', //加上边框 area: ['700px', '500px'], //宽高 content: $("#DialogApprove").html(), }); AjaxJson("/BackstageModule/PayForMange/GetApprove", { DataId: dataId }, function (data) { if (!!data) { var str = ""; for (var i = 0; i < data.length; i++) { str += "<tr>" str += "<td class=\"Dialog-table-tit\" style=\"text-align:center;\">" + data[i].Action + "</td>" str += "<td class=\"Dialog-table-tit\" style=\"text-align:center;\">" + data[i].CreateUserName + "</td>" str += "<td class=\"Dialog-table-tit\" style=\"text-align:center;\">" + formatDate(data[i].CreateDate, "yyyy-MM-dd") + "</td>" str += "<td class=\"Dialog-table-tit\" style=\"text-align:center;\">" + (!data[i].Idea ? '' : data[i].Idea) + "</td>" str += "</tr>"; } $("#Approve").html(str); } }); } //业务操作 function SetPayForState(elem) { var dataId = elem.attr("data-id"); layer.confirm("确定提交这条数据?", { icon: 0 }, function () { AjaxJson("/BackstageModule/PayForMange/SetPayForState", { KeyValue: dataId, PayForState: 1 }, function (data) { layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () { if (data.Code > 0) { Pager.reload(); } }); }); }); } //退回 function Return(elem) { var dataId = elem.attr("data-id"); layer.open({ title: "退回意见", type: 1, skin: 'layui-layer-rim', //加上边框 area: ['450px', '300px'], //宽高 content: $("#Return").html(), btn: ['保存', '取消'], //只是为了演示 yes: function () { AcceptClick(dataId); } }); } //提交退回意见表单 function AcceptClick(dataId) { if (!CheckDataValid('#form1', true)) { return false; } $("#form1").ajaxSubmit({ type: 'post', url: '/BackstageModule/PayForMange/SetPayForState?&KeyValue=' + dataId, dataType: "json", beforeSubmit: function () { layer.msg('正在提交信息,请稍后…', { icon: 16, shade: 0.2, time: 0 }); }, success: function (data) { layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () { layer.closeAll(); Pager.reload(); }); } }); } //查询按钮绑定事件 function searchEvent() { $("#searchBtn").on("click", function () { getPageData(); }); } //删除 function delBtn() { var allVal = ""; $(".dataTable tbody tr").find(".ckb").each(function () { var ckb = $(this); var ckbVal = ckb.prop("checked"); var dataId = ckb.attr("data-id"); if (ckbVal == "checked" || ckbVal == true) { allVal += (allVal == "" ? dataId : "," + dataId); } }); if (allVal == "") { layer.alert("您没有选中任何项,请选中后再进行操作!", { icon: 0 }); return false; } layer.confirm("是否删除这" + allVal.split(",").length + "条数据?", { icon: 0 }, function () { AjaxJson("/BackstageModule/PayForMange/DeleteOther", { KeyValue: allVal }, function (data) { layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () { Pager.reload(); }); }); }); } //分页数据加载后绑定的函数 function handleSuccess() { checkAll(); } //全选(包括) function checkAll() { //全选按钮 $(".dataTable thead").find(".ckbAll").change(function () { var chkAll = $(this); var chkVal = chkAll.prop("checked"); if (chkVal == "checked" || chkVal == true) { $(".dataTable tbody tr").each(function () { var chk = $(this).find(":checkbox"); chk.prop("checked", "checked"); }); } else { $(".dataTable tbody tr").each(function () { var chk = $(this).find(":checkbox"); chk.removeAttr("checked"); }); } }); } </script> }
在处理支付过程中,我们需要邮箱通知用户他们的充值结果,所以需要在配置文件中配置发送邮箱的服务设置,在之前创建的配置文件system.config中,添加节点如下:
<!-- ================== 5:给用户发送邮箱 ================== --> <!-- 来源邮箱 --> <add key="FromEmail" value="xxx@qq.com" /> <!-- 邮箱服务密码 --> <add key="EmailPwd" value="xkkmsms" /> <!-- Smtp服务名称 --> <add key="SmtpServer" value="smtp.qq.com" />
二、广告管理:
按流程创建一个BannerMangeController控制器和Index.cshtml视图:
(1)BannerMangeController
using Bobo.Utilities; using IA.Business; using IA.Entity; using IA.WebApp.SystemExtension; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; namespace IA.WebApp.Areas.BackstageModule.Controllers { [LoginAuthorize("~/BackstageModule/Login/Index")] /// <summary> /// 广告控制器 /// </summary> public class BannerMangeController : PublicController<Com_Banner> { // // GET: /BackstageModule/BannerMange/ /// <summary> /// 获取分页数据 /// </summary> /// <param name="ArticleTitle"></param> /// <param name="jgp"></param> /// <returns></returns> public ActionResult GetTable(string BannerTitle, JqGridParam jgp) { BannerTitle = BannerTitle.Replace(" ", ""); Com_BannerBll bll = new Com_BannerBll(); DataTable model = bll.GetTablePage(BannerTitle, ref jgp); //构建分页数据 var JsonData = new { success = true, pageData = jgp, message = "", data = model }; return Content(JsonData.ToJson()); } [HttpPost] [ValidateInput(false)] /// <summary> /// 添加编辑 /// </summary> /// <param name="entity"></param> /// <param name="KeyValue"></param> /// <returns></returns> public ActionResult SubmitFormData(Com_Banner entity, string KeyValue) { HttpPostedFileBase FileCover = Request.Files["BannerImg"]; Com_BannerBll bll = new Com_BannerBll(); try { int IsOk = 0; string Message = KeyValue == "" ? "新增成功。" : "编辑成功。"; #region 附件处理 bool FileHasCover = FileCover != null && FileCover.ContentLength > 0; List<string> fileType = ConfigHelper.GetSystemConfig("SystemConfig", "fileUploadPath", "ImageType").ToLower().Split('|').ToList(); string PicName = ""; if (FileHasCover) { PicName = Path.GetFileName(FileCover.FileName); } if ((FileHasCover && !fileType.Contains(Path.GetExtension(PicName).ToLower()))) { return Content(new JsonMessage { Code = "-1", Success = false, Message = "图片只能上传" + ConfigHelper.GetSystemConfig("SystemConfig", "fileUploadPath", "ImageType").ToLower() + "类型的文件!" }.ToString()); } if (FileHasCover && CommonHelper.GetInt(SizeHelper.CountSizeNum(FileCover.ContentLength)) > CommonHelper.GetInt(ConfigHelper.GetSystemConfig("SystemConfig", "fileUploadPath", "ImageSize"))) { return Content(new JsonMessage { Code = "-1", Success = false, Message = "文件大小不能超过" + ConfigHelper.GetSystemConfig("SystemConfig", "fileUploadPath", "ImageSize") + "M!" }.ToString()); } string AllPath = "";//ConfigHelper.GetSystemConfig("SystemConfig", "fileUploadPath", "AllFilePath"); string PicPath = "/Resource/BannerImg/"; DirFileHelper.CreateDirectory(Server.MapPath(AllPath + PicPath)); //上传广告图 if (FileCover != null && FileCover.ContentLength > 0) { string fileName = CommonHelper.GetGuidNotLine() + Path.GetFileName(FileCover.FileName); FileCover.SaveAs(Server.MapPath(AllPath + PicPath + fileName)); entity.BannerImg = PicPath + fileName; } #endregion if (!string.IsNullOrEmpty(KeyValue)) { Com_Banner Oldentity = bll.Factory.FindEntity(KeyValue);//获取没更新之前实体对象 entity.Modify(KeyValue); IsOk = bll.Factory.Update(entity); this.WriteLog(IsOk, entity, Oldentity, KeyValue, Message); } else { entity.Create(); IsOk = bll.Factory.Insert(entity); this.WriteLog(IsOk, entity, null, KeyValue, Message); } return Content(new JsonMessage { Success = true, Code = IsOk.ToString(), Message = Message }.ToString()); } catch (Exception ex) { this.WriteLog(-1, entity, null, KeyValue, "操作失败:" + ex.Message); return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString()); } } /// <summary> /// 假删方法(会刊) /// </summary> /// <param name="KeyValue"></param> /// <returns></returns> public ActionResult DeleteOther(string KeyValue) { Com_BannerBll bll = new Com_BannerBll(); try { int IsOk = 1; string Message = "删除成功"; if (!string.IsNullOrEmpty(KeyValue)) { string[] array = KeyValue.Split(','); foreach (var item in array) { Com_Banner Oldentity = bll.Factory.FindEntity(item);//获取没更新之前实体对象 Oldentity.DeleteMark = 1; Oldentity.Modify(item); IsOk = bll.Factory.Update(Oldentity); this.WriteLog(IsOk, Oldentity, Oldentity, item, Message); } } else { Message = "删除失败"; IsOk = 1; } return Content(new JsonMessage { Success = true, Code = IsOk.ToString(), Message = Message }.ToString()); } catch (Exception ex) { this.WriteLog(-1, null, null, KeyValue, "操作失败:" + ex.Message); return Content(new JsonMessage { Success = false, Code = "-1", Message = "操作失败:" + ex.Message }.ToString()); } } } }
(2)Index.cshtml
@{ ViewBag.Title = "广告管理"; Layout = "~/Views/Shared/_LayoutMange.cshtml"; } <style> html { background-color: #f3f4f4; } .w_header .header-nav .nav-item li a.wzgl { border-bottom: 2px solid #2D81E0; background-color: #E8F4FF; color: #2D81E0; font-weight: bold; } .w_center .center-nav-item a.gggl { color: #156cd1; } </style> <div class="w_center clear mAuto"> @Html.Partial("_PartialNav") <div class="center-main R"> <h2 class="center-main-title font-yahei"> <span>广告管理 /</span> <i>management of industry trends</i> </h2> <div class="center-main-box"> <div class="toolbarBox clear"> <div id="searchForm" class="L searchForm"> <span class="seachTit">产品标题:</span> <input type="text" id="BannerTitle" class="seachText" value="" /> <a id="searchBtn" class="searchBtn" href="javascript:;" title="搜索"></a> </div> <div class="toolbar R"> <input type="button" value="添加" class="mainBtn addBtn greenBtn" onclick="AddEditBtn(0,$(this))" /> <input type="button" value="删除" class="mainBtn delBtn blueBtn" onclick="delBtn()" /> </div> </div> <table class="dataTable" style="width:100%;"> <thead> <tr> <td style="width:10%;" class="remElem"><input type="checkbox" class="ckbAll " />选定</td> <td style="width:15%;">广告图片</td> <td style="width:20%;">广告标题</td> <td style="width:15%;">广告状态</td> <td style="width:15%;">广告地址</td> <td style="width:15%;">添加时间</td> <td style="width:10%;">操作</td> </tr> </thead> <tbody id="dataBody"></tbody> </table> <div id="listPage" class="m_pageBar com_pageBar" style="padding:0 30px;"></div> </div> </div> </div> @*隐藏弹窗模版*@ <script id="ReplyEdit" type="text/template"> <div style="margin:20px 20px;"> <form id="form1" action="/BackstageModule/BannerMange/SubmitFormData" method="post" enctype="multipart/form-data" style="margin: 1px"> <input type="hidden" id="KeyValue" name="KeyValue" /> <table class="layer-table-form"> <tr> <td><span class="layer-form-tit">广告标题:</span><input type="text" name="BannerTitle" class="layer-form-txt" id="BannerTitle" datacol="yes" err="标题" checkexpession="NotNull" /></td> </tr> <tr> <td> <span class="layer-form-tit">广告类型:</span> <select name="BannerType" class="layer-form-select" id="BannerType"> <option value="">==请选择==</option> <option value="Index">首页横幅</option> <option value="flink">友情链接</option> </select> </td> </tr> <tr> <td><span class="layer-form-tit">广告地址:</span><input type="text" name="BannerLink" class="layer-form-txt" id="BannerLink" /></td> </tr> <tr> <td> <div class="layer-form-tit L">广告图片:</div> <input type="text" name="BannerImgSet" id="BannerImgSet" class="layer-form-txt url1 L" readonly="readonly" style="display:none;" placeholder="请上传.JPG|.JPEG|.PNG|.GIF|.BMP格式的图片" datacol="yes" err="广告图片" /> <input type="text" name="BannerImg" id="BannerImg" class="layer-form-txt url2 L" readonly="readonly" placeholder="请上传.JPG|.JPEG|.PNG|.GIF|.BMP格式的图片" datacol="yes" err="广告图片" /> <div class="FileBox L"> <input class="file upFile" type="file" name="BannerImg" value="" onchange="SetFileVal($(this))" /> </div> </td> </tr> <tr> <td> <div class="layer-form-tit L">广告介绍:</div> <textarea class="layer-form-txt" id="BannerCenter" name="BannerCenter" maxlength=2147483647 datacol="yes" err="广告介绍" checkexpession="NotNull" style="width:99.9%;"></textarea> </td> </tr> </table> </form> </div> </script> @*分页数据模版*@ <script id="tempBody" type="text/template"> {#each data as item} <tr> <td style="text-align: center;"><input type="checkbox" class="ckb" data-id="!{item.BannerID}" onclick="change(this)" /></td> <td style="text-align: center;"><img src="!{item.BannerImg}" width="80" height="100" /> </td> <td style="text-align: center;">!{item.BannerTitle}</td> <td style="text-align: center;">!{item.State}</td> <td style="text-align: center;">!{item.BannerLink}</td> <td style="text-align: center;">!{formatDate(item.CreateDate, "yyyy-MM-dd")}</td> <td style="text-align:center;"><a href="javascript:;" onclick="AddEditBtn(1,$(this))" data-id="!{item.BannerID}" class="tbBtn tbEdit">编辑</a></td> </tr> {#/each} </script> @section scripts{ <script src="~/Content/Scripts/ueditor/ueditor.config.js"></script> <script src="~/Content/Scripts/ueditor/ueditor.all.js"></script> <script src="~/Content/Scripts/ueditor/lang/zh-cn/zh-cn.js"></script> <script type="text/javascript"> $(function () { juicer.register('formatDate', formatDate); searchEvent(); getPageData(); }); //初始化分页函数 function getPageData() { var param = { rows: 10, url: "/BackstageModule/BannerMange/GetTable", sidx: "CreateDate", sord: "DESC", searchForm: "#searchForm", infoPanel: '#dataBody', barPanel: '#listPage', template: '#tempBody', callback: handleSuccess } Pager.init(param); } //查询按钮绑定事件 function searchEvent() { $("#searchBtn").on("click", function () { getPageData(); }); } //文件域选择设置 function SetFileVal(elem) { var part = elem.parents("td"); if (!!elem.val()) { part.find(".url1").val(elem.val()).show().attr("checkexpession", "NotNull"); part.find(".url2").hide().removeAttr("checkexpession"); } else { part.find(".url1").show().attr("checkexpession", "NotNull"); part.find(".url2").hide().removeAttr("checkexpession"); } } //保存按钮 function AcceptClick() { if (!CheckDataValid('#form1', true)) { return false; } //提交表单 $("#form1").ajaxSubmit({ dataType: "json", beforeSubmit: function () { layer.msg('正在提交信息,请稍后…', { icon: 16, shade: 0.2, time: 0 }); }, success: function (data) { if (data.Success) { layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () { layer.closeAll(); getPageData(); }); } else { layer.alert(data.Message, { icon: data.Code }); } } }); } //添加编辑弹窗 function AddEditBtn(num, elem) { var allVal = ""; if (num > 0) { allVal = elem.attr("data-id"); } var index = layer.open({ title: "添加/编辑", type: 1, skin: 'layui-layer-rim', //加上边框 area: ['650px', '500px'], //宽高 content: $("#ReplyEdit").html(), btn: ['保存', '取消'], //只是为了演示 maxmin: true, yes: function () { AcceptClick(); } }); layer.full(index); InitControl(allVal); } //得到一个对象实体 function InitControl(allVal) { var ue = UE.getEditor('BannerCenter', { autoFloatEnabled: false, autoHeightEnabled: false }); AjaxJson("/BackstageModule/BannerMange/SetForm", { KeyValue: allVal }, function (data) { SetWebControls(data, "#form1"); $("#BannerCenter").val(data.BannerCenter); if (!!data.BannerCenter) { ue.addListener('ready', function (editor) { var height = $(window).height(), tabHeight = $(".form-table").outerHeight(); headHeight = $(".w_header").outerHeight(); footHeight = $(".w_footer").outerHeight(); editToolHeight = $("#edui1_toolbarbox").outerHeight(), editBottomHeight = $("#edui1_bottombar").outerHeight(), editHeight = 300; ue.setHeight(editHeight); ue.setContent(data.BannerCenter, false); }); } $("#KeyValue").val(data.BannerID); $("#BannerImg").attr("checkexpession", "NotNull"); }); } //删除 function delBtn() { var allVal = ""; $(".dataTable tbody tr").find(".ckb").each(function () { var ckb = $(this); var ckbVal = ckb.prop("checked"); var dataId = ckb.attr("data-id"); if (ckbVal == "checked" || ckbVal == true) { allVal += (allVal == "" ? dataId : "," + dataId); } }); if (allVal == "") { layer.alert("您没有选中任何项,请选中后再进行操作!", { icon: 0 }); return false; } layer.confirm("是否删除这" + allVal.split(",").length + "条数据?", { icon: 0 }, function () { AjaxJson("/BackstageModule/BannerMange/DeleteOther", { KeyValue: allVal }, function (data) { layer.msg(data.Message, { icon: data.Code, time: 1000 }, function () { Pager.reload(); }); }); }); } //分页数据加载后绑定的函数 function handleSuccess() { checkAll(); } //全选(包括) function checkAll() { //全选按钮 $(".dataTable thead").find(".ckbAll").change(function () { var chkAll = $(this); var chkVal = chkAll.prop("checked"); if (chkVal == "checked" || chkVal == true) { $(".dataTable tbody tr").each(function () { var chk = $(this).find(":checkbox"); chk.prop("checked", "checked"); }); } else { $(".dataTable tbody tr").each(function () { var chk = $(this).find(":checkbox"); chk.removeAttr("checked"); }); } }); } </script> }