|
导读部分
教程目录:http://www.sufeinet.com/thread-40967-1-1.html
教程部分
页面效果:
本页面做了多级单位分类处理, 此处的分类,主要用在小程序缴费时,进行缴费单位的选择
页面Jquery:
[C#] 纯文本查看 复制代码 <script type="text/javascript">
var path;
var rs = new Vue({
el: "#grid",
data: {
list: [],
pgsize: 20,
pgindex: 1,
model: {},
name: "",
linkman: "",
mobile: "",
proid:"",
cityid:"",
govid:"",
bjtext: "",
pids1: "",
parentlists1: [],
times: [{id:0,name:"0时"},{id:1,name:"1时"},{id:2,name:"2时"},{id:3,name:"3时"},{id:4,name:"4时"},{id:5,name:"5时"},{id:6,name:"6时"},{id:7,name:"7时"},{id:8,name:"8时"},{id:9,name:"9时"},{id:10,name:"10时"},{id:11,name:"11时"},{id:12,name:"12时"},{id:13,name:"13时"},{id:14,name:"14时"},{id:15,name:"15时"},{id:16,name:"16时"},{id:17,name:"17时"},{id:18,name:"18时"},{id:19,name:"19时"},{id:20,name:"20时"},{id:21,name:"21时"},{id:22,name:"22时"},{id:23,name:"23时"},{id:24,name:"24时"}]
},
methods: {
StrToGMT: function (time) {
let GMT = new Date(time)
return GMT
},
doInit: function () {
var info = danwei.list();
this.list = info;
},
savetype: function () {
if (!this.model.btime) {
layer.msg("请选择开始时间", { time: 800 });
return;
}
if (!this.model.etime) {
layer.msg("请选择结束时间", { time: 800 });
return;
}
if ($("#btn_save").html() == "保存") {
$("#btn_save").html("保存中...")
var index = layer.load(2, {
shade: [0.1, '#fff'] //0.1透明度的白色背景
});
danwei.addPro(this.model);
}
},
//添加编辑
bjList: function (id,ids,num) {
if (num== 0) {
this.bjtext = "添加顶级单位"
} else if (num== 1){
this.bjtext = "修改单位名称"
}else if (num== 2){
this.bjtext = "添加子单位"
}
var item = danwei.getInfo(id,ids);
this.model = item.info;
// if (this.model.btime == "0001-01-01T00:00:00") {
//this.model.btime = "";
//}
if (id == 0) {
this.model.btime = this.StrToGMT(item.time);
this.model.etime = this.StrToGMT(item.time);
} else {
this.model.btime =this.StrToGMT(this.model.btime);
this.model.etime =this.StrToGMT(this.model.etime);
}
//if (this.model.etime == "0001-01-01T00:00:00") {
// this.model.etime = "";
// }
module(['modal'],
function (md, exports) {
md.bind({
target: '#address'
});
});
},
delList: function (id) {
this.$confirm('此操作将永久删除该内容, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
var res = danwei.del(id);
if (res == 0) {
this.$message({
type: 'success',
message: '删除成功!'
});
rs.doInit();
}
}).catch(() => {
});
},
},
mounted: function () {
this.doInit();
}
});
function pageSet(pages) {
rs.isinit = 0;
rs.pgindex = 1;
rs.pgsize = pages;
rs.doInit();
}
</script>
c# 后台程序:
[C#] 纯文本查看 复制代码 // 获取所有缴费单位信息
funlist.TryAdd("danweilist", (context, _handitem) =>
{
JsonResultHelper<dynamic> resultJson = new JsonResultHelper<dynamic>() { msgCode = -1, msg = "获取失败" };
// 获取所有缴费单位数据
jiaofei_danweiBLL dbll = new jiaofei_danweiBLL();
List<jiaofei_danwei> list = dbll.GetAll();
resultJson.msgCode = 0;
resultJson.info = list;
resultJson.msg = "获取成功";
return resultJson;
});
// 获取实体
funlist.TryAdd("danweiinfo", (context, _handitem) =>
{
JsonResultHelper<dynamic> resultJson = new JsonResultHelper<dynamic>() { msgCode = -1, msg = "获取失败" };
// 获取参数
int id = InputHelper.GetInputInt(context.Request["id"]);
int pid = InputHelper.GetInputInt(context.Request["pid"]);
DateTime dt = DateTime.Now;
string dt_str = dt.ToString("yyyy-MM-dd HH:mm");
jiaofei_danwei info = new jiaofei_danwei();
jiaofei_danweiBLL dbll = new jiaofei_danweiBLL();
if (id > 0)
{
info = dbll.FindListOne($"id={id}") ?? new jiaofei_danwei();
}
else
{
// 获取当前层级信息, 处理pids以及层级参数
jiaofei_danwei p_info = dbll.FindListOne($"id={pid}") ?? new jiaofei_danwei();
string pids = "";
if (p_info != null && p_info.id > 0) { pids = (string.IsNullOrEmpty(p_info.pids) ? $",{pid}," : $"{p_info.pids}{pid},"); }
info = new jiaofei_danwei() { parentid = pid, levelnum = p_info.levelnum + 1, pids = pids,btime=DateTime.Now, etime=DateTime.Now };
}
// 处理当前实体的父信息
if (!string.IsNullOrEmpty(info.pids))
{
List<jiaofei_danwei> p_list = dbll.FindList($"id in({info.pids.TrimStart(',').TrimEnd(',')})") ?? new List<jiaofei_danwei>();
info.p_name = string.Join(" > ", p_list.Select(p => p.name));
}
dynamic dy = new ExpandoObject();
dy.info = info;
dy.time = dt_str;
resultJson.msgCode = 0;
resultJson.info = dy;
resultJson.msg = "获取成功";
return resultJson;
});
// 保存缴费单位
funlist.TryAdd("savedanwei", (context, _handitem) =>
{
JsonResultHelper<dynamic> resultJson = new JsonResultHelper<dynamic>() { msgCode = -1, msg = "保存失败" };
// 获取参数
jiaofei_danwei info = JsonHelper.JsonToObj<jiaofei_danwei>(context.Request["model"]);
// 参数校验
if (string.IsNullOrEmpty(info.name)) { resultJson.msg = "单位名称不能为空"; }
else
{
// 查询同上级下,名称不重复
jiaofei_danweiBLL dbll = new jiaofei_danweiBLL();
jiaofei_danwei is_exist = dbll.FindListOne($"parentid={info.parentid} AND name='{info.name}' AND id<>{info.id} AND is_del=0");
if (is_exist != null && is_exist.id > 0) { resultJson.msg = "该单位名称已存在"; }
else
{
// 处理父IDS
//if (info.parentid > 0 && !string.IsNullOrEmpty(info.pids)) { info.pids = $",{info.pids.TrimEnd(',').TrimStart(',')},"; }
int result = dbll.Save(info);
if (result > 0) { resultJson.msgCode = 0; resultJson.msg = "保存成功"; }
}
}
return resultJson;
});
// 删除缴费单位
funlist.TryAdd("deldanwei", (context, _handitem) =>
{
JsonResultHelper<dynamic> resultJson = new JsonResultHelper<dynamic>() { msgCode = -1, msg = "删除失败" };
// 获取参数
int id = InputHelper.GetInputInt(context.Request["id"]);
if (id < -0) { resultJson.msg = "参数有误"; }
else
{
// 判断该分类是否有子集
jiaofei_danweiBLL dbll = new jiaofei_danweiBLL();
if (dbll.Count($"parentid={id}") > 0) { resultJson.msg = "存在子单位,不允许删除"; }
else
{
// 获取当前删除的节点是否存在兄弟元素, 如果不存在,则同步修改父为叶子元素
string sql = $"update jiaofei_danwei set is_del=1 where id={id};";
if (dbll.Count($"parentid=(SELECT parentid FROM dbo.jiaofei_danwei WHERE id={id}) AND id<>{id} AND dbo.jiaofei_danwei.is_del=0") <= 0) { sql += $"UPDATE dbo.jiaofei_danwei SET isyezi=1 WHERE id=(SELECT parentid FROM dbo.jiaofei_danwei WHERE id={id}) "; }
int result = dbll.ExecuteNonQuery(System.Data.CommandType.Text, sql, null);
if (result > 0) { resultJson.msgCode = 0; resultJson.msg = "删除成功"; }
}
}
return resultJson;
});
点击查看, 缴费单位数据库设计+逻辑处理 |
|