Authored by 姜敏

资源位-品牌初步

1 var $ = require('jquery'), 1 var $ = require('jquery'),
2 common = require('../common/common'); 2 common = require('../common/common');
3 -  
4 var Button=require('./partials/Button1'); 3 var Button=require('./partials/Button1');
5 4
6 /*获取数据*/ 5 /*获取数据*/
@@ -18,8 +17,59 @@ common.util.__ajax({ @@ -18,8 +17,59 @@ common.util.__ajax({
18 var edit = new common.edit(".modal-body", { 17 var edit = new common.edit(".modal-body", {
19 bucket: "goodsimg" 18 bucket: "goodsimg"
20 }); 19 });
21 -  
22 var Bll={ 20 var Bll={
  21 + Brands: [],
  22 + Brands1: {},
  23 + Brdata: [],
  24 + //获取品牌
  25 + getBrands: function() {
  26 + var Brand = {};
  27 + $.get("/ajax/yohosearch", function(res) {
  28 + res.data.forEach(function(item, index) {
  29 + var brandAlif = (item.brand_alif || "").toUpperCase();
  30 + if (/^[0-9]$/.test(item.brand_alif)) {
  31 + brandAlif = "0-9";
  32 + }
  33 + if (/^\W$/.test(item.brand_alif)) {
  34 + brandAlif = "#";
  35 + }
  36 + Brand[brandAlif] = Brand[brandAlif] || [];
  37 + Brand[brandAlif].push(item);
  38 + Bll.Brands1[item.id] = item;
  39 + });
  40 + for (var i in Brand) {
  41 + Brand[i].sort(function(a, b) {
  42 + var aName = a.brand_name.toLowerCase(),
  43 + bName = b.brand_name.toLowerCase();
  44 + if (aName < bName) return -1;
  45 + if (aName > bName) return 1;
  46 + return 0;
  47 + });
  48 + Bll.Brands.push({
  49 + name: i,
  50 + items: Brand[i]
  51 + });
  52 + }
  53 + });
  54 + },
  55 + renderBrandPic: function(Brdata) {
  56 + var Brands2 = [];
  57 + Brdata.forEach(function(item, index) {
  58 + if(!item.brandIco){
  59 + var a = Bll.Brands1[item.id]
  60 + a.brandIco = common.util.__joinImg("brandLogo", a.brand_ico)
  61 + Brands2.push(a);
  62 + }else{
  63 + item.brandIco=common.util.__template(item.brandIco,{width:110,height:150});
  64 + Brands2.push(item);
  65 + }
  66 +
  67 + });
  68 + $("#addBrands").parent("div").parent("li").prevAll().remove();
  69 + $("#addPic").prepend(common.util.__template2($("#template3").html(), {
  70 + Brands: Brands2
  71 + }));
  72 + },
23 __render:function(selecter,templater,data){ 73 __render:function(selecter,templater,data){
24 $(selecter).html(common.util.__template2($("#"+templater).html(),data) ); 74 $(selecter).html(common.util.__template2($("#"+templater).html(),data) );
25 }, 75 },
@@ -193,6 +243,32 @@ $(document).on("click", '#icon-delOne', function() { @@ -193,6 +243,32 @@ $(document).on("click", '#icon-delOne', function() {
193 Bll.module.contentData.data.splice(index,1); 243 Bll.module.contentData.data.splice(index,1);
194 Bll.renderDialog("icon-template"); 244 Bll.renderDialog("icon-template");
195 }); 245 });
  246 +//获取品牌
  247 +Bll.getBrands();
  248 +/*渲染品牌*/
  249 +Bll.Brdata=ViewModel.brandList||[];
  250 +Bll.renderBrandPic(Bll.Brdata);
  251 +//打开品牌选择模态
  252 +$(document).on("click", "#addBrands", function() {
  253 + var e = new common.edit("#brandForm");
  254 + console.log("BLL",Bll);
  255 + console.log("Bll.Brands",Bll.Brands);
  256 + common.dialog.confirm("选择品牌", common.util.__template2($("#template5").html(), {
  257 + Brands: Bll.Brands,
  258 + Brdata: Bll.Brdata.join('|')
  259 + }), function() {
  260 + //todo
  261 + Bll.Brdata = $("#brandCheckBox").val().split('|');
  262 + Bll.Brdata = Bll.Brdata.map(function(item, index) {
  263 + return {
  264 + "brandCategory": "1",
  265 + "id": item
  266 + }
  267 + });
  268 + Bll.renderBrandPic(Bll.Brdata);
  269 + });
  270 + e.init();
  271 +});
196 /*自定义参数*/ 272 /*自定义参数*/
197 $(document).on("click", '.paramsGroupDel', function() { 273 $(document).on("click", '.paramsGroupDel', function() {
198 console.log($(this).data("index")); 274 console.log($(this).data("index"));
@@ -22,31 +22,26 @@ @@ -22,31 +22,26 @@
22 </td> 22 </td>
23 <td> 23 <td>
24 <div class="col-sm-12"> 24 <div class="col-sm-12">
25 - <label class="col-sm-2">跳转目的</label>  
26 - <select name="goTo" class="form-control observe" value="[[item.url.action]]" 25 + <select name="goTo" class="col-sm-4 observe" value="[[item.url.action]]"
27 data-field="[[index]].url.action"> 26 data-field="[[index]].url.action">
28 [[layout action_template]] 27 [[layout action_template]]
29 </select> 28 </select>
30 - </div>  
31 - <div class="col-sm-12">  
32 - <label class="col-sm-2">图片链接</label>  
33 - <input value="[[item.url.url]]" class="form-control observe" required="required"  
34 - data-field="[[index]].url.url"/> 29 + <div class="col-sm-1"></div>
  30 + <input value="[[item.url.url]]" class=" col-sm-4 observe" required="required"
  31 + data-field="[[index]].url.url" placeholder="图片链接"/>
35 32
36 - <p style="color:#999;margin-top: 5px;">注:链接中不能有英文单引号</p> 33 + <p style="color:#999;margin-top: 5px;">链接中不能有英文单引号</p>
37 </div> 34 </div>
38 <div class="col-sm-12"> 35 <div class="col-sm-12">
39 - <label class="col-sm-2">图片描述</label>  
40 - <input value="[[item.alt]]" class="form-control observe" required="required"  
41 - data-field="[[index]].alt"/>  
42 - </div> 36 + <input value="[[item.alt]]" class="col-sm-4 observe" required="required"
  37 + data-field="[[index]].alt" placeholder="图片描述"/>
  38 +
  39 + <div class="col-sm-1"></div>
43 [[if contentData.template_name=='addfloor']] 40 [[if contentData.template_name=='addfloor']]
44 - <div class="col-sm-12">  
45 - <label class="col-sm-2">英文描述</label>  
46 - <input value="[[item.altEn]]" class="form-control observe" required="required"  
47 - data-field="list.[[index]].altEn"/>  
48 - </div> 41 + <input value="[[item.altEn]]" class="col-sm-4 observe" required="required"
  42 + data-field="list.[[index]].altEn" placeholder="英文描述"/>
49 [[/if]] 43 [[/if]]
  44 + </div>
50 </td> 45 </td>
51 <td> 46 <td>
52 <a class="btn btn-danger" id="icon-delOne" data_index="[[index]]">删除</a> 47 <a class="btn btn-danger" id="icon-delOne" data_index="[[index]]">删除</a>
@@ -58,4 +53,120 @@ @@ -58,4 +53,120 @@
58 </div> 53 </div>
59 <a href="JavaScript:;" id="icon-addOne" class="btn btn-primary btn-xs">添加一个</a> 54 <a href="JavaScript:;" id="icon-addOne" class="btn btn-primary btn-xs">添加一个</a>
60 </div> 55 </div>
  56 +</script>
  57 +<!-- 推荐品牌-->
  58 +<script type="text/template" id="brands-template">
  59 + <div class="rows" id="brands1">
  60 + [[if contentData.template_name=='appHotBrands']]
  61 + <div class="form-group col-sm-12">
  62 + <label class="col-sm-1 control-label">标题</label>
  63 + <input class="col-sm-2" type="text" value="[[contentData.data.title.title]]"
  64 + data-field="title.title" placeholder="推荐品牌">
  65 + <label class="col-sm-1 control-label">显示名称</label>
  66 + <div class="col-sm-2 ">
  67 + <label style="cursor: pointer;"><input type="radio" name="is_show_name" value="Y"></label>
  68 + <label style="cursor: pointer;"><input type="radio" name="is_show_name" value="N"></label>
  69 + </div>
  70 + <input type="hidden" id="is_show_name" value="[[contentData.data.is_show_name]]"
  71 + data-field="is_show_name" for="radio" />
  72 + </div>
  73 + [[/if]]
  74 + [[if contentData.template_name=='customBrands']]
  75 + <div class="form-group col-sm-12">
  76 + <label class="col-sm-1 control-label">标题</label>
  77 + <input class="col-sm-2 " type="text" value="[[contentData.data.title.title]]"
  78 + data-field="title.title" placeholder="自定义品牌">
  79 + <label class="col-sm-1 control-label">附加参数</label>
  80 + <select class="col-sm-2 " value="[[contentData.data.title.param]]">
  81 + <option value="-1">请选择附加参数</option>
  82 + <option value="1">大分类</option>
  83 + </select>
  84 + <label class="col-sm-1 control-label">附加参数值</label>
  85 + <input class="col-sm-2" type="text" value="[[contentData.data.title.param_value]]"
  86 + data-field="title.param_value" placeholder="附加参数值">
  87 + </div>
  88 + [[/if]]
  89 + [[if contentData.template_name=='kidsBrands']]
  90 + <div class="form-group col-sm-12">
  91 + <label class="col-sm-1 control-label">标题</label>
  92 + <input class="col-sm-2 " type="text" value="[[contentData.data.params.title]]"
  93 + data-field="params.title">
  94 + <label class="col-sm-1 control-label">分类</label>
  95 + <select class="col-sm-2 " value="[[contentData.data.params.param]]" data-field="params.param">
  96 + <option value="-1">请选择附加参数</option>
  97 + <option value="1">大分类</option>
  98 + </select>
  99 + <label class="col-sm-1 control-label">附加参数值</label>
  100 + <input class="col-sm-2 " type="text" value="[[contentData.data.params.paramValue]]"
  101 + data-field="params.paramValue" placeholder="附加参数值">
  102 + </div>
  103 + <div class="form-group col-sm-12">
  104 + <label class="col-sm-1 control-label">跳转目的</label>
  105 + <select name="goTo" class="col-sm-2 observe" value="[[contentData.data.params.more]]"
  106 + data-field="params.more">
  107 + [[layout action_template]]
  108 + </select>
  109 + <label class="col-sm-1 control-label">链接</label>
  110 + <input value="[[contentData.data.params.more_url]]" class="col-sm-2 observe" required="required"
  111 + data-field="params.more_url"/>
  112 +
  113 + <p style="color:#999;margin-top: 5px;">注:链接中不能有英文单引号</p>
  114 + </div>
  115 + [[/if]]
  116 + <div class="form-group">
  117 + <label class="col-sm-2 control-label">添加品牌:</label>
  118 + <div class="col-sm-8">
  119 + <ul class="cover-image-list col-sm-10" id="addPic" style="padding: 0;margin: 0;">
  120 + <li class="cover-image-item fileinput-button">
  121 + <div class="goods-img">
  122 + <a class="fileinput-button-icon" href="javascript:void(0);" id="addBrands">+</a>
  123 + </div>
  124 + </li>
  125 + </ul>
  126 + </div>
  127 + </div>
  128 + </div>
  129 + <div id="brands2">
  130 +
  131 + </div>
  132 +</script>
  133 +
  134 +<!--品牌选择模态-->
  135 +<script type="text/template" id="template5">
  136 + <div class="row" id="brandForm">
  137 + <div class="form-group">
  138 + [[each Brands as brand index]]
  139 + <a class="btn brand-index" href="#[[brand.name]]">[[brand.name]]</a>
  140 + [[/each]]
  141 + </div>
  142 + <div class="form-group brand-wrap" style="height: 400px;overflow: auto;">
  143 + [[each Brands as brand index]]
  144 + <div class="form-group" name="[[brand.name]]">
  145 + [[each brand.items as item __index ]]
  146 + <a class="btn">
  147 + <input type="checkbox" value="[[item.id]]" name="brandCheckBox">
  148 + <label>[[item.brand_name]]</label>
  149 + </a>
  150 + [[/each]]
  151 + </div>
  152 + [[/each]]
  153 + </div>
  154 + <input type="hidden" id="brandCheckBox" for="checkbox" value="[[Brdata]]" />
  155 + </div>
  156 +</script>
  157 +<script type="text/template" id="template3">
  158 + [[each Brands as brand index]]
  159 + <li class="cover-image-item image-list" data-index="2">
  160 + <div class="goods-img">
  161 + <a class="fileinput-button-icon" href="javascript:void(0);">
  162 + <img src="[[brand.brandIco]]">
  163 + </a>
  164 + <i class="remove-item-btn remove1 glyphicon glyphicon-remove-circle" data-index="[[index]]"></i>
  165 + </div>
  166 + <div class="col-sm-12">
  167 + <label class="col-sm-6">图片名称</label>
  168 + <input class="col-sm-6" type="text" value="[[brand.title]]" data-field="brand.title">
  169 + </div>
  170 + </li>
  171 + [[/each]]
61 </script> 172 </script>