Newer
Older
import {Component, ElementRef, HostListener, NgZone, Renderer2, ViewChild} from '@angular/core';
import {
Content,
InfiniteScrollContent,
IonicPage,
ModalController,
NavController,
NavParams,
Slide,
Slides
} from 'ionic-angular';
import {SearchNewPage} from "../../home-pages/search-new/search-new";
import {TabsService} from "../tabs.service";
import {StuffDetailPage} from "../../home-pages/stuff-detail/stuff-detail";
import {PublishPage} from "../../discover-pages/publish/publish";
import {EmitService} from "../../../provide/emit.service";
import {NoticePage} from "../notice/notice";
import {PartyPersonComponent} from "../../../components/party-person/party-person";
import {DiscoverService} from "../../discover-pages/discover.service";
@ViewChild('fixedTab') fixedTab: ElementRef;
@ViewChild('topHeight') topHeight: ElementRef;
@ViewChild('tabsParent') tabsParent: ElementRef;
@ViewChild('tabsChildren') tabsChildren: ElementRef;
@ViewChild('tabSpan') tabSpan: ElementRef;
{
"name": "最新发布",
"type": 0,
"indexChildren": '01'
},
]
},
{
]
},
{
"name": "机关党委", "type": 5, "indexParent": 2, "children": [
{
"name": "支部成员",
"type": null,
"indexChildren": '34'
},
obj = {
"plateType": null, //分类
"parentName": null,
"childrenName": null,
slideList = new Array(7); //数组的改变 会导致上拉加载更多失效。。
slideArr = new Array(7);
slidersItems = [
{
"static": "true",
"id": null,
"plateType": "20",
"title": "不忘初心,牢记使命",
"imgUrl": "./assets/imgs/home/edu_banner.png"
}
];
branchObj = {
partyList: [],
show: false,
personList: []
};
mineInfo; //登录人信息
constructor(public navCtrl: NavController, public navParams: NavParams, private appMainSer: AppMainService,
public commonSer: CommonService, public renderer: Renderer2, private discoverSer: DiscoverService,
public zone: NgZone, public storage: Storage, private modalCtrl: ModalController,
this.appMainSer.readInfo.subscribe(value => {
this.noReadNum = value;
})
this.storage.get('userLoginInfo').then((value) => {
this.userId = value.userid;
});
//获取个人信息
this.appMainSer.mineInfo.subscribe(value => {
this.mineInfo = value;
});
const htmlFontSize = getComputedStyle(window.document.documentElement)['font-size'];
this.itemWidth = htmlFontSize.split("px")[0] * 8;
this.spanWidth = this.tabSpan.nativeElement.offsetWidth; //文字宽度
this.changeParent(this.tabsList[0])
});
ionViewDidLeave() {
const videoArr = document.querySelectorAll("video");
for (let i = 0; i < videoArr.length; i++) {
videoArr[i].pause();
}
}
//获取党支部
getBranch() {
this.tabsSer.getBranchList().subscribe(
(res) => {
const d = {
type: e.id,
name: e.name
};
return d;
});
getMemberList(id) {
const data = {
branchId: id
};
this.discoverSer.getMemberList(data).subscribe(
(res) => {
scrollHeight() {
const height = this.topHeight.nativeElement.offsetHeight;
this.content.ionScroll.subscribe(($event) => {
this.zone.run(() => {
if (this.content.scrollTop > height) {
this.renderer.addClass(this.fixedTab.nativeElement, 'tabs-fixed-scroll')
} else {
this.renderer.removeClass(this.fixedTab.nativeElement, 'tabs-fixed-scroll')
}
})
})
//初始化swiper
initSwiper() {
let that = this;
that.swiperImg = new Swiper('#swiper-slide', {
speed: 1000,
autoplay: {
delay: 3000,
disableOnInteraction: false,
},//可选选项,自动滑动
that.slideTitle = that.slidersItems[that.swiperImg.realIndex].title;
that.swiperImg.update();
}
click: function () {
const item = that.slidersItems[this.activeIndex];
if (item.static == "true") {
//前往主题教育
goEdu() {
this.swiper.slideTo(1, 500); //前往主题教育
}
//获取轮播图
getBanner() {
const data = {
obj: {
"resourceType": 2, //1标题图片,2推荐轮播图,3视频
"isRecommend": 1, //推荐(1是0否)
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
if (res.data.list.length > 0) {
res.data.list.forEach(e => {
if (e.attachments.length > 0) {
e.imgUrl = e.attachments[0].path;
}
this.slidersItems = this.slidersItems.concat(res.data.list);
this.slideTitle = this.slidersItems[0].title;
this.swiperImg.update();
slideChanged() {
const index = this.slides.realIndex;
const distance = index * this.itemWidth / 2; //滑动的长度
this.newContentParent.nativeElement.scrollLeft = distance;
this.changeParent(this.tabsList[index]);
}
this.obj.parentName = item.name;
this.obj.childrenName = item.children[0].name;
if (this.obj.parentName == "主题教育") {
this.obj.plateType = null;
this.relatePlateType = item.type;
} else {
this.obj.plateType = item.type;
this.relatePlateType = null;
}
this.resourceType = item.name == "知识拓展" ? 3 : 1;
if (this.childrenList.length > 0) this.indexChildren = this.childrenList[0].indexChildren;
this.tips.nativeElement.style.width = this.tabSpan.nativeElement.offsetWidth + 'px';
// 自身div的一半 - 滑块的一半
this.tips.nativeElement.style.left = this.itemWidth * (this.indexParent) + (this.itemWidth - this.spanWidth) / 2 + 'px';
if (!this.obj.branchId) this.obj.branchId = this.mineInfo.branchId;
if (this.obj.branchId) this.getMemberList(this.obj.branchId);
this.branchObj.show = true;
this.slides.slideTo(this.indexParent, 500);
return false;
} else {
this.branchObj.show = false;
}
if (item.name != "支部风采") this.obj.branchId = null;
"relatePlateType": this.relatePlateType,
"branchId": this.obj.branchId
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
e.path = e.attachments[1].path;
e.resourceType = e.attachments[1].resourceType;
}
}
)
}
//子级选择
changeChildren(item) {
this.indexChildren = item.indexChildren;
if (!this.obj.branchId) this.obj.branchId = this.mineInfo.branchId;
if (this.obj.branchId) this.getMemberList(this.obj.branchId);
if (this.obj.parentName == "主题教育") {
this.obj.plateType = null;
this.relatePlateType = item.type;
} else {
this.obj.plateType = item.type;
this.relatePlateType = null;
}
if (this.obj.childrenName == "你问我答") {
"relatePlateType": this.relatePlateType,
"branchId": this.obj.branchId
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
console.log(this.slideList);
console.log(this.slideList[this.indexParent]);
//查询我要出题
getQuestion() {
const data = {
pageNum: 1,
pageSize: 1000,
};
this.tabsSer.findPersonQuestions(data).subscribe(
(res) => {
this.slideList[this.indexParent] = this.newList;
}
)
}
if (this.obj.branchId) this.getMemberList(this.obj.branchId);
'plateType': this.obj.plateType,
'resourceType': this.resourceType,
"relatePlateType": this.relatePlateType
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
this.slideList[this.toIndex] = this.newList;
this.commonSer.toastTime('刷新成功!', 800);
if (this.totalNum == this.slideList[this.indexParent].length || this.totalNum < this.slideList[this.indexParent].length) {
e.complete();
return false;
}
this.pageNum++;
const data = {
pageNum: this.pageNum,
isRecent: this.isRecent,
obj: {
'plateType': this.obj.plateType,
'resourceType': this.resourceType,
"relatePlateType": this.relatePlateType
}
};
this.tabsSer.stuffPage(data).subscribe(
(res) => {
this.totalNum = res.data.total;
res.data.list.forEach(e => {
if (e.attachments && e.attachments.length > 0) {
e.path = e.attachments[0].path;
e.resourceType = e.attachments[0].resourceType;
}
this.slideList[this.indexParent].push(e);
});
e.complete();
}
)
}
//前往搜索页面
goToSearch() {
this.navCtrl.push(SearchNewPage);
}
//查看详情
goToDetail(item) {
this.navCtrl.push(StuffDetailPage, {
id: item.id
});
}
//前往发布页面
if (item.userId == this.userId) {
this.navCtrl.push('AcceptPage', {id: item.id})
} else {
//多模块
moreTab() {
let modal = this.modalCtrl.create(FilterComponent, {
list: this.tabsList,
type: this.obj.plateType,
title: '我的频道'
}, {
enterAnimation: 'modal-from-right-enter',
leaveAnimation: 'modal-from-right-leave'
});
modal.onDidDismiss(data => {
if (data) {
this.changeParent(data);
console.log(data);
}
});
modal.present();
}
let modal = this.modalCtrl.create(FilterComponent, {
list: this.branchObj.partyList,
type: this.obj.branchId,
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
}, {
enterAnimation: 'modal-from-right-enter',
leaveAnimation: 'modal-from-right-leave'
});
modal.onDidDismiss(data => {
if (data) {
this.obj.branchId = data.type;
let res;
if (this.obj.childrenName === "支部成员") {
res = {
type: null,
indexChildren: '34',
name: "支部成员"
};
} else {
res = {
type: this.obj.plateType,
indexChildren: this.indexChildren,
name: this.obj.childrenName
};
}
this.changeChildren(res);
}
});
modal.present();
}
//消息提醒页面
goToNotice() {
this.navCtrl.push(NoticePage);
}
this.isPublish = false;
}
stop(e) {
e.stopPropagation();
}
const videoArr = document.querySelectorAll("video");
for (let i = 0; i < videoArr.length; i++) {
if (videoArr[i] != e.target) {
videoArr[i].pause();
}
}
loadVideo(e) {
const scale = 0.8;
const canvas = document.createElement('canvas');
canvas.width = 120 * scale;
canvas.height = 120 * scale;
//绘制图片
canvas.getContext('2d').drawImage(e.target, 0, 0, canvas.width, canvas.height);
//设置标签的poster属性
let img = new Image();
img.src = canvas.toDataURL("image/png");
img.setAttribute("crossOrigin", 'Anonymous')
img.onload = () => {
e.target.setAttribute("poster", canvas.toDataURL("image/png"));
}