Index.js 4.45 KB
/*
 *@time: 2016.10.10
 *@author: LiQZ
 */
var $ = require('jquery'), common = require('../../../common/common');

var artTemplate = common.artTemplate;

new common.dropDown({el: "#brand-name", ajax: "brand"});

var tableGird = new common.grid({
    el: "#table-box",
    size: 30,
    parms: function() {
        return {
            "productName": common.util.__input('productName'),
            "productSkn": common.util.__input('productSkn'),
            "minCount": $("#minCount").val(),
            "brand": common.util.__input("brand-name")
        };
    },
    columns: [
    { display: "SKN", render: function(items) {
        return items.productSkn;
    }},
    { display: "图片", render: function(items) {
        if (items.defaultImg) {
            return "<img src=\"" + items.defaultImg + "\" />";
        }
        return "";
    }},
    { display: "商品信息", render: function(items) {
        return "名称:" + t(items.productName) + "<br/>品牌:" + t(items.brand) + "<br/>品类:" + t(items.sort);
    }},
    { display: "售价", render: function(items) {
        return "吊牌价:" + t(items.retailPrice) + "<br/> 销售价:" + t(items.salesPrice);
    }},
    { display: "量贩折扣", render: function(items) {
        return items.discount;
    }},
    { display: "起购件数", render: function(items) {
        return items.minCount;
    }},
    { display: "促销名称", render: function(items) {
        return items.promotionPhrase;
    }},
    { display: "状态", render: function(items) {
        return items.status == 1 ? "开启" : "关闭";
    }},
    { display: "操作信息", render: function(items) {
        return items.operator + " " + common.util.__secondsFormat(items.updateTime);
    }},
    { display: "操作", render: function(items) {
            var HtmArr = [];
            HtmArr.push('<a href="/product/batch/' + items.id + '" data-id="' + items.id + '" class="btn btn-primary btn-xs">编辑</a>');
            if (items.status == 1) {
                HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" data-status="2" class="btn btn-danger btn-xs delete">关闭</a>');
            } else {
                HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" data-status="1" class="btn btn-danger btn-xs delete">开启</a>');
            }
            HtmArr.push('<a href="javascript:void(0);" data-index="' + items.__index + '" data-id="' + items.id + '" class="btn btn-xs btn-info history">操作记录</a>');
            HtmArr.push('<a href="javascript:void(0);" data-id="' + items.id + '" class="btn btn-warning btn-xs sync">同步</a>');
            return HtmArr.join('');
        }
    }]
});

tableGird.init('/product/batch/list');

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

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

/**
 * 查看操作记录
 */
$(document).on('click', '.history', function () {

    var item = tableGird.rows[$(this).data("index")];

    var row = {};

    row.item = item;

    var id = $(this).attr("data-id");
    // 加载数据
    $.post('/product/batch/history', { id: id }, function (resp, textStatus, jqXHR) {

        row.data = resp.data;

        // 渲染列表
        var a = new common.dialog({
            title: "<h4>操作纪录详情</h4>",
            width: '50%',
            content: artTemplate("history_template", row)
        });
    });
});

function t(obj) {
    if (obj) { return obj; }
    return "";
}

//  导出
$(document).on("click", "#exportsearch", function () {
    var temp = $.extend(true, tableGird.__getparams(), {"size": 10000} );
    window.open("/ajax/down?queryConf=" + JSON.stringify(temp) + "&type=productBatchServiceExport");
});

// 同步
$(document).on('click', '.sync', function () {
    var id = $(this).attr("data-id");
    common.util.__ajax({
        url: '/product/batch/sync',
        data: { id: id }
    }, function (resp) {
        // common.util.__tip(resp.message, resp.code == 200 ? 'success' : 'warning');
    });
});