tab3.page.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { Component } from '@angular/core';
  2. import { ModalController, IonModal, IonHeader, IonToolbar, IonTitle, IonContent, IonList, IonItem, IonLabel, IonAvatar, IonButton, IonSegment, IonSegmentButton, IonSegmentContent, IonSegmentView, IonCardContent, IonCardTitle, IonCardHeader, IonCard, IonIcon, IonButtons, IonGrid, IonRow, IonThumbnail, IonSearchbar, IonCol } from '@ionic/angular/standalone';
  3. import { ExploreContainerComponent } from '../explore-container/explore-container.component';
  4. import { addIcons } from 'ionicons';
  5. import { airplane, bluetooth, call, wifi, close } from 'ionicons/icons';
  6. import { SaleCardComponent } from '../component/sale-card/sale-card.component';
  7. import { CommonModule } from '@angular/common';
  8. import { CloudObject, CloudQuery } from 'src/lib/ncloud';
  9. import { Router } from '@angular/router';
  10. import { FmChatModalInput } from 'fmode-ng';
  11. import { AllProductsModalComponent } from '../all-products-modal/all-products-modal.component';
  12. import { DetailModalComponent } from '../detail-modal/detail-modal.component'; // 确保此组件已创建
  13. import { IonicModule } from '@ionic/angular';
  14. addIcons({ airplane, bluetooth, call, wifi });
  15. @Component({
  16. selector: 'app-tab3',
  17. templateUrl: 'tab3.page.html',
  18. styleUrls: ['tab3.page.scss'],
  19. standalone: true,
  20. imports: [
  21. IonicModule,
  22. CommonModule,
  23. AllProductsModalComponent,
  24. DetailModalComponent,
  25. ExploreContainerComponent,
  26. SaleCardComponent,
  27. FmChatModalInput
  28. ]
  29. })
  30. export class Tab3Page {
  31. showDetailModal = false; // 控制详情模态显示与否
  32. currentProduct: any; // 当前选择的药品信息
  33. categories = [
  34. { name: '皮肤用药', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao1.png' },
  35. { name: '肠胃消化', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao5.png' },
  36. { name: '呼吸用药', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao11.png' },
  37. { name: '营养补充', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao9.png' },
  38. { name: '家庭常备', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao12.png' },
  39. { name: '耳鼻咽喉', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao10.png' },
  40. { name: '骨科疼痛', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao6.png' },
  41. { name: '心脑血管', image: 'https://app.fmode.cn/dev/jxnu/202226701019/yao7.png' },
  42. ];
  43. products: Array<CloudObject> = [];
  44. allProducts: Array<CloudObject> = []; // 存储所有药品数据,用于分类过滤
  45. hotProducts: Array<CloudObject> = [];
  46. specialProducts: Array<CloudObject> = [];
  47. constructor(
  48. private modalCtrl: ModalController,
  49. private router: Router,
  50. ) {}
  51. async ngOnInit() {
  52. await this.loadProducts();
  53. }
  54. async loadProducts() {
  55. try {
  56. const query = new CloudQuery('Drug');
  57. this.products = await query.find();
  58. this.allProducts = [...this.products]; // 初始化所有产品
  59. // 分类“热销”和“特价”药品
  60. this.hotProducts = this.allProducts.filter(product => product.get('marketing') === 'hot');
  61. this.specialProducts = this.allProducts.filter(product => product.get('marketing') === 'special');
  62. } catch (error) {
  63. console.error('加载药品数据失败', error);
  64. }
  65. }
  66. // 打开详情模态窗口
  67. openDetailModal(product: any) {
  68. this.currentProduct = product;
  69. this.showDetailModal = true;
  70. }
  71. // 关闭详情模态窗口
  72. closeDetailModal() {
  73. this.showDetailModal = false;
  74. this.currentProduct = null;
  75. }
  76. // 根据分类导航到 drug-category 页面
  77. onCategoryClick(category: any) {
  78. this.router.navigate(['/drug-category', category.name]);
  79. }
  80. // 分享链接功能(可选)
  81. shareDetailModal() {
  82. // 实现分享功能
  83. console.log('分享功能待实现');
  84. }
  85. // 复制链接功能
  86. copyLink() {
  87. const link = window.location.href;
  88. navigator.clipboard.writeText(link).then(() => {
  89. console.log('链接已复制');
  90. // 可添加用户提示
  91. }).catch(err => {
  92. console.error('复制失败', err);
  93. });
  94. }
  95. // 搜索功能
  96. searchTerm: string = '';
  97. async searchProducts(event: any) {
  98. this.searchTerm = event.detail.value.toLowerCase();
  99. if (this.searchTerm) {
  100. this.products = this.allProducts.filter(product =>
  101. product.get('name').toLowerCase().includes(this.searchTerm) ||
  102. product.get('function').toLowerCase().includes(this.searchTerm) ||
  103. product.get('composition').toLowerCase().includes(this.searchTerm)
  104. );
  105. } else {
  106. this.products = [...this.allProducts];
  107. }
  108. }
  109. // 查看更多功能,打开 AllProductsModalComponent 模态窗口
  110. async viewMore(type: string) {
  111. let filteredProducts: Array<CloudObject> = [];
  112. let title: string = '';
  113. if (type === 'hot') {
  114. filteredProducts = this.hotProducts;
  115. title = '热销药品';
  116. } else if (type === 'special') {
  117. filteredProducts = this.specialProducts;
  118. title = '特价药品';
  119. }
  120. const modal = await this.modalCtrl.create({
  121. component: AllProductsModalComponent,
  122. componentProps: {
  123. products: filteredProducts,
  124. title: title
  125. },
  126. cssClass: 'bottom-modal'
  127. });
  128. return await modal.present();
  129. }
  130. }