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

PromotionService.service("PromotionService", [
	'$rootScope',
	'BaseService',
	function ($rootScope,BaseService) {
		var _service = {
				promotions:[],
				promotion:{},
				promotionTypes:{},
				moneyGiftList:[],
				productGiftList:[],
				promotionList:function(queryParam){
					BaseService.request({
						url:BaseService.url.promotionList_url,
						method:'post',
						mark:true,
						data:queryParam,
						fn:function(response) {
							if(response.code == 0) {
								_service.promotions = response.data;
								$rootScope.$broadcast('promotion.list');
							}
						}
					});
				},
				promotionDetail:function(id){
					BaseService.request({
						url:BaseService.url.promotionDetail_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.promotion = response.data;
								$rootScope.$broadcast('promotion.detail');
							}
						}
					});
				},
				listMoneyGift:function(id){
					BaseService.request({
						url:BaseService.url.listMoneyGift_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.moneyGiftList = response.data;
								$rootScope.$broadcast('moneyGift:list');
							}
						}
					});
				},
				
				listProductGift:function(id){
					BaseService.request({
						url:BaseService.url.listProductGift_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.productGiftList = response.data;
								$rootScope.$broadcast('productGift:list');
							}
						}
					});
				},
				saveOrUpdate:function(obj) {
					BaseService.request({
						url:BaseService.url.promotionSaveOrUpdate_url,
						method:'post',
						data:obj,
						mark:false,
						fn:function(data){
							if(data.code == 0) {
								window.history.go(-1);
							}
							BaseService.updateAlert(data.message,data.code);
						}
					});
				},
				addMoneyGiftPromotion:function(obj) {
					BaseService.request({
						url:BaseService.url.saveMoneyGift_url,
						method:'post',
						data:obj,
						mark:false,
						fn:function(data){
							if(data.code == 0) {
								window.history.go(-1);
							}
							BaseService.updateAlert(data.message,data.code);
						}
					});
				},
				addProductGiftPromotion:function(obj) {
					BaseService.request({
						url:BaseService.url.saveProductGift_url,
						method:'post',
						data:obj,
						mark:false,
						fn:function(data){
							if(data.code == 0) {
								window.history.go(-1);
							}
							BaseService.updateAlert(data.message,data.code);
						}
					});
				},
				promotionDelete:function(id){
					BaseService.request({
						url:BaseService.url.promotionDelete_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								window.location.reload();
							}else{
								BaseService.updateAlert(response.message,response.code);
							}
						}
					});
				},
				
				
				promotionTypesList:function(){
					BaseService.request({
						url:BaseService.url.promotionTypes_url,
						method:'post',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.promotionTypes = response.data;
								$rootScope.$broadcast('promotion.types');
							}
						}
					});
				},
				deleteMoneyGift:function(id) {
					BaseService.request({
						url:BaseService.url.deleteMoneyGift_url+id,
						method:'get',
						mark:false,
						fn:function(data){
							if(data.code == 0) {
								window.location.reload(true);
							}
							BaseService.updateAlert(data.message,data.code);
						}
					});
				},
				deleteProductGift:function(id) {
					BaseService.request({
						url:BaseService.url.deleteProductGift_url+id,
						method:'get',
						mark:false,
						fn:function(data){
							if(data.code == 0) {
								window.location.reload(true);
							}
							BaseService.updateAlert(data.message,data.code);
						}
					});
				}
				
		}
		return _service;
	}]);