versionManage.js 3.66 KB
/**
 * Created by ty on 2016/3/22.
 * app版本更新管理
 */

var $ = require('jquery'),
    common = require('../common/common'),
    util = require('../common/util');

var g = new common.grid({
    el: "#appVersionList",
    hash: false,
    columns: [
        {display: "ID", name: "id"},
        {display: "APP版本", name: "version"},
        {display: "提醒内容", name: "content"},
        {display: "跳转链接", name: "url"},
        {display: "客户端类型", name: "clientType", render: function(item) {
            if(item.clientType != null && item.clientType.trim() != "") {
                var platform = item.clientType;
                var temp = platform.replace("iphone", "IOS手机").replace("ipad", "IOS Pad")
                    .replace("android", "安卓手机").replace("androidpad", "安卓Pad")
                    .replace(/,/g, " ");
                return temp;
            }
        }},
        {display: "状态", name: "status", render: function(item) {
            if(item.status == 1) {
                return "已开启";
            } else if(item.status == 0) {
                return "已关闭";
            }
        }},
        {
            display: "操作",name: "", render: function (item) {
                var arr = [];
                arr.push('<a class="btn btn-primary btn-xs add2" data-index="' + item.__index + '">编辑</a>');
            if(item.status == 0) {
                arr.push('<a class="btn btn-danger btn-xs change-status" data-index="' + item.__index + '">开启入口</a>');
            } else {
                arr.push('<a class="btn btn-info btn-xs change-status" data-index="' + item.__index + '">关闭入口</a>');
            }
                return arr.join("");
            }
        }
    ]
});

g.init('/operations/version/appVersionList');

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

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

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

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

$(document).on('click', '#addAppVersion', function() {
    var item = {};
    Bll.toast("/operations/version/addAppVersion", item, "添加版本提醒");
});

$(document).on('click', '.add2', function() {
    var item = g.rows[$(this).data("index")];
    item.clientType = item.clientType.replace(/,/g, "|");
    Bll.toast("/operations/version/editAppVersion", item, "修改版本提醒");
});

$(document).on('click', '.change-status', function() {
    var item = g.rows[$(this).data("index")];
    if(item.status == 1) {
        item.status = 0;
    } else {
        item.status = 1;
    }
    common.util.__ajax({
        url: '/operations/version/publishAppVersion',
        data: {
            id: item.id,
            status: item.status
        }
    }, function() {
        g.reload();
    });
});