cod-brand.js 8.76 KB
/**
 * Created by wangqianjun on 16/4/11.
 * 货到付款设置
 */
'use strict';
var $ = require('jquery'),
    common = require('../common/common');

var ENUM = {
    enum: {
        1: '待审核',
        2: '驳回',
        3: '通过',
        all: "全部商品"
    },
    tips: {
        "100": 0,
        "300": 0,
        "400": 0
    }
}


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

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


var t = new common.tab({
    el: "#basicTab",
    click: function() {

        var columnname = $(this).find('a').attr('columnname');

        if (columnname == '400') {
            g.options.columns[1].hidden = false;
            g.options.columns[2].hidden = true;
            g.options.columns[3].hidden = true;
            g.options.columns[4].hidden = true;
            g.options.columns[5].hidden = false;

        } else if(columnname == 100) {
            g.options.columns[1].hidden = true;
            g.options.columns[2].hidden = false;
            g.options.columns[3].hidden = false;
            g.options.columns[4].hidden = true;
            g.options.columns[5].hidden = false;
        } else {
            g.options.columns[1].hidden = true;
            g.options.columns[2].hidden = false;
            g.options.columns[3].hidden = false;
            g.options.columns[4].hidden = false;
            g.options.columns[5].hidden = true;
        }
        g.init('/supplier/baseproduct/ajax/index');
    },
    columns: [{
        name: "100",
        display: "待审核({1})",
        value: ''
    }, {
        name: "300",
        display: "驳回({2})",
        value: ''
    }, {
        name: "400",
        display: "全部",
        value: ''
    }]
}).init(ENUM.tips);


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

            //productSkn: common.util.__input("productSkn"),
            //productSkc: common.util.__input("productSkc"),
            //productSku: common.util.__input("productSku"),
            //productName: common.util.__input("productName"),
            //shopId: common.util.__input("shopId"),
            brandId: common.util.__input("brandId"),
            isPayDelivery: common.util.__input("isPayDelivery"),
            //gender: common.util.__input("gender"),
            //maxSortId: tabTree.selected.length > 0 ? tabTree.selected[0].id : "", // 一级类目
            //middleSortId: tabTree.selected.length > 1 ? tabTree.selected[1].id : "", // 二级类目
            //smallSortId: tabTree.selected.length > 2 ? tabTree.selected[2].id : "", // 三级类目
            //size: common.util.__input("size"),
            checkStatus: 100

        };
    },
    columns: [{
        display: '品牌',
        type: 'brandName'
        },
        // 审核状态(全部商品是显示) 1
        {
            display: "状态",
            render: function(item) {
                var html = [];
                html.push("<p>" + ENUM.status[item.status] + "</p>");

                //if (item.status == 3 || item.status == 6) {
                //    html.push("<p style='color:red;'>" + filterNull(item, 'rejectReason') + "</p>");
                //}

                return html.join('');
            }
        },
        { //2
            display: "申请人",
            hidden: true,

            render: function(item) {
                var html = [];
                html.push("<p>" + common.util.__filterNull(item, 'founderName') + "</p>");

                return html.join('');
            }
        }, { //3
            display: "申请时间",
            hidden: true,

            render: function(item) {
                var html = [];
                html.push("<p>" + common.util.__filterNull(item, 'editTime') + "</p>");

                return html.join('');
            }
        },{
            // 4
            display: '驳回理由',
            hidden: true,
            name: 'status', //  8待上架,2待审核,3驳回,4通过,1已上架,0已下架,5再上架待审核,6再上架驳回,7再上架通过
            render: function(item) {
                var html = '';
                html += ENUM.status[item.status];
                if (item.status == 3 || item.status == 6) {
                    html += '<p style="color:red;">' + common.util.__filterNull(item, 'rejectReason') + '</p>'
                }
                return html;
            }
        }, { // 5
            display: "操作",
            render: function(item) {
                var html = [];


                //html.push('<a data-index="'+ item.__index+ '" href="JavaScript:;" class="btn btn-info btn-xs edit-class-btn" id="btn-item-info">查看</a>');
                html.push('<a href="/goods/audit/info/' + item.productSkn + '" class="btn btn-info btn-xs info-btn">查看</a>');

                //if (item.status == 3 || item.status == 6) { // 驳回
                //    html.push('<a data-index="'+ item.__index+ '" href="JavaScript:;" class="btn operation btn-success btn-xs edit-class-btn" id="btn-item-pass">通过</a>');
                //}

                if (item.status == 2 || item.status == 5) { // 待审核
                    html.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn operation btn-success btn-xs edit-class-btn" id="btn-item-pass">通过</a>');
                    html.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn operation btn-danger btn-xs edit-class-btn" id="btn-item-reject">驳回</a>');
                }


                return html.join('');
            }
        },
    ]
});
g.init('/payDelivery/queryAllBrandPayDelivery');

// tab初始化
var loadTab = function() {
    t.active = undefined;
    setTimeout(function() {
        common.util.__ajax({
            url: "/supplier/baseproduct/auditCount",
            data: g.options.parms()
        }, function(res) {
            var __dt = $.extend({}, ENUM.tips, res.data);
            t.init(__dt);
        }, true);
    }, 800);
}

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

var Bll = {
    toast: function(content, fn) {
        common.dialog.confirm("温馨提示", content, function() {
            common.util.__ajax({
                url: '/supplier/baseproduct/auditReject',
                data: fn()
            }, function() {
                g.reload();
                loadTab();
            });
        });
    }
}


//批量驳回
$(document).on("click", "#reject-btn", function() {

    var selectedArr = g.selected,
        len = selectedArr.length,
        sknList = [];
    if (len <= 0) {
        common.util.__tip('请选择要驳回的商品', 'warning');
        return;
    }

    var data = function() {
        var reason = $('#reason').val();
        if (reason === '' || $.trim(reason) === '') {
            return "请填写驳回原因";
        }

        $.each(selectedArr, function(i, value) {
            sknList.push(value['productSkn']);

        });

        console.log(sknList);

        return {
            productSknList: JSON.stringify(sknList),
            targetStatus: 3, // 驳回
            rejectReason: reason
        };
    }
    Bll.toast($("#template").html(), data);
});

//批量通过
$(document).on("click", "#pass-btn", function() {

    var selectedArr = g.selected,
        len = selectedArr.length,
        sknList = [];
    if (len <= 0) {
        common.util.__tip('请选择审核通过的商品', 'warning');
        return;
    }

    var data = function() {

        $.each(selectedArr, function(i, value) {
            sknList.push(value['productSkn']);

        });

        console.log(sknList);

        return {
            productSknList: JSON.stringify(sknList),
            targetStatus: 4, // 通过
            rejectReason: ""
        };
    }
    Bll.toast("确定要通过该申请吗?", data);
});

// 单个驳回
$(document).on("click", "#btn-item-reject", function() {
    //auditOperation([],3,)
    var item = g.rows[$(this).data("index")];

    var data = function() {

        var reason = $('#reason').val();
        if (reason === '' || $.trim(reason) === '') {
            return "请填写驳回原因";
        }

        return {
            productSknList: JSON.stringify([item.productSkn]),
            targetStatus: 3, // 驳回
            rejectReason: reason
        };
    }
    Bll.toast($("#template").html(), data);
});


// 单个通过
$(document).on("click", "#btn-item-pass", function() {
    //auditOperation([],3,)
    var item = g.rows[$(this).data("index")];

    var data = function() {

        return {
            productSknList: JSON.stringify([item.productSkn]),
            targetStatus: 4, //通过
            rejectReason: ""
        };
    }
    Bll.toast("确定要通过该申请吗?", data);
});