Content.js 3.79 KB
var $ = require('jquery'),
    common = require('../../common/common'),
    util = require('../../common/util');

new common.dropDown({el: "#help-categoryId", "ajax": "getHelpCategory"});
new common.dropDown({el: "#help-platform"});

var ENUM = {id: []};

var g = new common.grid({
    el: "#content-list",
    hash: false,
    parms: function () {
        return {
            categoryId: common.util.__input('help-categoryId'),
            platform: common.util.__input('help-platform')
        };
    },
    columns: [
        {display: "编号", name: "id"},
        {display: "标题", name: "title"},
        {
            display: "分类", name: "categoryId", render: function (item) {
            return ENUM.id[item.categoryId];
        }
        },
        {
            display: "平台", name: "platform", render: function (item) {
            if (item.platform != null && item.platform.trim() != "") {
                var platform = item.platform;
                var temp = platform.replace("iphone", "IOS手机").replace("ipad", "IOS Pad")
                    .replace("android", "安卓手机").replace("androidpad", "安卓Pad")
                    .replace("h5", "手机网站").replace("web", "网站")
                    .replace("platform", "平台").replace(/\|/g, " ");
                return temp;
            }
        }
        },
        {
            display: "操作", name: "", render: function (item) {
            var arr = [];
            arr.push('<a class="btn btn-info btn-xs add2" data-index="' + item.__index + '">编辑</a>');
            arr.push('<a class="btn btn-danger btn-xs delbtn" data-index="' + item.__index + '">删除</a>');
            return arr.join("");
        }
        }
    ]

});

common.util.__ajax({
    url: '/operations/helpcategory/getAllHelpCategory',
    data: {}
}, function (res) {
    var list = res.data.list;
    for (var i = 0; i < list.length; i++) {
        ENUM.id[list[i].id] = list[i].categoryName;
    }
    g.init('/operations/helpcontent/getAllHelpContent');
}, function () {
    g.init('/operations/helpcontent/getAllHelpContent');
}, true);

var Bll = {
    toast: function (url, item, hint) {
        var e = new common.edit("#baseform");

        common.dialog.confirm(hint,
            common.util.__template($("#template").html(), item),
            function () {
                e.submit(url, function (option) {
                    option.success = function (res) {
                        if (res.code == 200) {
                            util.__tip(res.message, "success");
                        } else {
                            util.__tip(res.message);
                        }
                        g.reload();
                    };
                    option.error = function () {
                    };
                });
            });
        e.init();

        new common.dropDown({el: "#categoryId", "ajax": "getByCategoryId"});

        if (hint == "修改内容") {
            $("#select2-categoryId-container").html(ENUM.id[item.categoryId]);
        }
    }
};

$(document).on('click', '.add2', function () {
    var item = g.rows[$(this).data("index")];
    Bll.toast('/operations/helpcontent/updateHelpContent', item, "修改内容");
});

$('#add-content').on('click', function () {
    var item = {};
    Bll.toast('/operations/helpcontent/addHelpContent', item, "添加内容");
});

$(document).on('click', '.delbtn', function () {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("警告",
        "确认删除?",
        function () {
            common.util.__ajax({
                url: '/operations/helpcontent/deleteHelpContent',
                data: {id: item.id}
            }, function () {
                g.reload();
            });
        });
});

$(document).on('click', '#filter-btn', function () {
    g.reload(1);
});