Newer
Older
import {Component, ElementRef, Renderer2, ViewChild} from '@angular/core';
import {IonicPage, ModalController, NavController, NavParams} from 'ionic-angular';
import {TabsService} from "../../tabs/tabs.service";
import {Storage} from "@ionic/storage";
import {CommonService} from "../../../provide/common.service";
import {ReplyComponent} from "../../../components/reply/reply";
import {CommentComponent} from "../../../components/comment/comment";
@IonicPage()
@Component({
selector: 'page-stuff-detail',
templateUrl: 'stuff-detail.html',
})
export class StuffDetailPage {
@ViewChild('like') like: ElementRef;
@ViewChild('collection') collection: ElementRef;
constructor(public navCtrl: NavController, public navParams: NavParams, public sanitizer: DomSanitizer,
public tabSer: TabsService, public storage: Storage, public commonSer: CommonService) {
}
ionViewDidLoad() {
this.storage.get('userLoginInfo').then((value) => {
this.userId = value.userid;
//增加浏览量
}
//获取文章信息
getStuff() {
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
this.stuffObj = res.data;
let con = this.stuffObj.content.replace(/\r?\n/g, "<br />");
this.stuffObj.content = this.sanitizer.bypassSecurityTrustHtml(con);
}
)
}
ionViewWillLeave() {
this.footerView = false;
}
//更新浏览 点赞 收藏 评论
//根据类型,修改数量(1浏览,2点赞,3收藏,4评论)
type: 1,
num: 1,
userid: this.userId,
content: this.content,
}
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.commonSer.log('浏览数 +1')
}
}
)
}
//点赞
likeHandle() {
let num = this.countObj.like == true ? '-1' : 1;
const data = {
id: this.stuffId,
type: 2,
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
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
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
if (num == 1) {
this.commonSer.toastTime('谢谢点赞','1000');
this.renderer.addClass(this.like.nativeElement, 'animation');
}
if (num == -1){
this.commonSer.toastTime('点赞已取消','1000');
this.renderer.removeClass(this.like.nativeElement, 'animation');
}
this.countObj = res.data; //防止点赞,评论,收藏之后文章信息刷新刷新
}
)
}
}
)
}
//收藏
collectionHandle() {
let num = this.countObj.collection == true ? '-1' : 1;
const data = {
id: this.stuffId,
type: 3,
num: ~~num,
userid: this.userId,
content: this.content,
};
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.tabSer.stuffInfo(this.stuffId).subscribe(
(res) => {
if (num == 1) {
this.renderer.addClass(this.collection.nativeElement, 'animation');
this.commonSer.toastTime('功崇惟志,业广惟勤', '1000')
}
if (num == -1) {
this.renderer.removeClass(this.collection.nativeElement, 'animation');
this.commonSer.toastTime('收藏已取消', '1000')
}
this.countObj = res.data; //防止点赞,评论,收藏之后文章信息刷新刷新
}
)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//打开回复
openMask(item){
this.replyText = '回复' +item.username;
this.replyItem = item;
let modal = this.modalCtrl.create(CommentComponent,{placeholder:'回复:' +item.username});
modal.onDidDismiss(res=>{
if(res){
this.replyContent = res;
this.replyHandle();
}
});
modal.present();
}
//回复
replyHandle(){
const data = {
commentId:this.replyItem.id,
content:this.replyContent,
parentId:'',
};
this.tabSer.commentReply(data).subscribe(
(res)=>{
this.getStuff();
this.reply = false;
}
)
}
//取消评论
cancel() {
this.content = '';
this.comment = false;
this.reply = false;
}
//查看回复
commentSearch(comment){
let modal = this.modalCtrl.create(ReplyComponent,{
comment:comment
});
modal.present();
}
//打开评论
openComment(){
let modal = this.modalCtrl.create(CommentComponent,{placeholder:''});
modal.onDidDismiss(res=>{
if(res){
this.content = res;
this.sure();
}
})
modal.present();
}
// 提交评论
const data = {
userid: this.userId,
content: this.content,
id: this.stuffId,
this.tabSer.updateNumByType(data).subscribe(
(res) => {
if (res.errcode == '1000') {
this.getStuff();