operations.icon.Index.js 3.78 KB
webpackJsonp([115],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by ty on 2016/7/5.
	 * app图标管理
	 */

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

	var channelArr = ["通用","男生","女生","潮童","创意生活"];
	var module = {};
	var edit = new common.edit2("#base-form");

	new common.dropDown({el: "#status-filter"});
	new common.dropDown({el: "#type-filter"});

	var Bll = {
	    toast: function (item, prefix, url) {
	        var dialog = common.dialog.confirm(prefix + "图标信息",
	            common.util.__template2($("#toast-template").html(), item),
	            function () {
	                if(edit.validate()) {
	                    common.util.__ajax({
	                        url: url,
	                        data: module
	                    }, function () {
	                        dialog.close();
	                        g.reload();
	                    });
	                }
	                //console.log(item);
	                return false;
	        });
	        edit.init();
	        new common.dropDown({el: "#type"});
	        new common.dropDown({el: "#ico_key"});
	    }
	};

	var g = new common.grid({
	    el: "#content-list",
	    parms: function() {
	        return {
	            type: common.util.__input("type-filter"),
	            status: common.util.__input("status-filter"),
	            icoName:common.util.__input("icoName-filter")
	        }
	    },
	    columns: [
	        {display: "ID", name: 'id'},
	        {display: "名称", name: 'icoName'},
	        {display: "默认图片名称", name: 'defaultIco'},
	        {display: "高亮图片名称", name: 'ico'},
	        {display: "频道", render: function (item) {
	            return channelArr[item.type];
	        }},
	        {display: "key", name: 'icoKey'},
	        {display: "状态", render: function (item) {
	            if(item.status == 1) {
	                return "已开启";
	            } else {
	                return "已关闭";
	            }
	        }},
	        {display: "操作",
	            render: function(items) {
	                var HtmArr = [];
	                HtmArr.push('<a data-index="' + items.__index + '" class="btn btn-info btn-xs edit">编辑</a>');
	                if(items.status == 1) {
	                    HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-danger btn-xs closeStatus">关闭入口</a>');
	                } else {
	                    HtmArr.push('<a href="javascript:;" data-id="' + items.id + '" class="btn btn-success btn-xs publishStatus">开启入口</a>');
	                }
	                return HtmArr.join('');
	            }
	        }
	    ]
	});

	g.init("/icon/getList");


	//筛选
	$(document).on("click", "#filter-btn", function () {
	    g.reload(1);
	});

	//关闭图标入口
	$(document).on("click", ".closeStatus", function () {
	    common.util.__ajax({
	        url: "/icon/closeIcon",
	        data: {id: $(this).data("id")}
	    }, function () {
	        g.reload();
	    });
	});

	//开启图标入口
	$(document).on("click", ".publishStatus", function () {
	    common.util.__ajax({
	        url: "/icon/publishIcon",
	        data: {id: $(this).data("id")}
	    }, function () {
	        g.reload();
	    });
	});

	//添加信息
	$(document).on("click", "#addInfo", function () {
	    module = {};
	    Bll.toast(module, "添加", "/icon/addIcon");
	});

	//编辑
	$(document).on("click", ".edit", function () {
	    module = g.rows[$(this).data("index")];
	    Bll.toast(module, "编辑", "/icon/updateIcon");
	});

	//监听数据变化
	$(document).on("change", ".observe", function () {
	    module[$(this).data("field")] = $(this).val();
	});

	$(document).on("click", "#chooseFile", function () {
	    $("#uploadBox").click();
	});

/***/ }
]);