brand-cooperation.js 5.01 KB
'use strict';
var $ = require('jquery'),
    common = require('../common/common');


var ENUM = {
    cooperateTypeId: {
        0: '未设置',
        1: '代销',
        2: '经销',
        3: '自主'
    }
}

new common.dropDown({
    el: '#brandCooperation'
});
var brandSet = new common.dropDown({
    el: '#brandCooperationSet'
});


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

        return {
            brandName: common.util.__input("brand"),
            cooperateTypeId: common.util.__input("brandCooperation"),
            setFlag: common.util.__input("brandCooperationSet")
        };
    },
    columns: [{
            display: 'ID',
            name: 'brandId'
        }, {
            display: '品牌',
            name: 'brandName'
        }, {
            display: '合作模式',
            name: 'cooperateTypeName'
        }, {
            display: '是否设置',
            render: function(item) {
                if (item.cooperateTypeId == 0) {
                    return '未设置';
                } else {
                    return '已设置';
                }
            }
        },

        {
            display: '操作信息',
            render: function(item) {
                var html = '';
                if (item.updateUserName) {
                    html += '<p>' + item.updateUserName + '</p>';
                } else if (item.addUserName) {
                    html += '<p>' + item.addUserName + '</p>';
                }

                if (item.updateTime) {
                    var date = new Date(item.updateTime * 1000),
                        now = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds();
                    html += '<p>' + now + '</p>';
                }
                return html;
            }
        }, {
            display: '操作',
            render: function(item) {
                var htmlArr = [];

                if (item.cooperateTypeId != 1) {
                    htmlArr.push('<a href="javascript:;" class="btn btn-info btn-xs cooperate-type" data-brandid="' + item.brandId + '" data-id="' + item.id + '" data-type="1">代销</a>');
                }

                if (item.cooperateTypeId != 2) {
                    htmlArr.push('<a href="javascript:;" class="btn btn-info btn-xs cooperate-type" data-brandid="' + item.brandId + '" data-id="' + item.id + '" data-type="2">经销</a>');
                }

                if (item.cooperateTypeId != 3) {
                    htmlArr.push('<a href="javascript:;" class="btn btn-info btn-xs cooperate-type" data-brandid="' + item.brandId + '" data-id="' + item.id + '" data-type="3">自主</a>');
                }

                return htmlArr.join('');
            }
        }
    ]
});

g.init($("#gridurl").val());

$('#basicTable').on('click', '.cooperate-type', function() {
    var $brandId = $(this).data('brandid'),
        $id = $(this).data('id'),
        brandType = $(this).data('type');

    common.util.__ajax({
        url: '/goods/brandCooperation/update',
        data: {
            brandId: $brandId,
            id: $id,
            cooperateTypeId: brandType
        }

    }, function(res) {
        g.reload();
    });
});


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

//回车筛选
$('#brand').on('keyup', function(event) {
    if (event.keyCode == 13) {
        $("#filter-btn").trigger('click');
    }
});

//全部
$("#all-btn").click(function() {
    $('#brandCooperationSet').val('-1').trigger('change');
    $('#brandCooperation').val('-1').trigger('change');
    $('#brand').val('');
    g.reload();
});

//批量导入按钮点击事件
$('#import-btn').on('click', function() {
    /*if ($('#basicTable').css('display') == 'none') {
        location.reload();
    }*/
    $('#basicTable, .bulk-import').toggle();
    $('.panel-default a').addClass('disabled');
    $('.panel-default input, .panel-default select').attr('disabled', true);
});

$(' #sure-change, .priceTable-wrap').hide();

$('#upload-input').after('<div class="file-name btn btn-default">请选择文件</div>');
var loadModal = null;
common.edit.ajaxfileupload("#upload-input", {
    params: {
        type: "brandCooperation",
        __type: "batch-import"
    },
    onStart: function() {
        loadModal = common.dialog.load();
        $('.file-name').text($('#upload-input').val().replace("C:\\fakepath\\", ""));
    },
    onComplete: function(response) {
        if (loadModal) {
            loadModal.close();
        }
        if (response.code == 200) {
            var li = '';

            $.each(response.data.failFileReason, function(i, value) {
                li += '<li>' + value + '</li>';
            });
            $('#error-msg').html(li);

            if (response.data.succesList && response.data.succesList.length > 0) {
                common.util.__tip(response.message, 'success');
            }
        } else {
            common.util.__tip(response.message, 'warning');
        }
    }
});