operations.hotsuggest.Index.js 11.2 KB
webpackJsonp([111],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/6/16.
	 * 热门意见
	 */

	var $ = __webpack_require__(1),
	    common = __webpack_require__(2);

	var status = "-1";
	var quick_select = {};
	var statusArr = ["未编辑","已编辑", "已发布"];
	var HotSuggestBean = {
	    "status": 1,
	    "coverImage": "",
	    "orderBy": "",
	    "content": "",
	    "replyContent": "",
	};
	var module = {};
	var edit = new common.edit2("#edit-content", {bucket: "suggest"});

	$.timepicker.dateRange($("#startTime"), $("#endTime"));

	/**
	 * 搜索控件初始化
	 */
	new common.dropDown({
	    el: "#status-filter"
	});
	new common.dropDown({
	    el: "#clientType-filter"
	});
	new common.edit("#radios-select").init();

	var g = new common.grid({
	    el: '#content-list',
	    callback: function (res) {
	        if (res && res.data) {
	            quick_select = {
	                uneditCount: res.data.uneditCount,
	                editedCount: res.data.editedCount,
	                publishCount: res.data.publishCount,
	                status: status
	            };
	        }
	        $("#quick").html(common.util.__template2($("#status-search").html(), {quick_select: quick_select}));
	        return res.data;
	    },
	    parms: function () {
	        return {
	            startTime: common.util.__input('startTime'),
	            endTime: common.util.__input('endTime'),
	            status: status,
	            clientType: common.util.__input('clientType-filter'),
	            hasImage: common.util.__input('hasImage'),
	            isReliable: common.util.__input('isReliable')
	        };
	    },
	    columns: [
	        {
	            display: '',
	            type: 'checkbox'
	        },
	        {
	            display: "来源",
	            name: "clientType",
	            render: function (item) {
	                return item.clientType == "custom" ? "自定义" : item.clientType;
	            }
	        },
	        {
	            display: '反馈内容',
	            name: "content",
	            style:"width:20%;word-break:break-all;"
	        },
	        {
	            display: '回复内容',
	            name: "replyContent",
	            style:"width:20%; word-break:break-all;"
	        },
	        {
	            display: '封面图',
	            render: function (item) {
	                if(item.imageUrl) {
	                    return '<a href="'+ item.imageUrl +'"target="_blank"><img style="max-height: 150px" src="'+item.imageUrl+'"/></a>';
	                }
	            }
	        },
	        {
	            display: '时间',
	            name: "createTime"
	        },
	        {
	            display: '排序',
	            render: function (item) {
	                var arr = [];
	                arr.push('<input class="form-control" style="width: 50px;display: inline-block" id="order_by_'+ item.__index +'" value="'+ item.orderBy +'">');
	                arr.push('<a data-index="'+ item.__index +'" class="btn btn-info btn-xs updateOrder">更新</a>');
	                return arr.join("");
	            }
	        },
	        {
	            display: "状态",
	            render: function (item) {
	                return "<p>" + statusArr[item.status] + "</p>";
	            }
	        },
	        {
	            display: '靠谱',
	            name: "reliable"
	        },
	        {
	            display: '不靠谱',
	            name: "unreliable"
	        },
	        {
	            display: '操作',
	            render: function (item) {
	                var HtmArr = [];
	                //status 0 : 编辑、取消热门(删除操作) status 1:编辑、发布、取消热门(删除操作) status 2: 撤回(更新为已编辑状态)
	                if (item.status == 0) {
	                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs edit">编辑</a>');
	                    if(!item.suggestId) {
	                        HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs setHot">删除</a>');
	                    } else {
	                        HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs setHot">取消热门</a>');
	                    }
	                } else if (item.status == 1) {
	                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-primary btn-xs edit">编辑</a>');
	                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-success btn-xs publish">发布</a>');
	                    if(!item.suggestId) {
	                        HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs setHot">删除</a>');
	                    } else {
	                        HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs setHot">取消热门</a>');
	                    }
	                } else if (item.status == 2) {
	                    HtmArr.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn btn-warning btn-xs publish">撤回</a>');
	                }
	                return HtmArr.join('');
	            }
	        }]
	});
	g.init('/suggest/suggestHot/getSuggestHotList');

	var Bll = {
	    toast: function (item, url, title) {
	        var dialog = common.dialog({
	            title: title,
	            content: common.util.__template2($("#edit-template").html(), item),
	            width: "60%",
	            button: [
	                {
	                    value: '取消',
	                    css: "btn btn-default"
	                },
	                {
	                    value: '保存',
	                    css: "btn btn-primary",
	                    callback: function () {
	                        if(edit.validate() && Bll.__checkLength()) {
	                            module.status = 1;
	                            common.util.__ajax({
	                                url: url,
	                                data: item
	                            }, function () {
	                                dialog.close();
	                                g.reload();
	                            });
	                        }
	                        return false;
	                    }

	                },
	                {
	                    value: '发布',
	                    css: "btn btn-success",
	                    callback: function () {
	                        if(edit.validate() && Bll.__checkLength()) {
	                            module.status = 2;
	                            common.util.__ajax({
	                                url: url,
	                                data: item
	                            }, function () {
	                                dialog.close();
	                                g.reload();
	                            });
	                        }
	                        return false;
	                    }
	                }
	            ]
	        })
	        edit.init();
	        edit.on("file_onComplete", function (obj) {
	            module[obj.field] = obj.data;
	        });
	    },
	    __render: function () {
	        $(".modal-body").html(common.util.__template2($("#edit-template").html(), module));
	        edit.init();
	        edit.on("file_onComplete", function (obj) {
	            module[obj.field] = obj.data;
	        });
	    },
	    batch:function(url, hint) {
	        var ids = [];
	        $.each(g.selected,function (i, value) {
	            ids.push(value.id);
	        });
	        if(ids.length) {
	            common.dialog.confirm("发送确认", "是否确认发送?", function () {
	                common.util.__ajax({
	                    url: url,
	                    data: {
	                        id: ids.join(",")
	                    }
	                }, function () {
	                    g.reload();
	                });
	            });
	        } else {
	            common.util.__tip(hint,"warning");
	        }
	    },
	    __checkLength: function () {//校验长度
	        var contentLength = 0;
	        for(var i = 0; i < module.content.length; i++) {
	            if(/[\u4e00-\u9fa5]/i.test(module.content.charAt(i))) {
	                contentLength += 1;
	            } else {
	                contentLength += 0.5;
	            }
	        };
	        if(contentLength > 27) {
	            common.util.__tip("标题长度为:" + contentLength + ",超过了最大长度", "warning");
	            return false;
	        }
	        var replyLength = 0;
	        for(var i = 0; i < module.replyContent.length; i++) {
	            if(/[\u4e00-\u9fa5]/i.test(module.replyContent.charAt(i))) {
	                replyLength += 1;
	            } else {
	                replyLength += 0.5;
	            }
	        };
	        if(replyLength > 80) {
	            common.util.__tip("回复内容长度为:" + replyLength + ",超过了最大长度", "warning");
	            return false;
	        }
	        return true;
	    }
	};

	//新增修改
	$(document).on("click", ".edit", function () {
	    module = $.extend(true, {}, g.rows[$(this).data("index")]);
	    Bll.toast(module, "/suggest/suggestHot/updateSuggestHot", "修改热门反馈");
	});

	$(document).on("click", "#add", function () {
	    module = $.extend(true, {}, HotSuggestBean);
	    Bll.toast(module, "/suggest/suggestHot/addSuggestHot", "添加热门反馈");
	});

	$(document).on("change", ".observe", function () {
	    module[$(this).data("field")] = $(this).val();
	});

	//删除图片
	$(document).on("click", "#delImage", function () {
	    module["coverImage"] = "";
	    Bll.__render();
	});

	//筛选
	$(document).on("click", "input[name='quick_select']", function () {
	    status = $(this).val();
	    g.reload(1);
	    $(this).attr("checked", "");
	    $(this).parent().siblings().find("input[name='quick_select']").removeAttr('checked');
	});

	$(document).on("click", "#filter-info", function () {
	    status = common.util.__input('status-filter');
	    g.reload(1);
	});

	//发布/撤回
	$(document).on("click", ".publish", function () {
	    var item = g.rows[$(this).data("index")];
	    common.util.__ajax({
	        url: "/suggest/suggestHot/publishSuggestHot",
	        data: {id: item.id, status: 3-item.status}
	    }, function () {
	        g.reload();
	    });
	});

	//取消热门
	$(document).on("click", ".setHot", function () {
	    var item = g.rows[$(this).data("index")];
	    common.util.__ajax({
	        url: "/suggest/suggestHot/deleteSuggestHot",
	        data: {id: item.id}
	    }, function () {
	        g.reload();
	    });
	});

	//更新排序
	$(document).on("click", ".updateOrder", function () {
	    var index = $(this).data("index");
	    if(!/^[0-9]*$/.test($("#order_by_" + index).val())) {
	        common.util.__tip("排序只能是数字!");
	        return;
	    }
	    var item = g.rows[index];
	    item.orderBy = $("#order_by_" + index).val();
	    common.util.__ajax({
	        url: "/suggest/suggestHot/updateSuggestHot",
	        data: item
	    }, function () {
	        g.reload();
	    });
	});

	$(document).on("click", "#batchPublish", function () {
	    Bll.batch("/suggest/suggestHot/batchPublishSuggestHot", "请选择要发布的反馈");
	});

/***/ }
]);