resourceContentManage.js 8.72 KB
/**
 * Created by ty on 2016/3/31.
 * 资源内容管理
 */
var $ = require('jquery'),
    common = require('../common/common'),
    util = require('../common/util');

var param = location.href.substring(location.href.lastIndexOf("/") + 1);
var resources = {};
var btns = [
    {name:"text",text:"文本"},
    {name:"singleImage",text:"一张图"},
    {name:"smallPic",text:"添加小图"},
    {name:"focus",text:"焦点图"},
    {name:"goods",text:"添加商品"},
    {name:"goodsGroup",text:"添加商品组"},
    {name:"appIconList",text:"图标入口"},
    {name:"recommendContentOne",text:"推荐(1T-1L-4R)"},
    {name:"recommendContentTwo",text:"推荐(1T-6F)"},
    {name:"singleNameImage",text:"标题广告"},
    {name:"recommendContentThree",text:"推荐(1T-12F)"},
    {name:"trendsetterCollocation",text:"潮人搭配"},
    {name:"trendgoodsTopic",text:"潮品话题"},
    {name:"customBrands",text:"推荐品牌"},
    {name:"customBrands",text:"自定义品牌"},
    {name:"link",text:"一个链接"},
    {name:"promotion",text:"添加促销"},
    {name:"carouselBanner",text:"轮播banner"},
    {name:"kidsBrands",text:"kids品牌"},
    {name:"",text:"推荐(L1-RT1-RF2)"},
    {name:"",text:"添加楼层"},
    {name:"recommendContentFive",text:"推荐(标题 + 12张图)"},
    {name:"textNav",text:"文本导航"},
    {name:"imageList",text:"图片列表"},
    {name:"",text:"标题标签"},
    {name:"",text:"编辑推荐"},
    {name:"hotCategory",text:"热门品类"},
    {name:"debrisSlider",text:"有序焦点"},
    {name:"newUserFloor",text:"新人专享"},
    {name:"singleNameImage",text:"图片广告"},
    {name:"paramsGroup",text:"自定义参数"},
    {name:"",text:"自定义参数的图片"},
    {name:"announcement",text:"站内公告"}
];

var Bll = {
    addView: function(item) {
        switch (item.template_name) {
            case "text":
                Bll.addText(item.data?item.data.text:"");
                break;
            case "singleImage":
                break;
            case "smallPic":
                break;
            case "focus":
                break;
            case "goods":
                break;
            case "goodsGroup":
                break;
            case "appIconList":
                break;
            case "recommendContentOne":
                break;
            case "recommendContentTwo":
                break;
            case "singleNameImage":
                break;
            case "recommendContentThree":
                break;
            case "trendsetterCollocation":
                break;
            case "trendgoodsTopic":
                break;
            case "customBrands":
                break;
            case "link":
                break;
            case "promotion":
                break;
            case "carouselBanner":
                break;
            case "kidsBrands":
                break;
            case "recommendContentFive":
                break;
            case "textNav":
                break;
            case "imageList":
                break;
            case "hotCategory":
                break;
            case "debrisSlider":
                break;
            case "newUserFloor":
                break;
            case "paramsGroup":
                break;
        }
    },
    editTotal:function(item) {

    },
    addText:function(text) {
        $("#add-content").append(function (index, html) {
            var tempArr = [];
            var index = $("#add-content").children().length;
            tempArr.push('<li class="custom-group text" data-type="text" id="index_' + index + '">');
            tempArr.push('<div class="con" id="index__'+ index +'">' + text + '</div>');
            tempArr.push('<div class="actions-box"><div class="actions-wrap">');
            tempArr.push('<span class="edit" data-value="文本" data-index="' + index + '">编辑</span>');
            tempArr.push('<span class="del" data-id="" data-index="' + index + '">删除</span>');
            tempArr.push('</div></div></li>');
            return tempArr.join("");
        });
    },
    editText:function(text) {

    }
};

common.util.__ajax({
    url: "/resource/content/resContentIndex",
    data: {id: param}
},function(res) {
    console.log(res.data);
    resources = res.data;
    $("#content-list").html(common.util.__template2($("#content-template").html(), res.data));
    for(var i = 0; i < res.data.contentData.length; i++) {
        var item = res.data.contentData[i];
        var json = JSON.parse(item.contentData);
        Bll.addView(json);
        //console.log(json);
    }
    for(var i = 0; i < btns.length; i++) {
        var button = btns[i];
        $(".clearfix").append(function () {
            var tempArr = [];
            tempArr.push("<li><a href='javascript:void(0)' name='"+ button.name +"' class='add_btn' data-index='"+ i +"'>");
            tempArr.push(button.text);
            tempArr.push("</a></li>");
            return tempArr.join("");
        });
    }

},true);

var buttons=[
    {
        title:"文本",
        template:{
            content:function() {
                $("#add-content").append(function (index, html) {
                    var tempArr = [];
                    var index = $("#add-content").children().length;
                    tempArr.push('<li class="custom-group text" data-type="text" id="index_' + index + '">');
                    tempArr.push('<div class="con" id="index__'+ index +'"></div>');
                    tempArr.push('<div class="actions-box"><div class="actions-wrap">');
                    tempArr.push('<span class="edit" data-value="文本" data-index="' + index + '">编辑</span>');
                    tempArr.push('<span class="del" data-id="" data-index="' + index + '">删除</span>');
                    tempArr.push('</div></div></li>');
                    return tempArr.join("");
                });
            },
            dialog:{
              id:"#text-template",
              title:"新增文本"
            }
        },
        data:function(index) {
            return {content: $("#index__" + index).html()};
        },
        button:{
            add:function(index){
                $("#index__" + index).html($("#myArea").val());
            }
        }
    },
    {
        title:"一张图",
        template:{
            content:function() {
                $("#add-content").append(function (index, html) {
                    var tempArr = [];
                    var index = $("#add-content").children().length;
                    tempArr.push('<li class="custom-group text" data-type="singleImage" id="index_' + index + '">');
                    tempArr.push('<div class="con" id="index__' + index + '"><img src="/js/source/plugins/addBigPic/bigPic.jpg" width="96%/"></div>');
                    tempArr.push('<div class="actions-box"><div class="actions-wrap">');
                    tempArr.push('<span class="edit" data-value="一张图" data-index="' + index + '">编辑</span>');
                    tempArr.push('<span class="del" data-id="" data-index="' + index + '">删除</span>');
                    tempArr.push('</div></div></li>');
                    return tempArr.join("");
                });
            },
            dialog:{
                id:"#singleImage-template",
                title:"添加图片"
            }
        },
        data:function(index) {
            return {content: $("#index__" + index).find("img").val()};
        },
        button:{
            add:function(index){
                $("#index__" + index).html($("#myArea").val());
            }
        }
    }
];

$(document).on("click",".add_btn",function(){//添加
    //var title=$(this).html();
    //var index = parseInt($(this).attr("data-index"));
    ////console.log(title);
    //var btn=buttons.filter(function(item){
    //    return item.title==title;
    //});
    //btn[0].template.content();
    Bll.addView({template_name:$(this).attr("name")});
});

$(document).on("click", ".edit", function() {//编辑
    var title = $(this).attr("data-value");
    var btn=buttons.filter(function(item){
        return item.title==title;
    });
    var index = $(this).attr("data-index");
    //console.log($("index_" + index));
    //console.log($("#nidaye").html());
    console.log(btn[0].data(index));
    var e = new common.edit();
    common.dialog.confirm(btn[0].template.dialog.title,
        common.util.__template2($(btn[0].template.dialog.id).html(), btn[0].data(index)),
        function() {
            btn[0].button.add(index);
        });
    e.init();
});

$(document).on("click", ".del", function () {//删除
    var index = $(this).attr("data-index");
    $("#index_" + index).remove();
});

//for Button ->title
//    [[each Button ]]
//    <div class="btn">[[item.title]]</div>
//    [[/each]]