tab3.page.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. addIcons({ airplane, bluetooth, call, wifi });
  12. @Component({
  13. selector: 'app-tab3',
  14. templateUrl: 'tab3.page.html',
  15. styleUrls: ['tab3.page.scss'],
  16. standalone: true,
  17. imports: [
  18. IonHeader, IonToolbar, IonTitle, IonContent, ExploreContainerComponent,
  19. IonButton, IonGrid, IonRow, IonCol, IonCardHeader, IonItem, IonLabel, IonThumbnail, IonCardContent,
  20. IonCardTitle, IonCard, IonIcon, IonSearchbar, CommonModule, SaleCardComponent,
  21. FmChatModalInput, IonModal, IonButtons
  22. ]
  23. })
  24. export class Tab3Page {
  25. showDetailModal = false; // 控制模态显示与否
  26. currentProduct: any; // 当前选择的商品信息
  27. categories = [
  28. { name: '皮肤用药', image: '../../assets/image/doctor7.png' },
  29. { name: '妇科用药', image: '../../assets/image/doctor7.png' },
  30. { name: '肠胃消化', image: '../../assets/image/doctor7.png' },
  31. { name: '呼吸用药', image: '../../assets/image/doctor7.png' },
  32. { name: '营养补充', image: '../../assets/image/doctor7.png' },
  33. { name: '家庭常备', image: '../../assets/image/doctor7.png' },
  34. { name: '耳鼻咽喉', image: '../../assets/image/doctor7.png' },
  35. { name: '男科用药', image: '../../assets/image/doctor7.png' },
  36. ];
  37. products: Array<CloudObject> = [];
  38. allProducts: Array<CloudObject> = []; // 存储所有药品数据,用于分类过滤
  39. constructor(
  40. private modalCtrl: ModalController,
  41. private router: Router,
  42. ) {
  43. addIcons({close}); }
  44. async ngOnInit() {
  45. await this.loadProducts();
  46. }
  47. async loadProducts() {
  48. try {
  49. const query = new CloudQuery('Drug');
  50. this.products = await query.find();
  51. this.allProducts = [...this.products]; // 初始化所有产品
  52. } catch (error) {
  53. console.error('加载药品数据失败', error);
  54. }
  55. }
  56. openDetailModal(product: any) {
  57. this.currentProduct = product;
  58. this.showDetailModal = true;
  59. }
  60. closeDetailModal() {
  61. this.showDetailModal = false;
  62. this.currentProduct = null;
  63. }
  64. // 根据分类过滤产品
  65. filterProducts(categoryName: string) {
  66. if (categoryName === '全部') {
  67. this.products = [...this.allProducts];
  68. } else {
  69. this.products = this.allProducts.filter(product => product.get('category') === categoryName);
  70. }
  71. }
  72. // 分类点击事件
  73. onCategoryClick(category: any) {
  74. this.filterProducts(category.name);
  75. }
  76. // 分享链接功能(可选)
  77. shareDetailModal() {
  78. // 实现分享功能
  79. console.log('分享功能待实现');
  80. }
  81. // 复制链接功能
  82. copyLink() {
  83. const link = window.location.href;
  84. navigator.clipboard.writeText(link).then(() => {
  85. console.log('链接已复制');
  86. // 可添加用户提示
  87. }).catch(err => {
  88. console.error('复制失败', err);
  89. });
  90. }
  91. //搜索功能
  92. searchTerm: string = '';
  93. async searchProducts(event: any) {
  94. this.searchTerm = event.detail.value.toLowerCase();
  95. if (this.searchTerm) {
  96. this.products = this.allProducts.filter(product =>
  97. product.get('name').toLowerCase().includes(this.searchTerm) ||
  98. product.get('function').toLowerCase().includes(this.searchTerm) ||
  99. product.get('composition').toLowerCase().includes(this.searchTerm)
  100. );
  101. } else {
  102. this.products = [...this.allProducts];
  103. }
  104. }
  105. }