index.js 7.62 KB
'use strict';
var $ = require('jquery'),
    common=require('../common/common');

var ENUM={
    status:{0:'待审核',1:'审核通过',2:'驳回',3:'过期',4:'作废'},//全部
    tips:{"0":0,"1":0,"2":0,"3":0,"4":0,"all":0}
}

// 审核状态枚举
var AuditEnum = {
    status:{
        100:"未审核",
        200:"审核通过",
        300:"审核不通过"
    }
}

// 年龄层枚举
var AgeLevelEnum = {
    level: {
        1:"成人",
        2:"大童",
        3:"小童",
        "":"未知年龄"
    }
}

// 性别
var GenderEnum = {
    gender: {
        1: "男",
        2: "女",
        3: "通用"
    }
}

// 商品类型
var GoodsTypeEnum = {
    type: {
        1:"普通商品",
        2:"赠品",
        3:"虚拟商品",
        "":"未知类型"
    }
}


var YNEnum = {
    enum:{
        "Y":"是",
        "N":"否"
    }
}

/*下拉选择*/
new common.dropDown({el:"#shopId",ajax:"queryShop"});
new common.dropDown({el:"#brandId",ajax:"queryBrand"});
new common.dropDown({el:"#founder",ajax:"querySupplier"});

var tabTree=new common.tabTree("#sort");
tabTree.init();

var t = new common.tab({
    el:"#basicTab",
    click:function(){
        g.reload(1);
    },
    columns:[
        {name:"0",display:"待审核({0})"},
        {name:"1",display:"审核通过({1})"},
        {name:"2",display:"驳回({2})"},
        {name:"3",display:"过期({3})"},
        {name:"4",display:"作废({4})"},
        {name:"all",display:"全部({all})"}
    ]
}).init(ENUM.tips);


var g = new common.grid({
    el: '#basicTable',
    parms:function(){
    	return {
            productSkn:common.util.__input("productSkn"),
            brandId:common.util.__input("brandId"),
            name:common.util.__input("filter-name"),
            reqDepartment:common.util.__input("filter-dep"),
            status: t.active,
            sortId: tabTree.selected.length>0?tabTree.selected[tabTree.selected.length-1].id:""
        };
    },
    columns:[
        {display:"SKN",render:function(item){
            var html=[];
            html.push('<a data-index="'+ item.__index+ '" href="/base/goods/info/'+ item.productSkn +'" class="btn btn-info btn-xs edit-class-btn">'+item.productSkn+'</a>');

            return html.join('');
        }},
    	{display:"商品信息",render:function(item){
    		var html=[];

            var catgory = item.maxSortName;

    		html.push("<p>名称:"+item.productName+"</p>");
    		html.push("<p>品牌:"+item.brandName+"</p>");
    		html.push("<p>品类:"+catgory+"</p>");
    		return html.join('');
    	}},

        {display:"售价",render:function(item){
            var html=[];

            html.push("<p>吊牌价:"+item.retailPrice+"</p>");
            html.push("<p>销售价:"+item.salesPrice+"</p>");

            //待审核和驳回列表中只显示吊牌价和销售价,通过的列表中显示四种
            if (item.isAuditing === 200) {
                html.push("<p>是否VIP:"+YNEnum.enum(item.isVip)+"</p>");
                html.push("<p>yoho币:"+item.yohoCoin+"</p>");
            }

            return html.join('');
        }},

        {display:"年龄层/性别",render:function(item){
            var html=[];
            var ageLevel = AgeLevelEnum.level[item.ageLevel];
            var gender = GenderEnum.gender[item.gender];
            html.push("<p>"+ageLevel+" / "+gender+"</p>");

            return html.join('');
        }},

        {display:"是否预售",render:function(item){

            var html=[];
            //判断是否是预售商品
            if (item.isAdvance === "Y") {
                var t = new Date(item.createTime * 1000);
                var formatted = t.format("yyyy.mm.dd hh:MM:ss");
                html.push("<p>是</p>");
                html.push("<p>预售库存:"+item.productName+"</p>");
                html.push("<p>预计到货时间:"+formatted+"</p>");
            } else {
                var t = new Date(item.createTime * 1000);
                var formatted = t.format("yyyy.mm.dd hh:MM:ss");
                html.push("<p>否</p>");
                html.push("<p>预计上架时间:"+formatted+"</p>");
            }

            return html.join('');
        }},

    	{display:"奥莱", render: function(item) {
            if (item.isOutLets == "Y") {
                return "<p>奥莱</p>" ;
            } else {
                return "<p>否</p>";
            }
        }},

        {display:"商品类别", render: function(item) {
            var type = GoodsTypeEnum.type[item.attribute] ? GoodsTypeEnum.type[item.attribute]:"未知类型";
            return "<p>"+type+"</p>"
        }},

        {display:"其他",render:function(item){
            var html=[];
            var grade = (item.grade == 1) ? "重点款" : "非重点款";
            var limited = (item.isLimited == "Y")? "限量款" : "非限量款";
            var limitedPurchase = (item.isLimitbuy == "Y")? "限购" : "非限购";
            var replenishment = "暂无此字段";
            var gender = GenderEnum.gender[item.gender];

            html.push("<p>"+grade+"</p>");
            html.push("<p>"+limited+"</p>");
            html.push("<p>"+limitedPurchase+"</p>");
            html.push("<p>"+replenishment+"</p>");


            return html.join('');
        }},


        {display:"创建时间",render: function (item) {
            var t = new Date(item.createTime * 1000);
            var formatted = t.format("yyyy-mm-dd hh:MM:ss");
            return "<p>"+formatted+"</p>";
        }},
    	{display:"创建人",name:"createUser"},

        {display:"操作",render:function(item){
            var html=[];
            html.push('<a data-index="'+ item.__index+ '" href="JavaScript:;" class="btn btn-info btn-xs edit-class-btn">修改</a>');
            html.push('<a data-index="'+ item.__index+ '" href="JavaScript:;" class="btn btn-info btn-xs edit-class-btn">通过</a>');
            html.push('<a data-index="'+ item.__index+ '" href="JavaScript:;" class="btn btn-info btn-xs edit-class-btn">驳回</a>');

            return html.join('');
        }},
    ]
});
g.init('/base/goods/ajax/index');

// 筛选
$(document).on('click', "#filter-btn", function () {

    g.reload();
});


var Bll={
	toast:function(content,fn){
        common.dialog.confirm("温馨提示",content,function(){
            common.util.__ajax({
                url:'/supplier/index/status',
                data:fn()
            },function(){
                g.reload();
            });
        });
    }
}
//通过
$(document).on("click",".apply-success",function(){
	var item=g.rows[$(this).data("index")];
    var data=function(){
        return {
                id:item.id
            };
    }
    Bll.toast("你确定审核通过吗?",data);
});
//驳回
$(document).on("click",".apply-back",function(){
	var item=g.rows[$(this).data("index")];
    var data=function(){
        return {
                id:item.id
            };
    }
    Bll.toast($("#template").html(),data);
});


// 时间转化
Date.prototype.format = function(format) {
    var date = {
        "M+": this.getMonth() + 1,
        "d+": this.getDate(),
        "h+": this.getHours(),
        "m+": this.getMinutes(),
        "s+": this.getSeconds(),
        "q+": Math.floor((this.getMonth() + 3) / 3),
        "S+": this.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
}