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

StoreService.service("StoreService", [
    '$rootScope',
    'BaseService',
    function ($rootScope,BaseService) {
        var _service = {
            stores:[],
            store:[],
            storeRefundAddressList:[],
            storeRefundAddress:[],
            storePager:function(){
                BaseService.request({
                    url:BaseService.url.storePager_url,
                    method:'post',
                    mark:true,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.stores = response.data;
                            $rootScope.$broadcast('store.list');
                        }
                    }
                });
            },
            getStoreDetail:function(callback){
                BaseService.request({
                    url:BaseService.url.getStoreDetail_url,
                    method:'GET',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            editStore:function(editStoreInfo){
                BaseService.request({
                    url:BaseService.url.updateStore_url,
                    method:'post',
                    data:editStoreInfo,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            storeRefundAddressPager:function(query){
                BaseService.request({
                    url:BaseService.url.storeRefundAddressPager_url,
                    method:'post',
                    mark:true,
                    data:query,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.storeRefundAddressList = response.data;
                            $rootScope.$broadcast('storeRefundAddress.list');
                        }
                    }
                });
            },
            deleteStoreRefundAddress:function(id,callback) {
                BaseService.request({
                    url: BaseService.url.deleteStoreRefundAddress_url + "/" + id,
                    method: 'get',
                    mark: true,
                    fn: function (response) {
                        if (response.code == 0) {
                            callback.call();
                        } else {
                            BaseService.updateAlert(response.message, response.code);
                        }

                    }
                });
            },
            getStoreRefundAddressDetail:function(id,callback){
                BaseService.request({
                    url:BaseService.url.getStoreRefundAddressDetail_url+id,
                    method:'GET',
                    mark:true,
                    fn:function(response) {
                        if(callback) {
                            callback.call(this, response);
                        }
                    }
                });
            },
            editStoreRefundAddress:function(editStoreRefundAddressInfo){
                var url ;
                if(editStoreRefundAddressInfo.id !== ''){
                    url = BaseService.url.updateStoreRefundAddress_url;
                }else {
                    url = BaseService.url.addStoreRefundAddress_url;
                }
                BaseService.request({
                    url:url,
                    method:'post',
                    data:editStoreRefundAddressInfo,
                    mark:false,
                    fn:function(data){
                        if(data.code == 0) {
                            window.history.go(-1);
                        }
                        BaseService.updateAlert(data.message,data.code);
                    }
                });
            },
            listStore:function() {
                BaseService.request({
                    url:BaseService.url.listStore_url,
                    method:'POST',
                    mark:true,
                    fn:function(response) {
                        if(response.code == 0) {
                            _service.stores = response.data;
                            $rootScope.$broadcast('store.list');
                        }
                    }
                });
            },
        }
        return _service;
    }]);