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


var $ = require('jquery'),
    common = require('../common/common');

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

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

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

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("productName"),
            status: common.util.__input("status")

        };
    },
    columns: [{
        display: '',
        type: 'checkbox'
    }, {
        display: 'ID',
        name: 'id',

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

    }, {
        display: '款型系列名称',
        name: 'seriesName'
    }, {
        display: '类型',
        name:'type'
    }, {
        display: 'banner图片',
        render: function(item) {
            return '<img src="' + item.picImgUrl + '">';
        }

    }, {
        display: '排序',
        name: 'orderBy'
    }, {
        display: '状态',
        name: 'status'
    },  {
        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', {});
});

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

    console.log(item);
    attributeOp("修改", '/erpproduct/brandfolder/update', item);
});


function attributeOp(prefix, url, item) {

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

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

    });

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

    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}
    },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}
    },function(){
        g.reload();
    });
});