SupplierService.js 12.4 KB
"use strict";
var SupplierService = angular.module('SupplierService',[]);

SupplierService.service("SupplierService", [
    '$rootScope',
    'BaseService',
    function ($rootScope,BaseService) {
        var _service = {
            suppliers:[],
            supplier:[],
            supplierRefundAddressList:[],
            supplierRefundAddress:[],
            supplierRelatedProductList:[],
            supplierRelatedProduct:[],
            productList:[],
            product:[],
            supplierPager:function(query){
                BaseService.request({
                    url:BaseService.url.supplierPager_url,
                    method:'post',
                    mark:true,
                    data:query,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.suppliers = response.data;
                            $rootScope.$broadcast('supplier.list');
                        }
                    }
                });
            },
            getSupplierDetail:function(id,callback){
                BaseService.request({
                    url:BaseService.url.getSupplierDetail_url+id,
                    method:'GET',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            editSupplier:function(editSupplierInfo,id){
                var url = id ? BaseService.url.updateSupplier_url : BaseService.url.addSupplier_url;
                BaseService.request({
                    url:url,
                    method:'post',
                    data:editSupplierInfo,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            totalSupplierProduct:function(id,callback){
                BaseService.request({
                    url:BaseService.url.totalSupplierProduct_url+id,
                    method:"post",
                    mark:true,
                    fn:function(data){
                        if(callback){
                            callback.call(this,data);
                        }
                    }
                });
            },
            deleteSupplier:function(id,callback) {
                BaseService.request({
                    url: BaseService.url.deleteSupplier_url + "/" + id,
                    method: 'get',
                    mark: true,
                    fn: function (response) {
                        if (response.code == 0) {
                            callback.call();
                        } else {
                            BaseService.updateAlert(response.message, response.code);
                        }

                    }
                });
            },
            supplierRefundAddressPager:function(query){
                BaseService.request({
                    url:BaseService.url.supplierRefundAddressPager_url,
                    method:'post',
                    mark:true,
                    data:query,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.supplierRefundAddressList = response.data;
                            $rootScope.$broadcast('supplierRefundAddress.list');
                        }
                    }
                });
            },
            deleteSupplierRefundAddress:function(id,callback) {
                BaseService.request({
                    url: BaseService.url.deleteSupplierRefundAddress_url + "/" + id,
                    method: 'get',
                    mark: true,
                    fn: function (response) {
                        if (response.code == 0) {
                            callback.call();
                        } else {
                            BaseService.updateAlert(response.message, response.code);
                        }

                    }
                });
            },
            getSupplierRefundAddressDetail:function(id,callback){
                BaseService.request({
                    url:BaseService.url.getSupplierRefundAddressDetail_url+id,
                    method:'GET',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            editSupplierRefundAddress:function(editSupplierRefundAddressInfo){
                var url ;
                if(editSupplierRefundAddressInfo.id !== ''){
                    url = BaseService.url.updateSupplierRefundAddress_url;
                }else {
                    url = BaseService.url.addSupplierRefundAddress_url;
                }
                BaseService.request({
                    url:url,
                    method:'post',
                    data:editSupplierRefundAddressInfo,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            listSupplier:function() {
                BaseService.request({
                    url:BaseService.url.listSupplier_url,
                    method:'POST',
                    mark:true,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.suppliers = response.data;
                            $rootScope.$broadcast('supplier.list');
                        }
                    }
                });
            },
            supplierRelatedProductPager:function(query){
                BaseService.request({
                    url:BaseService.url.supplierRelatedProductPager_url,
                    method:'post',
                    mark:true,
                    data:query,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.supplierRelatedProductList = response.data;
                            $rootScope.$broadcast('supplierRelatedProduct.list');
                        }
                    }
                });
            },
            listSupplierRelatedProducts:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.listSupplierRelatedProducts_url,
                    method:'post',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.supplierRelatedProductList = response.data;
                            $rootScope.$broadcast('supplierRelatedProduct.list');
                        }
                    }
                });
            },
            deleteSupplierRelatedProduct:function(id,callback) {
                BaseService.request({
                    url: BaseService.url.deleteSupplierRelatedProduct_url + "/" + id,
                    method: 'get',
                    mark: true,
                    fn: function (response) {
                        if (response.code == 0) {
                            callback.call();
                        } else {
                            BaseService.updateAlert(response.message, response.code);
                        }

                    }
                });
             },
            getSupplierRelatedProductDetail:function(id,callback){
                BaseService.request({
                    url:BaseService.url.getSupplierRelatedProductDetail_url+id,
                    method:'GET',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            listProduct:function(productQuery) {
                BaseService.request({
                    url:BaseService.url.listProduct_url,
                    method:'POST',
                    mark:true,
                    data:productQuery,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.productList = response.data;
                            $rootScope.$broadcast('product.list');
                        }
                    }
                });
            },

            insertCampaginProducts:function (postData, callback) {
                BaseService.request({
                    url:BaseService.url.insertCampaginProducts_url,
                    method:'post',
                    mark:true,
                    data:postData,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                        BaseService.updateAlert(response.message,response.code);
                    }
                });
            },
            editSupplierRelatedProduct:function(supplierRelatedProductInfo,id){
                var url = id ? BaseService.url.updateSupplierRelatedProduct_url : BaseService.url.addSupplierRelatedProduct_url;
                BaseService.request({
                    url:url,
                    method:'post',
                    data:supplierRelatedProductInfo,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            supplierProductCategoryProportionPager:function(query){
                BaseService.request({
                    url:BaseService.url.supplierProductCategoryProportionPager_url,
                    method:'post',
                    mark:true,
                    data:query,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.suppliers = response.data;
                            $rootScope.$broadcast('supplier.list');
                        }
                    }
                });
            },
            deleteSupplierProductCategoryProportion:function(id,callback) {
                BaseService.request({
                    url: BaseService.url.deleteSupplierProductCategoryProportion_url + "/" + id,
                    method: 'get',
                    mark: true,
                    fn: function (response) {
                        if (response.code == 0) {
                            callback.call();
                        } else {
                            BaseService.updateAlert(response.message, response.code);
                        }

                    }
                });
            },
            getSupplierProductCategoryProportionDetail:function(id,callback){
                BaseService.request({
                    url:BaseService.url.getSupplierProductCategoryProportionDetail_url+id,
                    method:'GET',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            editSupplierProductCategoryProportion:function(editSpcpInfo,id){
                var url = id ? BaseService.url.updateSupplierProductCategoryProportion_url : BaseService.url.addSupplierProductCategoryProportion_url;
                BaseService.request({
                    url:url,
                    method:'post',
                    data:editSpcpInfo,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
        }
        return _service;
    }]);