unserver-unify
Version:
263 lines (257 loc) • 7.49 kB
JavaScript
angular.module('bamboo.company').controller('CompanyListInCategoryCtrl', function($scope, $rootScope, loginService, ApiService, $stateParams, $state, $timeout) {
var _self = this;
console.log("---- CompanyListInCategoryCtrl -----");
this.key = $stateParams.key;
console.log($stateParams.key)
this.id = $stateParams.cid;
this.defaultPhoto = "assets/images/company.png";
this.companypath = ApiService.SHOST + '/company/';
console.log($state.current.name);
this.items = [];
this.itemNumber = 6;
this.page = 0;
this.companycategory = ApiService.companycategory;
this.companykeys = ApiService.school.companykeys;
this.criteria = '';
this.q;
this.ckey;
$scope.setting = {
listName: "company",
pageSize: _self.itemNumber,
currentPage: (_self.page + 1)
};
this.currentPage=1;
this.categorylist = [];
var sortmethod;
var searchmethod;
this.filtersearch;
this.charArrays=[];
var startChar='A';
var stopChar='Z';
console.log(loginService.subDomain);
if(loginService.subDomain == 'poiz'){
$rootScope.companyLabel = "Shop";
}
for(var idx=startChar.charCodeAt(0), end=stopChar.charCodeAt(0);idx<=end;++idx){
_self.charArrays.push(String.fromCharCode(idx));
}
console.log(_self.charArrays);
/*function getcmpcategoryinfo() {
var info = {
action: "getcompanycategoryinfo"
};
ApiService.post("/business", info).then(function(result) {
//console.log(result);
if (result.data.success) {
console.log(result.data.data);
var _result = result.data.data;
for (var key in _result) {
var info = {
key: key,
counter: _result[key],
};
_self.categorylist.push(info);
console.log(_self.categorylist)
}
}
});
}
getcmpcategoryinfo();*/
var currentkey;
this.getitems = function(key) {
_self.listReady = false;
currentkey = key;
//_self.items = [];
var info = {
limit: _self.itemNumber,
start: _self.itemNumber * (_self.currentPage - 1)
};
console.log($state.current.name);
if (key) {
info.action = "getcompanysbycategory";
if(ApiService.school.excludedepartmentFlag){
info.action="getgroupcompanysbycategory";
}
info.key = key;
} else {
info.action = "getvalidcompanys";
if(ApiService.school.excludedepartmentFlag){
info.action="getgroupcompanys";
}
}
console.log(sortmethod)
if (sortmethod) {
info.sort = sortmethod;
}
if (searchmethod) {
info.search = searchmethod;
}
if(_self.filtersearch){
info.filtersearch = _self.filtersearch;
}
console.log(info);
ApiService.post("/business", info).then(function(result) {
console.log(result.data.data);
if (result.data.success) {
_self.items = result.data.data.items;
if (!_self.allcounter || _self.allcounter < result.data.data.counter) {
_self.allcounter = result.data.data.counter;
}
_self.catCount = result.data.data.counter;
if (!_self.totalCount || _self.totalCount < result.data.data.counter) {
_self.totalCount = result.data.data.counter;
}
angular.forEach(_self.items, function(item, index) {
if (item.sellingprice) {
_self.items[index].deals = 100 * (item.price - item.sellingprice) / item.price;
}
});
$timeout(function(){
_self.listReady = true;
},500);
}
});
};
this.pageChanged = function(page) {
console.log(page);
_self.currentPage = page;
_self.getitems(currentkey);
};
function generateCategoryList() {
var catList = [];
console.log(_self.companycategory);
getArray(_self.companycategory, catList, 0, '');
console.log(catList);
if (!_self.companykeys) {
console.log("-- 1");
$scope.catitems = catList;
} else {
var keyindex = {};
var results = [];
angular.forEach(catList, function(val, index) {
var key = val.title;
keyindex[key] = val;
});
console.log(_self.companykeys);
angular.forEach(_self.companykeys, function(key, index) {
if (keyindex[key]) {
results.push(keyindex[key]);
}
});
angular.forEach(keyindex, function(val, key) {
var found = false;
for (var i = 0; i < results.length; i++) {
var record = results[i].title;
if (record == key) {
found = true;
break;
}
}
if (!found) {
results.push(val);
}
});
console.log("-- 2");
$scope.catitems = results;
console.log($scope.catitems);
}
getlateststatus();
if($rootScope.shopCat&&$rootScope.shopCat!='')
{
setTimeout(function(){
_self.option = $rootScope.shopCat;
_self.getitems($rootScope.shopCat);
$rootScope.shopCat = '';
},1);
} else {
_self.getitems();
}
}
function getlateststatus() {
var info = {
action: "getcompanycategoryinfo"
};
if(ApiService.school.excludedepartmentFlag){
info.action="getgroupcompanycategoryinfo";
}
ApiService.post('/business', info).then(function(result) {
console.log(result);
if (result.data.success) {
_self._totalCoursesCountUnderCat = 0;
for (var i = 0; i < $scope.catitems.length; i++) {
var catitem = $scope.catitems[i];
var key = catitem.key;
if (result.data.data[key]) {
catitem.counter = result.data.data[key];
_self._totalCoursesCountUnderCat += (catitem.counter || 0);
}
}
}
});
}
function getArray(obj, array, level, parent) {
if ((typeof obj) === "object") {
for (var key in obj) {
var fullkey;
if (parent == '') {
fullkey = key;
} else {
fullkey = parent + "," + key;
}
var _i = {
key: fullkey,
value: level,
title: key,
items: [],
};
array.push(_i);
var info = obj[key];
if (typeof info === "object") {
getArray(info, _i.items, level + 1, fullkey);
}
}
}
}
this.list = function(key) {
console.log(key);
_self.q = null;
sortmethod = null;
searchmethod = null;
_self.filtersearch=null;
_self.option = key;
_self.getitems(key);
};
generateCategoryList();
this.get = function(flag, reverse) {
console.log(flag, reverse);
_self.page = 1;
sortmethod = {
predicate: flag,
reverse: reverse
};
_self.q = null;
searchmethod = null;
_self.filtersearch=null;
_self.getitems();
};
this.search = function(tosearch) {
searchmethod = {
name: tosearch
};
sortmethod = null;
_self.filtersearch=null;
_self.getitems();
};
this.filter=function(str){
_self.filtersearch = {
name: str
};
sortmethod = null;
// filtersearch=null;
searchmethod=null;
_self.getitems();
}
this.clearSearch = function() {
_self.q = null;
};
});