Index.js 8.05 KB

'use strict';
var $ = require('jquery'),
    common=require('../../common/common');
//基础模板,经典模板切换
$(document).on("click",".tabheader .nav-tabs li",function(){
    $(this).addClass('active').siblings('li').removeClass('active');
});

//店铺VIP管理
new common.dropDown({el: "#brand-name", ajax: "brand"});
new common.dropDown({el: "#supplier-name", ajax: "supplier"});
new common.dropDown({el: "#shop-name", ajax: "queryShopNames", params: function() {
    return {
        "checkStatus": common.util.__input("status"),
        "operationStatus": 2, // 店铺表中只有创建和未创建两个状态,没有operation_status为0的店铺信息
        "checkStatusArr": "200,300,900"
    };
}});


$('#filter-btn').on('click', function () {
    g1.reload(1);
});

var g1 = new common.grid({
    el: '#basicTable',
    parms: function () {
        return {
            "supplierId": common.util.__input("supplier-name"),
            "brandId": common.util.__input("brand-name"),
            "operationStatus": 2,
            "checkStatusArr": "200,300,900",
            "blkCheckStatus": 200,
            "shopsId": common.util.__input("shop-name"),
            "vipStatus": common.util.__input("vip-status"),
            "vipFlag": "1"
        };
    },
    columns: [
        {display: "店铺ID", name: "shopsId"},
        {display: "店铺名称", name: "shopName"},
        {
            display: "包含品牌", name: "shopRelationList", render: function (item) {
            var brandArr = [];
            if (item.shopRelationList) {
                $.each(item.shopRelationList, function (index, a) {
                    if($.inArray(a.brandName, brandArr) === -1) {
                        brandArr.push(a.brandName);
                    }
                });
            }

            return '<p>' + brandArr.join('</p><p>') + '</p>';
        }
        },
        {display: "创建时间", name: "createTime"},
        {display: "更新时间", name: "updateTime"},
        {
            display: "VIP设置", name: "vipStatus", render: function (item) {
            var status = '';
            if(+item.vipStatus == 1){
                status = "开启";
            } else {
                status = "关闭";
            }
            return status;
        }
        },
        {
            display: "操作", name: "", render: function (item) {
            var HtmArr = [];

            if (+item.agreementVipStatus == 1) {
                if (+item.vipStatus == 1) {
                    HtmArr.push('<a href="javascript:void(0);" data-id="' + item.shopsId + '" data-status="2" class="btn btn-danger btn-xs delete">关闭</a>');
                } else {
                    HtmArr.push('<a href="javascript:void(0);" data-id="' + item.shopsId + '" data-status="1" class="btn btn-success btn-xs delete">开启</a>');
                }
            }

            return HtmArr.join('');
        }
        }
    ]
})
g1.init($('#url').val());

/**
 * 关闭--点击事件
 */
$(document).on('click', '.delete', function () {
    var shopsId = $(this).attr("data-id");
    var vipStatus = $(this).attr("data-status");
    var message = (vipStatus == 1 ? "开启": "关闭");
    common.dialog.confirm("警告",
        "确认" + message + "?",
        function () {
            common.util.__ajax({
                url: '/vip/shop/trigger',
                data: { shopsIds: shopsId, vipStatus: vipStatus }
            }, function () {
                g1.reload();
            });
        });
});


// 初始化筛选框
new common.dropDown({el: "#shopId", ajax: "shopsRest"});
new common.dropDown({el: "#brandId", ajax: "brand"});
/**
 * 商品VIP列表
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#productVipTable',
    parms: function () {
        return {
            productSkn: common.util.__input('productSkn'),
            shopId: common.util.__input('shopId'),
            brandId: common.util.__input('brandId'),
            productVipStatus: common.util.__input('productVipStatus')
        };
    },
    columns: [
        {
            display: "复选框",
            width: 90,
            render: function (item) {
                var HtmArr = [];
                    HtmArr.push('<label><input name="choose" type="checkbox" value="'+item.productSKN+'"/></label>');
                return HtmArr.join('');
            }
        },
        {
            display: "SKN",
            name: "productSKN"
        }, {
            display: "店铺",
            name: "shopName"
        }, {
            display: "品牌",
            name: "brandName"
        }, {
            display: "VIP状态",
            render: function (item) {
                var HtmArr = [];
                if(item.productVipStatus == 1){
                    HtmArr.push('<label>开启</label>');
                }else{
                    HtmArr.push('<label>关闭</label>');
                }
                return HtmArr.join('');
            }
        }, {
            display: "跟随店铺",
            render: function (item) {
                var HtmArr = [];
                if(item.isFlowShop == 0){
                    HtmArr.push('<label>是</label>');
                }else{
                    HtmArr.push('<label>否</label>');
                }
                return HtmArr.join('');
            }
        }, {
            display: '操作',
            render: function (item) {
                var HtmArr = [];
                    HtmArr.push('<a onclick="changeStatus('+item.productSKN+',0)" href="javascript:;" class="btn btn-primary">跟随店铺</a>');
                    HtmArr.push('<a onclick="changeStatus('+item.productSKN+',1)" href="javascript:;" class="btn btn-info">开启</a>');
                    HtmArr.push('<a onclick="changeStatus('+item.productSKN+',2)" href="javascript:;" class="btn btn-danger">关闭</a>');
                return HtmArr.join('');
            }
        }]
});
g.init('/vip/queryProductVipList');
/**
 * 批量修改商品VIP状态
 * @param status
 */
function batchChangeStatus(status) {
    var chk_value =[];
    $('input[name="choose"]:checked').each(function(){
        chk_value.push($(this).val());
    });
    if(chk_value.length==0) {
        alert("你还没有选择任何SKN!");
        return;
    }
    var params= {
        sknList: chk_value.toString(),
        changeStatus: status
    };
    common.dialog.confirm("警告",
        "确认批量修改商品VIP状态?",
        function () {
            common.util.__ajax({
                url: '/vip/batchChangeStatus',
                data: params
            }, function(res) {
                g.reload();
                $("[name='all']").removeAttr("checked");
            });
        });
}

/**
 * 搜索商品VIP
 */
$("#searchFilter").click(function() {
    g.reload(1);
    $("[name='all']").removeAttr("checked");
});

/**
 * 当个修改商品VIP状态
 * @param productSkn
 * @param status
 */
function changeStatus(productSkn,status) {
    var param = {
        productSkn: productSkn,
        productVipStatus: status
    };
    common.dialog.confirm("警告",
        "确认修改商品VIP状态?",
        function () {
            common.util.__ajax({
                url: '/vip/changeStatus',
                data: param
            }, function(res) {
                g.reload();
                $("[name='all']").removeAttr("checked");
            });
        });
};

/**
 * 全选、反选
 * @constructor
 */
function DoCheck()
{
    var ch=document.getElementsByName("choose");
    if(document.getElementsByName("all")[0].checked==true)
    {
        for(var i=0;i<ch.length;i++)
        {
            ch[i].checked=true;
        }
    }else{
        for(var i=0;i<ch.length;i++)
        {
            ch[i].checked=false;
        }
    }
}
window.DoCheck = DoCheck;
window.changeStatus = changeStatus;
/**
 * 切换TAB
 * @param tab
 */
function changeTab(tab) {
    if(tab == 1){
        $("#shopVipTab").show();
        $("#productVipTab").hide();
    }else if(tab == 2){
        $("#shopVipTab").hide();
        $("#productVipTab").show();
    }
}
window.changeTab = changeTab;
window.batchChangeStatus = batchChangeStatus;