Authored by chenly5

投票发布页面

... ... @@ -13,6 +13,7 @@ import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHValueOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.quartz.utils.DateUtils;
import com.yoho.service.model.sns.model.enums.GrassInboxBusinessTypeEnum;
import com.yoho.service.model.social.request.BaseReqBO;
import com.yoho.service.model.social.request.UicUserReqBO;
... ... @@ -97,6 +98,8 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
private IGrassInformRecordDao grassInformRecordDao;
@Resource
private IGrassArticleExtraDao grassArticleExtraDao;
@Resource
private IGrassVoteOptionDao grassVoteOptionDao;
@Autowired
private ServiceCaller serviceCaller;
... ... @@ -209,6 +212,9 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
article.setArticleTitle(req.getTitle());
article.setFlowType(req.getFlowType());
article.setDispatchChannel(req.getDispatchChannel());
article.setVoteType(req.getVoteType());
article.setVoteStart(req.getVoteStart());
article.setVoteDeadline(req.getVoteDeadline());
try {
grassArticleDao.insertArticleSeletive(article);
logger.info("insert grass article success, uid is {}, ariticle id is {}", article.getAuthorUid(), article.getId());
... ... @@ -289,6 +295,11 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
addVideoTask(req.getFileId(), article.getId());
}
//投票发布,投票选项处理
if(sort == 5 && StringUtils.isNotEmpty(req.getVoteOptions())){
insertVoteOptions(req);
}
//后台文章发布成功需要给被at的用户发送站内信通知
sendInBoxForAtUsers(article.getId(),article.getAuthorUid(),false);
if(article.getAuthStatus() == 1){
... ... @@ -298,6 +309,23 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
return article.getId();
}
private void insertVoteOptions(GrassArticleReq req){
String voteOptions = req.getVoteOptions();
String[] options = voteOptions.split(",");
for(int i = 0 ; i < options.length ; i++){
GrassVoteOption option = new GrassVoteOption();
option.setArticleId(req.getArticleId());
option.setContent(options[i]);
option.setOrderNum(i+1);
option.setStatus(1);
option.setCreateTime(DateUtil.getCurrentTimeSeconds());
option.setUpdateTime(DateUtil.getCurrentTimeSeconds());
grassVoteOptionDao.insert(option);
}
}
private List<GrassArticleLabel> buildArticleLabels(int articleId, List<Integer> lableList, Integer authStatus) {
List<GrassArticleLabel> grassArticleLables = Lists.newArrayList();
for (Integer lableId : lableList) {
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Yoho!Buy运营平台</title>
<script src="/pfcms/js/include.js"></script>
<script src="/pfcms/js/ajaxfileupload.js"></script>
<script src="/pfcms/js/jquery.imageUpload.js"></script>
<style>
.btn-long {
width: 120px;
height: 37px;
line-height: 37px;
font-size: 15px;
color: white;
border-radius: 5px;
display: inline-block;
cursor: pointer;
text-align: center;
}
.btn-long:hover {
opacity: 0.9;
}
.tag{
display: block;
float: left;
padding: 2px 5px;
background: #1caf9a;
margin-right: 5px;
margin-bottom: 5px;
margin-top: 5px;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
font-size: 13px;
}
.goodTag{
display: block;
float: right;
font-size: 18px;
}
</style>
<link rel="stylesheet" href="/pfcms/js/emoji/emojionearea.css">
<script type="text/javascript" src="/pfcms/js/emoji/emojionearea.js"></script>
</head>
<body class="easyui-layout " fit="true">
<div region="north" style="height: 100px;">
<script>
document.write(addHead('种草社区管理', '种草投票发布'));
</script>
</div>
<div region="center" id="labelGroupList" style="margin-left: 20px;width: 100%">
<div id="tt" class="easyui-layout" style="margin-right:20px;height:100%;overflow-y: scroll">
<form name="publishArticleForm" id="publishArticleForm" 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 style="width:100% ">
<div style="float: left;width:700px;" >
<span style="color:red">*</span><label style="font-size: 14px;">选择用户</label> <br>
<input id="articleUid" name="authorUid" style="width:600px " class="easyui-textbox" />
<a id="userBotton" class="btn btn-small" style="font-size: 18px; " >确认</a>
<br>
<span style="color:red"> 必填项,选择某个用户身份后,才能发布</span>
</div>
<div id="userInfo" style="float: left;margin-left: 30px;">
</div>
</td>
</tr>
<tr style="height: 60px">
<td style="width:100%;">
<div style="float: left;width:700px;" >
<span style="color:red">*</span><label style="font-size: 14px;">选择分发渠道</label> <br>
<input class="easyui-combobox" id="dispatchChannel" name="dispatchChannel" style="width:600px ">
</div>
</td>
</tr>
<tr style="height: 60px">
<td style="width:100%; word-wrap:break-word;" >
<label style="font-size: 14px;">标题</label> <br>
<div style="width:600px; word-wrap:break-word;float: left;position: relative" >
<input id="title" name="title" style="width:600px " class="easyui-textbox" />
</div>
<!--<div style="clear: both;"> <span id="content-count">0</span>/500</div>-->
</td>
</tr>
<tr style="height: 60px">
<td style="width:100%; word-wrap:break-word;" >
<span style="color:red">*</span><label style="font-size: 14px;">文字内容(必填项,内容不能为空)</label> <br>
<div style="width:600px; word-wrap:break-word;float: left;position: relative" >
<textarea rows="5" id="content" style="width:60%; white-space: pre-wrap;" name = "content" class="form-control" placeholder="请在这里输入1-2000字的笔记" required="" maxlength="2000"></textarea>
<div style="position: absolute;bottom:0;right:-50px"> <span id="content-count">0</span>/2000</div>
</div>
<!--<div style="clear: both;"> <span id="content-count">0</span>/500</div>-->
</td>
</tr>
<tr style="height: 60px">
<td style="width:100%; word-wrap:break-word;" >
<a id="verifyUserBotton" class="btn btn-small" style="font-size: 18px; " >@用户信息查看</a>
<span style="color:red"> 温馨提示: @功能直接手动输入@符号和用户uid,并且以#结尾(举例:@600032938# )</span>
</td>
</tr>
<tr>
<td style="width:100%; word-wrap:break-word;">
<div id="atUserInfo" style="float: left;"></div></td>
</tr>
<tr style="height: 60px">
<td style="width:100%;">
<label style="font-size: 14px;">选择标签</label> <br>
<input id="labelId" name="labelId" class="easyui-combobox" style="width:600px; "/><br>
<span style="color:red">至多添加5个标签,非必填项</span><label></label>
<input id="labelIds" name="labelIds" hidden="hidden"/>
<div id="labelList">
</div>
</td>
</tr>
<tr style="height: 60px">
<td style="width:100%;">
<label style="font-size: 14px;">选择话题</label> <br>
<input id="topicGroupId" name="topicGroupId" class="easyui-combobox" style="width:300px; "/>
<input id="topicId" name="topicId" class="easyui-combobox" style="width:300px; "/><br>
<span style="color:red">至多添加1个话题,非必填项</span><label></label>
<input id="topicIds" name="topicIds" hidden="hidden"/>
<div id="topicList">
</div>
</td>
</tr>
<tr style="height: 60px">
<td style="width:100%;">
<label style="font-size: 14px;">设置投票</label> <br>
<input class="easyui-combobox" id="voteType" name="voteType" style="width:200px ">
</td>
</tr>
<tr style="height: 20px">
<td >
<span style="color:red">*</span><label style="font-size: 14px;">选择图片(最多九张)</label><br>
<span style="color:red">1.需要上传1-9张图片,必填项;&nbsp&nbsp&nbsp
2.请上传1-9张图片,图片比例1:1、3:4、4:3(宽:高),大小不超过500k</span><label></label><br>
<!--<a id="addImage" class="btn btn-primary" >选择图片+</a>-->
<input id="imgs" name="articleImages" hidden="hidden"/>
</td>
</tr>
<tr style="height: 60px">
<td id="imgTd">
<div id="imageUpload1">
</div>
</td>
</tr>
<tr style="height: 60px">
<td>
<label>封面</label> <br>
<div id="coverImageUpload" style="float:left;">
</div>
<div>
<div style="float:left;">
<span style=" margin-left: 10px; color: red">1. 请上传 3:4/4:3/1:1 的图片,优质清晰的封面有利于推荐</span></br>
<span style=" margin-left: 10px; color: red">2. 请上传500K以内的图片,请勿上传像素过高的图片</span>
</div>
</div>
</td>
</tr>
<!--选择信息流结构-->
<tr style="height: 60px">
<td style="width:100%;">
<div style="float: left;width:700px;" >
<label style="font-size: 14px;">选择结构类型</label> <br>
<input class="easyui-combobox" id="flowType" name="flowType" style="width:200px ">
</div>
</td>
</tr>
<tr style="height: 60px">
<td>
<label style="font-size: 14px;">关联商品</label> <br>
<span style="color:red">1.支持商品编号(SKN&SKUP)查询商品;&nbsp&nbsp&nbsp
2.至多添加10个商品,非必填项</span><label></label><br>
<a id="addSkn" class="btn btn-primary" style="font-size: 15px">选择商品+</a>
<!--<input id="skns" name="articleSkns" hidden="hidden"/>-->
<!--<input id="sknType" name="sknType" hidden="hidden"/>-->
<span id ="products"></span>
</td>
</tr>
<tr style="height: 60px">
<td id="goodstd">
<div id="good0" style="float: left;margin-left: 30px;width: 150px;">
</div>
</td>
</tr>
<tr>
<td valign="bottom">
<input id="draftBotton" class="btn btn-primary" style="font-size: 16px; height: 36px;" value="保存到草稿箱"/>
<input id="timerBotton" class="btn btn-primary" style="font-size: 16px; height: 36px;" value="定时发布"/>
<input id="subBotton" class="btn btn-primary" style="font-size: 16px; margin-left: 30px; height: 36px;" value="立即发布"/>
<span style="color:red">*运营平台发布的内容,均免审核,直接发布。</span><label></label><br>
</td>
</tr>
</table>
</div>
</form>
</div>
</div>
</body>
<script>
var checkedItems = [];
var checkedItemsObj = {};
var searchType = 1;
var checkType = 1;
$(function () {
$("#title").textbox({
prompt: "请输入80字以内的标题",
validType:"length[1,80]",
onChange: function () {
}
});
$("#content").emojioneArea({
// options
autoHideFilters: true,
autocomplete : false,
search :false,
recentEmojis: false,
tones: false,
filters: {
// see in source file
animals_nature : true,
food_drink :true,
activity: true,
travel_places :true,
objects:true,
symbols: true,
flags:true
}
});
$("#addImage").linkbutton({
iconCls : "icon-search",
onClick : function() {
}
});
$("#addSkn").linkbutton({
iconCls : "icon-search",
onClick : function() {
getEditDialog();
}
});
$("#userBotton").linkbutton({
iconCls : "icon-search",
onClick : function() {
//发送请求
$.ajax({
type: "POST",
url: serverContextPath + "/grassArticle/getUserInfo", //提交到后端的url
dataType: 'json',
data:{
uid : $("#articleUid").textbox("getValue")
},
success: function (result) {
if(result.code == 200) {
if(result.data !=null && result.data !=''){
var headIco = result.data.headIco.substring(0, result.data.headIco.indexOf("?"));
var html = '';
html += "<span style='font-size: 18px;'>&nbsp&nbsp<img src='"+headIco+"' width='60px;' height='60px;'></span>&nbsp&nbsp&nbsp&nbsp";
html += "<span style='font-size: 15px;'>&nbsp&nbsp<label>"+result.data.nickName+"</label></span>";
$("#userInfo").html(html);
}else{
var html = '<span style="color:red;font-size: 15px;">获取用户信息失败,请检查uid输入是否正确</span>';
$("#userInfo").html(html);
}
}
else {
var html = '<span style="color:red;font-size: 15px;">获取用户信息失败,请稍后重试</span>';
$("#userInfo").html(html);
}
}
});
}
});
$("#verifyUserBotton").linkbutton({
iconCls : "icon-search",
onClick : function() {
//发送请求
$.ajax({
type: "POST",
url: serverContextPath + "/grassArticle/verifyAtUser", //提交到后端的url
dataType: 'json',
data:{
content : $("#content").val()
},
success: function (result) {
if(result.code == 200) {
var userList = result.data;
if(userList !=null && userList.length > 0){
var html = '';
for (i = 0; i < userList.length; i++) {
var userInfo = userList[i];
var headIco = userInfo.headIco.substring(0, userInfo.headIco.indexOf("?"));
html += "<span style='font-size: 15px;'><label>"+userInfo.uid+"</label></span>&nbsp&nbsp&nbsp&nbsp";
html += "<span style='font-size: 15px;'>&nbsp&nbsp<label>"+userInfo.nickName+"</label></span>&nbsp&nbsp&nbsp&nbsp";
html += "<span style='font-size: 18px;'>&nbsp&nbsp<img src='"+headIco+"' width='60px;' height='60px;'></span><br>";
}
$("#atUserInfo").html(html);
}else{
var html = '<span style="color:red;font-size: 15px;">没有查到有效的用户信息</span>';
$("#atUserInfo").html(html);
}
}
else {
var html = '<span style="color:red;font-size: 15px;">获取用户信息失败,请稍后重试</span>';
$("#atUserInfo").html(html);
}
}
});
}
});
$("#timerBotton").linkbutton({
iconCls : "icon-search",
onClick : function() {
getTimeDialog();
}
});
$("#dispatchChannel").combobox({
valueField : "value",
textField : "text",
required:true,
prompt: "选择分发渠道",
data:[{text:"全部",value:"-1"},{text:"社区",value:"1"},{text:"导购",value:"2"}]
});
/*选择信息结构*/
$("#flowType").combobox({
valueField : "value",
textField : "text",
required:false,
prompt: "选择结构类型",
data:[{text:"",value:""},{text:"长图",value:"1"},{text:"方图",value:"2"}]
});
/*选择投票类型*/
$("#voteType").combobox({
valueField : "value",
textField : "text",
required:true,
prompt: "选择投票类型",
data:[{text:"单选",value:"1"},{text:"多选",value:"2"}]
});
$("#articleUid").textbox({
required: true,
missingMessage: "发布用户不能为空",
prompt: "请输入发布用户",
});
$("#content").emojioneArea()[0].emojioneArea.on("keyup change",function (edite,event) {
debugger
var $this = $(this);
var count = $this[0].getText().length;
var content = $this[0].getText();
if(count>2000){
$this[0].setText(content.substring(0,2000));
count = $this[0].getText().length;
}
$("#content-count").text(count);
});
$("#labelId").combobox({
prompt: "请选择标签",
required: false,
selectOnNavigation : true,
valueField: 'id',
textField: 'labelName',
multiple:true,
url : serverContextPath + "/grassLabelManage/getAllGrassLabelInfo",
loadFilter: function (data) {
return defaultLoadFilter(data);
},
onChange:function (data) {
var arr = $(this).combobox("getValues");
var textarr = $(this).combobox("getData");
if(arr.length > 5 ){
$(this).combobox("unselect",arr[arr.length-1]);
// $.messager.alert("提示","标签最多只能选择5个", "info");
arr = $(this).combobox("getValues");
}
var labelList='';
debugger
for (var i=0; i<arr.length;i++){
var text = '';
for (var j=0; j< textarr.length;j++){
if(arr[i] == textarr[j].id){
text=textarr[j].labelName;
}
}
labelList+='<span class="tag"><span>'+text+'</span><a href="#" class="labelTag" data-index="'+i+'">x</a></span>&nbsp&nbsp&nbsp'
}
$("#labelList").html(labelList);
}
});
$("#topicGroupId").combobox({
prompt: "选择话题分组",
required: false,
selectOnNavigation : true,
valueField: 'id',
textField: 'groupName',
url : serverContextPath + "/topicGroupManage/getAllTopicGroupInfo",
loadFilter: function (data) {
return defaultLoadFilter(data);
},
onChange:function (data) {
$('#topicId').combobox('reload',serverContextPath + "/grassTopicManage/grassTopicByGroupId?groupId="+data);
// 清空业务线
$("#topicId").combobox("setValue",'');
}
});
$("#topicId").combobox({
prompt: "选择话题",
required: false,
selectOnNavigation : true,
valueField: 'id',
textField: 'topicName',
url : serverContextPath + "/grassTopicManage/grassTopicByGroupId",
loadFilter: function (data) {
return defaultLoadFilter(data);
},
onChange:function (data) {
var arr = $(this).combobox("getValue");
var textarr = $(this).combobox("getData");
var html='';
debugger
var text = '';
for (var j=0; j< textarr.length;j++){
if( arr == textarr[j].id){
text=textarr[j].topicName;
}
}
if(text !=''){
html+='<span class="tag"><span>'+text+'</span><a href="#" class="topicTag" ">x</a></span>&nbsp&nbsp&nbsp'
}
$("#topicList").html(html);
}
});
$(document).on("click", ".labelTag", function () {
var index = $(this).attr("data-index");
var arr = $("#labelId").combobox("getValues");
$("#labelId").combobox("unselect",arr[index]);
});
$(document).on("click", ".topicTag", function () {
$("#topicId").combobox("setValue","");
});
$(document).on("click", ".goodTag", function () {
debugger
var product_skn = $(this).attr("data-index");
removeSingleItemById(product_skn);
var div= $(this).parent("span").parent("div");
div.remove();
});
$("#subBotton").linkbutton({
iconCls: "icon-save",
width:200,
onClick: function () {
$("#publishArticleForm").form("submit",{
url : serverContextPath+"/grassArticle/publishArticle",
onSubmit : function(param) {
debugger;
if (!$("#publishArticleForm").form("validate")) {
return false;
}
var content = $("#content").val();
if(content == '' || content.length<=0){
$.messager.alert("发布失败", "请输入文字内容", "error");
return false;
}
if(content.length>2000){
$.messager.alert("发布失败", "内容长度超过2000,请重新输入", "error");
return false;
}
var imgs = '';
var imageCount = 0;
$("input[name='url']").each(function(j,item){
debugger
var url = item.value;
if(imgs == ''){
imgs = url;
}else{
imgs = imgs + ","+url;
}
imageCount++;
});
$("#imgs").val(imgs);
if(imageCount > 9){
$.messager.alert("发布失败", "最多只能选择9张图片", "error");
return false;
}
if(imageCount < 1){
$.messager.alert("发布失败", "请选择至少一张图片", "error");
return false;
}
var labels = '';
$("input[name='labelId']").each(function(j,item){
debugger
var id = item.value;
if(labels == ''){
labels = id;
}else{
labels = labels + ","+id;
}
});
$("#labelIds").val(labels);
var html = '';
for (var i = 0; i < checkedItems.length; i++) {
html += "<input name='products["+i+"].productSkn' hidden value='"+checkedItems[i].productSkn+"'/><br>";
html += "<input name='products["+i+"].productType' hidden value='"+checkedItems[i].productType+"'/>";
}
$("#products").html(html);
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");
}
}
});
}
});
$("#draftBotton").linkbutton({
iconCls: "icon-save",
width:200,
onClick: function () {
$("#publishArticleForm").form("submit",{
url : serverContextPath+"/grassArticle/saveArticleDraft",
onSubmit : function(param) {
debugger;
if (!$("#publishArticleForm").form("validate")) {
return false;
}
var content = $("#content").val();
if(content == '' || content.length<=0){
$.messager.alert("保存失败", "请输入文字内容", "error");
return false;
}
if(content.length>2000){
$.messager.alert("发布失败", "内容长度超过2000,请重新输入", "error");
return false;
}
var imgs = '';
var imageCount = 0;
$("input[name='url']").each(function(j,item){
debugger
var url = item.value;
if(imgs == ''){
imgs = url;
}else{
imgs = imgs + ","+url;
}
imageCount++;
});
$("#imgs").val(imgs);
if(imageCount > 9){
$.messager.alert("保存失败", "最多只能选择9张图片", "error");
return false;
}
var labels = '';
$("input[name='labelId']").each(function(j,item){
debugger
var id = item.value;
if(labels == ''){
labels = id;
}else{
labels = labels + ","+id;
}
});
$("#labelIds").val(labels);
var html = '';
for (var i = 0; i < checkedItems.length; i++) {
html += "<input name='products["+i+"].productSkn' hidden value='"+checkedItems[i].productSkn+"'/><br>";
html += "<input name='products["+i+"].productType' hidden value='"+checkedItems[i].productType+"'/>";
}
$("#products").html(html);
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");
}
}
});
}
});
/*封面图上传*/
$("#coverImageUpload").imageUpload({
width: 171,
height: 120,
realInputName: "coverImage",
uploadInputName: "files",
url: serverContextPath + '/fileupload/uploadImgFile',
queryParams: {
bucket: "grassImg"
},
onBeforeSubmit: function () {
debugger;
var oobj = $(this).find("input[type='file']");
var files = oobj[0].files;
for(var i=0; i<files.length;i++){
var obj = files[i];
if(obj!=null && obj!=''){
debugger
if(obj.name.substring(obj.name.lastIndexOf(".")).toLowerCase() == '.png'){
$.messager.alert("提示","不允许上传png格式的图片", "info", function(){return false;});
return false;
}
if(obj.type.toLowerCase() == 'image/png'){
$.messager.alert("提示","不允许上传png格式的图片", "info", function(){return false;});
return false;
}
}
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误", data.message);
return "";
}
return data.data;
},
onLoadSuccess: function (data) {
$.messager.progress("close");
return false;
}
});
$("#imageUpload1").imageUpload({
width: 171,
height: 120,
realInputName: "url",
uploadInputName: "files",
url: serverContextPath + '/fileupload/uploadImgFile',
queryParams: {
bucket: "grassImg"
},
onBeforeSubmit: function () {
debugger;
var oobj = $(this).find("input[type='file']");
var files = oobj[0].files;
for(var i=0; i<files.length;i++){
var obj = files[i];
if(obj!=null && obj!=''){
debugger
if(obj.name.substring(obj.name.lastIndexOf(".")).toLowerCase() == '.png'){
$.messager.alert("提示","不允许上传png格式的图片", "info", function(){return false;});
return false;
}
if(obj.type.toLowerCase() == 'image/png'){
$.messager.alert("提示","不允许上传png格式的图片", "info", function(){return false;});
return false;
}
}
}
var imageCount = 0;
$("input[name='url']").each(function(j,item){
debugger
var url = item.value;
if(url != ''){
imageCount++;
}
});
if(imageCount +files.length > 9 ){
$.messager.alert("提示","最多上传九张图片", "info");
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
initimg(1,1);
$(this).remove();
$.messager.alert("错误",data.message);
return "";
}
return data.data[0];
},
onLoadSuccess: function (data) {
debugger;
initimg(1,data.data.length);
for (var i= 1; i<= data.data.length; i++){
$("#imageUpload"+i).imageUpload("setValue",data.data[i-1])
}
$.messager.progress("close");
return false;
},
onClose:function(data){
$("#imageUpload1").remove();
}
});
});
// 定时 选择时间
function getTimeDialog(data,id, status){
var timeChoose = $("<div id='timeChoose'>").appendTo($(document.body));
var title = "选择时间";
var textVar = "确认";
window.self.paramObject.mkData = data;
$(timeChoose).myDialog({
title: title,
width: "20%",
height: "30%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
debugger;
var time=''
if($("#publishTimeStr").datetimebox('getValue') !=null && $("#publishTimeStr").datetimebox('getValue') !=''){
time = parseInt(new Date($("#publishTimeStr").datetimebox('getValue')).getTime() );
}else {
$.messager.alert("发布失败", "请选择时间", "error");
return;
}
$("#publishArticleForm").form("submit",{
url : serverContextPath+"/grassArticle/timerPublish",
onSubmit : function(param) {
debugger;
if (!$("#publishArticleForm").form("validate")) {
return false;
}
var content = $("#content").val();
if(content == '' || content.length<=0){
$.messager.alert("保存失败", "请输入文字内容", "error");
return false;
}
if(content.length>2000){
$.messager.alert("发布失败", "内容长度超过2000,请重新输入", "error");
return false;
}
param.publishTime =time;
var imgs = '';
var imageCount = 0;
$("input[name='url']").each(function(j,item){
debugger
var url = item.value;
if(imgs == ''){
imgs = url;
}else{
imgs = imgs + ","+url;
}
imageCount++;
});
$("#imgs").val(imgs);
if(imageCount > 9){
$.messager.alert("发布失败", "最多只能选择9张图片", "error");
return false;
}
if(imageCount < 1){
$.messager.alert("发布失败", "请选择至少一张图片", "error");
return false;
}
var labels = '';
$("input[name='labelId']").each(function(j,item){
debugger
var id = item.value;
if(labels == ''){
labels = id;
}else{
labels = labels + ","+id;
}
});
$("#labelIds").val(labels);
var html = '';
for (var i = 0; i < checkedItems.length; i++) {
html += "<input name='products["+i+"].productSkn' hidden value='"+checkedItems[i].productSkn+"'/><br>";
html += "<input name='products["+i+"].productType' hidden value='"+checkedItems[i].productType+"'/>";
}
$("#products").html(html);
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");
}
}
});
$(timeChoose).dialog("close");
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(timeChoose).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/article/chooseTime.html"
});
}
// 选择商品
function getEditDialog(data){
var labelGroupList = $("<div id='labelGroupList'>").appendTo($(document.body));
var title = "选择商品";
var textVar = "确认";
var msgVar = "确认新增吗?";
window.self.paramObject.mkData = data;
$(labelGroupList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
debugger;
$("#goodstd").html("<div id=\"good0\" style=\"float: left;margin-left: 30px;width: 300px\">\n" +
" </div>");
var skns = '';
for (var i = 0; i < checkedItems.length; i++) {
buildgood(i,checkedItems[i]);
}
$(labelGroupList).dialog("close");
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(labelGroupList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/article/chooseSkns.html"
});
}
function oo(num){
$("#imageUpload"+num).imageUpload({
width: 171,
height: 120,
realInputName: "url",
uploadInputName: "files",
url: serverContextPath + '/fileupload/uploadImgFile',
queryParams: {
bucket: "grassImg"
},
onBeforeSubmit: function () {
var oobj = $(this).find("input[type='file']");
var files = oobj[0].files;
for(var i=0; i<files.length;i++){
var obj = files[i];
if(obj!=null && obj!=''){
debugger
if(obj.name.substring(obj.name.lastIndexOf(".")).toLowerCase() == 'png'){
$.messager.alert("提示","不允许上传png格式的图片", "info", function(){return false;});
return false;
}
if(obj.type.toLowerCase() == 'image/png'){
$.messager.alert("提示","不允许上传png格式的图片", "info", function(){return false;});
return false;
}
}
}
var imageCount = 0;
$("input[name='url']").each(function(j,item){
debugger
var url = item.value;
if(url != ''){
imageCount++;
}
});
if(imageCount +files.length > 9 ){
$.messager.alert("提示","最多上传九张图片", "info");
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
initimg(num,1);
$(this).remove();
$.messager.alert("错误",data.message);
return "";
}
return data.data[0];
},
onLoadSuccess: function (data) {
debugger;
initimg(num,data.data.length);
var c =0;
for (var i= 0; i<= data.data.length; i++){
nnum = num +i;
$("#imageUpload"+nnum).imageUpload("setValue",data.data[c]);
c++;
}
$.messager.progress("close");
return false;
},
onClose:function(data){
$("#imageUpload"+num).remove();
}
});
}
function initimg(m,n) {
for (var i =1 ; i<=n; i++){
debugger
var nnum = m+i;
$("#imageUpload"+(nnum-1)).after('<div id="imageUpload'+nnum+'"> </div>');
oo(nnum);
}
}
function buildgood(index,obj) {
debugger;
var data = checkedItemsObj[obj.productSkn];
$("#good"+index).html(gooddiv(data));
$div = $("#good"+(index+1));
$("#good"+index).after('<div id="good'+(index+1)+'"style="float: left;margin-left: 30px;width: 300px"> </div>');
}
function gooddiv(data) {
return " <span>商品图:<img width=\"120\" height=\"60\" src="+getImageUrl(data.default_images)+
" /> <a href=\"#\" class=\"goodTag\" data-index=\""+data.product_skn+"\">x</a></span>" +
"<h5 style=\"margin-top: 0px;margin-bottom: 0px\">商品名:"+ data.product_name +"</h5>\n" +
"<h5 style=\"margin-top: 0px;margin-bottom: 0px\">价格:"+data.sales_price+"</h5>"
}
function getImageUrl(image) {
var result='';
if (image) {
if(image.indexOf('http://') == 0){
result = image.split("?")[0];
}else{
var fileMode = image.substring(15, 17);
if(fileMode=='01'){
result= "http://"+"img11.static.yhbimg.com"+"/goodsimg"+image;
}
if(fileMode=='02'){
result= "http://"+"img12.static.yhbimg.com"+"/goodsimg"+image;
}
}
}
else {
result = ""
}
if (result) {
return result + "?imageMogr2/thumbnail/320x320/extent/320x320/background/d2hpdGU=/position/center/quality/90";
} else {
return "";
}
}
function findCheckedItem(ID) {
for (var i = 0; i < checkedItems.length; i++) {
if (checkedItems[i].productSkn == ID) return i;
}
return -1;
}
function addcheckItem() {
// if(searchType != checkType && checkedItems.length>0){
// checkedItems=[];
// }
checkType = searchType;
var i=0;
$("input[type='checkbox'][name='product_skn']:checked").each(function () {
if(i > 9){
alert("最多只能选择10个商品");
return false;
}
var k = findCheckedItem($(this).val());
if (k == -1) {
var product = {};
product.productSkn = $(this).val();
product.productType = checkType;
checkedItems.push(product);
}
i++;
});
}
function removeAllItem(rows) {
$("input[type='checkbox'][name='product_skn']").each(function () {
if (!this.checked) {
var k = findCheckedItem($(this).val());
if (k != -1) {
checkedItems.splice(k, 1);
}
}
});
}
function resetSelectedCheckBox(data){
$("input[type='checkbox'][name='product_skn']").each(function () {
var cb=$(this);
$.each(checkedItems,function(index,value){
if(value.productSkn==cb.val()){
cb.attr("checked",true);
return false;
}
});
});
}
function removeSingleItem(rowIndex, rowData) {
var k = findCheckedItem(rowData.product_skn);
if (k != -1) {
checkedItems.splice(k, 1);
}
}
function removeSingleItemById(id) {
var k = findCheckedItem(id);
if (k != -1) {
checkedItems.splice(k, 1);
}
}
</script>
</html>
\ No newline at end of file
... ...