brandImage.js 5 KB
var $ = require('jquery');
var common = require('../../common/common');
var edit = require('../../common/edit');

require('../../common/umeditor.config');
require('../../common/umeditor');
require('../../common/zh-cn');

new common.dropDown({
    el: "#g-brandId",
    ajax: 'brand',
    params: {
        status: 1
    }
});

// var client ;
var g = new common.grid({
    el: '#basicTable',
    size: 10,
    parms: function () {

        return {
            brandId: common.util.__input('g-brandId'),
            channelId:common.util.__input('channel')
        };
    },
    columns: [
        {
            display: 'ID',
            name: "id"
        },
        {
            display:'频道',
            render:function(item){
                if (item.channelId) {
                    return "<p>" + replaceNumToChannel(item.channelId) + "</p>";
                }
            }
        },
        {
            display: '品牌ID',
            name: "brandId"
        }, {
            display: '品牌名称',
            name: "brandName"
        },
        {
            display:'店铺id',
            render:function(item){
                if(item.shopIds){
                    return "<p>" + item.shopIds + "</p>";
                }
            }
        },
        {
            display: '品牌图片',
            render: function (item) {
                if (item.src) {
                    return '<a class="list-img" target="_blank">' +
                        '<img src="' + item.src + '"></a>';
                } else {
                    return '';
                }

            }
        },
        {
            display: '更新时间',
            render: function (item) {
                var t = new Date(item.updateTime * 1000);
                var formatted = common.util.__dateFormat(t, "yyyy-MM-dd hh:mm:ss");
                return "<p>" + formatted + "</p>";
            }
        },

        {
            display: '操作',
            //}
            name: "status",
            render: function (items) {
                var HtmArr = [];

                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-info btn-xs info-modify">查看 / 编辑</a>');
                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs info-del">删除</a>');

                return HtmArr.join('');
            }
        }],
    complete: function () {

    }
});
g.init('/brandImage/list');

$("#filter-btn").click(function() {
    g.reload(1);
});

$(document).on('click', '.info-del', function() {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("警告", "是否确认删除?",function() {
        common.util.__ajax({
            url: '/brandImage/delete',
            data: {
                id: item.id,
            }
        }, function (res) {
            if (res.code == 200) {
                common.util.__tip('删除成功', 'success');
                g.reload();
            } else {
                common.util.__tip(res.message);
            }
        }, true);
    });
});


//将1,2,3,4 转换成男生,女生,潮童,创意生活
function replaceNumToChannel(channelIds){
    return channelIds.replace('0','通用')
        .replace('1','男生')
        .replace('2','女生')
        .replace('3','潮童')
        .replace('4','创意生活');
}

//添加
$(document).on('click', '#add-btn', function () {
    brandImageOP("新增", '/brandImage/add', {});

});

//编辑
$(document).on('click', '.info-modify', function () {
    var item = g.rows[$(this).data("index")];
    common.util.__ajax(
        {
            url: '/brandImage/detail',
            data: {
                id: item.id
            }
        }, function (res) {

            //var item = res.data;
            brandImageOP("编辑", '/brandImage/update', res.data);
        }, true);

});

function brandImageOP(prefix, url, item) {
    console.log("item",item);
    var a = new common.edit("#templete-top", {
        "bucket": "brandImage"
    });

    a.on("validate", function () {
    });
    common.dialog.confirm(prefix + '品牌图片', common.util.__template2($("#template").html(), item), function () {
        return a.submit(url, function (option) {


            option.success = function (res) {
                if (res.code == "200") {
                    a.$tip("提交成功", function () {
                        g.reload();
                    }, 'growl-success');
                } else {
                    a.$tip(res.message);
                }
                return false;
            },
                option.error = function (res) {
                    a.$tip(res.message);
                }
        });
    });
    $(".modal-dialog").css("width","800px");

    a.init();

    if (prefix == "编辑") {
        $('#brandId').attr('disabled', true);
    } else {
        $('#brandId').attr('disabled', false);

    }


    new common.dropDown({
        el: "#brandId",
        ajax: 'brand',
        params: {
            status: 1
        }

    });

}