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


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

new common.dropDown({el:'#brandCooperation'});
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: '合作模式', render: function(item) {
            return ENUM.cooperateTypeId[item.cooperateTypeId];
        }},
        {display: '是否设置', name: 'cooperateTypeName'},
        {display: '操作信息', render: function(item) {
            var html = '';
            if (item.addUserName) {
                html += '<p>' + item.addUserName + '</p>';
            }

            if (item.updateTime) {
                html += '<p>' + item.updateTime + '</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);
});

//批量导入按钮点击事件
$('#import-btn').on('click', function() {
    $('#basicTable, .bulk-import').toggle();
});

$('.excel-model, #sure-change, .priceTable-wrap').hide();
common.edit.ajaxfileupload("#upload-input",{
    params:{type:"brandCooperation",__type:"batch-import"},
    onStart: function() {
        $('.load-modal').show();
    },
    onComplete:function(response){
        console.log(response);
        var li = '';
        $('.load-modal').hide();
        $.each(response.data.failFileReason, function(i, value) {
            li += '<li>' + value + '</li>';
        });
        $('#error-msg').html(li);
    }
});