页面引用layui.css和layui.js
${now } |
---|
js代码如下:
var tableIns;
var form;
var laydate;
var index;
var two;
layui
.use(
[ 'table', 'form', 'element', 'form', 'layer', 'laydate' ],
function() {
var table = layui.table;
var element = layui.element, layer = layui.layer;
laydate = layui.laydate;
form = layui.form;
tableIns = table
.render({
elem : '#dg',
url : $webURI
+ "/protal/sourceno/foundNowSource.action",
limit : 10,
where : {
centerid : centerid
},
cols : [ [ // 表头
{
field : 'sunday',
title : '日',
width : "14.29%",
event : 'setsunday',
style : 'height:100px;text-align:center;',
templet : function(row) {
if (row.sunday != null) {
var date = row.sunday.numDate
.substr(
8,
row.sunday.numDate.length);
if (row.sunday.isDisable == '1') {
return date
+ "休";
} else if (row.sunday.periodState == '2') {
return date
+ ""
+ row.sunday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
},
{
field : 'monday',
title : '一',
width : "14.29%",
event : 'setmonday',
style : 'height:100px;text-align:center;',
templet : function(row) {
if (row.monday != null) {
var date = row.monday.numDate
.substr(
8,
row.monday.numDate.length);
if (row.monday.isDisable == '1') {
return date
+ "休";
} else if (row.monday.periodState == '2') {
return date
+ ""
+ row.monday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
},
{
field : 'tuesday',
title : '二',
width : "14.29%",
event : 'settuesday',
style : 'height:100px;text-align:center;',
templet : function(row) {
if (row.tuesday != null) {
var date = row.tuesday.numDate
.substr(
8,
row.tuesday.numDate.length);
if (row.tuesday.isDisable == '1') {
return date
+ "休";
} else if (row.tuesday.periodState == '2') {
return date
+ ""
+ row.tuesday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
},
{
field : 'wednesday',
title : '三',
width : "14.29%",
event : 'setwednesday',
style : 'height:100px;text-align:center;',
templet : function(row) {
if (row.wednesday != null) {
var date = row.wednesday.numDate
.substr(
8,
row.wednesday.numDate.length);
if (row.wednesday.isDisable == '1') {
return date
+ "休";
} else if (row.wednesday.periodState == '2') {
return date
+ ""
+ row.wednesday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
},
{
field : 'thursday',
title : '四',
width : "14.29%",
event : 'setthursday',
style : 'height:100px;text-align:center;',
templet : function(row) {
if (row.thursday != null) {
var date = row.thursday.numDate
.substr(
8,
row.thursday.numDate.length);
if (row.thursday.isDisable == '1') {
return date
+ "休";
} else if (row.thursday.periodState == '2') {
return date
+ ""
+ row.thursday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
},
{
field : 'friday',
title : '五',
width : "14.29%",
event : 'setfriday',
style : 'height:100px;text-align:center;',
templet : function(row) {
if (row.friday != null) {
var date = row.friday.numDate
.substr(
8,
row.friday.numDate.length);
if (row.friday.isDisable == '1') {
return date
+ "休";
} else if (row.friday.periodState == '2') {
return date
+ ""
+ row.friday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
},
{
field : 'saturday',
title : '六',
width : "14.7%",
event : 'setsaturday',
style : 'height:100px;text-align:center;line-height:80px;',
templet : function(row) {
if (row.saturday != null) {
var date = row.saturday.numDate
.substr(
8,
row.saturday.numDate.length);
// console.log(row.saturday);
if (row.saturday.isDisable == '1') {
return date
+ "休";
} else if (row.saturday.periodState == '2') {
return date
+ ""
+ row.saturday.timeName
+ "";
} else {
return date;
}
} else {
return "";
}
}
} ] ],
done : function(res, curr, count) {
var now = $(".date").html();
var d = new Date(Date.parse(now));
var t = new Date();
var year = t.getFullYear();
var month = t.getMonth() + 1;
var mydate = (year.toString() + "-" + month
.toString());
var date = new Date(Date.parse(mydate));
if (d < date) {
return;
} else {
}
if (qx == 1 || sys == 0) {
if (res.data.length == 0) {
layer
.confirm(
'该中心当月还有没有生成号源,是否一键生成?',
{
title : "提示",
icon : 7,
btn : [ '确定',
'取消' ]
},
function() {
/*
* layer.msg("正在生成", {
* time : 50000,
* icon : 16 });
*/
form
.val(
"sourceno2",
{
"timeTypeId" : '',
"centerid" : centerid
})
two = layer
.open({
title : '时段类型', // 标题
type : 1,
area : [
'520px',
'400px' ],
shadeClose : false, // 点击遮罩关闭
content : $('.tongyong'),
skin : 'pop-class'
});
});
}
}
}
});
// 执行一个laydate实例
laydate.render({
elem : '#date' // 指定元素
});
$("th").css("text-align", "center");
$(".xz_tsbz").css("margin-top", "-10px");
$("table").addClass("xz_align_center");
// 标配单击监听
table.on('tool(Event)', function(obj) {
console.log(obj);
var data = obj.data;
//
if (qx == 1 || sys == 0) {
if (obj.event == 'setsaturday') {
var s = data.saturday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
if (obj.event == 'setfriday') {
var s = data.friday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
if (obj.event == 'setthursday') {
var s = data.thursday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
if (obj.event == 'setwednesday') {
var s = data.wednesday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
if (obj.event == 'settuesday') {
var s = data.tuesday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
if (obj.event == 'setmonday') {
var s = data.monday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
if (obj.event == 'setsunday') {
var s = data.sunday;
if (s.numDate == null || s.numDate == "") {
return;
}
var typeid;
if (s.periodState == "2") {
typeid = s.timeTypeId;
} else {
typeid = "";
}
form.val("sourceno", {
"id" : s.id,
"timeTypeId" : typeid,
"date" : s.numDate
})
}
index = layer.open({
title : '时段类型', // 标题
type : 1,
area : [ '520px', '400px' ],
shadeClose : false, // 点击遮罩关闭
content : $('.czmm-pop'),
skin : 'pop-class'
});
$("#timeTypeId").focus();
}
});
// 表单监听
form.on(("submit(submit)"), function(data) {
var param = {};
param = data.field;
param.centerid = centerid;
console.log(11111);
console.log(param);
// 单独修改特殊类型
$.ajax({
url : $webURI
+ "/protal/sourceno/updateTimeType.action",
type : 'post',
dataType : 'text',
data : param,
success : function(d) {
if (d > 0) {
layer.msg("成功!", {
time : 1000,
icon : 6
});
} else if (d == "") {
layer.msg("该类型没有设置时间段!请设置时间段再来操作!", {
time : 1000,
icon : 6
});
} else {
layer.msg("失败!", {
time : 1000,
icon : 5
});
}
layer.close(index);
tableIns.reload({});
$("table").addClass("xz_align_center");
}
});
return false;
});
// 表单监听
form.on(("submit(submit2)"), function(data) {
var param = {};
param = data.field;
console.log(param);
// 一键生成
$.ajax({
url : $webURI
+ "/protal/sourceno/insertOrUpdate.action",
type : 'post',
dataType : 'text',
data : param,
success : function(d) {
if (d > 0) {
layer.msg("成功", {
time : 1000,
icon : 6
});
layer.close(two);
tableIns.reload({});
$("table").addClass("xz_align_center");
} else if (d == -5) {
layer.msg("该时段类型下没有设置详细时段号源!请设置后再来一键生成!", {
time : 1000,
icon : 6
});
layer.close(two);
} else {
layer.msg("系统错误", {
time : 1000,
icon : 6
});
layer.close(two);
}
}
});
return false;
});
});
// 字符串转日期格式,strDate要转为日期格式的字符串
function getDate(strDate) {
var date = eval('new Date('
+ strDate.replace(/\d+(?=-[^-]+$)/, function(a) {
return parseInt(a, 10) - 1;
}).match(/\d+/g) + ')');
}
// 去除周末
function deleteWeek() {
var date = $(".date").html();
$.ajax({
url : $webURI + '/protal/sourceno/removeWeek.action',
type : 'post',
dataType : 'text',
data : {
strdate : date,
centerid : centerid
},
success : function(d) {
layer.msg(d, {
time : 1000
});
tableIns.reload({});
$("table").addClass("xz_align_center");
}
})
}
function deleteHoliday() {
var date = $(".date").html();
$.ajax({
url : $webURI + '/protal/sourceno/removeHoliday.action',
type : 'post',
dataType : 'text',
data : {
strdate : date,
centerid : centerid
},
success : function(d) {
layer.msg(d, {
time : 1000
});
tableIns.reload({});
$("table").addClass("xz_align_center");
}
})
}
function right() {
var now = $(".date").html();
var d = new Date(now.replace(/-/g, "/"));
d.setMonth(d.getMonth() + 1);
var str = d.getFullYear() + "-"
+ (d.getMonth() >= 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1));
$(".date").html(str);
$("#strdate").val(str);
tableIns.reload({
where : {
strdate : str,
centerid : centerid
}
});
$("table").addClass("xz_align_center");
}
function left() {
var now = $(".date").html();
var d = new Date(now.replace(/-/g, "/"));
d.setMonth(d.getMonth() - 1);
var str = d.getFullYear() + "-"
+ (d.getMonth() >= 9 ? d.getMonth() + 1 : "0" + (d.getMonth() + 1));
$(".date").html(str);
$("#strdate").val(str);
tableIns.reload({
where : {
strdate : str,
centerid : centerid
}
});
$("table").addClass("xz_align_center");
}
java 代码如下(生成号源的功能):
/**
* 概要说明 : 批量新增一键生成
* 详细说明 : 批量新增
*
* @param s
* @return String 类型返回值说明
* @see com.jinge.portal.controller.SourceNoController#insertOrUpdate()
* @author by liuhao @ 2018年7月26日, 上午8:59:02
* @throws ParseException
*/
@RequestMapping(value = "insertOrUpdate", produces = "text/plain;charset=utf-8")
@ResponseBody
public String insertOrUpdate(SourceNo s, HttpSession session) throws ParseException
{
Integer days = null;
Integer resulet = null;
String date = "";
LogSession ls = (LogSession) session.getAttribute(SysConstants.SYSLOGUSER);
SimpleDateFormat format = new SimpleDateFormat("EEEE");
Calendar c = Calendar.getInstance();
if (s.getStrdate() == null || s.getStrdate() == "")
{
date = DateUtils.backYearMonth();
days = DateUtils.getDaysOfMonth(date);
}
else
{
date = s.getStrdate();
days = DateUtils.getDaysOfMonth(date);
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM");
c.setTime(f.parse(date));
}
String week = "";
MakeTime m = new MakeTime();
m.setTimeTypeId(s.getTimeTypeId());
m.setCenterid(s.getCenterid());
Integer aMount = makeTimeService.number(m);
if (aMount == null)
{
return "-5";
}
List times = makeTimeService.simplefound(m);
List sourceNos = new ArrayList();
for (int i = 1; i <= days; i++)
{
c.set(Calendar.DATE, i);
week = format.format(c.getTime());
String strdate = DateUtils.getStrDate(c.getTime());
SourceNo sno = new SourceNo();
sno.setFoundDate(DateUtils.backDate(strdate));
sno.setNumweek(week);
sno.setaMount(aMount);
sno.setUnMount(aMount);
sno.setCreater(ls.getUserId());
sno.setTimeTypeId(s.getTimeTypeId());
sno.setCenterid(s.getCenterid());
sno.setStrdate(date);
if (week.equals("星期日") || week.equals("星期六"))
{
sno.setHoliday(1);
}
else
{
sno.setHoliday(0);
}
sourceNos.add(sno);
}
resulet = sourceNoService.insertlist(sourceNos);
if (resulet > 0)
{
SourceNo sno = new SourceNo();
sno.setStrdate(date);
sno.setCenterid(s.getCenterid());
List sns = sourceNoService.simplefound(sno);
List nos = new ArrayList();
for (SourceNo so : sns)
{
for (MakeTime mt : times)
{
SourceTimeNo stn = new SourceTimeNo();
stn.setStartHourTime(mt.getStartHourTime());
stn.setEndHourTime(mt.getEndHourTime());
stn.setCreater(ls.getUserId());
stn.setCenterid(mt.getCenterid());
stn.setNumber(mt.getNumber());
stn.setLeftCan(mt.getNumber());
stn.setTimeTypeName(mt.getTimename());
stn.setSeasonalName(mt.getSeasname());
stn.setSourceNoId(so.getId() + "");
nos.add(stn);
}
}
resulet = noService.inserts(nos);
}
return resulet + "";
}
/**
* 概要说明 : 查看当月号源
* 详细说明 : 查看当月号源
*
* @return String 类型返回值说明
* @see com.jinge.portal.controller.SourceNoController#foundNowSource()
* @author by liuhao @ 2018年7月25日, 下午5:49:21
* @throws ParseException
*/
@RequestMapping("foundNowSource")
@ResponseBody
public String foundNowSource(SourceNo s, LayuiPage p) throws ParseException
{
JSONObject obj = new JSONObject();
Integer count = 5;
List weeks = new ArrayList();
if (s.getStrdate() == null || s.getStrdate().equals(""))
{
String now = DateUtils.backYearMonth();
// Integer days = DateUtils.getDaysOfMonth(now);
s.setStrdate(now);
}
List list = new ArrayList();
List sourceNos = sourceNoService.simplefound(s);
// System.out.println(JSONArray.toJSON(sourceNos));
if (sourceNos != null && sourceNos.size() > 0)
{
String wk[] = Globalvariable.WEEKS;
Integer num = 0;
num = DateUtils.backNumtoWeek(sourceNos.get(0).getNumweek());
for (int i = 0; i < num; i++)
{
SourceNo no = new SourceNo();
no.setNumweek(wk[i]);
list.add(no);
}
list.addAll(sourceNos);
for (SourceNo sn : list)
{
if (sn.getNumDate() != null && (sn.getNumDate().substring(sn.getNumDate().lastIndexOf("-") + 1, sn.getNumDate().length()).equals("01")))
{
if (sourceNos.size() == 31 && (sn.getNumweek().equals("星期五") || sn.getNumweek().equals("星期六")))
{
count = 6;
}
if (sourceNos.size() == 30 && sn.getNumweek().equals("星期六"))
{
count = 6;
}
}
}
for (int i = 0; i < count; i++)
{
Week week = new Week();
Iterator it = list.iterator();
while (it.hasNext())
{
SourceNo sn = it.next();
if (sn.getNumweek().equals("星期六"))
{
week.setSaturday(sn);
it.remove();
break;
}
if (sn.getNumweek().equals("星期日"))
{
week.setSunday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期一"))
{
week.setMonday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期二"))
{
week.setTuesday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期三"))
{
week.setWednesday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期四"))
{
week.setThursday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期五"))
{
week.setFriday(sn);
it.remove();
}
}
weeks.add(week);
}
}
obj.put("code", 0);
obj.put("msg", "");
obj.put("data", weeks);
obj.put("count", count);
return obj.toString();
}
/**
* 概要说明 : 去除周末
* 详细说明 : 去除周末
*
* @param session session
* @return String 类型返回值说明
* @see com.jinge.portal.controller.SourceNoController#removeWeek()
* @author by liuhao @ 2018年7月30日, 上午9:25:34
*/
@RequestMapping(value = "removeWeek", produces = "text/plain;charset=utf-8")
@ResponseBody
public String removeWeek(HttpSession session, SourceNo s)
{
LogSession ls = (LogSession) session.getAttribute(SysConstants.SYSLOGUSER);
s.setUpdater(ls.getUserId());
Integer result = sourceNoService.disableWeek(s);
return SimpleUitl.backMsg(result);
}
/**
* 概要说明 : 去除法定节假日
* 详细说明 : 去除法定节假日
*
* @param session session
* @param s 实体
* @return String 类型返回值说明
* @see com.jinge.portal.controller.SourceNoController#removeHoliday()
* @author by liuhao @ 2018年7月30日, 上午11:01:20
*/
@RequestMapping(value = "removeHoliday", produces = "text/plain;charset=utf-8")
@ResponseBody
public String removeHoliday(HttpSession session, SourceNo s)
{
LogSession ls = (LogSession) session.getAttribute(SysConstants.SYSLOGUSER);
s.setUpdater(ls.getUserId());
Hodday h = new Hodday();
String[] ids = null;
h.setYearMon(s.getStrdate());
List list = new ArrayList();
List hoddays = hoddayService.simpleFound(h);
if (hoddays.size() == 1 && hoddays.get(0) != null && hoddays.get(0).getDays() != null && !hoddays.get(0).getDays().equals(""))
{
String str = hoddays.get(0).getDays();
ids = str.split(",");
}
else
{
return "该月没有设置节假日!请先设置再来操作!";
}
for (String id : ids)
{
list.add(s.getStrdate() + "-" + id);
}
Integer c = sourceNoService.disableHoliday(list, s);
return SimpleUitl.backMsg(c);
}
/**
* 概要说明 : 修改为特殊类型
* 详细说明 : 修改为特殊类型
*
* @param session session
* @param s 实体
* @return String 类型返回值说明
* @see com.jinge.portal.controller.SourceNoController#updateTimeType()
* @author by liuhao @ 2018年7月27日, 上午10:29:17
* @throws ParseException
*/
@RequestMapping(value = "updateTimeType", produces = "text/plain;charset=utf-8")
@ResponseBody
public String updateTimeType(HttpSession session, SourceNo s, String date) throws ParseException
{
@SuppressWarnings("unused")
Integer result;
Integer id = s.getId();
LogSession ls = (LogSession) session.getAttribute(SysConstants.SYSLOGUSER);
s.setFoundDate(DateUtils.backDate(date));
// 查询该类型的时间段
MakeTime m = new MakeTime();
m.setTimeTypeId(s.getTimeTypeId());
Integer count = makeTimeService.number(m);// 得到一天总数量
if (count == null)
{
return "";
}
s.setaMount(count);
s.setUnMount(count);
s.setUpdater(ls.getUserId());
// 修改号源表数据
result = sourceNoService.update(s);
List times = makeTimeService.simplefound(m);
// 删除当日类型的时间段,从新增加特殊类型的时间段
SourceTimeNo timeNo = new SourceTimeNo();
timeNo.setSourceNoId(id + "");
result = noService.deletes(timeNo);// 删除当天的所有时间段
// 批量新增时间段号源
List timeNos = new ArrayList();
for (MakeTime mt : times)
{
SourceTimeNo stn = new SourceTimeNo();
stn.setStartHourTime(mt.getStartHourTime());
stn.setEndHourTime(mt.getEndHourTime());
stn.setCreater(ls.getCenterId());
stn.setCenterid(mt.getCenterid());
stn.setNumber(mt.getNumber());
stn.setLeftCan(mt.getNumber());
stn.setTimeTypeName(mt.getTimename());
stn.setSeasonalName(mt.getSeasname());
stn.setSourceNoId(id + "");
timeNos.add(stn);
}
Integer num = noService.inserts(timeNos);
return num + "";
}
/**
* 概要说明 : 查看当月号源
* 详细说明 : 查看当月号源
*
* @return String 类型返回值说明
* @see com.jinge.portal.controller.SourceNoController#foundNowSource()
* @author by liuhao @ 2018年7月25日, 下午5:49:21
* @throws ParseException
*/
@RequestMapping("foundNowSource")
@ResponseBody
public String foundNowSource(SourceNo s, LayuiPage p) throws ParseException
{
JSONObject obj = new JSONObject();
Integer count = 5;
List weeks = new ArrayList();
if (s.getStrdate() == null || s.getStrdate().equals(""))
{
String now = DateUtils.backYearMonth();
// Integer days = DateUtils.getDaysOfMonth(now);
s.setStrdate(now);
}
List list = new ArrayList();
List sourceNos = sourceNoService.simplefound(s);
// System.out.println(JSONArray.toJSON(sourceNos));
if (sourceNos != null && sourceNos.size() > 0)
{
String wk[] = Globalvariable.WEEKS;
Integer num = 0;
num = DateUtils.backNumtoWeek(sourceNos.get(0).getNumweek());
for (int i = 0; i < num; i++)
{
SourceNo no = new SourceNo();
no.setNumweek(wk[i]);
list.add(no);
}
list.addAll(sourceNos);
for (SourceNo sn : list)
{
if (sn.getNumDate() != null && (sn.getNumDate().substring(sn.getNumDate().lastIndexOf("-") + 1, sn.getNumDate().length()).equals("01")))
{
if (sourceNos.size() == 31 && (sn.getNumweek().equals("星期五") || sn.getNumweek().equals("星期六")))
{
count = 6;
}
if (sourceNos.size() == 30 && sn.getNumweek().equals("星期六"))
{
count = 6;
}
}
}
for (int i = 0; i < count; i++)
{
Week week = new Week();
Iterator it = list.iterator();
while (it.hasNext())
{
SourceNo sn = it.next();
if (sn.getNumweek().equals("星期六"))
{
week.setSaturday(sn);
it.remove();
break;
}
if (sn.getNumweek().equals("星期日"))
{
week.setSunday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期一"))
{
week.setMonday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期二"))
{
week.setTuesday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期三"))
{
week.setWednesday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期四"))
{
week.setThursday(sn);
it.remove();
}
if (sn.getNumweek().equals("星期五"))
{
week.setFriday(sn);
it.remove();
}
}
weeks.add(week);
}
}
obj.put("code", 0);
obj.put("msg", "");
obj.put("data", weeks);
obj.put("count", count);
return obj.toString();
}