AdvertController.js
6.2 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
"use strict";
var advertController = angular.module('advertController',[]);
advertController.controller('advertController', [
'$rootScope',
'$scope',
'AdvertService',
function($rootScope, $scope, AdvertService) {
$scope.currentPage = 1;
$scope.numPages = 5;
$scope.totalRecord = 0;
$scope.pageSize = 50;
$scope.adverts = [];
AdvertService.listAdverts($scope.currentPage, $scope.pageSize);
$scope.$on('advert.list', function() {
$scope.adverts = AdvertService.adverts.datas;
$scope.numPages = AdvertService.adverts.totalPage;
$scope.totalRecord = AdvertService.adverts.totalRecord;
});
}]
);
advertController.controller('addAdvertController', [
'$rootScope',
'$scope',
'ProductService',
'AdvertService',
'CampaginCategoryService',
'CategoryService',
'BaseService',
function($rootScope, $scope, ProductService, AdvertService, CampaginCategoryService,CategoryService,BaseService) {
var aid = $rootScope.$stateParams.advertId;
$scope.imageUrl = "";
$scope.editAdvertInfo={
imAdvertId:'',
name:'',
imageUrl:'',
linkUrl:'',
typeId:0,
imProductId:'',
isShow:1,
sortIndex:0
};
$scope.imProductId = "";
$scope.products=[];
$scope.campagins=[];
$scope.selectProductObj ="";
$scope.selectCampaginObj ={};
var isLoad = 0;
$scope.currentPage = 1;
$scope.numPages = 1;
$scope.pageSize = 3;
$scope.totalRecord = 0;
$scope.pages = [];
$scope.name=[];
$scope.editProductInfo= {
name: ''
};
function getProductId(){
if(isLoad&&$scope.products.length){
var productId = $scope.editAdvertInfo.imProductId;
ProductService.getProductDetail(productId, function (data) {
$scope.editProductInfo = data.data;
$scope.name = $scope.editProductInfo.name;
$scope.selectProductObj =$scope.name;
});
}
}
$scope.showProduct=function(){
$scope.productQuery={
keyword:'',
pageNow:1,
pageSize:6
};
$("#contents").hide();
$("#productNames").show(); //显示弹出框
CategoryService.listParent();
$scope.$on('parentCategory.list', function() {
$scope.parentCategory = CategoryService.parentCategory;
});
ProductService.pagerProductByAdvert($scope.productQuery);
$scope.$on('product.list', function() {
$scope.products = ProductService.products.datas;
$scope.numPages = ProductService.products.totalPage;
$scope.totalRecord = ProductService.products.totalRecord;
});
$scope.onSelectPage = function(page) {
$scope.productQuery.pageNow=page;
ProductService.pagerProductByAdvert($scope.productQuery);
};
$scope.isActive = function(page){
return $scope.currentPage === page;
};
$scope.searchProduct=function() {
$scope.productQuery.pageNow = 1;
ProductService.pagerProductByAdvert($scope.productQuery);
};
};
$scope.ForProductObj=function(product){
$scope.selectProductObj =product.name;
$scope.editAdvertInfo.imProductId=product.imProductId;
//隐藏弹出框
$("#contents").show();
$("#productNames").hide();
};
CampaginCategoryService.listCampaignCategoryToAdvert();
$scope.$on('Campaigncategory.list', function() {
$scope.campagins = CampaginCategoryService.categorys;
getCampaginCategoryType();
});
function getCampaginCategoryType(){
if(isLoad&&$scope.campagins.length){
var type = $scope.editAdvertInfo.imProductId;
var list = $scope.campagins;
for(var i=0;i<list.length;i++){
if(list[i]['imCampaignCategoryId'] == type){
$scope.selectCampaginObj = $scope.campagins[i];
break;
}
if(type == '') {
$scope.selectCampaginObj = null;
break;
}
}
}
}
var type=0;
$scope.onChangeAdvertType=function(typeId) {
$scope.editAdvertInfo.typeId=typeId;
type=typeId;
};
$scope.onSubmitAdvert= function () {
var re = /^[0-9]+[0-9]*]*$/;
$scope.editAdvertInfo.imageUrl=$scope.imageUrl;
if(type==0) {
BaseService.updateAlert("小主,您还没有选择广告位类型!");
}else {
if(!re.test($scope.editAdvertInfo.sortIndex)) {
BaseService.updateAlert("小主,广告位的位置只能输入0或正整数!");
}else if(($scope.editAdvertInfo.typeId == 1 || type==1) ){
if($scope.selectProductObj == ''){
BaseService.updateAlert("小主,关联的现金商品不能为空!");
}else {
$scope.editAdvertInfo.imProductId = $scope.editAdvertInfo.imProductId;
AdvertService.addAdvert($scope.editAdvertInfo, $scope.editAdvertInfo.imAdvertId);
}
}else if(($scope.editAdvertInfo.typeId == 2 || type==2)){
if($scope.editAdvertInfo.linkUrl==''){
BaseService.updateAlert("小主,广告位链接URL不能为空!");
}else {
$scope.editAdvertInfo.linkUrl=$scope.editAdvertInfo.linkUrl;
AdvertService.addAdvert($scope.editAdvertInfo, $scope.editAdvertInfo.imAdvertId);
}
}else if(($scope.editAdvertInfo.typeId == 3 || type==3)){
if( $scope.selectCampaginObj == null){
BaseService.updateAlert("小主,关联相关的专场不能为空!");
}else {
$scope.editAdvertInfo.imProductId = $scope.selectCampaginObj.imCampaignCategoryId;
AdvertService.addAdvert($scope.editAdvertInfo, $scope.editAdvertInfo.imAdvertId);
}
}
}
};
$scope.deleteAdvert=function(imAdvertId) {
if(confirm("您确定要删除这个广告位吗?")) {
AdvertService.deleteAdvert(imAdvertId);
}
};
if(aid) {
AdvertService.getAdvertDetail(aid, function (data) {
$scope.editAdvertInfo=data.data;
$scope.imProductId = $scope.editAdvertInfo.imProductId;
$scope.imageUrl = $scope.editAdvertInfo.imageUrl;
isLoad = 1;
getCampaginCategoryType();
if($scope.editAdvertInfo.typeId==1){
ProductService.getProductDetail($scope.imProductId, function (data) {
$scope.editProductInfo = data.data;
$scope.name = $scope.editProductInfo.name;
$scope.selectProductObj =$scope.name;
});
}
});
}
$scope.myKeyup = function(e){
//IE 编码包含在window.event.keyCode中,Firefox或Safari 包含在event.which中
var keycode = window.event?e.keyCode:e.which;
if(keycode==13){
$scope.onSubmitAdvert();
}
};
}]
);