Authored by 张帅

后台长文章添加商品

... ... @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<title>Yoho!Buy运营平台</title>
<script src="/pfcms/js/include.js"></script>
<script src="/pfcms/js/include_grass.js"></script>
<script src="/pfcms/js/ajaxfileupload.js"></script>
<script src="/pfcms/js/jquery.imageUpload.js"></script>
<script charset="utf-8" src="/pfcms/ueditor/ueditor.config.js"></script>
... ... @@ -243,7 +243,6 @@
'-' : 'script style object iframe embed input select',
'p': {$:{}},
'br':{$:{}},
'div':{'$':{}},
'li':{'$':{}},
'h1':{'$':{}},
'h2':{'$':{}},
... ... @@ -629,7 +628,8 @@
}
if(!$("#appurl").is(":checked")){
var content = ue.getContent();
var content = handleGoodsBeforeSubmit(ue.getContent());
param.content=content;
if(content ==null ||content == ''){
$.messager.alert("发布失败", "正文内容不能为空", "error");
return false;
... ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<!--<style type="text/css">-->
<!--*{margin:0;padding:0;color: #838383;}-->
<!--table{font-size: 12px;margin: 10px;line-height: 30px; width: 80%; margin: 50px auto;}-->
<!--.txt{width:300px;height:21px;line-height:21px;border:1px solid #d7d7d7;}-->
<!--</style>-->
<script src="/pfcms/js/include_grass.js"></script>
</head>
<body>
<div id="tt" class="easyui-layout" fit="true" >
<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 >
<span style="color:red">*</span><label>手动搜索商品</label> <br>
<input id="skn" name="skn" class="easyui-textbox" style="width: 380px;"/>
<a id="searchGoodBtn" class="go-search btn btn-primary">搜索商品</a>
<a id="searchUfoBtn" class="go-search btn btn-primary">搜索UFO商品</a>
</td>
</tr>
</table>
</div>
</form>
<table id="labelGroupListTable"></table>
</div>
<div region="center" id="labelGroupList" style="margin-left: 20px">
</div>
<!--页面中一定要引入internal.js为了能直接使用当前打开dialog的实例变量-->
<!--internal.js默认是放到dialogs目录下的-->
<!--<script type="text/javascript" src="../../third-party/jquery-1.10.2.min.js"></script>-->
<script type="text/javascript" src="../internal.js"></script>
<script>
var checkedItems = [];
var checkedItemsObj = {};
var searchType = 1;
var checkType = 1;
$(function () {
function handleDialogOk(){
var skns = '';
if(checkedItems.length == 0){
return;
}
var goodsHtml='';
for (var i = 0; i < checkedItems.length; i++) {
goodsHtml+=buildgood(i,checkedItems[i]);
}
// editor.setContent(goodsHtml,true);
editor.focus();
editor.execCommand('inserthtml',goodsHtml);
dialog.close();
}
dialog.onok = handleDialogOk;
function buildgood(index,obj) {
debugger;
var data = checkedItemsObj[obj.productSkn];
var goodDiv = '<div class="yhproduct" data-option="'+data.product_skn+'">';
var goods = gooddiv(data);
var goodDivEnd = '</div>';
return goodDiv+goods+goodDivEnd;
}
function gooddiv(data) {
return '商品图:<img width=\"120\" height=\"60\" src="'+getImageUrl(data.default_images)+ '">' +
'<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>\n';
}
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 "";
}
}
// ---------------------------------------------/**/
$("#searchUfoBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
searchType=2;
$("#labelGroupListTable").datagrid("load", {
query: $("#skn").textbox("getValue"),
// sales: "Y",
type: "UFO"});
}
});
$("#searchGoodBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
searchType=1;
$("#labelGroupListTable").datagrid("load", {
query: $("#skn").textbox("getValue"),
status: 1,
// sales: "Y",
stocknumber: "1",
attribute_not: "2"});
}
});
$("#skn").textbox({
prompt: "请输入skn,多个以逗号隔开"
});
$("#labelGroupListTable").myDatagrid({
fit: true,
fitColumns: true,
striped: true,
onCheckAll: addcheckItem,
onCheck: addcheckItem,
onUncheckAll: removeAllItem,
onUncheck: removeSingleItem,
queryParams: {
query: $("#skn").textbox("getValue"),
status: 1,
// sales: "Y",
stocknumber: "1",
attribute_not: "2"
},
// url: serverContextPath+"/grassArticle/queryGoods",
url: contextPath+"/search/queryGoods",
method: 'POST',
loadFilter: function (data) {
var tmp = defaultLoadFilter(data);
tmp.rows = tmp.list;
return tmp;
},
columns: [[
{
title: "产品skn",
field: "product_skn",
width: 30,
align: "left",
checkbox:true
},
{
title: "产品图片",
field: "default_images",
width: 15,
align: "center",
formatter: function (value, rowData, rowIndex) {
var result='';
if (value) {
if(value.indexOf('http://') == 0){
result = item.default_images.split("?")[0];
}else{
var fileMode = value.substring(15, 17);
if(fileMode=='01'){
result= "http://"+"img11.static.yhbimg.com"+"/goodsimg"+value;
}
if(fileMode=='02'){
result= "http://"+"img12.static.yhbimg.com"+"/goodsimg"+value;
}
}
}
else {
result = ""
}
if (result) {
return "<img width=120 height=60 src='" + result + "?imageMogr2/thumbnail/320x320/extent/320x320/background/d2hpdGU=/position/center/quality/90'/>";
} else {
return "";
}
}
},
{
title: "产品名称",
field: "product_name",
width: 30,
align: "left"
},
{
title: "品牌",
field: "brand_name",
width: 20,
align: "left"
}, {
title: "现价",
field: "sales_price",
width: 25,
align: "left"
}, {
title: "吊牌价",
field: "market_price",
width: 25,
align: "left" ,
formatter: function (value, rowData, rowIndex) {
var result=rowData.market_price;
if(rowData.market_price==null || rowData.market_price==''){
result ="——————————"
}
return result;
}
}, {
title: "库存",
field: "stock_number",
width: 25,
align: "left" ,
formatter: function (value, rowData, rowIndex) {
var result=rowData.stock_number;
if(rowData.stock_number==null || rowData.stock_number==''){
result ="——————————"
}
return result;
}
}
]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
checkbox:true,
onLoadSuccess: function (data) {
debugger
for (var i=0; i<data.list.length;i++){
var rowdata = data.list[i]
checkedItemsObj[rowdata.product_skn] = rowdata;
}
resetSelectedCheckBox(data);
}
});
});
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 () {
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) {
debugger
var k = findCheckedItem(id);
if (k != -1) {
checkedItems.splice(k, 1);
}
}
</script>
</body>
</html>
\ No newline at end of file
... ...
... ... @@ -354,7 +354,7 @@
//默认过滤规则相关配置项目
//,disabledTableInTable:true //禁止表格嵌套
//,allowDivTransToP:true //允许进入编辑器的div标签自动变成p标签
,allowDivTransToP:false //允许进入编辑器的div标签自动变成p标签
//,rgb2Hex:true //默认产出的数据中的color自动从rgb格式变成16进制格式
// xss 过滤是否开启,inserthtml等操作
... ... @@ -387,7 +387,7 @@
dd: ['class', 'style'],
del: ['datetime'],
details: ['open'],
div: ['class', 'style'],
div: ['class', 'style','data-option'],
dl: ['class', 'style'],
dt: ['class', 'style'],
em: ['class', 'style'],
... ...
... ... @@ -67,4 +67,87 @@ UE.registerUI('yohoLink',function(editor,uiName){
});
return btn;
}/*index 指定添加到工具栏上的那个位置,默认时追加到最后,editorId 指定这个UI是那个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮*/);
\ No newline at end of file
}/*index 指定添加到工具栏上的那个位置,默认时追加到最后,editorId 指定这个UI是那个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮*/);
UE.registerUI('yohoProduct',function(editor,uiName){
//注册按钮执行时的command命令,使用命令默认就会带有回退操作
editor.registerCommand(uiName,{
execCommand:function(value){
editor.insert(value);
console.log("exeCommand", uiName, "value", value);
}
});
//创建dialog
var dialog = new UE.ui.Dialog({
//指定弹出层中页面的路径,这里只能支持页面,因为跟addCustomizeDialog.js相同目录,所以无需加路径
iframeUrl: UEDITOR_CONFIG.UEDITOR_HOME_URL + 'dialogs/yohoproduct/yohoProduct.html?v=1',
//需要指定当前的编辑器实例
editor:editor,
//指定dialog的名字
name:uiName,
//dialog的标题
title:"yohoProduct",
//指定dialog的外围样式
cssRules:"width:1225px;height:600px;",
//如果给出了buttons就代表dialog有确定和取消
buttons:[
{
className:'edui-okbutton',
label:'确定',
onclick:function () {
editor.execCommand(uiName);
dialog.close(true);
editor.execCommand(uiName);
}
},
{
className:'edui-cancelbutton',
label:'取消',
onclick:function () {
dialog.close(false);
}
}
]});
var btn = new UE.ui.Button({
name:'dialogbutton' + uiName,
title:'dialogbutton' + uiName,
//需要添加的额外样式,指定icon图标,这里默认使用一个重复的icon
cssRules :'background-position: -422px -20px;',
onclick:function () {
//渲染dialog
dialog.render();
dialog.open();
}
});
//当点到编辑内容上时,按钮要做的状态反射
editor.addListener('selectionchange', function () {
var start = editor.selection.getStart();
var text = editor.selection.getText();
// 选中文字或者图片
// if (start.tagName == 'IMG' || text.length > 0) {
// btn.setDisabled(false);
// } else {
// btn.setDisabled(true);
// }
});
return btn;
}/*index 指定添加到工具栏上的那个位置,默认时追加到最后,editorId 指定这个UI是那个编辑器实例上的,默认是页面上所有的编辑器都会添加这个按钮*/);
function handleGoodsBeforeSubmit(html) {
var div=document.createElement("div");
div.innerHTML = html;
var node = div.getElementsByClassName("yhproduct");
for (var n in node){
node[n].innerHTML = "";
}
return div.innerHTML;
}
\ No newline at end of file
... ...