normalAppSuggest.js 7.11 KB
/**
 * Created by ty on 2016/3/28.
 * APP意见反馈管理
 */
var $ = require('jquery'),
    common = require('../common/common'),
    util = require('../common/util');

new common.edit("#filter").init();
new common.dropDown({el: "#isHot-filter"});
new common.dropDown({el: "#status-filter"});
new common.dropDown({el: "#source-filter"});
new common.dropDown({el: "#clientType-filter"});

common.util.__ajax({
    url: '/suggest/getAllAppVersions',
    data: {}
},function(res) {
    $("#version-search").html(common.util.__template2($("#version-template").html(), res));
    new common.dropDown({el: "#appVersion-filter"});
},true);

var g = new common.grid({
    el: "#basicTable",
    parms: function () {
        return {
            uid: common.util.__input('uid-filter'),
            status: common.util.__input('status-filter'),
            clientType: common.util.__input('clientType-filter'),
            startTime: common.util.__input('startTime'),
            endTime: common.util.__input('endTime'),
            isHot: common.util.__input('isHot-filter'),
            appVersion: common.util.__input('appVersion-filter'),
            //status:t.active
        };
    },
    columns: [
        {display: " ", type:"checkbox"},
        {display: "UID", name: "uid"},
        {display: "来源", name: "clientType", width: "56px", render: function(item) {
            if(item.clientType) return item.clientType;
            return "未知";
        }},
        {display: "版本号", name: "appVersion", style:"min-width: 56px;"},
        {display: "图片", name: "", render: function(item) {
            var url = item.imageUrl ? item.imageUrl.substring(0, item.imageUrl.indexOf("?")) : "";
            if(item.imageUrl) {
                return '<a href="'+ url +'" target="_blank"><img src="' + item.imageUrl + '" height="60px" width="60px" /></a>';
            }
        }},
        {display: "反馈内容", name: "content", width:"20%"},
        {display: "回复内容", name: "replyContent", width:"20%"},
        {display: "时间", name: "createTime", width:"88px;"},
        {display: "发送状态", name: "", width:"70px;",render: function(item) {
            if (item.status == "0") {
                return "未发送";
            } else if (item.status == "1") {
                return "未发送";
            } else if (item.status == "2") {
                return "已发送";
            }
        }},
        {display: "状态",name: "", width:"70px;",render: function(item) {
            if (item.status == "0") {
                return "未回复";
            } else if (item.status == "1") {
                return "已回复";
            } else if (item.status == "2") {
                return "已回复";
            }
        }},
        {
            display: "操作",name: "", width:"156px;", render: function (item) {
            var replyDisabled = item.status < 2 ? "" : "disabled";
            var sendDisabled = item.status == 1 ? "" : "disabled";
            var isHotDisabled = item.isHot == 0 ? "" : "disabled";
            var arr = [];
            arr.push('<button '+ replyDisabled + ' class="btn btn-primary btn-xs replyBtn" data-index="'+ item.__index +'">回</button>');
            arr.push('<button '+ sendDisabled + ' class="btn btn-success btn-xs sendBtn" data-index="'+ item.__index +'">发</button>');
            if(isHotDisabled) {
                arr.push('<button ' + isHotDisabled + ' class="btn btn-warning btn-xs hotBtn" data-index="' + item.__index + '">热</button>');
            } else {
                arr.push('<button ' + isHotDisabled + ' class="btn btn-danger btn-xs hotBtn" data-index="' + item.__index + '">热</button>');
            }
            arr.push('<button class="btn btn-inverse btn-xs delBtn" data-index="'+ item.__index +'">删</button>');
            return arr.join("");
        }
        }
    ]

});

g.init("/suggest/getSuggestList");
//console.log(g);

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

        common.dialog.confirm(hint,
            common.util.__template2($("#reply-template").html(), item),
            function() {
                e.submit(url, function (option) {
                    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();
    },
    batch:function(url, hint) {
        var ids = [];
        $.each(g.selected,function (i, value) {
            ids.push(value.id);
        });
        if(ids.length) {
            if(url.indexOf("Publish") != -1) {
                common.dialog.confirm("发送确认", "是否确认发送?", function () {
                    common.util.__ajax({
                        url: url,
                        data: {
                            id: ids.join(",")
                        }
                    }, function () {
                        g.reload();
                    });
                });
            } else {
                window.open("/ajax/down?queryConf=" + JSON.stringify({"id":ids.join(",")}) + "&type=suggestExport");
            }
        } else {
            util.__tip(hint,"warning");
        }
    }
};

//设置回复
$(document).on('click', '.replyBtn', function() {
    var item = g.rows[$(this).data("index")];
    Bll.toast("/suggest/replySuggest", item, "回答反馈内容");
});

//设置热门
$(document).on('click', '.hotBtn', function() {
    var item = g.rows[$(this).data("index")];
    common.util.__ajax({
        url: '/suggest/setHotSuggest',
        data: {
            id: item.id,
            isHot: 1//只能设置热门
        }
    },function() {
        g.reload();
    },true);
});

//发送回复
$(document).on('click', '.sendBtn',function() {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("发送确认","是否确认发送?",function() {
        common.util.__ajax({
            url: '/suggest/publishSuggest',
            data: {
                id: item.id
            }
        },function() {
            g.reload();
        });
    });
});

//删除一条记录
$(document).on('click', '.delBtn',function() {
    var item = g.rows[$(this).data("index")];
    common.dialog.confirm("删除确认","是否确认删除?",function() {
        common.util.__ajax({
            url: '/suggest/deleteSuggest',
            data: {
                id: item.id
            }
        },function() {
            g.reload();
        });
    });
});

$(document).on('click', '#batchSend', function() {//批量发送
    Bll.batch("/suggest/batchPublishSuggest", "请选择要发送的回复!");
});

$(document).on('click', '#batchExport', function() {//批量导出
    Bll.batch("/suggest/batchExportSuggest", "请选择要导出的数据!");
});

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