normalAppSuggest.js 6.47 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: "#version-filter"});
new common.dropDown({el: "#clientType-filter"});
new common.dropDown({el: "#clientType-filter"});

var ENUM = {
    status: {all: '全部', noReply: '未回复', replied: '已回复'},//全部
    tips: {"all": 0, "noReply": 0, "replied": 0},
    statusStr: {
        0: '未回复',
        1: '已回复'
    }
}

var t = new common.tab({
    el: "#basicTab",
    click: function () {
        g.init('/suggest/getSuggestList');

    },
    columns: [
        {name: "all", display: "全部({all})"},
        {name: "noReply", display: "未回复({noReply})"},
        {name: "replied", display: "已回复({replied})"}
    ]
}).init(ENUM.tips);

// tab初始化
var loadTab = function () {
    t.active = undefined;
    setTimeout(function () {
        common.util.__ajax({
            url: "/base/goods/ajax/auditCount",
            data: g.options.parms()
        }, function (res) {
            var __dt = $.extend({}, ENUM.tips, res.data);
            t.init(__dt);
        }, true);
    }, 400);
}

loadTab();

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')
        };
    },
    columns: [
        {display: " ", type:"checkbox"},
        {display: "UID", name: "uid"},
        {display: "来源", name: "clientType", width: "56px"},
        {display: "版本号", name: "appVersion", width:"56px"},
        {display: "图片", name: "", render: function(item) {
            if(item.imageUrl) {
                return '<img src="' + item.imageUrl + '" height="70px" width="100px" />';
            }
        }},
        {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:"56px;",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();
    }
};

//设置回复
$(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', '#filter-btn', function() {
    g.reload(1);
    loadTab();
});