baserule.Brandmodel.js 5.03 KB
webpackJsonp([6],[
/* 0 */
/***/ function(module, exports, __webpack_require__) {

	/**
	 * Created by wangqianjun on 16/3/7.
	 * 【商品基础规则】->【品牌款型系列】
	 */


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

	var TypeEnum = {
	    enum: {
	        1:"品牌款型",
	        2:"品牌系列",
	        "":""
	    }
	}

	var StatusEnum = {
	    enum: {
	        1:"开启",
	        0:"关闭",
	        "":""
	    }
	}


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

	new common.dropDown({
	    el:"#shop",
	    ajax:"queryShopPass"
	});

	new common.dropDown({
	    el:"#brand",
	    ajax:"brand"
	});

	var BUCKET={
	    "bucket" : "brandBanner"
	};

	var e = new common.edit('#form-base',BUCKET);
	e.init();

	var g = new common.grid({
	    el: "#basicTable",
	    parms: function() {

	        return {
	            seriesName: common.util.__input("models-name"),
	            shopsId: common.util.__input("shop"),
	            brandId: common.util.__input("brand"),
	            type: common.util.__input("models-type"),
	            status: common.util.__input("status"),
	            bannarImg: common.util.__input("bannarImg"),
	            id: common.util.__input("id")
	        };
	    },
	    columns: [{
	        display: '',
	        type: 'checkbox'
	    }, {
	        display: 'ID',
	        name: 'id',

	    }, {
	        display: '店铺',
	        name: 'shopsName'
	    }, {
	        display: '品牌',
	        name: 'brandName',

	    }, {
	        display: '款型系列名称',
	        name: 'seriesName'
	    }, {
	        display: '类型',
	        render: function(item) {

	            return '<p>'+TypeEnum.enum[item.type] +'<p>';
	        }
	    }, {
	        display: 'banner图片',
	        render: function(item) {
	            if(item.seriesBanner){
	                return '<img src="' + item.seriesBanner + '" style="width:78px; height:78px">';
	            }
	        }

	    }, {
	        display: '排序',
	        name: 'orderBy'
	    }, {
	        display: '状态',
	        render: function(item) {
	            return '<p>'+StatusEnum.enum[item.status] +'<p>';
	        }
	    },  {
	        display: '操作',
	        render: function(items) {
	            var HtmArr = [];

	            HtmArr.push('<a data-index="'+ items.__index+ '" href="JavaScript:;" class="btn btn-info btn-xs edit-class-btn">编辑</a>');

	            if (items.status === 0) {
	                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-warning btn-xs open-brand">开启</a>');
	            }
	            if (items.status === 1) {
	                HtmArr.push('<a data-index="' + items.__index + '" href="JavaScript:;" class="btn btn-danger btn-xs close-brand">关闭</a>');
	            }
	            return HtmArr.join('');
	        }
	    }]
	});

	g.init("/erpproduct/brandfolder/list");


	//全部
	$("#filter-btn").click(function(){
	    g.reload();
	});


	$("#add-btn").click(function(){
	    attributeOp("新建", '/erpproduct/brandfolder/add', {"orderBy":0});
	    $('#type').attr("disabled", false);
	});

	$(document).on('click', '.edit-class-btn', function () {
	    var item = g.rows[$(this).data('index')];

	    console.log(item);
	    attributeOp("修改", '/erpproduct/brandfolder/update', item);
	    $('#type').attr("disabled", true);

	});


	function attributeOp(prefix, url, item) {

	    var a = new common.edit(".confirm",BUCKET);
	    common.dialog.confirm(prefix + "款型系列", common.util.__template2($("#template").html(), item), function () {

	        return a.submit(url, function (option) {
	            option.data.categoryId = item.categoryId;
	            option.data.attributeId = item.attributeId;
	            option.data.shopsId = common.util.__input("shopsId");
	            option.success = function (res) {
	                res = res;
	                if (res.code == "200") {
	                    a.$tip("提交成功", function () {
	                        g.reload();
	                    }, 'growl-success');
	                } else {
	                    a.$tip(res.message);
	                }
	                return false;
	            },
	                option.error = function (res) {
	                    a.$tip(res.message);
	                }
	        });

	    });

	    new common.dropDown({
	        el:"#shopsId",
	        ajax:"queryShopPass"
	    });

	    new common.dropDown({
	        el:"#brandId",
	        ajax:"brand"
	    });
	    a.init();
	}


	//关闭
	$('tbody').on('click', '.close-brand', function() {
	    var item=g.rows[$(this).data("index")];
	    common.util.__ajax({
	        url:'/erpproduct/brandfolder/close',
	        data:{id:item.id, type: item.type}
	    },function(){
	        g.reload();
	    });
	});

	//开启
	$('tbody').on('click', '.open-brand', function() {
	    var item=g.rows[$(this).data("index")];
	    common.util.__ajax({
	        url:'/erpproduct/brandfolder/open',
	        data:{id:item.id, type: item.type}
	    },function(){
	        g.reload();
	    });
	});

/***/ }
]);