vip.component.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { Component, OnInit } from '@angular/core';
  2. import { IonicModule, ModalController } from '@ionic/angular';
  3. import { NavComponent } from '../../../app/components/nav/nav.component';
  4. import { FormsModule } from '@angular/forms';
  5. import * as Parse from 'parse';
  6. import { AuthService } from '../../../services/auth.service';
  7. import { DatePipe,CommonModule } from '@angular/common';
  8. import { AgreementComponent } from '../../login/agreement/agreement.component';
  9. @Component({
  10. selector: 'app-vip',
  11. templateUrl: './vip.component.html',
  12. styleUrls: ['./vip.component.scss'],
  13. standalone: true,
  14. imports: [IonicModule, NavComponent, CommonModule,FormsModule],
  15. providers: [DatePipe],
  16. })
  17. export class VipComponent implements OnInit {
  18. user: any = Parse.User.current();
  19. profile?: Parse.Object;
  20. goodsList: Array<Parse.Object> = [];
  21. myVip: any;
  22. registerAgreement: any;
  23. isCheck:boolean = false;
  24. currentGoods?: Parse.Object; //当前选择的会员
  25. constructor(
  26. private modalController: ModalController,
  27. private authSer: AuthService,
  28. private datePipe: DatePipe
  29. ) {}
  30. ngOnInit() {
  31. this.refresh();
  32. }
  33. refresh() {
  34. this.getGoods();
  35. this.getUserVip();
  36. this.getAgreement();
  37. }
  38. //获取当前VIP等级
  39. async getUserVip() {
  40. let vip = new Parse.Query('UserVip');
  41. vip.equalTo('user', Parse.User.current()?.id);
  42. vip.equalTo('company', this.authSer.company);
  43. let reqVip = await vip.first();
  44. if (reqVip && reqVip.id) {
  45. let myVip = reqVip.toJSON();
  46. let now = new Date().getTime();
  47. let lastDate = new Date(myVip?.['expiredAt'].iso).getTime();
  48. myVip['expiredAt'] = this.datePipe.transform(
  49. myVip?.['expiredAt'].iso,
  50. 'yyyy-MM-dd'
  51. );
  52. if (lastDate >= now) {
  53. myVip['validity'] = true;
  54. }
  55. this.myVip;
  56. }
  57. }
  58. async getGoods() {
  59. let goods = new Parse.Query('ShopGoods');
  60. goods.equalTo('company', this.authSer.company);
  61. goods.equalTo('type', 'vip');
  62. goods.equalTo('status', true);
  63. goods.ascending('top');
  64. goods.notEqualTo('isDeleted', true);
  65. goods.include('services');
  66. this.goodsList = await goods.find();
  67. this.currentGoods = this.goodsList[0];
  68. }
  69. getAgreement() {
  70. let Agreement = new Parse.Query('ContractAgreement');
  71. Agreement.equalTo('company', this.authSer.company);
  72. Agreement.equalTo('type', 'register');
  73. Agreement.first().then((res) => {
  74. console.log(res);
  75. this.registerAgreement = res;
  76. });
  77. }
  78. async showAgreement() {
  79. const modal = await this.modalController.create({
  80. component: AgreementComponent,
  81. cssClass: 'my-custom-class',
  82. componentProps: {
  83. agreement: this.registerAgreement,
  84. },
  85. });
  86. return await modal.present();
  87. }
  88. onchang(data: Parse.Object) {
  89. this.currentGoods = data;
  90. }
  91. openpay(){
  92. if(this.isCheck){
  93. // this.authSer.openPay(this.currentGoods);
  94. }else{
  95. this.showAgreement();
  96. }
  97. }
  98. }