dropDown.js 1.79 KB
require('../util/select2');

var $=require('jquery');

var urlObj={
    'supplier':'/supplier/supplier/getSupplierListByIdName',
    'brand':'/brand/getBrandNames',
    'managerName':'/supplier/storeadmin/managerName',
    'sortattribute':'/erpproduct/sortattribute/ajax/automatic',
    'sortsize':'/erpproduct/sortsize/ajax/automatic',
    'queryBrand': '/product/query/brand',
    'querySupplier': '/product/query/supplier',
    'queryShop': '/product/query/shop',
    'maxSort': '/product/query/maxSort',
    'shopsRest':'/ShopsRest/getShopsByName'
};

var dropDown=function(option){
    new dropDown.prototype.init(option);
}

dropDown.prototype={
    constructor:dropDown,
    init:function(_option){
        var option={
            el:'.select2-offscreen',
            url:urlObj[_option.ajax]
        };
        for(var i in _option){
            if(_option.hasOwnProperty(i)){
                option[i]=_option[i];
            }
        }
        if(option.ajax){
            $(option.el).select2({
                ajax:{
                    url: option.url,
                    dataType: 'json',
                    type:'POST',
                    delay: 250,
                    data: function (params) {
                        return {
                            idName: params.term
                        };
                    },
                    processResults: function (data, params) {
                        params.page = params.page || 1;
                         return {
                            results: data.data.data
                         }
                    },
                    cache: true
                }
            });
           
        }else{
            $(option.el).select2();
        }
    }
}
dropDown.prototype.init.prototype = dropDown.prototype;

module.exports=dropDown;