Index.js 7.08 KB
var $ = require('jquery'),
    common = require('../../../common/common');

new common.dropDown({el: '#filter-dep'});

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

var t = new common.tab({
    el: "#basicTab",
    click: function () {
        g.reload(1);
    },
    columns: [
        {name: "0", display: "待审核({0})"},
        {name: "1", display: "审核通过({1})", active: true},
        {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 {
            batchNo: common.util.__input("filter-id"),
            name: common.util.__input("filter-name"),
            reqDepartment: common.util.__input("filter-dep"),
            status: t.active,
            skn: common.util.__input("filter-skn"),
            sku: common.util.__input("filter-sku")
        };
    },
    columns: [
        {
            display: "批次号", name: "batchNo", render: function (item) {
            return '<a href="/market/limitcode/info/' + item.id + '">' + item.batchNo + '</a>';
        }
        },
        {
            display: "基本信息", render: function (item) {
            var arr = [];
            arr.push("<p>名称:" + item.name + "</p>");
            arr.push("<p>数量:" + item.limitTimes + "</p>");
            arr.push("<p>次数:" + item.userUseLimit + "</p>");
            arr.push("<p>部门:" + item.reqDepartment + "</p>");
            return arr.join('');
        }
        },
        {
            display: "使用日期", render: function (item) {
            return item.limitDateFrom + "</br> 至 " + item.limitDateTo;
        }
        },
        {
            display: "限购码使用说明", name: "describe", render: function (item) {
            return '<p style="max-width: 200px;word-wrap: break-word;">' + item.describe + '</p>';
        }
        },
        {
            display: "SKN/SKU", render: function (item) {
            var arr = [];
            var skn = item.limitSkn ? item.limitSkn : "";
            arr.push('<p style="max-width: 200px;word-wrap: break-word;">SKN:' + skn + '</p>');
            if (item.limitCodeType == "U" && item.skus) {
                var skuArr = item.skus.split(";");
                arr.push('<p style="max-width: 200px;word-wrap: break-word;">SKU:');
                for (var i = 0; i < skuArr.length; i++) {
                    if (i > 0) {
                        arr.push(";");
                    }
                    if (i != 0 && i % 2 == 0) {
                        arr.push("<br>");
                    }
                    arr.push(skuArr[i]);
                }
                arr.push('</p>');
            }
            return arr.join("");
        }
        },
        {
            display: "申请人", name: "creatorName", render: function (item) {
            item.creatorName=item.creatorName?item.creatorName:"";
            item.createTime=item.createTime?item.createTime:"";
            return item.creatorName+ '<br>' + item.createTime;
        }
        },
        {
            display: '状态', render: function (item) {
            var html = ENUM.status[item.status] || '全部';
            if (item.reason) {
                if (item.status == 2 || item.status == 4) {
                    html += '<p style="color:red;word-wrap: break-word;">(' + item.reason + ')</p>';
                }
            }
            return html;
        }
        },
        {
            display: "操作", render: function (item) {
            var HtmArr = [];
            //限购码状态0:待审核 1:审核通过 2:驳回 3:过期 4:作废
            HtmArr.push('<a href="/market/limitcode/info/' + item.id + '" class="btn btn-primary btn-xs">查看详情</a>');
            if (item.status == 0) {
                HtmArr.push('<a class="btn btn-success btn-xs apply-success" data-index="' + item.__index + '" href="javascript:;">通过</a>');
                HtmArr.push('<a class="btn btn-warning btn-xs apply-back" data-index="' + item.__index + '" href="javascript:;">驳回</a>');
                HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-index="' + item.__index + '" href="javascript:;">作废</a>');
            } else if (item.status == 1) {
                HtmArr.push('<a class="btn btn-danger btn-xs apply-cancel" data-index="' + item.__index + '" href="javascript:;">作废</a>');
                HtmArr.push('<a class="btn btn-info btn-xs" data-index="' + item.__index + '" href="/market/limitcode/edit/' + item.id + '">编辑</a>');
            } else if (item.status == 2) {
                HtmArr.push('<a class="btn btn-info btn-xs apply-modify" href="/market/limitcode/update/' + item.id + '">修改</a>');
            }
            return HtmArr.join('');
        }
        }
    ]
});
g.init("/limitCode/getLimitCodeList");

//tab
var loadtab = function () {
    t.active = undefined;
    setTimeout(function () {
        common.util.__ajax({
            url: '/limitCode/getLimitCodeCountByStatus',
            data: g.options.parms()

        }, function (res) {
            var __dt = $.extend({}, ENUM.tips, res.data);
            t.init(__dt);
        }, true);
    }, 400);
};
loadtab();

$("#filter-btn").click(function () {
    g.reload(1);
});

var Bll = {
    toast: function (content, fn) {
        common.dialog.confirm("温馨提示", content, function () {
            common.util.__ajax({
                url: '/limitCode/auditLimitCode',
                data: fn()
            }, function () {
                g.reload();
                loadtab();
            });
        });
    }
};
//审核通过
$('#basicTable').on('click', '.apply-success', function () {
    var item = g.rows[$(this).data("index")];
    var data = function () {
        return {
            id: item.id,
            status: 1
        };
    };
    Bll.toast("确定要通过该申请吗?", data);
});

//驳回
$('#basicTable').on('click', '.apply-back', function () {
    var item = g.rows[$(this).data("index")];
    var data = function () {
        var reason = $('#reason').val();
        if (reason === '' || $.trim(reason) === '') {
            return "请填写驳回原因";
        }
        return {
            id: item.id,
            status: 2,
            reason: reason
        };
    };
    Bll.toast(common.util.__template($("#template").html(), {name: "你确定要驳回该申请吗?"}), data);
});

//作废
$('#basicTable').on('click', '.apply-cancel', function () {
    var item = g.rows[$(this).data("index")];

    var data = function () {
        var reason = $('#reason').val();
        if (reason == '' || $.trim(reason) == '') {
            return "请填写作废原因";
        }
        return {
            id: item.id,
            status: 4,
            reason: reason
        };
    };
    Bll.toast(common.util.__template($("#template").html(), {name: "你确定要作废此限购码吗?"}), data);
});