AdvertService.js 1.9 KB
"use strict";
var advertService = angular.module('AdvertService',[]);

advertService.service("AdvertService", [
	'$rootScope',
	'BaseService',
	function ($rootScope,BaseService) {
		var _service = {
				adverts:[],
				advert:{},
				listAdverts:function(pageNow, pageSize) {
					BaseService.request({
						url:BaseService.url.advert_url+"?pageNow="+pageNow+"&pageSize="+pageSize,
						method:'get',
						mark:true,
						fn:function(response) {
							if(response.code == 0) {
								_service.adverts = response.data;
								$rootScope.$broadcast('advert.list');
							}
						}
					});
				},
				addAdvert:function(ops, id) {
					var url = id ? BaseService.url.editAdvert_url+'/'+id : BaseService.url.addAdvert_url;
					if(id) {
						if(ops.typeId == 1) {
							if(ops.imProductId == '') {
								BaseService.updateAlert("您要添加的是商品广告位,请选择关联的商品", 2);
								return;
							}
						}
					}
					BaseService.request({
						url:url,
						method:'post',
						data:ops,
						mark:false,
						fn:function(data){
							if(data.code == 0) {
								window.history.go(-1);
							}
							BaseService.updateAlert(data.message,data.code);
						}
					});
				},
				getAdvertDetail:function(id, callback) {
					BaseService.request({
						url:BaseService.url.getAdvert_url+id,
						method:'get',
						mark:true,
						fn:function(response) {
							if(callback){
								callback.call(this,response)
							}
							/*if(response.code == 0) {
								_service.advert = response.data;
							}*/
						}
					});
				},
				deleteAdvert:function(id) {
					BaseService.request({
						url:BaseService.url.delAdvert_url+id,
						method:'get',
						mark:true,
						fn:function(data){
							if(data.code == 0) {
								window.history.go(-1);
							}
							BaseService.updateAlert(data.message,data.code)
						}
					});
				}
		}
		return _service;
	}]);