|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
|
|
|
|
import { ModalController, NavController, AlertController } from "@ionic/angular";
|
|
|
|
|
import { Router } from "@angular/router";
|
|
|
|
|
import { HomeService } from '../home.service';
|
|
|
|
|
import { Column } from '../../shared/model/column';
|
|
|
|
|
import { getUser } from "../../mine/mine.service";
|
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: 'app-special-column',
|
|
|
|
@ -11,9 +13,10 @@ import { getUser } from "../../mine/mine.service";
|
|
|
|
|
styleUrls: ['./special-column.page.scss'],
|
|
|
|
|
standalone: false,
|
|
|
|
|
})
|
|
|
|
|
export class SpecialColumnPage implements OnInit {
|
|
|
|
|
export class SpecialColumnPage implements OnInit, OnDestroy {
|
|
|
|
|
name: string = ""
|
|
|
|
|
column!: Column;
|
|
|
|
|
column: Column | null = null;
|
|
|
|
|
private destroy$ = new Subject<void>();
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
private navCtrl: NavController,
|
|
|
|
@ -33,36 +36,58 @@ export class SpecialColumnPage implements OnInit {
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
|
this.destroy$.next();
|
|
|
|
|
this.destroy$.complete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getColumnData() {
|
|
|
|
|
this.homeService.getColumnByName(this.name).subscribe(data => {
|
|
|
|
|
this.column = data;
|
|
|
|
|
})
|
|
|
|
|
this.homeService.getColumnByName(this.name)
|
|
|
|
|
.pipe(takeUntil(this.destroy$))
|
|
|
|
|
.subscribe(data => {
|
|
|
|
|
this.column = data;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onBuyClick() {
|
|
|
|
|
// 检查用户是否已登录
|
|
|
|
|
getUser().subscribe(user => {
|
|
|
|
|
if (!user?.username) {
|
|
|
|
|
getUser().pipe(takeUntil(this.destroy$)).subscribe((res)=>{
|
|
|
|
|
if(res.username == "") {
|
|
|
|
|
// 未登录,显示提示框
|
|
|
|
|
this.alertCtrl.create({
|
|
|
|
|
header: '提示',
|
|
|
|
|
message: '请先登录后再进行操作',
|
|
|
|
|
buttons: ['确定']
|
|
|
|
|
buttons: [
|
|
|
|
|
{
|
|
|
|
|
text: '取消',
|
|
|
|
|
role: 'cancel'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text: '去登录',
|
|
|
|
|
handler: () => {
|
|
|
|
|
// 保存当前路径并跳转到登录页
|
|
|
|
|
this.navCtrl.navigateForward('/mine/login', {
|
|
|
|
|
state: { returnUrl: this.router.url }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}).then(alert => alert.present());
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
// 已登录,获取价格并跳转到购买页面
|
|
|
|
|
this.getColumnPrice();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 已登录,获取价格并跳转到购买页面
|
|
|
|
|
this.getColumnPrice();
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getColumnPrice() {
|
|
|
|
|
this.homeService.getColumnPrice(this.column.id).subscribe((res)=>{
|
|
|
|
|
this.navCtrl.navigateForward('/home/column-buy', {
|
|
|
|
|
state: { column: this.column, price: res }
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
this.homeService.getColumnPrice(this.column!.id)
|
|
|
|
|
.pipe(takeUntil(this.destroy$))
|
|
|
|
|
.subscribe((res)=>{
|
|
|
|
|
this.navCtrl.navigateForward('/home/column-buy', {
|
|
|
|
|
state: { column: this.column, price: res }
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe(){
|
|
|
|
|