index.js 10.1 KB
/**
 * Created by jiangmin on 2016/5/9.
 * 反馈管理
 */
var $ = require('jquery');
common = require('../common/common');
datepicker = require('../util/datepicker');

var ENUM = {
    //发送状态
    StatusEnum1: {
        '0': '未发送',
        '1': '未发送',
        '2': '已发送'
    },
    //状态
    StatusEnum2: {
        '0': '未回复',
        '1': '已回复',
        '2': '已回复'
    }
};
/**
 * 下拉框
 */
new common.dropDown({
    el: "#isHot-filter"
});
new common.dropDown({
    el: "#status-filter"
});
new common.dropDown({
    el: "#clientType-filter"
});
/**
 * 日期插件
 */
$('.hasDatepicker').fdatepicker({
    format: 'yyyy-mm-dd'
});
var appVersion = {};
var replyPersonName = {};
var quick_select = {};
var status = "-1";
/**
 * 列表
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#content-list',
    callback: function (data) {
        if (data && data.data) {
            quick_select = {
                replyTotal: data.data.replyTotal,
                unReplyTotal: data.data.unReplyTotal,
                status: status
            };
        }
        $("#quick").html(common.util.__template2($("#quick-search").html(), {quick_select: quick_select}));
        return data.data;
    },
    parms: function () {
        if (common.util.__input('status-filter')) {
            status = common.util.__input('status-filter');
        }
        return {
            uid: common.util.__input('uid-filter'),
            startTime: common.util.__input('startTime'),
            endTime: common.util.__input('endTime'),
            isHot: common.util.__input('isHot-filter'),
            status: status,
            clientType: common.util.__input('clientType-filter'),
            appVersion: common.util.__input('choose-appVersion'),
            replyPersonId: common.util.__input('choose-replyPersonName')
        };
    },
    columns: [
        {
            display: '',
            type: 'checkbox'
        }, {
            display: "UID",
            name: "uid"
        }, {
            display: "来源",
            name: "clientType"
        }, {
            display: '版本号',
            name: "appVersion"
        }, {
            display: '图片',
            render: function (item) {
                var a = item.imageUrl.split('?');
                return '<a href="' + a[0] + '" target="_blank"><img src="' + item.imageUrl + '"></a>'
            }
        }, {
            display: '反馈内容',
            name: "content",
            style:"width:20%;word-break:break-all;"
        }, {
            display: '回复内容',
            name: "replyContent",
            style:"width:20%; word-break:break-all;"
        }, {
            display: '回复人',
            name: "replyPersonName",
            render: function (item) {
                if (item.status == '0') {
                    return "";
                }
                else {
                    return item.replyPersonName
                }
            }
        }, {
            display: '时间',
            name: "createTime"
        }, {
            display: "发送状态",
            render: function (item) {
                return "<p>" + ENUM.StatusEnum1[item.status] + "</p>";
            }
        }, {
            display: "回复状态",
            name: 'status',
            render: function (item) {
                return "<p>" + ENUM.StatusEnum2[item.status] + "</p>";
            }
        }, {
            display: '操作',
            render: function (item) {
                var HtmArr = [];
                //已发送,已回复,uid为0,则不可再“回”、“发”
                if (item.status == 2 || item.uid == '0') {
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs reply" disabled="true">回</a>');
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-success btn-xs publish" disabled="true">发</a>');
                }
                else if (item.status == 0) {
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs reply">回</a>');
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-success btn-xs publish" disabled="true">发</a>');
                }
                else {
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs reply">回</a>');
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-success btn-xs publish">发</a>');
                }
                if (item.isHot == 1) {
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs setHot" disabled="false">热</a>');
                }
                else {
                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs setHot">热</a>');
                }
                HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-dark btn-xs delete">删</a>');
                return HtmArr.join('');
            }
        }]
});
g.init('/suggest/suggest/getSuggestList');

$(document).on("click", "input[name='quick_select']", function () {
    status = $(this).val();
    g.reload();
    $(this).attr("checked", "");
    $(this).parent().siblings().find("input[name='quick_select']").removeAttr('checked');
});
var Bll = {
    dropDown: function (url, title, data) {
        common.util.__ajax({
            url: url,//获取所有版本号
            data: {}
        }, function (res) {
            $("#" + title + "-content").html(common.util.__template2($("#search-" + title).html(), res));
            new common.dropDown({el: "#choose-" + title});
            data = res.data;
        }, true);
    },
    toast: function (url, item, content) {
        common.dialog.confirm("",
            content,
            function () {
                common.util.__ajax({
                    url: url,
                    data: item
                }, function () {
                    g.reload();
                });
            });
    },
    toastBatch: function (url, id, content) {
        common.dialog.confirm("", content,
            function () {
                common.util.__ajax({
                    url: url,
                    data: {
                        id: id
                    }
                }, function (res) {
                    //console.log(res);
                    g.reload(1);
                });
            });
    }
};
Bll.dropDown("/suggest/suggest/getAllAppVersions", "appVersion", appVersion);
Bll.dropDown("/suggest/suggest/findAllReplyInfo", "replyPersonName", replyPersonName);
/**
 * 查询按钮点击时间
 */
$("#filter-btn").click(function () {
    g.reload(1);
});
/**
 * 回
 */
$(document).on('click', '.reply', function () {
    var item = g.rows[$(this).data("index")];
    common.dialog({
        title: "回答反馈内容",
        content: common.util.__template2($("#replyTemplate").html(), item),
        button: [
            {
                value: "保存",
                callback: function () {
                    common.util.__ajax({
                        url: "/suggest/suggest/replySuggest",
                        data: {
                            id: item.id,
                            replyContent: $("#replyContent").val()
                        }
                    }, function (res) {
                        if (res.code == '200') {
                            g.reload();
                        }
                    })
                },
                css: "btn btn-info"
            }, {
                value: "取消"
            }
        ]
    });
});
/**
 * 发
 */
$(document).on('click', '.publish', function () {
    var item = g.rows[$(this).data("index")];
    item = {
        id: item.id
    };
    Bll.toast('/suggest/suggest/publishSuggest', item, "是否确认发送?");
});
/**
 * 热
 */
$(document).on('click', '.setHot', function () {
    var item = g.rows[$(this).data("index")];
    item = {
        id: item.id,
        isHot: 1
    };
    Bll.toast('/suggest/suggest/setHotSuggest', item, "是否确认设置热门?");
});
/**
 * 删除
 */
$(document).on('click', '.delete', function () {
    var item = g.rows[$(this).data("index")];
    Bll.toast('/suggest/suggest/deleteSuggest', item, "是否确认删除?");
});

//批量发送
$(document).on('click', '#batchPublish', function () {
    var selectedArr = g.selected,
        len = selectedArr.length,
        idList = [],
        idstatus0 = [],
        idstatus2 = [];
    var msg = "";
    var msgs = [];
    if (len <= 0) {
        common.util.__tip('请选择反馈', 'warning');
        return;
    }
    $.each(selectedArr, function (i, value) {
        idList.push(value['id']);
        if (value['status'] == 0) {
            idstatus0.push(value['uid']);
        }
        if (value['status'] == 2) {
            idstatus2.push(value['uid']);
        }
    });
    var msg1 = idstatus0.length + '条反馈还没有回复,不可发送!';
    var msg2 = idstatus2.length + '条反馈已发送,不可重复发送!';
    if (idstatus0.length > 0) {
        msgs.push(msg1);
    }
    if (idstatus2.length > 0) {
        msgs.push(msg2);
    }
    if (msgs.length > 0) {
        for (var i = 0; i < msgs.length; i++) {
            msg = msg + '<p>' + msgs[i] + '</p>'
        }
        common.util.__tip(msg, 'warning');
        return;
    }
    Bll.toastBatch("/suggest/suggest/batchPublishSuggest", idList.join(","), "确定批量发送吗?");

});
/**
 * 批量导出
 */
$(document).on('click', '#batchExport', function () {
    var selectedArr = g.selected,
        len = selectedArr.length,
        idList = [];
    if (len <= 0) {
        common.util.__tip('请选择反馈', 'warning');
        return;
    }
    $.each(selectedArr, function (i, value) {
        idList.push(value['id']);
    });
    var data = {
        id: idList.join(",")
    };
    window.open("/ajax/down?queryConf=" + JSON.stringify(data) + "&type=suggestExport");
});