Authored by weiqingting

update

//店铺装修
'use strict';
var $ = require('jquery'),
common=require('../../common/common');
var g; //grid
var curDialogId; //当前打开的编辑弹层ID
var curPlatform = "pc"; //当前渲染页面用的模板名称
var curTemplateType = "2"; //当前模板类型 1:基础模板,2:经典模板
var shopType = 1; //店铺类型 1:单品牌,2:多品牌
var shopOperate = 'view'; //操作 editor:可编辑, view:查看不可编辑
var defaultSrc = "http://img01.yohoboys.com/staticimg/2016/05/19/15/01091c21f2317a64f123f1649fbbccf7ba.png"; //初始化默认图片路径
var ENUM = {
"editor-largePic":{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0},
"editor-largePic2":{"position":"", "data":[{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0}]},
"editor-smallPic":{"src": "", "url": "", "startTime": "", "endTime": "", "publishStatus": 0},
"editor-brand":{"position":"", "name":"", "url":""},
"editor-recommend": {"position":"", "name":"", "enName":"", "src":"", "url":""},
"editor-hotRecommend":{"position":"", "src":"", "url":""},
"editor-signboard":{"position":"", "src":"", "url":"","startTime": "","endTime": "","publishStatus": 0},
"editor-newGoodTab":{"position":"", "name":"", "url":""},
"editor-hotGoodTab":{"position":"", "name":"", "url":""},
"editor-newProduct":{"productId":"", "position":"", "productName":"", "productSkn":"", "salesPrice":"", "src":"", "url":""},
"editor-hotProduct":{"productId":"", "position":"", "productName":"", "productSkn":"", "salesPrice":"", "src":"", "url":""}
}; //添加一条不同弹层使用的初始化模板
var resourcesNew = {
"shopTopBanner":{
"id":"",
"data": [{"shopSrc": defaultSrc, "detailSrc": defaultSrc, "isShowShopName": "N"}]
},
"shopTopBanner_base":{
"id":"",
"data": [{"shopSrc": defaultSrc, "detailSrc": defaultSrc, "isShowShopName": "N"}]
},
"navigationBar":{
"id":"",
"data": [{"name":"",url:""}, {"name":"",url:""}, {"name":"",url:""}]
},
"largeSlideImg":{
"id":"",
"data": [{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}]
},
"oneRowTwoColImages":{
"id":"",
"data": [
{"position": 2, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]},
{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}
]
},
"brandBrowse":{
"id":"",
"data": []
},
"recommend":{
"id":"",
"title":"经典推荐",
"data": [{"position":1, "name":"默认商品", "enName":"", "src":defaultSrc, "url":""}]
},
"hotRecommend":{
"id":"",
"title":"",
"data": [{"position":1, "src":defaultSrc, "url":""}]
},
"signboard":{
"id":"",
"data": [{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}]
},
"goodsTabBar":{
"id":"",
"data": {
"new":[{"position":0, "name":"MORE", "url":""}],
"hot":[{"position":0, "name":"MORE", "url":""}]
}
},
"newProducts":{
"id":"",
"data": []
},
"hotProducts":{
"id":"",
"data": []
},
"allNewProducts":{
"id":"",
"data":[]
},
"allHotProducts":{
"id":"",
"data":[]
},
"shopTopBanner_APP":{
"id":"",
"isUsed":"N",
"data": [{"shopSrc": defaultSrc, "detailSrc": defaultSrc, "isShowShopName": "N"}]
},
"oneRowTwoColImages_APP":{
"id":"",
"isUsed":"N",
"data": [
{"position": 2, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]},
{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}
]
},
"hotProducts_APP":{
"id":"",
"isUsed":"N",
"data": []
},
"allHotProducts_APP":{
"id":"",
"data":[]
},
"largeSlideImg_APP":{
"id":"",
"isUsed":"N",
"data": [{"position": 1, "data":[{"src": defaultSrc, "url": "", "startTime": "", "endTime": ""}]}]
},
"recommend_APP":{
"id":"",
"isUsed":"N",
"data": [{"position":1, "name":"默认商品", "enName":"", "src":defaultSrc, "url":""}]
}
} //初始化装修信息json
var shopsId, _id, jsonMain, jsonClone;
getParams();
findDecoration();
/********************主流程*********************/
//URL获取参数
function getParams(){
var paramUrl = location.href + "";
var param = paramUrl.substring(paramUrl.indexOf("decorationDetail"));
var paramList = param.split("/");
if(paramList){
shopsId = paramList[1];
shopType = paramList[2];
shopOperate = paramList[3];
_id = paramList[4];
}
if(shopOperate == 'editor'){
$(".moduleSubmite").show().siblings().hide();
}else if(shopOperate == 'view'){
$(".tabheader").hide();
$(".moduleView").show().siblings().hide();
}else if(shopOperate == 'check'){
$(".tabheader").hide();
$(".moduleCheck").show().siblings().hide();
}
}
//json渲染模板
function showMain(){
// tab自动选中基础模板,经典模板
$('.tabheader .nav').find("li[data-toggle='"+ curTemplateType +"']").addClass("active");
// radio自动选中pc端或者app端
$('.moduleTypeView').find("input[name='brandLevel'][value='"+ curPlatform +"']").attr("checked","checked");
//渲染装修模板
if(curTemplateType == 1){
$('#main').empty().html(common.util.__template2($("#"+curTemplateType+"-pc").html(),jsonMain));
}else if(curTemplateType == 2){
$('#main').empty().html(common.util.__template2($("#"+curTemplateType+"-"+curPlatform).html(),jsonMain));
}
//基础模板不显示pc端跟app端
if(curTemplateType == "1"){
$(".moduleTypeView").hide();
}else{
$(".moduleTypeView").show();
}
//单品牌,多品牌
if(shopType == 2){
$(".model-brand").show();
}else if(shopType == 1){
$(".model-brand").hide();
}
//标签长度样式自适应
$.each($(".contentpanel-pc .model-showTitle .showTab"),function(){
if($(this).width() > 280){
$(this).css("right",(280-($(this).width()))+"px");
}
})
showEditorIconEvent();
}
//弹窗编辑主流程
function editorIconEvent(title,id){
$('.editorIcon').on('click',function(){
curDialogId = id;
var option = {
title:title,
content:"<div class='editorTitle'></div><div class='editor-dialog' id='"+ id +"'></div><div class='editorTip'></div> ",
width:'70%',
button:[
{
value:"取消",
callback:function(){
if(curDialogId != "editor-brand-app"){
freshJson(id, g.__rows, 0);
}
}
},
{
value:"确认",
css:"btn-info",
callback:function(){
if(editorCheck(id)){
if(curDialogId != "editor-brand-app"){
freshJson(id, g.__rows, 1);
}
showMain();
}else{
return false;
}
}
}
]
}
if(curPlatform == "pc"){
option = setSendToAppBtm(id, option);
}
new common.dialog(option);
gridInit(id);
untilEditorEvent(id);
editorTipInit(id);
})
}
/********************接口Ajax*********************/
//Ajax查询
function findDecoration(){
console.log('1');
common.util.__ajax(
{
url:'/shop/ShopsDecoratorRest/findShopsDecoratorDetail',
data: {
"shopsId": shopsId
}
},
function(rs) {
console.log(rs.data);
if(rs.data){
jsonMain = rs.data;
}
//没有装修信息,初始化装修信息
if($.isEmptyObject(jsonMain.resources)){
jsonMain.resources = $.extend(true,{},resourcesNew);
}
//装修信息中品牌内容为空,初始化品牌
if(jsonMain.brandList){
if(jsonMain.resources.brandBrowse.data.length < 1){
cloneArr(jsonMain.brandList,jsonMain.resources.brandBrowse.data);
}
}else{
common.util.__tip("店铺没有品牌,无法装修,请返回添加品牌!");
return;
}
//初始化模板类型
if(jsonMain.templateType && jsonMain.templateType != "0"){
curTemplateType = jsonMain.templateType;
}
//装修json克隆
jsonClone = $.extend(true,{},jsonMain);
//最新上架,最热商品接口
if(shopOperate == 'editor'){
if(!jsonMain.resources.allNewProducts.data || jsonMain.resources.allNewProducts.data.length < 1){
findTopNewProducts();
}
if(!jsonMain.resources.allHotProducts.data || jsonMain.resources.allHotProducts.data.length < 1){
findTopHotProducts();
}
if(!jsonMain.resources.allHotProducts_APP.data || jsonMain.resources.allHotProducts_APP.data.length < 1){
findTopHotProducts_APP();
}
/*findTopNewProducts(); findTopHotProducts(); findTopHotProducts_APP();*/
}
showMain();
},true);
}
//Ajax最新上架商品
function findTopNewProducts(){
common.util.__ajax({
url:'/shop/ShopsDecoratorRest/findNewProductList',
data: {
"shopsId": jsonMain.shopsId,
"size": 20
}
},function(rs){
if(rs.data.product_list){
jsonMain.resources.allNewProducts.data = rs.data.product_list;
}
},true);
}
//Ajax热销商品
function findTopHotProducts(){
common.util.__ajax({
url:'/shop/ShopsDecoratorRest/findHotProductList',
data: {
"shopsId": jsonMain.shopsId,
"size": 20
}
},function(rs){
if(rs.data.product_list){
jsonMain.resources.allHotProducts.data = rs.data.product_list;
}
},true);
}
//Ajax热销商品---APP
function findTopHotProducts_APP(){
common.util.__ajax({
url:'/shop/ShopsDecoratorRest/findHotProductList',
data: {
"shopsId": jsonMain.shopsId,
"size": 20
}
},function(rs){
if(rs.data.product_list){
jsonMain.resources.allHotProducts_APP.data = rs.data.product_list;
}
},true);
}
//Ajax保存,暂存:100,提交审核:200
function saveDecoration(submitStatus){
console.log(jsonMain);
common.util.__ajax({
url:'/shop/ShopsDecoratorRest/saveShopsDecorator',
data: {
"submitStatus": submitStatus,
"shopsId": jsonMain.shopsId,
"platform": jsonMain.platform,
"templateType": jsonMain.templateType,
"resources": JSON.stringify(jsonMain.resources)
}
},function(rs){
if(rs.data){
if(submitStatus == 100){
jsonMain = rs.data;
jsonClone = $.extend(true,{},jsonMain);
showMain();
}else{
setTimeout(function() {
location.href="/supplier/shop/decoration";
}, 1000);
}
}
});
}
//Ajax审核,审核通过:300,驳回:900
function checkDecoration(checkStatus,comment){
if(comment){ //驳回
common.util.__ajax({
url:'/shop/ShopsDecoratorRest/auditShopsDecorator',
data: {
"id": _id,
"checkStatus": checkStatus,
"comment": comment
}
},function(rs){
common.util.__tip("审核驳回成功!","success");
setTimeout(function() {
location.href="/supplier/check/index";
}, 1000);
},true);
}else{ //通过
common.util.__ajax({
url:'/shop/ShopsDecoratorRest/auditShopsDecorator',
data: {
"id": _id,
"checkStatus": checkStatus
}
},function(rs){
common.util.__tip("审核通过成功!","success");
setTimeout(function() {
location.href="/supplier/check/index";
}, 1000);
},true);
}
}
/********************工具类*********************/
//弹层表单grid生成器
function gridInit(id){
switch (id){
//基础模板顶部banner
case "editor-banner-base":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"店铺banner图片", render:function(item){
return "<input type=file name='shopBannerImage' id='shopBannerImage_"+item.__index+"' value='"+item.shopSrc+"' />";
}},
{display:"是否显示店铺名称", render:function(item){
if(item.isShowShopName == "Y"){
return "<lable><input type='radio' name='isShowShopName' value='Y' checked='checked'>显示店铺名称</lable><br>" +
"<lable><input type='radio' name='isShowShopName' value='N'>不显示店铺名称</lable>";
}else{
return "<lable><input type='radio' name='isShowShopName' value='Y'>显示店铺名称</lable><br>" +
"<lable><input type='radio' name='isShowShopName' value='N' checked='checked'>不显示店铺名称</lable>";
}
}},
{display:"商品详情页banner图片", render:function(item){
return "<input type=file name='DetailbannerImage' id='DetailbannerImage_"+item.__index+"' value='"+item.detailSrc+"' />";
}}
]
});
g.__rows=""||jsonClone.resources.shopTopBanner_base.data;
g.init(g.__rows);
break;
//经典模板顶部banner
case "editor-banner":
if(curPlatform == "pc"){
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"店铺banner图片", render:function(item){
return "<input type=file name='shopBannerImage' id='shopBannerImage_"+item.__index+"' value='"+item.shopSrc+"' />";
}},
{display:"是否显示店铺名称", render:function(item){
if(item.isShowShopName == "Y"){
return "<lable><input type='radio' name='isShowShopName' value='Y' checked='checked'>显示店铺名称</lable><br>" +
"<lable><input type='radio' name='isShowShopName' value='N'>不显示店铺名称</lable>";
}else{
return "<lable><input type='radio' name='isShowShopName' value='Y'>显示店铺名称</lable><br>" +
"<lable><input type='radio' name='isShowShopName' value='N' checked='checked'>不显示店铺名称</lable>";
}
}},
{display:"商品详情页banner图片", render:function(item){
return "<input type=file name='DetailbannerImage' id='DetailbannerImage_"+item.__index+"' value='"+item.detailSrc+"' />";
}}
]
});
g.__rows=""||jsonClone.resources.shopTopBanner.data;
}
if(curPlatform == "app"){
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"店铺banner图片", render:function(item){
return "<input type=file name='shopBannerImage' id='shopBannerImage_"+item.__index+"' value='"+item.shopSrc+"' />";
}},
{display:"是否显示店铺名称", render:function(item){
if(item.isShowShopName == "Y"){
return "<lable><input type='radio' name='isShowShopName' value='Y' checked='checked'>显示店铺名称</lable><br>" +
"<lable><input type='radio' name='isShowShopName' value='N'>不显示店铺名称</lable>";
}else{
return "<lable><input type='radio' name='isShowShopName' value='Y'>显示店铺名称</lable><br>" +
"<lable><input type='radio' name='isShowShopName' value='N' checked='checked'>不显示店铺名称</lable>";
}
}}
]
});
g.__rows=""||jsonClone.resources.shopTopBanner_APP.data;
}
g.init(g.__rows);
break;
//店铺导航nav
case "editor-nav":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"编号", render:function(item){
return item.__index+1;
}},
{display:"名称", render:function(item){
return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' maxlength='5' />";
}},
{display:"链接", render:function(item){
return "<input class='form-control inputChange urlInput' type=text name='url' value='"+(item.url).replace(/'/g,'\"')+"' data-index='"+item.__index+"' />";
}}
]
});
g.__rows=""||jsonClone.resources.navigationBar.data;
g.init(g.__rows);
break;
//店铺大图资源位
case "editor-largePic":
$('.editorTitle').html("<a href='javascript:' class='btn btn-success addBtn2' style='margin-right: 20px'><i class='fa fa-plus'></i> 添加资源大图</a><span class='largePicAddTip'></span>").css("margin-bottom","10px");
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"<div class='row'><div class='col-sm-2'>图片</div><div class='col-sm-3'>链接</div><div class='col-sm-2'>开始时间</div><div class='col-sm-2'>结束时间</div> " +
"<div class='col-sm-1'>状态</div><div class='col-sm-2'>操作</div></div>",
render: function (item) {
return resourcesHtmlInit(item,"largePic");
}
},
{display:"操作", render:function(item){
if(g.__rows.length > 1){
return "<input type=button class='btn btn-warning btn-xs deleteBtn' style='margin-top:6px' value='删除' data-index='"+item.__index+"' />";
}
}}
]
});
if(curPlatform == "pc"){
g.__rows=""||jsonClone.resources.largeSlideImg.data;
}
if(curPlatform == "app"){
g.__rows=""||jsonClone.resources.largeSlideImg_APP.data;
}
g.init(g.__rows);
break;
//店铺小图资源位
case "editor-smallPic":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{
display:"<div class='row'><div class='col-sm-2'>图片</div><div class='col-sm-3'>链接</div><div class='col-sm-2'>开始时间</div><div class='col-sm-2'>结束时间</div> " +
"<div class='col-sm-1'>状态</div><div class='col-sm-2'>操作</div></div>",
render: function (item) {
return resourcesHtmlInit(item,"smallPic");
}
}
]
});
if(curPlatform == "pc"){
g.__rows=""||jsonClone.resources.oneRowTwoColImages.data;
}
if(curPlatform == "app"){
g.__rows=""||jsonClone.resources.oneRowTwoColImages_APP.data;
}
g.init(g.__rows);
break;
//品牌一览
case "editor-brand":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"名称", render:function(item){
return item.brandName;
}},
]
});
g.__rows=""||jsonClone.resources.brandBrowse.data;
g.init(g.__rows);
break;
//经典推荐recommend
case "editor-recommend":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"名称", render:function(item){
return "<div style='width: 5%; float: left; line-height: 40px; color: #ff0000'>*</div><div style='width: 95%; float: left'>" +
"<input class='form-control inputChange' type=text name='name' value='"+item.name+"' placeholder='中文' data-index='"+item.__index+"' />" +
"<input class='form-control inputChange' style='margin-top:10px' type=text name='enName' value='"+item.enName+"' placeholder='英文' data-index='"+item.__index+"' />" +
"</div>";
}},
{display:"图片", render:function(item){
return "<input type=file name='recommendImage' id='recommendImage_"+item.__index+"' value='"+item.src+"' />";
}},
{display:"链接", render:function(item){
return "<input class='form-control inputChange urlInput' type=text name='url' value='"+(item.url).replace(/'/g,'\"')+"' data-index='"+item.__index+"' />";
}},
{display:"操作", render:function(item){
var htmlPic = "",i=item.__index;
if(g.__rows.length == 1){
htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
}
if(g.__rows.length > 1){
if(i == (g.__rows.length-1) && i < 15){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
}
if(i == (g.__rows.length-1) && i >= 15){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
}
if(i < (g.__rows.length-1)){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
}
}
return htmlPic;
}}
]
});
if(curPlatform == "pc"){
$('.editorTitle').html("<div class='form-inline' style='margin-bottom: 10px'><label>标题名称编辑:</label><input class='form-control' type=text name='title' value='"+ jsonMain.resources.recommend.title +"' /></div> ");
g.__rows=""||jsonClone.resources.recommend.data;
}
if(curPlatform == "app"){
g.__rows=""||jsonClone.resources.recommend_APP.data;
}
g.init(g.__rows);
break;
//热销推荐hotRecommend
case "editor-hotRecommend":
$('.editorTitle').html("<div class='form-inline' style='margin-bottom: 10px'><label>标题名称编辑:</label><input class='form-control' type=text name='title' value='"+ jsonMain.resources.hotRecommend.title +"' /></div> ");
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"图片", render:function(item){
return "<input type=file name='signboardImage' id='hotRecommendImage_"+item.__index+"' value='"+item.src+"' />";
}},
{display:"链接", render:function(item){
return "<input class='form-control inputChange urlInput' type=text name='url' value='"+(item.url).replace(/'/g,'\"')+"' data-index='"+item.__index+"' />";
}},
{display:"操作", render:function(item){
var htmlPic = "",i=item.__index;
if(g.__rows.length == 1){
htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
}
if(g.__rows.length > 1){
if(i == (g.__rows.length-1) && i < 5){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
}
if(i == (g.__rows.length-1) && i >= 5){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
}
if(i < (g.__rows.length-1)){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
}
}
return htmlPic;
}}
]
});
g.__rows=""||jsonClone.resources.hotRecommend.data;
g.init(g.__rows);
break;
//水牌signboard
case "editor-signboard":
$('.editorTitle').html("<a href='javascript:' class='btn btn-success addBtn2' style='margin-right: 20px'><i class='fa fa-plus'></i> 添加水牌</a><span class='largePicAddTip'></span>").css("margin-bottom","10px");
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"<div class='row'><div class='col-sm-2'>图片</div><div class='col-sm-3'>链接</div><div class='col-sm-2'>开始时间</div><div class='col-sm-2'>结束时间</div> " +
"<div class='col-sm-1'>状态</div><div class='col-sm-2'>操作</div></div>",
render: function (item) {
return resourcesHtmlInit(item,"signboard");
}
},
{display:"操作", render:function(item){
if(g.__rows.length > 1){
return "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' />";
}
}}
]
});
g.__rows=""||jsonClone.resources.signboard.data;
g.init(g.__rows);
break;
//新品上架标签tab
case "editor-newGoodTab":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
if(item.__index == 0){
return item.position;
}else{
item.position=item.position || (item.__index);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}
}},
{display:"名称", render:function(item){
if(item.__index == 0){
return item.name;
}else{
return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' maxlength='5' />";
}
}},
{display:"链接", render:function(item){
if(item.__index == 0){
return "http://店铺商品列表页(默认)";
}else{
return "<input class='form-control inputChange urlInput' type=text name='url' value='"+(item.url).replace(/'/g,'\"')+"' data-index='"+item.__index+"' />";
}
}},
{display:"操作", render:function(item){
var html = "";
if(item.__index == 0 && g.__rows.length == 1){
html += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
}else{
if(g.__rows.length > 1 && item.__index > 0){
html += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
if(g.__rows.length > 1 && g.__rows.length < 5 && item.__index == g.__rows.length - 1){
html += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
}
}
}
return html;
}}
]
});
g.__rows=""||jsonClone.resources.goodsTabBar.data.new;
g.init(g.__rows);
break;
//人气单品标签tab
case "editor-hotGoodTab":
g = new common.grid({
hash: false,
el:"#"+id,
columns:[
{display:"排序", render:function(item){
if(item.__index == 0){
return item.position;
}else{
item.position=item.position || (item.__index);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}
}},
{display:"名称", render:function(item){
if(item.__index == 0){
return item.name;
}else{
return "<input class='form-control inputChange' type=text name='name' value='"+item.name+"' data-index='"+item.__index+"' maxlength='5' />";
}
}},
{display:"链接", render:function(item){
if(item.__index == 0){
return "http://店铺商品列表页(默认)";
}else{
return "<input class='form-control inputChange urlInput' type=text name='url' value='"+(item.url).replace(/'/g,'\"')+"' data-index='"+item.__index+"' />";
}
}},
{display:"操作", render:function(item){
var html = "";
if(item.__index == 0 && g.__rows.length == 1){
html += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+item.__index+"' />";
}else{
if(g.__rows.length > 1 && item.__index > 0){
html += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
if(g.__rows.length > 1 && g.__rows.length < 5 && item.__index == g.__rows.length - 1){
html += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+item.__index+"' />";
}
}
}
return html;
}}
]
});
g.__rows=""||jsonClone.resources.goodsTabBar.data.hot;
g.init(g.__rows);
break;
//新品上架
case "editor-newProduct":
$("#"+id).html("<div id='editor-newProduct-grid' style='width: 50%; float:left;padding-left: 20px'></div><div class='top20List' style='float:left; padding-left:10%'></div> ");
g = new common.grid({
hash: false,
el:"#editor-newProduct-grid",
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"图片", render:function(item){
return "<img src='"+item.src+"' style='width:75px; height:80px'>";
}},
{display:"操作", render:function(item){
var html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
return html;
}}
]
});
g.__rows=""||jsonClone.resources.newProducts.data;
productTopDataShow(id, jsonMain.resources.allNewProducts); //右侧热销排名前20商品
g.init(g.__rows);
break;
//人气单品
case "editor-hotProduct":
$("#"+id).html("<div id='editor-hotProduct-grid' style='width: 50%; float:left;padding-left: 20px'></div><div class='top20List' style='float:left; padding-left:10%'></div> ");
g = new common.grid({
hash: false,
el:"#editor-hotProduct-grid",
columns:[
{display:"排序", render:function(item){
item.position=item.position || (item.__index+1);
return "<input class='form-control numInput inputChange' type=text name='position' value='"+item.position+"' data-index='"+item.__index+"' />";
}},
{display:"图片", render:function(item){
return "<img src='"+item.src+"' style='width:75px; height:80px'>";
}},
{display:"操作", render:function(item){
var html = "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+item.__index+"' /><br>";
return html;
}}
]
});
if(curPlatform == "pc"){
g.__rows=""||jsonClone.resources.hotProducts.data;
productTopDataShow(id, jsonMain.resources.allHotProducts); //右侧热销排名前20商品
}
if(curPlatform == "app"){
g.__rows=""||jsonClone.resources.hotProducts_APP.data;
productTopDataShow(id, jsonMain.resources.allHotProducts_APP); //右侧热销排名前20商品
}
g.init(g.__rows);
break;
default :
break;
}
}
//弹层表单确定后刷新json数据,status参数:1:确定,0:取消
function freshJson(id,data,status){
switch (id){
case "editor-banner-base":
if(status == 1){
data[0].isShowShopName = $("input[name='isShowShopName']:checked").val();
cloneArr(data,jsonMain.resources.shopTopBanner_base.data);
}else if(status == 0){
cloneArr(jsonMain.resources.shopTopBanner_base.data,data);
}
break;
case "editor-banner":
if(status == 1){
data[0].isShowShopName = $("input[name='isShowShopName']:checked").val();
if(curPlatform == "pc"){
cloneArr(data,jsonMain.resources.shopTopBanner.data);
if(jsonMain.resources.shopTopBanner_APP.isUsed == "N"){
cloneArr(data,jsonMain.resources.shopTopBanner_APP.data);
cloneArr(data,jsonClone.resources.shopTopBanner_APP.data);
}
}
if(curPlatform == "app"){
jsonMain.resources.shopTopBanner_APP.isUsed = "Y";
cloneArr(data,jsonMain.resources.shopTopBanner_APP.data);
}
}else if(status == 0){
if(curPlatform == "pc"){
cloneArr(jsonMain.resources.shopTopBanner.data,data);
}
if(curPlatform == "app"){
cloneArr(jsonMain.resources.shopTopBanner_APP.data,data);
}
}
break;
case "editor-nav":
if(status == 1){
cloneArr(data,jsonMain.resources.navigationBar.data);
}else if(status == 0){
cloneArr(jsonMain.resources.navigationBar.data,data);
}
break;
case "editor-largePic":
if(status == 1){
if(curPlatform == "pc"){
cloneArr(sortJson(data,1),jsonMain.resources.largeSlideImg.data);
if(jsonMain.resources.largeSlideImg_APP.isUsed == "N"){
cloneArr(sortJson(data,1),jsonMain.resources.largeSlideImg_APP.data);
cloneArr(sortJson(data,1),jsonClone.resources.largeSlideImg_APP.data);
removeUrlParam(id,jsonMain.resources.largeSlideImg_APP.data); //去除url
removeUrlParam(id,jsonClone.resources.largeSlideImg_APP.data);
}
}
if(curPlatform == "app"){
jsonMain.resources.largeSlideImg_APP.isUsed = "Y";
cloneArr(sortJson(data,1),jsonMain.resources.largeSlideImg_APP.data);
}
}else if(status == 0){
if(curPlatform == "pc"){
cloneArr(jsonMain.resources.largeSlideImg.data,data);
}
if(curPlatform == "app"){
cloneArr(jsonMain.resources.largeSlideImg_APP.data,data);
}
}
break;
case "editor-smallPic":
if(status == 1){
if(curPlatform == "pc"){
cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages.data);
if(jsonMain.resources.oneRowTwoColImages_APP.isUsed == "N"){
cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages_APP.data);
cloneArr(sortJson(data,1),jsonClone.resources.oneRowTwoColImages_APP.data);
removeUrlParam(id,jsonMain.resources.oneRowTwoColImages_APP.data); //去除url
removeUrlParam(id,jsonClone.resources.oneRowTwoColImages_APP.data);
}
}
if(curPlatform == "app"){
jsonMain.resources.oneRowTwoColImages_APP.isUsed = "Y";
cloneArr(sortJson(data,1),jsonMain.resources.oneRowTwoColImages_APP.data);
}
}else if(status == 0){
if(curPlatform == "pc"){
cloneArr(jsonMain.resources.oneRowTwoColImages.data,data);
}
if(curPlatform == "app"){
cloneArr(jsonMain.resources.oneRowTwoColImages_APP.data,data);
}
}
break;
case "editor-brand":
if(status == 1){
cloneArr(sortJson(data,1),jsonMain.resources.brandBrowse.data);
}else if(status == 0){
cloneArr(jsonMain.resources.brandBrowse.data,data);
}
break;
case "editor-recommend":
if(status == 1){
if(curPlatform == "pc"){
var title = $(".editorTitle input[name='title']").val();
jsonMain.resources.recommend.title = jsonClone.resources.recommend.title = title;
cloneArr(sortJson(data,1),jsonMain.resources.recommend.data);
if(jsonMain.resources.recommend_APP.isUsed == "N"){
cloneArr(sortJson(data,1),jsonMain.resources.recommend_APP.data);
cloneArr(sortJson(data,1),jsonClone.resources.recommend_APP.data);
removeUrlParam(id,jsonMain.resources.recommend_APP.data); //去除url
removeUrlParam(id,jsonClone.resources.recommend_APP.data);
}
}
if(curPlatform == "app"){
jsonMain.resources.recommend_APP.isUsed = "Y";
cloneArr(sortJson(data,1),jsonMain.resources.recommend_APP.data);
}
}else if(status == 0){
if(curPlatform == "pc"){
cloneArr(jsonMain.resources.recommend.data,data);
}
if(curPlatform == "app"){
cloneArr(jsonMain.resources.recommend_APP.data,data);
}
}
break;
case "editor-hotRecommend":
if(status == 1){
jsonMain.resources.hotRecommend.title = jsonClone.resources.hotRecommend.title = $(".editorTitle input[name='title']").val();
cloneArr(sortJson(data,1),jsonMain.resources.hotRecommend.data);
}else if(status == 0){
cloneArr(jsonMain.resources.hotRecommend.data,data);
}
break;
case "editor-signboard":
if(status == 1){
cloneArr(sortJson(data,1),jsonMain.resources.signboard.data);
}else if(status == 0){
cloneArr(jsonMain.resources.signboard.data,data);
}
break;
case "editor-newGoodTab":
if(status == 1){
cloneArr(sortJson(data,0),jsonMain.resources.goodsTabBar.data.new);
}else if(status == 0){
cloneArr(jsonMain.resources.goodsTabBar.data.new,data);
}
break;
case "editor-hotGoodTab":
if(status == 1){
cloneArr(sortJson(data,0),jsonMain.resources.goodsTabBar.data.hot);
}else if(status == 0){
cloneArr(jsonMain.resources.goodsTabBar.data.hot,data);
}
break;
case "editor-newProduct":
if(status == 1){
cloneArr(sortJson(data,1),jsonMain.resources.newProducts.data);
}else if(status == 0){
cloneArr(jsonMain.resources.newProducts.data,data);
}
break;
case "editor-hotProduct":
if(status == 1){
if(curPlatform == "pc"){
cloneArr(sortJson(data,1),jsonMain.resources.hotProducts.data);
if(jsonMain.resources.hotProducts_APP.isUsed == "N"){
cloneArr(sortJson(data,1),jsonMain.resources.hotProducts_APP.data);
cloneArr(sortJson(data,1),jsonClone.resources.hotProducts_APP.data);
}
}
if(curPlatform == "app"){
jsonMain.resources.hotProducts_APP.isUsed = "Y";
cloneArr(sortJson(data,1),jsonMain.resources.hotProducts_APP.data);
}
}else if(status == 0){
if(curPlatform == "pc"){
cloneArr(jsonMain.resources.hotProducts.data,data);
}
if(curPlatform == "app"){
cloneArr(jsonMain.resources.hotProducts_APP.data,data);
}
}
break;
default :
break;
}
}
//同步至APP按钮生成
function sendToAppBtmInit(id, json){
return {
value:"保存并同步至APP",
css:"btn-success",
callback: function(){
if(editorCheck(id)){
json.isUsed = "N";
freshJson(id, g.__rows, 1);
json.isUsed = "Y";
common.util.__tip("同步APP成功!","success");
showMain();
}else{
return false;
}
}
}
}
//pc端根据模块不同增加同步至APP按钮
function setSendToAppBtm(id, option){
switch (id){
case "editor-banner":
if(jsonMain.resources.shopTopBanner_APP.isUsed == "Y"){
option.button.push(sendToAppBtmInit(id, jsonMain.resources.shopTopBanner_APP));
}
return option;
break;
case "editor-largePic":
if(jsonMain.resources.largeSlideImg_APP.isUsed == "Y"){
option.button.push(sendToAppBtmInit(id, jsonMain.resources.largeSlideImg_APP));
}
return option;
break;
case "editor-smallPic":
if(jsonMain.resources.oneRowTwoColImages_APP.isUsed == "Y"){
option.button.push(sendToAppBtmInit(id, jsonMain.resources.oneRowTwoColImages_APP));
}
return option;
break;
case "editor-recommend":
if(jsonMain.resources.recommend_APP.isUsed == "Y"){
option.button.push(sendToAppBtmInit(id, jsonMain.resources.recommend_APP));
}
return option;
break;
case "editor-hotProduct":
if(jsonMain.resources.hotProducts_APP.isUsed == "Y"){
option.button.push(sendToAppBtmInit(id, jsonMain.resources.hotProducts_APP));
}
return option;
break;
default :
return option;
break;
}
}
//tip生成
function editorTipInit(id){
var tipHtml = "";
switch (id){
case "editor-banner-base":
tipHtml = "<span>提示:请上传像素1150*200的图片,图片大小不能超过500KB。</span>";
break;
case "editor-banner":
if(curPlatform == "pc"){
tipHtml = "<span>提示:请上传像素1150*200的图片,图片大小不能超过500KB。</span>";
}
if(curPlatform == "app"){
tipHtml = "<span>提示:请上传像素640*200的图片,图片大小不能超过500KB。</span>";
}
break;
case "editor-nav":
tipHtml = "<span>提示:标题名称最多5个汉字。</span>";
break;
case "editor-largePic":
tipHtml = "<span>提示:请上传像素660*358的图片,图片大小不能超过500KB。</span>";
break;
case "editor-smallPic":
if(curPlatform == "app"){
tipHtml = "<span>提示:请上传像素275*160的图片,图片大小不能超过500KB。</span>";
}else{
tipHtml = "<span>提示:请上传像素300*174的图片,图片大小不能超过500KB。</span>";
}
break;
case "editor-brand":
tipHtml = "<span>提示:内容会适配到APP的【品牌一览】中。</span>";
break;
case "editor-brand-app":
tipHtml = "<span>提示:【品牌一览】由PC端【品牌集合】适配,修改请到PC端【品牌集合】修改。</span>";
break;
case "editor-recommend":
tipHtml = "<span>提示:请上传像素150*150的图片,图片大小不能超过500KB。</span>";
break;
case "editor-signboard":
tipHtml = "<span>提示:请上传像素160*240的图片,图片大小不能超过500KB。</span>";
break;
case "editor-hotRecommend":
tipHtml = "<span>提示:请上传像素160*240的图片,图片大小不能超过500KB。</span>";
break;
case "editor-newGoodTab":
tipHtml = "<span>提示:最多编辑5个标签,标题名称最多5个汉字。</span>";
break;
case "editor-hotGoodTab":
tipHtml = "<span>提示:最多编辑5个标签,标题名称最多5个汉字。</span>";
break;
default :
break;
}
$(".editorTip").html(tipHtml);
}
//弹出框编辑校验
function editorCheck(id){
switch (id){
case "editor-nav":
return checkUrlInput();
break;
case "editor-largePic":
return (checkNumInput() && checkEndTime() && checkUrlInput());
break;
case "editor-smallPic":
return (checkNumInput() && checkEndTime() && checkUrlInput());
break;
case "editor-brand":
return checkNumInput();
break;
case "editor-recommend":
var title = $(".editorTitle input[name='title']");
if(title.length > 0 && title.val().trim() == ""){
title.focus().addClass("error");
common.util.__tip("模块标题不能为空!");
return false;
}
if(checkNumInput() && checkUrlInput()){
var nameList = $(".grid input[name='name']");
for(var i=0; i<nameList.length; i++){
if(!nameList.eq(i).val()){
nameList.eq(i).focus().addClass("error");
common.util.__tip("中文名不能为空!");
return false;
}
}
return true;
}
break;
case "editor-hotRecommend":
return (checkNumInput() && checkUrlInput());
break;
case "editor-signboard":
return (checkNumInput() && checkEndTime() && checkUrlInput());
break;
case "editor-newGoodTab":
return (checkNumInput() && checkUrlInput());
break;
case "editor-hotGoodTab":
return (checkNumInput() && checkUrlInput());
break;
case "editor-newProduct":
return checkNumInput();
break;
case "editor-hotProduct":
return checkNumInput();
break;
default :
return true;
break;
}
}
//排序序号校验
function checkNumInput(){
var positionList = $(".grid input[name='position']");
for(var i=0; i<positionList.length; i++){
if(positionList.eq(i).val()){
if(!isNaN(positionList.eq(i).val())){
if(positionList.eq(i).val() <= 0){
positionList.eq(i).focus().select().addClass("error");
common.util.__tip("排序数字请大于0!");
return false;
}
}else{
positionList.eq(i).focus().select().addClass("error");
common.util.__tip("排序必须为数字!");
return false;
}
}else{
positionList.eq(i).focus().addClass("error");
common.util.__tip("排序不能为空!");
return false;
}
}
return true;
}
//url域名校验
function checkUrlInput(){
var urlList = $(".grid input[name='url']");
for(var i=0; i<urlList.length; i++){
var reg = new RegExp(".+\.yoho[^.]*\.(com|cn).*","g");
if(urlList.eq(i).val() != ""){
if(!reg.test(urlList.eq(i).val())){
urlList.eq(i).focus().select().addClass("error");
common.util.__tip("Url必须包含yohobuy或者yoho,域名格式为com或者cn!");
return false;
}
}
}
return true;
}
//结束时间校验
function checkEndTime(){
var endTimeList = $(".grid input[name='endTime']");
for(var i=0; i<endTimeList.length; i++){
if(!endTimeList.eq(i).val()){
endTimeList.eq(i).focus().addClass("error");
common.util.__tip("结束时间不能为空!");
return false;
}
}
return true;
}
//编辑动画事件
function showEditorIconEvent(){
if(shopOperate == 'editor'){
$(".contentpanel .model-editor").hover(
function () {
var _this = $(this);
var editorModelId = $(this).attr("data-toggle");
var editorModelTitle = $(this).attr("data-title");
var editorIcon = "";
if(editorModelId == "editor-brand-app"){
editorIcon += "<div class='editorBorder' style='border: 5px solid #ff69b4'></div>"
}else{
editorIcon += "<div class='editorBorder'></div>"
}
editorIcon += "<a class='editorIcon' href='javascript:'>编辑</a>"
_this.append(editorIcon);
//编辑事件
editorIconEvent(editorModelTitle,editorModelId);
},
function () {
$(".editorIcon").remove();
$(".editorBorder").remove();
}
);
}
}
//工具类编辑表单初始化
function untilEditorEvent(id){
var e = new common.edit("#"+id,{bucket:"yhb-img02"});
e.init();
e.on("callback",function(obj){
if(/^file_onComplete_shopBannerImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_shopBannerImage_/,'');
g.__rows[_index].shopSrc = obj.data;
}
if(/^file_onComplete_DetailbannerImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_DetailbannerImage_/,'');
g.__rows[_index].detailSrc = obj.data;
}
if(/^file_onComplete_largePicImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_largePicImage_/,'');
var _indexList = _index.split("_");
g.__rows[_indexList[0]].data[_indexList[1]].src = obj.data;
}
if(/^file_onComplete_smallPicImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_smallPicImage_/,'');
var _indexList = _index.split("_");
g.__rows[_indexList[0]].data[_indexList[1]].src = obj.data;
}
if(/^file_onComplete_recommendImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_recommendImage_/,'');
g.__rows[_index].src = obj.data;
}
if(/^file_onComplete_hotRecommendImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_hotRecommendImage_/,'');
g.__rows[_index].src = obj.data;
}
if(/^file_onComplete_signboardImage_/.test(obj.key)){
var _index = obj.key.replace(/^file_onComplete_signboardImage_/,'');
var _indexList = _index.split("_");
g.__rows[_indexList[0]].data[_indexList[1]].src = obj.data;
}
});
$("#"+id+" nav").hide();
$(".modal-dialog .modal-header .close").hide();
$(".modal-dialog .modal-body .editor-dialog").css("overflow-y","auto");
$(".modal-dialog .modal-body .editor-dialog").css("overflow-x","hidden");
}
//资源位图片代码生成器
function resourcesHtmlInit(item,resName){
var picList = item.data,
htmlPic = "";
for(var i=0; i<picList.length; i++){
picList[i].url=picList[i].url.replace(/'/g,'\"'); // 字符串里面双引号转换成单引号
htmlPic += "<div class='row'>" +
"<div class='col-sm-2'><input type=file name='"+ resName +"Image' id='"+ resName +"Image_"+item.__index+"_"+i+"' value='"+picList[i].src+"' /></div>" +
"<div class='col-sm-3'><input type=text class='form-control inputChange urlInput' name='url' value='"+picList[i].url+"' data-index='"+item.__index+"_"+i+"' /></div>" +
"<div class='col-sm-2'>";
if(i>0){
htmlPic += "<input type=text class='form-control' disabled jsaction='time:end:endTime_"+item.__index+"_"+ i +"' id='startTime_"+item.__index+"_"+ i +"' name='startTime' value='"+ picList[i].startTime +"' />" +
"<span style='color: #999; font-size: 12px'>*上一条结束时间</span>";
}else{
htmlPic += "<input type=text class='form-control inputChange' style='background-color:#fff' readOnly='true' jsaction='time:end:endTime_"+item.__index+"_"+ i +"' id='startTime_"+item.__index+"_"+ i +"' name='startTime' value='"+ picList[i].startTime +"' data-index='"+ item.__index +"_"+ i +"' />";
}
htmlPic += "</div><div class='col-sm-2'>" +
"<input type=text class='form-control inputChange' style='background-color:#fff' readOnly='true' jsaction='time:start:startTime_"+item.__index+"_"+ i +"' id='endTime_"+item.__index+"_"+ i +"' name='endTime' value='"+ picList[i].endTime +"' data-index='"+ item.__index +"_"+ i +"' /></div>" +
"<div class='col-sm-1'><span class='publishStatus' style='white-space: nowrap; line-height: 40px'>"+ checkdate(picList[i].startTime,picList[i].endTime) +"</span></div>" +
"<div class='col-sm-2' style='line-height: 40px'>";
if(i == (picList.length-1) && picList.length > 1){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+ item.__index +"_"+ i +"' /><br>";
htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' style='margin-top: 10px' value='添加一条' data-index='"+ item.__index +"_"+ i +"' />";
}
if(i < (picList.length-1) && picList.length > 1){
htmlPic += "<input type=button class='btn btn-danger btn-xs deleteBtn' value='删除' data-index='"+ item.__index +"_"+ i +"' />";
}
if(i == (picList.length-1) && picList.length == 1){
htmlPic += "<input type=button class='btn btn-info btn-xs addBtn' value='添加一条' data-index='"+ item.__index +"_"+ i +"' />";
}
htmlPic += "</div></div>";
}
return htmlPic;
}
//展示最新,最热排名前20条
function productTopDataShow(id, products){
if(products.data && products.data.length > 0){
$("#"+id+" .top20List").html(common.util.__template2($("#top20Products").html(),products));
productTopDataLink(g.__rows);
}else{
$("#"+id+" .top20List").html("<font color='red'>*&nbsp;&nbsp;最新上架20条加载失败,请重新加载页面!</font>");
}
}
//top20商品根据以展示商品自动勾选
function productTopDataLink(productList){
$(".top20List li").removeClass("selected");
for(var i=0; i<productList.length; i++){
var productId = productList[i].productId;
$(".top20List").find("li[data-productId = "+ productId +"]").addClass("selected");
}
$(".topTip span").text("已经勾选"+ productList.length +"件,最多勾选8件商品!");
}
//json数组排序, dis参数:0:从小到大,1:从大到小
function sortJson(arr,dir){
var len = arr.length, tmp;
for(var i=0; i < len-1; i++){
if(dir == 0){
for(var j=0; j < len-1-i; j++){
if(parseInt(arr[j].position) > parseInt(arr[j+1].position)){
tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
}
if(dir == 1){
for(var j=0; j < len-1-i; j++){
if(parseInt(arr[j].position) < parseInt(arr[j+1].position)){
tmp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = tmp;
}
}
}
}
return arr;
}
//数组克隆
function cloneArr(arr1,arr2){
arr2.length = 0;
for(var i=0; i<arr1.length; i++){
arr2.push($.extend(true,{},arr1[i]));
}
return arr2;
}
//时间校验
function checkdate(startDate,endDate){
if (endDate) {
var endDateTemp = endDate.split(" ");
var arrEndDate = endDateTemp[0].split("-");
var arrEndTime = endDateTemp[1].split(":");
var allEndDate = new Date(arrEndDate[0], parseInt(arrEndDate[1])-1, arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);
}
if(startDate){
var startDateTemp = startDate.split(" ");
var arrStartDate = startDateTemp[0].split("-");
var arrStartTime = startDateTemp[1].split(":");
var allStartDate = new Date(arrStartDate[0], parseInt(arrStartDate[1])-1, arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
}
var nowDate = new Date();
if(startDate && endDate){
if(nowDate > allEndDate) {
return "<b style='color: #ec971f'>已过期</b>";
}else if(allStartDate > nowDate){
return "<b style='color: #428bca'>未发布</b>";
}else{
return "<b style='color: #5cb85c'>发布中</b>";
}
}else if(!startDate && endDate){
if(nowDate > allEndDate) {
return "<b style='color: #ec971f'>已过期</b>";
}else{
return "<b style='color: #5cb85c'>发布中</b>";
}
}else{
return "<b style='color: #428bca'>未发布</b>";
}
return true;
}
//去除json中的url参数
function removeUrlParam(id, data){
if(id == "editor-largePic" || id == "editor-smallPic"){
for(var i=0; i<data.length; i++){
var data2 = data[i].data;
for(var j=0; j<data2.length; j++){
data2[j].url = "";
}
}
}
if(id == "editor-recommend"){
for(var i=0; i<data.length; i++){
data[i].url = "";
}
}
}
/********************事件绑定*********************/
//基础模板,经典模板切换
$(document).on("click",".tabheader .nav-tabs li",function(){
$(this).addClass('active').siblings('li').removeClass('active');
curTemplateType = $(this).attr("data-toggle");
showMain();
})
//pc,app切换
$(document).on("click","input[name=brandLevel]",function(){
curPlatform = $("input[name=brandLevel]:checked").val();
showMain();
})
//暂存模板
$(document).on("click","#saveModule",function(){
saveDecoration(100);
})
//提交审核
$(document).on("click","#submitModule",function(){
jsonMain.templateType = curTemplateType;
var templateName = curTemplateType=='2'?"经典模板":"基础模板";
common.dialog.confirm(
"提交审核确认",
"你确认使用<strong style='color:#5cb85c'>"+ templateName + "</strong>,并提交审核么?审核过程中,店铺装修将无法修改!",
function(){
saveDecoration(200);
},
function(){}
)
})
//审核通过
$(document).on("click","#checkOk",function(){
common.dialog.confirm(
"审核确认",
"你确认<strong style='color:#5cb85c'>审核通过</strong>么?",
function(){
checkDecoration(300);
},
function(){}
);
})
//驳回
$(document).on("click","#checkNo",function(){
common.dialog.confirm(
"审核驳回",
"你确认<strong style='color:#d9534f'>审核驳回</strong>么?如果确认,<strong style='color: #f0ad4e'>请填写驳回理由!</strong>" +
"<textarea id='checkComment' class='form-control' rows='3' style='margin: 10px 0'></textarea>" +
"<div class='editorTip' style='display: none'><span>提示:请填写驳回理由!</span></div>",
function(){
var comment = $("#checkComment").val();
if(comment){
checkDecoration(900,comment);
}else{
$(".editorTip").show();
return false;
}
},
function(){}
);
})
//删除
$(document).on("click",".deleteBtn",function(){
var _index = $(this).data("index")+"";
var indexList = _index.split("_");
if(indexList.length > 1){
[].splice.call(g.__rows[indexList[0]].data,indexList[1],1);
}else{
[].splice.call(g.__rows,indexList[0],1);
}
g.init(g.__rows);
untilEditorEvent(curDialogId);
if(curDialogId == "editor-newProduct" || curDialogId == "editor-hotProduct"){
productTopDataLink(g.__rows);
}
});
//添加一条
$(document).on("click",".addBtn",function(){
var _index = $(this).data("index")+"";
var indexList = _index.split("_");
if(indexList.length > 1){
g.__rows[indexList[0]].data.push($.extend({},ENUM[curDialogId]));
if(curDialogId == "editor-largePic" || curDialogId == "editor-smallPic" || curDialogId == "editor-signboard"){
(g.__rows[indexList[0]].data)[(parseInt(indexList[1]) + 1)].startTime = (g.__rows[indexList[0]].data)[indexList[1]].endTime;
}
}else{
g.__rows.push($.extend({},ENUM[curDialogId]));
}
g.init(g.__rows);
untilEditorEvent(curDialogId);
});
//资源位大图,水牌添加一条资源位
$(document).on("click",".addBtn2",function(){
if( curDialogId == "editor-largePic" && g.__rows.length > 4){
$(".largePicAddTip").text("* 最多只能添加5个资源位大图!").css("color","#ff0000");
return;
}else{
$(".largePicAddTip").empty();
g.__rows.push($.extend(true,{},ENUM["editor-largePic2"]));
g.init(g.__rows);
untilEditorEvent(curDialogId);
}
});
//input change同时更新json
$(document).on("change",".inputChange",function(){
var _index = $(this).attr("data-index");
var indexList = _index.split("_");
var _name = $(this).attr("name");
if(indexList.length > 1){
(g.__rows[indexList[0]].data)[indexList[1]][_name] = $(this).val();
}else{
g.__rows[indexList[0]][_name] = $(this).val();
}
if(curDialogId == "editor-largePic" || curDialogId == "editor-smallPic" || curDialogId == "editor-signboard"){
if($(this).attr("name") == "endTime"){
if(g.__rows[indexList[0]].data.length - 1 > indexList[1]){
(g.__rows[indexList[0]].data)[(parseInt(indexList[1]) + 1)].startTime = $(this).val();
$(this).parents(".row").next().children().find("input[name='startTime']").val($(this).val());
var endDate = $(this).parents(".row").next().children().find("input[name='endTime']").val();
$(this).parents(".row").next().children().find(".publishStatus").html(checkdate($(this).val(),endDate));
}
var startDate = $(this).parents(".row").find("input[name='startTime']").val();
$(this).parents(".row").find(".publishStatus").html(checkdate(startDate,$(this).val()));
}
if($(this).attr("name") == "startTime"){
var endDate = $(this).parents(".row").find("input[name='endTime']").val();
$(this).parents(".row").find(".publishStatus").html(checkdate($(this).val(),endDate));
}
}
$(this).removeClass("error");
});
//选择Top20
$(document).on("click",".topAdd",function(){
if($(this).hasClass("selected")){
$(this).removeClass("selected");
var cutProductId = $(this).attr("data-productId");
for(var i=0; i<g.__rows.length; i++){
if(g.__rows[i].productId == cutProductId){
[].splice.call(g.__rows,i,1);
break;
}
}
g.init(g.__rows);
untilEditorEvent(curDialogId);
productTopDataLink(g.__rows);
}else{
if(g.__rows.length < 8){
$(this).addClass("selected");
var item = $.extend({},ENUM[curDialogId]);
item.src = $(this).find('img').attr("src");
item.productId = $(this).attr("data-productId");
item.productName = $(this).attr("data-productName");
item.salesPrice = $(this).attr("data-productPrice");
item.productSkn = $(this).attr("data-productSkn");
item.goodsId = $(this).attr("data-goodsId");
item.cnAlphabet = $(this).attr("data-cnAlphabet");
g.__rows.push(item);
g.init(g.__rows);
untilEditorEvent(curDialogId);
productTopDataLink(g.__rows);
}else{
$(".topTip span").text("商品数量已满8个,无法继续添加商品!");
}
}
});
\ No newline at end of file