Goods.js 8.18 KB
/**
 * Created by wangqianjun on 16/4/12.
 */
'use strict';
var $ = require('jquery'),
    common = require('../../../common/common');

var ENUM = {
    tips: {
        "100": 0,
        "300": 0,
        "all": 0
    },
    status: {
        '1': "开启",
        '0': "关闭"

    }
};

var currentSelItem, currentTab = 'all';

/*下拉选择*/
common.dropDown({
    el: "#brandId",
    ajax: "brand",
    params:function(){
        return{userLimitFlag:true};
    }
});
common.dropDown({
    el: "#productSkn",
    ajax: "codGetSknList"
});

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

var t = new common.tab({
    el: "#basicTab",
    click: function () {
        var columnname = $(this).find('a').attr('columnname');
        currentTab = columnname;
        layoutGridCloum(columnname);
        g.init('/payDelivery/queryPayDeliveryList');
    },
    columns: [{
        name: "100",
        display: "待审核({1})",
        value: ''
    }, {
        name: "300",
        display: "驳回({2})",
        value: ''
    }, {
        name: "all",
        display: "全部({3})",
        value: ''
    }]
}).init(ENUM.tips);

var g = new common.grid({
    el: '#basicTable',
    parms: function () {
        return {
            brandId: common.util.__input("brandId"),
            isPayDelivery: common.util.__input("isPayDelivery"),
            productSkn: common.util.__input("productSkn"),
            status: (currentTab && currentTab != 'all') ? currentTab : 400
        };
    },
    columns: [{
        display: 'SKN',
        name: 'productSkn'
    }, {
        display: '品牌',
        name: 'brandName'
    },
        // 审核状态(全部商品是显示) 2
        {
            display: "货到付款状态",
            render: function (item) {
                var html = [];
                html.push("<p>" + ENUM.status[item.isPayDelivery] + "</p>");
                return html.join('');
            }
        },
        { //3
            display: "申请人",
            hidden: true,

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

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

            render: function (item) {
                var html = [];
                html.push("<p>" + common.util.__filterNull(item, 'createTime') + "</p>");
                return html.join('');
            }
        }, {
            // 5
            display: '驳回理由',
            hidden: true,
            name: 'rejectReason', //  8待上架,2待审核,3驳回,4通过,1已上架,0已下架,5再上架待审核,6再上架驳回,7再上架通过
            render: function (item) {
                return '<p style="color:red;">' + common.util.__filterNull(item, 'rejectReason') + '</p>';
            }
        }, { // 6
            display: "操作",
            render: function (item) {
                var html = [];
                if (item.isPayDelivery == 1) { // 待审核
                    html.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn operation btn-danger btn-xs edit-class-btn" id="btn-item-close" data-type="close">关闭</a>');
                } else {
                    html.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn operation btn-success btn-xs edit-class-btn" id="btn-item-open" data-type="open">开启</a>');

                }
                return html.join('');
            }
        }, { // 7
            display: "操作",
            hidden: true,
            render: function (item) {
                var html = [];
                html.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn operation btn-danger btn-xs edit-class-btn" id="btn-item-reject" data-type="reject">驳回</a>');
                html.push('<a data-index="' + item.__index + '" href="JavaScript:;" class="btn operation btn-success btn-xs edit-class-btn" id="btn-item-pass" data-type="pass">通过</a>');
                return html.join('');
            }
        }
    ]
});
g.init('/payDelivery/queryPayDeliveryList');

function layoutGridCloum(tabname) {
    if (tabname == 'all') {
        g.options.columns[2].hidden = false;
        g.options.columns[3].hidden = true;
        g.options.columns[4].hidden = true;
        g.options.columns[5].hidden = true;
        g.options.columns[6].hidden = false;
        g.options.columns[7].hidden = true;
    } else if (tabname == 100) {
        g.options.columns[2].hidden = true;
        g.options.columns[3].hidden = false;
        g.options.columns[4].hidden = false;
        g.options.columns[5].hidden = true;
        g.options.columns[6].hidden = true;
        g.options.columns[7].hidden = false;
    } else {
        g.options.columns[2].hidden = true;
        g.options.columns[3].hidden = false;
        g.options.columns[4].hidden = false;
        g.options.columns[5].hidden = false;
        g.options.columns[6].hidden = true;
        g.options.columns[7].hidden = true;
    }
}

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

var reloadTab = function () {
    t.active = undefined;
    setTimeout(function () {
        common.util.__ajax({
            url: "/payDelivery/queryCountProductPayDelivery",
            data: g.options.parms()
        }, function (res) {
            var __dt = $.extend({}, ENUM.tips, res.data);
            t.load(__dt);
        }, true);
    }, 800);
};

loadTab();
// 筛选
$(document).on('click', "#filter-btn", function () {
    //loadTab();
    reloadTab();
    //g.options.columns[2].hidden = false;
    //g.options.columns[3].hidden = true;
    //g.options.columns[4].hidden = true;
    //g.options.columns[5].hidden = true;
    //g.options.columns[6].hidden = false;
    //g.options.columns[7].hidden = true;
    layoutGridCloum(currentTab);
    g.reload();
    //g.init('/payDelivery/queryPayDeliveryList');
});

$(document).on('click', ".edit-class-btn", function () {
    var btnType = $(this).data('type');
    var url = '';
    var alertContent;
    currentSelItem = g.rows[$(this).data("index")];
    var data = function () {

        var reason = $('#reason').val();
        if (reason === '' || $.trim(reason) === '') {
            if (btnType == 'reject') {
                return "请填写驳回原因";
            }
        }
        return {
            productSkn: currentSelItem.productSkn,
            brandName: currentSelItem.brandName,
            brandId: currentSelItem.brandId,
            rejectReason: reason,
            id: currentSelItem.id
        };
    };

    switch (btnType) {
        case 'open':
        {
            url = '/payDelivery/openPayDelivery';
            alertContent = '开启货到付款无需组长审核,您确定开启吗?';
        }
            break;

        case 'close':
        {
            url = '/payDelivery/closePayDelivery';
            alertContent = '关闭货到付款需组长审核,您确定提交此申请吗?';

        }
            break;

        case 'pass':
        {
            url = '/payDelivery/passPayDelivery';
            alertContent = '您确定要通过申请吗?';
        }
            break;

        case 'reject':
        {
            url = '/payDelivery/rejectPayDelivery';
            alertContent = $("#template").html();
        }
            break;

        default :
        {
            url = '';
            alertContent = '未知弹框~';
        }
            break;
    }

    common.dialog.confirm("温馨提示", alertContent, function () {
        common.util.__ajax({
            url: url,
            data: data()
        }, function () {
            g.reload();
            reloadTab();
        });
    });
});

$('#export-btn').on('click', function () {
    window.open("/ajax/down?queryConf=" + JSON.stringify(g.options.parms()) + "&type=productPayDeliveryExport");
});