Authored by mlge

种草-新增话题页面

... ... @@ -41,10 +41,17 @@ public class GrassTopicController {
return new ApiResponse.ApiResponseBuilder().build();
}
@RequestMapping("/getAllTopic")
@RequestMapping("/grassTopicById")
@ResponseBody
public ApiResponse grassTopicById(GrassTopicReq req){
TopicRespBo resp = topicService.grassTopicById(req);
return new ApiResponse.ApiResponseBuilder().data(resp).build();
}
/*@RequestMapping("/getAllTopic")
@ResponseBody
public ApiResponse getAllTopic(){
List<TopicRespBo> result = topicService.getAllTopic();
return new ApiResponse.ApiResponseBuilder().data(result).build();
}
}*/
}
... ...
... ... @@ -18,4 +18,6 @@ public interface ITopicService {
List<TopicRespBo> getAllTopic();
void addUpGrassTopic(GrassTopicReq req);
TopicRespBo grassTopicById(GrassTopicReq req);
}
... ...
... ... @@ -88,9 +88,22 @@ public class TopicServiceImpl implements ITopicService {
record.setTopicName(req.getTopicName());
record.setTopicDesc(req.getTopicDesc());
record.setStatus(req.getStatus());
String relatedLabels = req.getRelatedLabels();
if(StringUtils.isNotEmpty(relatedLabels) && StringUtils.endsWith(relatedLabels,",")){
relatedLabels = StringUtils.substring(relatedLabels, 0,relatedLabels.length() -1);
String relatedLabels = "";
//一定要关联标签(前台)
//每个标签id都不能为空,标签id 不能重复(前台没有做判断)
if(StringUtils.isNotEmpty(req.getRelatedLabels()) && StringUtils.endsWith(req.getRelatedLabels(),",")){
String[] str = StringUtils.split(req.getRelatedLabels(),",");
Set<String> labelSet = new HashSet<>();
for(String s : str){
if(StringUtils.isNotEmpty(s)){//前台可能传递重复的或者空值
labelSet.add(s);
}
}
for(String labelId : labelSet){
relatedLabels += labelId + ",";
}
// relatedLabels = StringUtils.substring(relatedLabels, 0,relatedLabels.length() -1);
}
record.setRelatedLabels(relatedLabels);
record.setTopicImageUrl(req.getTopicImageUrl());
... ... @@ -108,6 +121,51 @@ public class TopicServiceImpl implements ITopicService {
}
}
/**
* 获取话题的详细信息
* @param req
* @return
*/
@Override
public TopicRespBo grassTopicById(GrassTopicReq req) {
logger.info("enter grassTopicById req={}", req);
if(req == null || req.getId() == null){
return null;
}
Integer topicId = req.getId();
GrassTopic grassTopic = grassTopicDAO.selectByPrimaryKey(topicId);
if(grassTopic == null){//没找到
logger.warn("grassTopicById topic not exists topicId={} ", topicId);
return null;
}
//返回结果
TopicRespBo bo = new TopicRespBo();
BeanUtils.copyProperties(grassTopic,bo);
bo.setCreateTimeStr(grassTopic.getCreateTime() == null ? "" : DateUtil.int2DateStr(grassTopic.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
//关联的标签
String relatedLabels = grassTopic.getRelatedLabels();
if(StringUtils.isNotEmpty(relatedLabels)){
List<String> list = Arrays.asList(StringUtils.split(relatedLabels,","));
Set<Integer> labelSet = list.stream().filter(o -> StringUtils.isNotBlank(o)).map(org.apache.commons.lang3.math.NumberUtils::toInt).collect(Collectors.toSet());
if(CollectionUtils.isNotEmpty(labelSet)){
//查询label名称
List<GrassLabel> labelList = grassLabelDAO.selectBatchByIds(labelSet);
List<TopicRespBo.LabelInfo> labelInfoList = new ArrayList<>();
for(GrassLabel grassLabel : labelList){
TopicRespBo.LabelInfo labelInfo = new TopicRespBo.LabelInfo(grassLabel.getId(), grassLabel.getLabelName());
labelInfoList.add(labelInfo);
}
bo.setLabelInfoList(labelInfoList);
}
}
return bo;
}
//转换
private List<TopicRespBo> convertTopicRespBo(List<GrassTopic> sourceList) {
if(CollectionUtils.isEmpty(sourceList)){
... ... @@ -121,6 +179,7 @@ public class TopicServiceImpl implements ITopicService {
bo.setCreateTimeStr(grassTopic.getCreateTime() == null ? "" : DateUtil.int2DateStr(grassTopic.getCreateTime(),"yyyy-MM-dd HH:mm:ss"));
String relatedLabels = grassTopic.getRelatedLabels();
//关联的标签id
if(StringUtils.isNotEmpty(relatedLabels)){
List<String> list = Arrays.asList(StringUtils.split(relatedLabels,","));
List<Integer> labelIdList = list.stream().filter(o -> StringUtils.isNotBlank(o)).map(org.apache.commons.lang3.math.NumberUtils::toInt).collect(Collectors.toList());
... ... @@ -129,7 +188,7 @@ public class TopicServiceImpl implements ITopicService {
}
result.add(bo);
}
//从标签表中查询数据
if(CollectionUtils.isNotEmpty(labelIdSet)){
//查询label名称
List<GrassLabel> labelList = grassLabelDAO.selectBatchByIds(labelIdSet);
... ...
<!DOCTYPE html>
<head>
<style>
span .tag {
display: block;
float: left;
padding: 2px 5px;
background: #1caf9a;
margin-right: 5px;
margin-bottom: 5px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
font-size: 13px;
}
</style>
</head>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="activityAddForm" id="activityAddForm" method="post" enctype="multipart/form-data">
<form name="topicForm" id="topicForm" method="post">
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td >
<span style="color:red">*</span><label>话题名称</label> <br>
<td>
<span style="color:red">*</span><label>话题名称</label> <br>
<input id="topicName" name="topicName" class="easyui-textbox" style="width: 380px;"/>
</td>
</tr>
<tr style="height: 60px">
<td >
<span style="color:red">*</span><label>话题描述</label> <br>
<textarea id="topicDesc" name="topicDesc" style="width: 380px;" rows="6" ></textarea>
<td>
<span style="color:red">*</span><label>话题描述</label> <br>
<textarea id="topicDesc" name="topicDesc" style="width: 380px;" rows="6" placeholder=""
required="true" maxlength="500"></textarea>
</td>
</tr>
<tr style="height: 60px">
<td>
<span style="color:red">*</span><label>图片</label> <br>
<span style="color:red">*</span><label>图片</label> <br>
<div id="imageUpload">
</div>
<!-- <span style=" margin-left: 10px; color: red"> 图片宽高(186x170)</span>-->
<!-- <span style=" margin-left: 10px; color: red"> 图片宽高(186x170)</span>-->
</td>
</tr>
<tr style="height: 60px">
<tr style="height: 80px">
<td >
<span style="color:red">*</span><label>关联内容标签</label> <br>
<a id="searchLabelBtn" class="btn-info">查询</a>
<td>
<span style="color:red">*</span><label>关联标签</label> <br>
<div id="relatedLabelsDiv">
<div id="taglist" class="tagwrap">
<!--<span class="tag"><span>32132</span><a href="#" title="Removing tag" data-index="0" class="removetag">x</a></span>
<span class="tag"><span>淋淋惹</span><a href="#" title="Removing tag" data-index="1" class="removetag" >x</a></span>-->
<span>已选择:</span><br>
<div id="labelListDiv" style="margin-bottom: 10px; height:40px ">
</div>
</div>
<input id="labelId" name="labelId" class="easyui-combobox" style="width:380px "/>
<!--<a id="searchLabelBtn" class="btn-info">+选择标签</a>-->
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
$(function () {
var topicId = getUrlParam("topicId");
$(function () {
$("#topicName").textbox({
required: true,
missingMessage: "话题名称不能为空",
... ... @@ -99,7 +89,7 @@
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误",data.message);
$.messager.alert("错误", data.message);
return "";
}
return data.data.url;
... ... @@ -116,89 +106,296 @@
}
});
$("#labelId").combobox({
prompt: "请选择标签",
required: false,
selectOnNavigation: true,
valueField: 'id',
textField: 'labelName',
multiple: true,
url: serverContextPath + "/grassLabelManage/getAllGrassLabelInfo",
onSelect: function (newVal, oldVal) {//选中事件
debugger
labelChange(newVal, oldVal);
// //被选中的值
// var selectedValue = data;
// //被选中的文本
// var allData = $(this).combobox('getData');
// console.log("aa" + aa);
var data = paramObject.mkData;
},
loadFilter: function (data) {
return defaultLoadFilter(data);
}
});
if (data){
var data = paramObject.mkData;
if (data) {//编辑窗口
$("#topicName").textbox("setValue", data.topicName);
$("#topicDesc").html(data.topicDesc);
//图片
$("#imageUpload").imageUpload('setValue', data.topicImageUrl);
// //已经选择的标签
debugger
$("#topicDesc").val(data.topicDesc);
$("#imageUpload").imageUpload("setValue", data.topicImageUrl);
//展示已经关联的标签
var labelInfoList = data.labelInfoList;
for(var i=0; i< labelInfoList.length; i++){
var choosedTagSpan = '<span style="margin-left: 10px" class="tag" name="choosedTag" data-labelId="'+labelInfoList[i].labelId+'"><span style="background-color: #1caf9a;color: white">'+labelInfoList[i].labelName+'</span><a href="#" style="background-color: #1caf9a" title="Removing tag" data-index="0" class="removetag">x</a></span>' ;
$("#taglist").append(choosedTagSpan);
if (labelInfoList != null) {
for (var i = 0; i < labelInfoList.length; i++) {
var tempId = labelInfoList[i].labelId;
var tempName = labelInfoList[i].labelName;
var choosedTagSpan = '<span class="tag" role="choose" style="margin-left: 10px;font-size: 14px" name="choosedTag" data-labelId="' + tempId + '" data-labelName="' + tempName + '"><span style="background-color: #1caf9a;color: white;font-size: 14px">' + tempName + '</span><a href="#" style="background-color: #1caf9a;font-size: 14px" title="Removing tag" data-index="0" class="removetag">x</a></span>';
$("#labelListDiv").append(choosedTagSpan);
}
}
}
$(document).on('click', '.removetag', function() {
/* //查询标签列表
$("#searchLabelBtn").linkbutton({
iconCls: "icon-search",
onClick: function () {
chooseLabels();
}
});*/
// //新建--修改话题--提交
// $("#subBotton").linkbutton({
// iconCls: "icon-save",
// width: 100,
// onClick: function () {
// $("#topicForm").form("submit", {
// url: serverContextPath + "/grassTopicManage/addUpGrassTopic",
// onSubmit: function (param) {
// debugger;
// //1)表单基本检查
// if (!$("#topicForm").form("validate")) {
// return false;
// }
//
// //2)是否上传了图片
// var imageCount = 0;
// $("input[name='topicImageUrl']").each(function (j, item) {
// var url = item.value;
// if (url != '') {
// imageCount++;
// }
// });
// if (imageCount == 0) {
// $.messager.alert("保存失败", "至少要选择一张图片", "error");
// return false;
//
// }
// //3)是否选择了标签
// var relatedLabels = "";
// var tagCount = 0;
// $("#taglist").find("span[role='choose']").each(function (item, index) {
// debugger
// var tempId = $(this).attr('data-labelid');
// if (tempId != null) {
// tagCount++;
// relatedLabels += tempId + ",";
// }
// });
//
// if (tagCount == 0 || tagCount > 5) {
// $.messager.alert("保存失败", "至少选择一个标签,最多5个", "error");
// return false;
// }
//
// param.relatedLabels = relatedLabels;
// param.id = topicId;
// return true;
//
//
// },
// success: function (data) {
// if (data) {
// data = $.parseJSON(data);
// if (data.code == 200) {
// $.messager.alert("提示", "保存成功", "info", function () {
// window.location.reload()
// });
// // alert("保存成功");
//
//
// } else {
// $.messager.alert("保存失败", data.message, "error");
// }
// } else {
// $.messager.alert("保存失败", data.message, "error");
// }
// }
// });
//
// }
// });
// //编辑话题
// if (topicId != "null") {//去加载数据
// var title = "修改话题";
// $("#titleSpan").html(title);
// //加载数据
// $.ajax({
// type: "get",
// url: serverContextPath + "/grassTopicManage/grassTopicById?id=" + topicId,
// success: function (data) {
// debugger
// if (data != null && data.code == 200) {//成功的
// var detailInfo = data.data;
// $("#topicName").textbox("setValue", detailInfo.topicName);
// $("#topicDesc").html(detailInfo.topicDesc);
// //图片
// $("#imageUpload").imageUpload('setValue', detailInfo.topicImageUrl);
//
// //已经选择的标签
// var labelInfoList = detailInfo.labelInfoList;
// if(labelInfoList!=null){
// for (var i = 0; i < labelInfoList.length; i++) {
// var tempId = labelInfoList[i].labelId;
// var tempName = labelInfoList[i].labelName;
// var choosedTagSpan = '<span class="tag" role="choose" style="margin-left: 10px" name="choosedTag" data-labelId="' + tempId + '" data-labelName="' + tempName + '"><span style="background-color: #1caf9a;color: white">' + tempName + '</span><a href="#" style="background-color: #1caf9a" title="Removing tag" data-index="0" class="removetag">x</a></span>';
// $("#taglist").append(choosedTagSpan);
//
// }
// }
//
//
//
// }
// }
// });
//
//
// }
$(document).on('click', '.removetag', function () {
// $(this).remove();
$(this).closest(".tag").remove();
});
//查询标签列表
$("#searchLabelBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
chooseLabels();
}
});
});
//选择标签列表
function chooseLabels(){
var chooseLabelList = $("<div id='chooseLabelList'>").appendTo($(document.body));
var title = "选择标签";
$("#chooseLabelList").myDialog({
title: title,
width: "60%",
height: "70%",
resizable:false,
buttons:[{
id : "saveChooseLabelBtn",
text: "保存",
iconCls : "icon-save",
handler:function(){
//确定保存之前,要把之前已经选择的标签清空
$("#taglist").html("");
//做相应的处理 回填信息--所有被选择的复选框
debugger
$("input[type='checkbox'][class='tagCheckbox']:checked").each(function () {
var labelId = $(this).attr("data-labelId");
var labelName = $(this).attr("data-labelName");
var choosedTagSpan = '<span class="tag" style="margin-left: 10px" name="choosedTag" data-labelId="'+labelId+'"><span style="background-color: #1caf9a;color: white">'+labelName+'</span><a href="#" style="background-color: #1caf9a" title="Removing tag" data-index="0" class="removetag">x</a></span>' ;
$("#taglist").append(choosedTagSpan);
});
// //选择标签列表
// function chooseLabels() {
// var chooseLabelList = $("<div id='chooseLabelList'>").appendTo($(document.body));
// var chooseLabelList = $("<div id='chooseLabelList'>").appendTo($(document.body));
// var title = "选择标签";
// $("#chooseLabelList").myDialog({
// title: title,
// width: "60%",
// height: "70%",
// resizable: false,
// buttons: [{
// id: "saveChooseLabelBtn",
// text: "保存",
// iconCls: "icon-save",
// handler: function () {
// //确定保存之前,要把之前已经选择的标签清空
//
// $("#taglist").html("");
// //做相应的处理 回填信息--所有被选择的复选框
// var tempHtml = $("#choosedDiv").html();
// debugger
// $("#taglist").html(tempHtml);
// /* $("#taglist").find("span[role='choose']").each(function (item, index) {
// $(item).val(picTextData[index][$(item).attr('data-')]);
// });*/
//
//
// $(chooseLabelList).dialog("close");
//// $.messager.show({
//// title: "提示",
//// msg: title + "成功!",
//// height: 120
//// });
// }
// }, {
// id: "closeChooseBtn",
// text: "关闭",
// iconCls: "icon-cancel",
// handler: function () {
// $.messager.confirm("确认", "确认关闭吗?", function (flag) {
// if (flag) {
// $(chooseLabelList).dialog("close");
// }
// });
// }
// }],
// modal: true,
// href: contextPath + "/html/grass/labelManage/chooseLabels.html",
// });
//
// }
//获取url中的参数方法
function getUrlParam(name) {
//构造一个含有目标参数的正则表达式对象
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
//匹配目标参数
var r = window.location.search.substr(1).match(reg);
//返回参数
if (r != null) {
return unescape(r[2]);
} else {
return null;
}
}
function labelChange(newVal, oldVal) {
//newVal---是指新增加的值
if (newVal == null) {
return;
}
//新增加的数据
var selectedValue = newVal;
var tempId = selectedValue.id;
var tempName = selectedValue.labelName;
var divStr = '<span class="tag" role="choose" style="margin-left: 10px;font-size: 14px" name="choosedTag" data-labelId="' + tempId + '" data-labelName="' + tempName + '"><span style="background-color: #1caf9a;color: white;font-size: 14px">' + tempName + '</span><a href="#" style="background-color: #1caf9a;font-size: 14px" title="Removing tag" data-index="0" class="removetag">x</a></span>';
//新增加的数据
$("#labelListDiv").append(divStr);
// //新增加的数据
// var selectedValue = newVal;
//
// //被选中的文本
// var allData = $("#labelId").combobox('getData');
// //
// var divStr = "";
// for(var i = 0; i< selectedValue.length; i++){
//
//
// var tempId = selectedValue[i];
// if(tempId == null){//搜索的时候 有可能把搜索项给写进去了
// continue;
// }
// //找出对应的文本
// var tempName="";
//
// for(var j = 0; j< allData.length; j++){
// if(selectedValue[i] == allData[j].id){
// tempName = allData[j].labelName;
// break;//跳出循环
// }
// }
// //把文本写到已选择的里面去
// divStr += '<span class="tag" role="choose" style="margin-left: 10px;font-size: 14px" name="choosedTag" data-labelId="' + tempId + '" data-labelName="' + tempName + '"><span style="background-color: #1caf9a;color: white;font-size: 14px">' + tempName + '</span><a href="#" style="background-color: #1caf9a;font-size: 14px" title="Removing tag" data-index="0" class="removetag">x</a></span>';
// }
//
//
// $("#labelListDiv").html(divStr);
}
$(chooseLabelList).dialog("close");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
}
}, {
id:"closeChooseBtn",
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(chooseLabelList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/labelManage/chooseLabels.html",
});
}
</script>
</html>
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta charset="UTF-8"/>
<title>Yoho!Buy运营平台</title>
<script src="/pfcms/js/include.js"></script>
<script src="/pfcms/js/ajaxfileupload.js"></script>
... ... @@ -17,14 +17,15 @@
cursor: pointer;
text-align: center;
}
.btn-long:hover {
opacity: 0.9;
}
</style>
</head>
<body class="easyui-layout" >
<div region="north" style="height: 200px;">
<body class="easyui-layout">
<div region="north" style="height: 200px;">
<script>
document.write(addHead('运营管理', '话题管理'));
</script>
... ... @@ -32,15 +33,15 @@
<div style="margin-left: 20px;margin-top: 10px">
<input class="easyui-textbox" id="topicNameParam" style="width: 140px">
</input>
<input class="easyui-combobox" id="statusParam" >
<input class="easyui-combobox" id="statusParam">
</input>
<input id="startTimeStr" name="startTimeStr" class="easyui-datetimebox" data-options="prompt:'开始时间'"/>
~ &nbsp;
~ &nbsp;
<input id="endTimeStr" name="endTimeStr" class="easyui-datetimebox" data-options="prompt:'结束时间'"/>
</input>
... ... @@ -64,45 +65,45 @@
<script>
$(function() {
$(function () {
//用于页面刷新后的数据行定位
var index ="";
var index = "";
$("#allBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
iconCls: "icon-search",
onClick: function () {
$("#labelListTable").datagrid("load", {});
}
});
$("#topicNameParam").textbox({
required:false,
required: false,
prompt: "请输入话题名称"
});
$("#statusParam").combobox({
valueField : "value",
textField : "text",
required:false,
valueField: "value",
textField: "text",
required: false,
prompt: "请选择状态",
data:[{text:"请选择状态",value:""},{text:"进行中",value:"1"},{text:"已下架",value:"0"}]
data: [{text: "请选择状态", value: ""}, {text: "进行中", value: "1"}, {text: "已下架", value: "0"}]
});
$("#searchBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
var startTime="";
var endTime="";
if ($("#startTimeStr").datetimebox('getValue')!='') {
iconCls: "icon-search",
onClick: function () {
var startTime = "";
var endTime = "";
if ($("#startTimeStr").datetimebox('getValue') != '') {
startTime = parseInt(new Date($("#startTimeStr").datetimebox('getValue')).getTime() / 1000);
}
if ($("#endTimeStr").datetimebox('getValue')!='') {
if ($("#endTimeStr").datetimebox('getValue') != '') {
endTime = parseInt(new Date($("#endTimeStr").datetimebox('getValue')).getTime() / 1000);
}
$("#labelListTable").datagrid("load", {
topicName: $("#topicNameParam").textbox("getValue"),
status: $("#statusParam").combobox("getValue"),
startTime:startTime,
endTime:endTime
startTime: startTime,
endTime: endTime
});
}
});
... ... @@ -119,10 +120,10 @@
fitColumns: true,
striped: true,
/*queryParams: {
rewardName: $("#rewardName1").textbox("getValue"),
status: $("#rewardstatus1").combobox("getValue"),
type: $("#rewardtype1").combobox("getValue")
},*/
rewardName: $("#rewardName1").textbox("getValue"),
status: $("#rewardstatus1").combobox("getValue"),
type: $("#rewardtype1").combobox("getValue")
},*/
url: serverContextPath + "/grassTopicManage/getGrassTopicList",
method: 'POST',
loadFilter: function (data) {
... ... @@ -155,7 +156,7 @@
width: 25,
align: "left",
formatter: function (value, rowData, rowIndex) {
return '<a target="_blank" href="'+value+'"><img src="' + value + '" style="width: 120px;height: 120px;" /></a>';
return '<a target="_blank" href="' + value + '"><img src="' + value + '" style="width: 120px;height: 120px;" /></a>';
}
},
{
... ... @@ -164,34 +165,33 @@
width: 25,
align: "left",
formatter: function (value, rowData, rowIndex) {
var str ="";
for (var i=0;i< value.length;i++)
{
str += value[i].labelName + "&nbsp;&nbsp;";
var str = "";
for (var i = 0; i < value.length; i++) {
str += value[i].labelName + "&nbsp;&nbsp;";
}
return str;
}
},{
}, {
title: "创建时间",
field: "createTimeStr",
width: 25,
align: "left"
},{
}, {
title: "参与人数",
field: "attAmount",
width: 25,
align: "left"
},{
}, {
title: "状态",
field: "status",
width: 25,
align: "left",
formatter: function (value, rowData, rowIndex) {
if(value == 1){
return "进行中";
}else{
return "已下架";
}
if (value == 1) {
return "进行中";
} else {
return "已下架";
}
}
},
... ... @@ -201,10 +201,11 @@
width: 40,
align: "center",
formatter: function (value, rowData, rowIndex) {
var str = "<a role='edit' dataId='"+ rowData.id +"' style='margin-left:10px;background-color: #31b0d5' index='"+ rowIndex +"'>编辑</a>";
var changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='0' dataId='"+ rowData.id +"' index='"+ rowIndex +"'>下架</a>";;
if(rowData.status == 0){
changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='1' dataId='"+ rowData.id +"' index='"+ rowIndex +"'>上架</a>";
var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #31b0d5' index='" + rowIndex + "'>编辑</a>";
var changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='0' dataId='" + rowData.id + "' index='" + rowIndex + "'>下架</a>";
;
if (rowData.status == 0) {
changeStatus = "<a role='changeStatus' style='margin-left:10px;background-color: #ffa951' changedStatus='1' dataId='" + rowData.id + "' index='" + rowIndex + "'>上架</a>";
}
return str + changeStatus;
}
... ... @@ -219,8 +220,8 @@
singleSelect: true,
onLoadSuccess: function (data) {
if(index != ""){
$(this).datagrid("scrollTo",index);
if (index != "") {
$(this).datagrid("scrollTo", index);
index = "";
}
// $(this).datagrid("getPanel").find("a[role='close']").linkbutton({
... ... @@ -252,9 +253,9 @@
// 编辑
$(this).datagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls : "icon-edit",
onClick : function() {
iconCls: "icon-edit",
onClick: function () {
index = $(this).attr("index");
var row = $("#labelListTable").datagrid('getData').rows[index];
getEditDialog(row);
... ... @@ -263,8 +264,8 @@
// 上架下架
$(this).datagrid("getPanel").find("a[role='changeStatus']").linkbutton({
iconCls : "icon-edit",
onClick : function() {
iconCls: "icon-edit",
onClick: function () {
var index = $(this).attr("index");
var row = $("#labelListTable").datagrid('getData').rows[index];
row.status = $(this).attr("changedStatus");
... ... @@ -277,60 +278,200 @@
// 编辑分组
function getEditDialog(data){
function getEditDialog(data) {
/*var labelList = $("<div id='labelList'>").appendTo($(document.body));
var title = data == null ? "新建话题":"修改话题";
var textVar = data == null ? "保存":"保存";
var msgVar = data == null ? "确认新增话题吗?":"确认保存话题吗?";*/
var topicId = data == null ? null : data.id;
//新建话题--打开一个新窗口
window.open(contextPath + "/html/grass/topicManage/topicEdit.html?topicId=" + topicId, "_blank");
/*window.self.paramObject.mkData = data;
$(labelList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
$("#activityAddForm").form("submit", {
url: serverContextPath + "/grassTopicManage/addUpGrassTopic",
onSubmit: function (param) {
if(data != null){
param.id = data.id;
}
if (!$("#activityAddForm").form("validate")) {
return false;
}
var topicDesc = $("#topicDesc").val();
if(topicDesc==null || topicDesc==""){
$.messager.alert("失败", "话题描述不能为空!", "error");
return false;
}
if(topicDesc.length>100){
$.messager.alert("失败", "话题描述不能超过100字!", "error");
return false;
}
// param.status = $("input[name='statusRadio'][checked]").val
var topicImageUrl = $("input[name='topicImageUrl']").val();
if(topicImageUrl == null || topicImageUrl ==""){
$.messager.alert("失败", "提交失败,请选择图片", "error");
return false;
}
// debugger
var relatedLabels = "";
$("#taglist").find("span[name=choosedTag]").each(function () {
var choosedTagId = $(this).attr("data-labelid");
relatedLabels +=choosedTagId+",";
});
if(relatedLabels == ""){
$.messager.alert("失败", "提交失败,请至少选择一个标签", "error");
return false;
}
param.relatedLabels = relatedLabels;
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(labelList).dialog("close");
$("#labelListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(labelList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/topicManage/topicEdit.html",
});*/
}
// 上架下架
function changeStatus(data) {
var param = {
id: data.id,
status: data.status
};
$.post(serverContextPath + "/grassTopicManage/addUpGrassTopic", param, function (data) {
//数据填到框框里面
// debugger
if (data.code == 200) {
//刷新table
$("#labelListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: "更新成功!",
height: 120
});
} else {//
$.messager.alert("失败", "更新失败,请稍后再试!", "error");
}
}, "json");
}
// 编辑分组
function getEditDialog(data) {
var labelList = $("<div id='labelList'>").appendTo($(document.body));
var title = data == null ? "新建话题":"修改话题";
var textVar = data == null ? "保存":"保存";
var msgVar = data == null ? "确认新增话题吗?":"确认保存话题吗?";
var title = data == null ? "新建话题" : "修改话题";
var textVar = data == null ? "保存" : "保存";
var msgVar = data == null ? "确认新增标签吗?" : "确认保存标签吗?";
window.self.paramObject.mkData = data;
$(labelList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
$("#activityAddForm").form("submit", {
resizable: false,
buttons: [{
id: "saveBtn",
text: textVar,
iconCls: "icon-save",
handler: function () {
$("#topicForm").form("submit", {
url: serverContextPath + "/grassTopicManage/addUpGrassTopic",
onSubmit: function (param) {
if(data != null){
if (data != null) {
param.id = data.id;
}
if (!$("#activityAddForm").form("validate")) {
return false;
}
var topicDesc = $("#topicDesc").val();
if(topicDesc==null || topicDesc==""){
$.messager.alert("失败", "话题描述不能为空!", "error");
//1)表单基本检查
if (!$("#topicForm").form("validate")) {
return false;
}
if(topicDesc.length>100){
$.messager.alert("失败", "话题描述不能超过100字!", "error");
//2)是否上传了图片
var imageCount = 0;
$("input[name='topicImageUrl']").each(function (j, item) {
var url = item.value;
if (url != '') {
imageCount++;
}
});
if (imageCount == 0) {
$.messager.alert("保存失败", "至少要选择一张图片", "error");
return false;
}
// param.status = $("input[name='statusRadio'][checked]").val
var topicImageUrl = $("input[name='topicImageUrl']").val();
if(topicImageUrl == null || topicImageUrl ==""){
$.messager.alert("失败", "提交失败,请选择图片", "error");
return false;
}
// debugger
//3)是否选择了标签
var relatedLabels = "";
$("#taglist").find("span[name=choosedTag]").each(function () {
var choosedTagId = $(this).attr("data-labelid");
relatedLabels +=choosedTagId+",";
var tagCount = 0;
$("#labelListDiv").find("span[role='choose']").each(function (item, index) {
debugger
var tempId = $(this).attr('data-labelid');
if (tempId != null) {
tagCount++;
relatedLabels += tempId + ",";
}
});
if(relatedLabels == ""){
$.messager.alert("失败", "提交失败,请至少选择一个标签", "error");
if (tagCount == 0 || tagCount > 5) {
$.messager.alert("保存失败", "至少选择一个标签,最多5个", "error");
return false;
}
... ... @@ -355,7 +496,7 @@
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
$.messager.alert("失败", "操作失败", "error");
}
}
});
... ... @@ -365,7 +506,7 @@
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
if (flag) {
$(labelList).dialog("close");
}
});
... ... @@ -376,37 +517,6 @@
});
}
// 上架下架
function changeStatus(data){
var param = {
id : data.id,
status : data.status
};
$.post(serverContextPath + "/grassTopicManage/addUpGrassTopic", param,function (data) {
//数据填到框框里面
// debugger
if(data.code ==200){
//刷新table
$("#labelListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: "更新成功!",
height: 120
});
}else{//
$.messager.alert("失败", "更新失败,请稍后再试!", "error");
}
}, "json");
}
});
</script>
... ...