AdvertService.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"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;
}]);