Authored by 姜敏

资源位-品牌管理

... ... @@ -21,60 +21,11 @@ var Bll={
Brands: [],
Brands1: {},
Brdata: [],
//获取品牌
getBrands: function() {
var Brand = {};
$.get("/ajax/yohosearch", function(res) {
res.data.forEach(function(item, index) {
var brandAlif = (item.brand_alif || "").toUpperCase();
if (/^[0-9]$/.test(item.brand_alif)) {
brandAlif = "0-9";
}
if (/^\W$/.test(item.brand_alif)) {
brandAlif = "#";
}
Brand[brandAlif] = Brand[brandAlif] || [];
Brand[brandAlif].push(item);
Bll.Brands1[item.id] = item;
});
for (var i in Brand) {
Brand[i].sort(function(a, b) {
var aName = a.brand_name.toLowerCase(),
bName = b.brand_name.toLowerCase();
if (aName < bName) return -1;
if (aName > bName) return 1;
return 0;
});
Bll.Brands.push({
name: i,
items: Brand[i]
});
}
});
},
renderBrandPic: function(Brdata) {
var Brands2 = [];
Brdata.forEach(function(item, index) {
if(!item.brandIco){
var a = Bll.Brands1[item.id]
a.brandIco = common.util.__joinImg("brandLogo", a.brand_ico)
Brands2.push(a);
}else{
item.brandIco=common.util.__template(item.brandIco,{width:110,height:150});
Brands2.push(item);
}
});
$("#addBrands").parent("div").parent("li").prevAll().remove();
$("#addPic").prepend(common.util.__template2($("#template3").html(), {
Brands: Brands2
}));
},
contentDatas:[],
module: null,
__render:function(selecter,templater,data){
$(selecter).html(common.util.__template2($("#"+templater).html(),data) );
},
contentDatas:[],
module: null,
toast: function(index, module) {
var d = new common.dialog({
title: (!!~index ? "修改" : "添加") + module.contentData.template_intro,
... ... @@ -115,8 +66,76 @@ var Bll={
}
});
},
//获取品牌
getBrands: function() {
var Brand = {};
$.get("/ajax/yohosearch", function(res) {
res.data.forEach(function(item, index) {
var brandAlif = (item.brand_alif || "").toUpperCase();
if (/^[0-9]$/.test(item.brand_alif)) {
brandAlif = "0-9";
}
if (/^\W$/.test(item.brand_alif)) {
brandAlif = "#";
}
Brand[brandAlif] = Brand[brandAlif] || [];
Brand[brandAlif].push(item);
Bll.Brands1[item.id] = item;
});
for (var i in Brand) {
Brand[i].sort(function(a, b) {
var aName = a.brand_name.toLowerCase(),
bName = b.brand_name.toLowerCase();
if (aName < bName) return -1;
if (aName > bName) return 1;
return 0;
});
Bll.Brands.push({
name: i,
items: Brand[i]
});
}
});
},
renderBrandPic: function(Brdata) {
var Brands2 = [];
Brdata.forEach(function(item, index) {
if(!item.brandIco){
var a = Bll.Brands1[item];
a.brandIco = common.util.__joinImg("brandLogo", a.brand_ico);
Brands2.push(a);
}else{
item.brandIco=common.util.__template(item.brandIco,{width:110,height:150});
Brands2.push(item);
}
});
Bll.module=Bll.module||{};
Bll.module.contentData=Bll.module.contentData||{};
Bll.module.contentData.data=Bll.module.contentData.data||{};
Bll.module.contentData.data.list=Bll.module.contentData.data.list||[];
for(var i=0;i<Brands2.length;i++){
var pic={};
if( Bll.module.contentData.template_name=="kidsBrands"){
pic={
"src":Brands2[i].brandIco,
"id":Brands2[i].id,
"title":Brands2[i].brand_name
};
}else{
pic={
"src":Brands2[i].brandIco,
"id":Brands2[i].id,
"name":Brands2[i].brand_name
};
}
Bll.module.contentData.data.list.push(pic);
}
Bll.renderDialog("brands-template");
}
}
};
... ... @@ -177,9 +196,13 @@ $(document).on("click", ".edit", function() {
$(document).on("change", ".observe", function() {
var $this = $(this);
var name = $this.data("field");
console.log("name");
console.log(name);
Bll.module.contentData.data=common.util.__buildobj(name, '.', Bll.module.contentData.data, function(obj, name) {
obj[name] = $this.val();
});
console.log("Bll.module.contentData.data");
console.log(Bll.module.contentData.data);
});
$(document).on("click", '#multiLabelImage-addImage', function() {
... ... @@ -251,24 +274,23 @@ Bll.renderBrandPic(Bll.Brdata);
//打开品牌选择模态
$(document).on("click", "#addBrands", function() {
var e = new common.edit("#brandForm");
console.log("BLL",Bll);
console.log("Bll.Brands",Bll.Brands);
console.log("Bll.Brdata",Bll.Brdata);
common.dialog.confirm("选择品牌", common.util.__template2($("#template5").html(), {
Brands: Bll.Brands,
Brdata: Bll.Brdata.join('|')
Brands: Bll.Brands,//所有品牌数据
Brdata: []
}), function() {
//todo
Bll.Brdata = $("#brandCheckBox").val().split('|');
Bll.Brdata = Bll.Brdata.map(function(item, index) {
return {
"brandCategory": "1",
"id": item
}
});
Bll.renderBrandPic(Bll.Brdata);
});
e.init();
});
//删除一个品牌
$(document).on("click", '#remove_brand', function() {
var index = $(this).data("index");
Bll.module.contentData.data.list.splice(index,1);
Bll.renderDialog("brands-template");
});
/*自定义参数*/
$(document).on("click", '.paramsGroupDel', function() {
console.log($(this).data("index"));
... ...
... ... @@ -26,6 +26,7 @@
data-field="[[index]].url.action">
[[layout action_template]]
</select>
<div class="col-sm-1"></div>
<input value="[[item.url.url]]" class=" col-sm-4 observe" required="required"
data-field="[[index]].url.url" placeholder="图片链接"/>
... ... @@ -36,11 +37,11 @@
<input value="[[item.alt]]" class="col-sm-4 observe" required="required"
data-field="[[index]].alt" placeholder="图片描述"/>
<div class="col-sm-1"></div>
[[if contentData.template_name=='addfloor']]
<div class="col-sm-1"></div>
[[if contentData.template_name=='addfloor']]
<input value="[[item.altEn]]" class="col-sm-4 observe" required="required"
data-field="list.[[index]].altEn" placeholder="英文描述"/>
[[/if]]
[[/if]]
</div>
</td>
<td>
... ... @@ -56,48 +57,49 @@
</script>
<!-- 推荐品牌-->
<script type="text/template" id="brands-template">
<div class="rows" id="brands1">
<div class="rows">
[[if contentData.template_name=='appHotBrands']]
<div class="form-group col-sm-12">
<label class="col-sm-1 control-label">标题</label>
<input class="col-sm-2" type="text" value="[[contentData.data.title.title]]"
<input class="col-sm-2 observe" type="text" value="[[contentData.data.title.title]]"
data-field="title.title" placeholder="推荐品牌">
<label class="col-sm-1 control-label">显示名称</label>
<div class="col-sm-2 ">
<label style="cursor: pointer;"><input type="radio" name="is_show_name" value="Y"></label>
<label style="cursor: pointer;"><input type="radio" name="is_show_name" value="N"></label>
<div class="col-sm-2 observe">
<label style="cursor: pointer;"><input type="radio" name="is_show_name" value="Y"></label>
<label style="cursor: pointer;"><input type="radio" name="is_show_name" value="N"></label>
</div>
<input type="hidden" id="is_show_name" value="[[contentData.data.is_show_name]]"
data-field="is_show_name" for="radio" />
<input type="hidden" id="is_show_name" value="[[contentData.data.is_show_name]]" class="observe"
data-field="is_show_name" for="radio"/>
</div>
[[/if]]
[[if contentData.template_name=='customBrands']]
<div class="form-group col-sm-12">
<label class="col-sm-1 control-label">标题</label>
<input class="col-sm-2 " type="text" value="[[contentData.data.title.title]]"
<input class="col-sm-2 observe" type="text" value="[[contentData.data.title.title]]"
data-field="title.title" placeholder="自定义品牌">
<label class="col-sm-1 control-label">附加参数</label>
<select class="col-sm-2 " value="[[contentData.data.title.param]]">
<option value="-1">请选择附加参数</option>
<option value="1">大分类</option>
</select>
<label class="col-sm-1 control-label">附加参数值</label>
<input class="col-sm-2" type="text" value="[[contentData.data.title.param_value]]"
<select class="col-sm-2 " value="[[contentData.data.title.param]]">
<option value="-1">请选择附加参数</option>
<option value="1">大分类</option>
</select>
<label class="col-sm-2 control-label">附加参数值</label>
<input class="col-sm-2 observe" type="text" value="[[contentData.data.title.param_value]]"
data-field="title.param_value" placeholder="附加参数值">
</div>
[[/if]]
[[if contentData.template_name=='kidsBrands']]
<div class="form-group col-sm-12">
<label class="col-sm-1 control-label">标题</label>
<input class="col-sm-2 " type="text" value="[[contentData.data.params.title]]"
<input class="col-sm-2 observe" type="text" value="[[contentData.data.params.title]]"
data-field="params.title">
<label class="col-sm-1 control-label">分类</label>
<select class="col-sm-2 " value="[[contentData.data.params.param]]" data-field="params.param">
<option value="-1">请选择附加参数</option>
<option value="1">大分类</option>
<option value="-1">促销id</option>
<option value="1">大分类ID</option>
</select>
<label class="col-sm-1 control-label">附加参数值</label>
<input class="col-sm-2 " type="text" value="[[contentData.data.params.paramValue]]"
<label class="col-sm-2 control-label">附加参数值</label>
<input class="col-sm-2 observe" type="text" value="[[contentData.data.params.paramValue]]"
data-field="params.paramValue" placeholder="附加参数值">
</div>
<div class="form-group col-sm-12">
... ... @@ -113,22 +115,41 @@
<p style="color:#999;margin-top: 5px;">注:链接中不能有英文单引号</p>
</div>
[[/if]]
<div class="form-group">
<label class="col-sm-2 control-label">添加品牌:</label>
<div class="col-sm-8">
<ul class="cover-image-list col-sm-10" id="addPic" style="padding: 0;margin: 0;">
<li class="cover-image-item fileinput-button">
<div class="goods-img">
<a class="fileinput-button-icon" href="javascript:void(0);" id="addBrands">+</a>
</div>
</li>
</ul>
</div>
</div>
<div class="panel-body">
<div>
<table class="table table-hover table-bordered responsive dataTable no-footer">
<thead>
<tr>
<th>品牌图标</th>
<th>品牌名称</th>
<th>操作</th>
</tr>
</thead>
<tbody>
[[each contentData.data.list as item index]]
<tr>
<td><input type="file" name="file" value="[[item.src]]" class="observe" data-field="[[index]].src"/>
</td>
<td>
[[if contentData.template_name=='kidsBrands']]
<input class="col-sm-8 observe" type="text" value="[[item.title]]"
data-field="[[index]].title">
[[else]]
<input class="col-sm-8 observe" type="text" value="[[item.name]]" data-field="[[index]].name">
[[/if]]
</td>
<td>
<a class="btn btn-danger" id="remove_brand" data_index="[[index]]">删除</a>
</td>
</tr>
[[/each]]
</tbody>
</table>
</div>
<a href="JavaScript:;" id="addBrands" class="btn btn-primary btn-xs">添加品牌</a>
</div>
<div id="brands2">
</div>
</script>
<!--品牌选择模态-->
... ... @@ -151,22 +172,6 @@
</div>
[[/each]]
</div>
<input type="hidden" id="brandCheckBox" for="checkbox" value="[[Brdata]]" />
<input type="hidden" id="brandCheckBox" for="checkbox" value="[[Brdata]]"/>
</div>
</script>
<script type="text/template" id="template3">
[[each Brands as brand index]]
<li class="cover-image-item image-list" data-index="2">
<div class="goods-img">
<a class="fileinput-button-icon" href="javascript:void(0);">
<img src="[[brand.brandIco]]">
</a>
<i class="remove-item-btn remove1 glyphicon glyphicon-remove-circle" data-index="[[index]]"></i>
</div>
<div class="col-sm-12">
<label class="col-sm-6">图片名称</label>
<input class="col-sm-6" type="text" value="[[brand.title]]" data-field="brand.title">
</div>
</li>
[[/each]]
</script>
\ No newline at end of file
... ...