UNPKG

unserver-unify

Version:

64 lines (63 loc) 1.99 kB
'use strict'; angular.module('bamboo.course').factory('companyCommentBizModel', function(ApiService, $q, CommonService) { var Comment = function(conf) { this.items = []; this.busy = false; this.nomoredata = false; this.after = ''; this.conf = conf; this.total = Number.MAX_SAFE_INTEGER; }; Comment.prototype.nextPage = function() { if (this.busy) return; if (this.conf.start >= this.total) { this.nomoredata = true; return; } this.busy = true; getCompanyCommentsByConf(this.conf).then(function(data) { console.info(data); this.total = data.counter; var items = data.items; for (var i = 0; i < items.length; i++) { this.items.push(items[i]); } this.busy = false; this.conf.start = this.items.length; }.bind(this)); }; Comment.prototype.reload = function() { var conf = angular.copy(this.conf); conf.start = 0; conf.limit = this.conf.start; getCompanyCommentsByConf(conf).then(function(data) { this.total = data.counter; var items = data.items; this.items = []; for (var i = 0; i < items.length; i++) { this.items.push(items[i]); } this.busy = false; this.conf.start = this.items.length; }.bind(this)); } function getCompanyCommentsByConf(info) { if (!info) return; info.action = "getcompanycomments"; var deferred = $q.defer(); ApiService.post('/business', info).then(function(result) { if (result.data.success && result.data.data) { console.log(result.data.data); var topics = result.data.data.items; angular.forEach(topics, function(val, index) { val.avatar_url = CommonService.getAvatarSrc(val.author); }) deferred.resolve(result.data.data); } else { deferred.reject(); } }); return deferred.promise; } return Comment; });